 /**
 //
 // Purpose:    If the especified key exists as a parameter name in the
 //             query string, return the value of the parameter. Otherwise
 //             return the specified default value.
 //
 // Parameters: key - the query string parameter name
 //             defaultValue - the default value to return if the parameter
 //             is not part of the query string.
 //
 */
 function getQueryStringParameterValue(key, defaultValue) {
   if (defaultValue==null) {
     defaultValue="";
   }   
   key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
   var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
   var qs = regex.exec(window.location.href);
   if(qs == null) {
     return defaultValue;
   } else {
     return qs[1];
   }  
 } 
      
      
 /**
 //
 // Purpose:    If the especified param exists as a parameter name in the
 //             query string, replace its current value for the specified
 //             value. Otherwise add the parameter to the query string with
 //             the specified value.
 //
 // Parameters: param - the query string parameter name
 //             value - the value.
 //
 */
 function replaceQueryStringParameterValue(url, param, value) {
   var re = new RegExp("([?|&])" + param + "=.*?(&|$)","i");
   if (url.match(re))
     return url.replace(re,'$1' + param + "=" + value + '$2');
   else if (url.indexOf("?") == -1)
     return url + '?' + param + "=" + value;
   else
     return url + '&' + param + "=" + value;
 }
      
         
 /**
 //
 // Purpose:    If the especified param does no already exists as in the
 //             query string, add it with the specified value. Otherwise 
 //             don't do anything.
 //
 // Parameters: param - the query string parameter name
 //             value - the value.
 //
 */
 function addIfNotExistsQueryStringParameterValue(url, param, value) {
   var re = new RegExp("([?|&])" + param + "=.*?(&|$)","i");
   if (!(url.match(re))) {
     if (url.indexOf("?") == -1)
       return url + '?' + param + "=" + value;
     else
       return url + '&' + param + "=" + value;
   } else {
     return url;
   }       
 }
 
 
 /**
 //
 // Purpose:    Modified unescape function to work around the problem
 //             of spaces being converted to spaces by some browsers.
 //
 // Parameters: str - string to escape.
 //
 */ 
 function unescapeWithSpaceHack(str) {
	 str = "" + str;
	 while (true) {
		 var i = str . indexOf ('+');
		 if (i < 0)
		 	break;
		 str = str . substring (0, i) + '%20' +
		 	str . substring (i + 1, str . length);
	 }
	 return unescape(str);
 }
 
 
         
