
function getURLVar(URLVarName){
	// Get QueryString and Trim off ?
	var str = location.search.substring(1, location.search.length);
	// split vars into array
	if(str.length){
		arrVars = str.split("&")
		// vars were passed
		if(arrVars.length){
			//loop over vars
			for(i=0;i<arrVars.length;i++){
				// get first name value pair			
				arrValues = arrVars[i].split("=")
				//split name value pair and check var name
				if(arrValues[0] == URLVarName){
					return unescape(arrValues[1])
				}
			return 'Could not find '+URLVarName +' in url'
			}	
		}
	}else{
		return
	}
}

// populates form elements default values
function defaultValue(frmElement,val)
{
	if(frmElement)
	{
		//alert(frmElement.type)
		if(frmElement.type=="text"||frmElement.type=="hidden"){
			frmElement.value = val;
		}else{
			for(i=0;i<frmElement.length;i++)
			{
				optionValue = String(frmElement[i].value)
				optionValue = optionValue.toLowerCase()
			
				targetValue = String(val)
				targetValue = targetValue.toLowerCase()
				
				if (optionValue == targetValue){
					
					
					if(frmElement.type=="select-one"){
						frmElement.selectedIndex = i;
					}else if (frmElement.type=="select-multiple"){
						frmElement[i].selected = true;
					}else if (frmElement[i].type=="radio"){
						frmElement[i].checked = true;
					}else if (frmElement[i].type=="checkbox"){
					frmElement[i].checked = true;	
					}
				}
			}
		
		}
	} else {
	alert('form element not found')
	}
}

function IsNumeric(formfield,fieldname)
{
	var field = formfield;
	var val = parseInt(field.value);
	var newval = ""+val;  
	if (newval != field.value) {
   		alert("You must use only numbers in the "+fieldname+" field ");
    	return false;
	}else{
  		return true;
 	}
}
function IsEmailAddress(field){
  var str = field.value; // email string
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  if (!(!reg1.test(str) && reg2.test(str))) { // if syntax is valid
  	alert("\"" + str + "\" is an invalid e-mail address"); // this is also optional
	field.focus();
  	field.select();
  	return false;
  }else{
  	return true;
  }
}
function HasText(field,fieldname){
	//alert("HELLO")
	if (field.value == ""){
			alert("Please enter your "+fieldname+"")
			field.focus();
			return false
	}
}
function HasNumChars(field,fieldname,threshold){
	//alert("HELLO")
	strCheck = field.value
	if (strCheck.length < threshold)
	{
			alert("Please enter at least "+threshold+" characters in your "+fieldname+"")
			field.focus();
			return false
	}
}