function getURLparamValue(strParamName,strURL){  
//gets the value for a parameter in the URL

   strParamName = strParamName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  

   var regexS = "[\\?&]"+strParamName+"=([^&#]*)";  
   var regex = new RegExp( regexS );  
   var results = regex.exec(strURL);  

   if( results == null )    
      return "";  
   else    
      return results[1];
}

function hasParms(strURL) {

   var matchPos1;

   matchPos1 = strURL.search(/\?/);

   if(matchPos1 != -1)
	return true; //? was found
   else
	return false;  //? was NOT found
}

function ReplaceURLParamValue(strParamName,strNewParamValue, strCurrURL) {
//replaces the value of a parameter in the URL

   var strCurrParamValue;
   var boolHasParms;

   //check if this URL is using params
   boolHasParms = hasParms(strCurrURL);

   //check if the URL is already using the parameter
   strCurrParamValue = getURLparamValue(strParamName,strCurrURL);

   if (!boolHasParms) {
        //if the URL is not yet using parms then put it's first parm
        return strCurrURL + "?" + strParamName + "=" + strNewParamValue;
   }else{
      //the URL has parms
      if (strCurrParamValue == "") {
          //not using the parm yet, add it in
          return strCurrURL + "&" + strParamName + "=" + strNewParamValue;
      } else {
          //we are using this parameter, replace value with new value
          return strCurrURL.replace(strParamName + "=" + strCurrParamValue, strParamName + "=" + strNewParamValue);
      }
   }

}

