﻿// JScript File
function querySt(strName) 
        {
            var strLocationSearch = window.location.search.substring(1);
            var NameValuesPairs = strLocationSearch.split("&");
            for (i=0;i<NameValuesPairs.length;i++) 
            {
                strNameValue = NameValuesPairs[i].split("=");
                if (strNameValue[0] == strName) 
                {
                    return strNameValue[1];
                }
            }
            return "empty";
        }
        
function ReplaceInQueryString(strURL, strName, strValue)
        {                  
            var strQryStValue = querySt(strName);
            var strReplacementString = "";                
            var strReturn;
            
            if (strQryStValue == "empty")
            {       
                if (strURL.indexOf("?") > -1)         
                {
                    return strURL + "&" + strName + "=" + strValue;
                }
                else
                {
                    return strURL + "?" + strName + "=" + strValue;
                }
            }
            else
            {                
              
                    strReplacementString = strName + "=" + querySt(strName);                    
                    strReturn = strURL.replace(strReplacementString, strName + "=" + strValue); 
                                                            
                return strReturn;
            }
                        
        }   
        
function ReplaceInIframeSrc(strIframeSrc, strKey, strValue)
        {            
            var strKeyValueString = strIframeSrc.substring((strIframeSrc.indexOf("?") + 1));
            var strKeyValue = GetValueFromKeyInString(strKeyValueString, strKey);
            var strReplacementString = "";                
            var strReturn;
            
            if (strKeyValue == "empty")
            {       
                if (strIframeSrc.indexOf("?") > -1)         
                {
                    return strIframeSrc + "&" + strKey + "=" + strValue;
                }
                else
                {
                    return strIframeSrc + "?" + strKey + "=" + strValue;
                }
            }
            else
            {                
              
                    strReplacementString = strKey + "=" + GetValueFromKeyInString(strKeyValueString, strKey);                    
                    strReturn = strIframeSrc.replace(strReplacementString, strKey + "=" + strValue); 
                                                            
                return strReturn;
            }
        }            


function GetValueFromKeyInString(strString, strKey)
        {
            var strContentString = strString;
            var KeyValuesPairs = strContentString.split("&");
            for (i=0;i<KeyValuesPairs.length;i++) 
            {
                strKeyValue = KeyValuesPairs[i].split("=");
                if (strKeyValue[0] == strKey) 
                {
                    return strKeyValue[1];
                }
            }
            return "empty";
        }