String.prototype.trim = function(){
return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))
}

String.prototype.startsWith = function(str){
return (this.match("^"+str)==str)
}

String.prototype.endsWith = function(str){
return (this.match(str+"$")==str)
}

Array.prototype.contains = function(searchStr) {
	return (this.getIndex(searchStr) == -1?  false: true);
}

Array.prototype.getIndexStartsWith = function(searchStr) {
   var pos = -1;
   for (var i=0; i<this.length; i++) {
     if (this[i].startsWith(searchStr)) {
		pos = i;
		break;
	}
   }
   return pos;
}

Array.prototype.getIndex = function(searchStr) {
   var pos = -1;
   for (var i=0; i<this.length; i++) {
     if (this[i]==searchStr) {
		pos = i;
		break;
	}
   }
   return pos;
}
function getQuestionText(id){
	var atag = document.getElementById("QuestText"+id);
	if(atag){
		return atag.innerHTML;
	}
	return "Please answer the question(s)";
}

function showIt(givenname){	
	var atag = document.getElementById(givenname);
	if(atag){
		atag.style.display ="block";
	}
}

function hideIt(givenname){	
	var atag = document.getElementById(givenname);
	if(atag){
		atag.style.display ="none";
	}
}
function showItStyle(givenname){	
	var atag = document.getElementById(givenname);
	if(atag){
		atag.style.display ="block";
	}
}

function hideItStyle(givenname){	
	var atag = document.getElementById(givenname);
	if(atag){
		atag.style.display ="none";
	}
}
function startAnimation(){
	var atag = document.getElementById("busyimage");
	if(atag){
		atag.src = "images/busy.gif";		
	}
}

function unloadPage(){
	hideIt("busyIcon");
	showIt("nextButton");
}

function popUp(URL, swidth, sheight) {
	 var day = new Date();
	 var id = day.getTime();
	 
	if (swidth && sheight) {
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+swidth+",height="+sheight+",left=150,top=200');");
	}
	else{
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=620,height=300,left = 150,top = 200');");
	}
}

///////////////////////////////////
function uncheckRadio(obj, pos){
	if(obj){
		if(obj[pos].checked){					
			obj[pos].checked = false;			
		}
	}	
}

function onKeyPressOnlyNumbers(e){
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || 
		(key==13) || (key==27) || (key==37) || (key==39) || (key==46))
	   return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	return false;
}
//general
function setRadioDefault(name, objectName, pos){
	if(objectName){
		if(pos <=1){
			if(!objectName[0].checked && !objectName[1].checked ){
				objectName[pos].checked = true;
			}
		}
		else{
			if(!objectName[2].checked && !objectName[3].checked ){
				objectName[pos].checked = true;
			}
		}
	}
}
function setRadioMust(name, objectName, pos){
	if(objectName){
		objectName[pos].checked = true;
	}
}
function setRadioMustNot(name, objectName, pos){
	if(objectName){
		objectName[pos].checked = false;
	}
}
function setSelectDefault(fieldName, value){
	if(fieldName){
		fieldName.value = value;
	}
}
function setSelectDefaultCheck(fieldName, value){
	if(fieldName){
		if(fieldName.value ==''){
			fieldName.value = value;
		}
	}
}
function alertSelectEmpty(obj, msgtext){
	if(obj){
		if(obj.value ==''){
			alert(msgtext);
			obj.focus();
			return true;
		}
	}
	return false;
}
function checkEmptyRadio(obj){
	if(obj){
		for (var i = 0; i < obj.length; i++){
			if(obj[i].checked){					
				return false;
			}
		}
		return true;
	}
	return false;	
}
function checkMustNotRadio(obj, pos, msgtext){
	if(obj){
		if(obj[pos].checked){
			alert(msgtext);			
			obj[pos].checked = false;
			return true;
		}
	}
	return false;
}
function setFormValue(name, val){
	var obj = document.UserForm[name];
	if(obj){
		if(obj.type == undefined){
			for(var i =0; i< obj.length; i++){		
				if(obj[i].value == val){
					obj[i].checked = true;
					break;
				}
			}
		}
		else{
			obj.value = val;
		}
	}
}
function checkGeneralEmpty(name, msgtext){
	var obj = document.UserForm[name];
	if(obj){
		if(obj.type == undefined){
			var flag = true;
			for (var i = 0; i < obj.length; i++){
				if(obj[i].checked){
					flag = false;
					break;
				}
			}
			if(flag){
				alert(msgtext);	
				if(obj.length>0){
					obj[0].focus();
				}
				return true;
			}			
		}
		else{
			if(obj.value == ''){
				alert(msgtext);	
				obj.focus();
				return true;
			}
		}
	}
	return false;
}
function showAlertZip(type){
	switch(type){
		case 1:
			alert("Please enter a valid Zip Code. Thank You!");	
			break;
		case 2:
			alert("Please enter a valid Zip Code in the USA. Thank You!");	
			break;
		case 3:
			alert("We are sorry, there is no program matched. Thank You!");				
			break;
	}
	document.UserForm.ZIP.focus();
}

function alertRadioEmpty(obj, msgtext){
	if(checkEmptyRadio(obj)){
		alert(msgtext);
		return true;
	}
	return false;
}
function alertRadioByPos(obj, pos, msgtext){
	if(obj){
		if(obj[pos].checked){
			alert(msgtext);			
			obj[pos].checked = false;
			return true;
		}
	}
	return false;
}
function trimString (str) {
	if(str =='')
		return str;

  while (str.charAt(0) == ' ')
    str = str.substring(1);
  while (str.charAt(str.length - 1) == ' ')
    str = str.substring(0, str.length - 1);
  return str;
}

function autoTab(element, nextElement) {
	if (element.value.length >= element.maxLength && nextElement != null) {
		var atag  = document.getElementById(nextElement);
		if (atag){
			atag.focus();
		}
	}	
}
function checkzip(zipnum){
	var numExp = /[^0-9]/;
	if(numExp.test(zipnum)){
		return 0;
	}
	
	if(zipnum.length!=5){
		return 0;
	}
	
	var invalidZip = Array(
		"000", "001", "002", "003", "004", "099", "213", "269", "343", "345",
		"348", "353", "419", "428", "429", "517", "518", "519", "529", "533",
		"536", "552", "568", "578", "579", "589", "621", "632", "642", "643",
		"659", "663", "682", "694", "695", "696", "697", "698", "699", "702",
		"709", "715", "732", "742", "771", "817", "818", "819", "839", "848",
		"849", "851", "854", "858", "861", "862", "866", "867", "868", "869",
		"872", "876", "886", "887", "888", "892", "896", "899", "909", "929",
		"987");	
	if(invalidZip.contains(zipnum.substring(0,3))){
		return 0;
	}
	return 1;
}











