// JavaScript Document
function fillInputValsFromURL(){
 var URLString = location.href;

 //find the "?" in the URL
 var questionMarkIndex = URLString.indexOf("?");
 URLString = URLString.substring(questionMarkIndex+1);

 while (URLString.indexOf("&") > -1) {
   //find the next "=" index after the "?"
   var equalSignIndex = URLString.indexOf("=");

   //save off the variable name
   var URLVarName = URLString.substring(0, equalSignIndex);

   //save off the variable value
   var URLVarValue = URLString.substring(equalSignIndex+1, URLString.indexOf("&"));

   //use the eval function to create a variable named URLVarName
   //that has a value equal to URLVarValue
   try{
     eval("document.forms[0]." + URLVarName + ".value = '" + unescape(URLVarValue) + "';");
   }catch(e){}

   //cut off used part of URLString
   URLString = URLString.substring(URLString.indexOf("&")+1);
 }
}

function URLDecode(encodedString)
{
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}

function getURLParameter(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return URLDecode(results[1]);
}

// Replaces all instances of the given substring.
String.prototype.replaceAll = function( 
	strTarget, // The substring you want to replace
	strSubString // The string you want to replace in.
	){
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
	 
	// Keep looping while an instance of the target string
	// still exists in the string.
	while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strText = strText.replace( strTarget, strSubString )
		 
		// Get the index of any next matching substring.
		intIndexOfMatch = strText.indexOf( strTarget );
	}
	 
	// Return the updated string with ALL the target strings
	// replaced out with the new substring.
	return( strText );
}