//page1
//updated: 08-22-2009
//

function resetPageA(str, zipmsg, oldcode){
	var count =0;
	var num;
	while (str.length > 0 && count < 15){
		count++;
		var pos = str.indexOf(',');
		if(pos !=-1){
			num = parseInt(str.substring(0, pos));
		    str = str.substring(pos+1);
		}
		else{
			num = parseInt(str);
		    str = '';
		}
		setSubject(num);
	}
	changeZipDislay(zipmsg, oldcode);
	return true;
}
function changeZipDislay(zipmsg, oldcode){	
	
	if(zipmsg !='' && oldcode !=''){
		if(document.UserForm.zip.value ==oldcode){
			alert(zipmsg);
			document.UserForm.zip.focus();
		}
	}		

}

function setSubject(num){
	if(num >=1 && num <=12){
		document.UserForm.selectArea[num-1].checked = true;
	}
}
function validateSubArea(sel_area){
	for(var i = 0; i<sel_area.length; i++){
		if(sel_area[i].checked){
			return true;
		}
	}
	return false;
}


function validateForm1(){
	if(validateSubArea(document.UserForm.selectArea) == false){
		alert("Please pick one or more subject areas that you are interested in");
		return false;
	}

	if(document.UserForm.degreeid.value ==""){
		alert("What is your highest level of education?");
		document.UserForm.degreeid.focus();
		return false;
	}

	if(!checkZipEmpty(document.UserForm.zip.value)){
		document.UserForm.zip.focus();
		return false;
	}

	return true;
}
function checkzip(value){
	if(value.length == 5){
		checkZipEmpty(value);
	}
}
function checkpostal(value){
	if(value.length == 7){
		checkPostalEmpty(value);
	}
}
function checkPostalEmpty(zipnum){
	var postalExp=/[a-zA-Z][0-9][a-zA-Z]\s[0-9][a-zA-Z][0-9]/;
	if(trimString(zipnum)==""){
		alert("Please enter a valid postal code");
		return false;
	}

	if(!postalExp.test(zipnum)){
		alert("For Canadian postal code, please use a valid format, eg 'V5K 1A1'.");
		return false;
	}
	return true;
}
function checkZipEmpty(zipnum){
	var zipExp = /[^0-9]/;
	var zipflag = false;
	
	if(trimString(zipnum)==""){
		alert("What is your zip code?");	
	}
	else if(zipnum.length != 5){
		alert("Please enter a valid zipcode");
	}
	else{
		zipflag = validZip(zipnum);
		if(zipflag == false){
			alert("Please enter a valid zipcode");
		}
	}
	return zipflag;	
}
function validZip(zipnum){

	////doing zipcode check ////
	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 false;
	}
	return true;
}