window.onload = function() {
	resetPage();
}
function resetPage(){

	reValue();
	if(document.UserForm.SOURCE.value != ""){		
		if(document.UserForm.MILITARY && document.UserForm.MILITARY.value ==""){			
			document.UserForm.MILITARY.value = "0";		
		}		
	}
	document.UserForm.ZIP.focus();
}

function showAlert(zipcode, code){
	if(document.UserForm.ZIP.value !=""){
		if(zipcode == document.UserForm.ZIP.value){
			if(code ==1){
				alert("We're sorry that " +document.UserForm.SCHOOLNAME.value+" doesn't offer programs near your location.");
			}
			else{
				alert("Please enter a valid Zip Code. Thank You!");
			}
			document.UserForm.ZIP.focus();
		}
	}
}

function getQuestionText(id){
	var atag = document.getElementById(id);
	if(atag){
		return atag.innerHTML;
	}
	return "";
}
function checkEduLevel(obj){
	if(obj.value =='-1'){
		alert("Based on the information you provided, you do not currently meet the application requirements for "+
			document.UserForm.SCHOOLNAME.value);
		obj.value ="";
		obj.focus();
		return false;
	}
	return true;
}

function validateForm1(form){
	
	if(checkzip(form.ZIP.value) == 0){
		alert("Please enter a valid zip code");
		form.ZIP.focus();
		return false;
	}	


	if(form.DEGREELEVEL.value ==''){
		alert("Please select the hightest level of education you have completed");
		form.DEGREELEVEL.focus();
		return false;
	}
	else if(checkEduLevel(form.DEGREELEVEL) == false){
		return false;
	}	
	
	if(document.UserForm.MILITARY.value ==""){
		var questxt = getQuestionText("LABEL_MILITARY");		
		if(questxt != ""){
			alert(questxt);
		}
		else{
			alert("Please indicate whether you are associated with the U.S. military");
		}
		form.MILITARY.focus();
		return false;	
	}

	if(form.ONLINECAMPUS){
		if(!form.ONLINECAMPUS[0].checked && !form.ONLINECAMPUS[1].checked && !form.ONLINECAMPUS[2].checked){
			alert("Please indicate whether you are interested in online or campus-based learning.");			
			return false;
		}
	}
	
	return true;	
}


function checkzip(value){
	if(trimString(value)==""){
		return 0;
	}
	else if(value.length != 5){
		return 0;
	}
	else{
		return validZip(value);
	}
}

function validZip(zipnum){

	var numExp = /[^0-9]/;
	if(numExp.test(zipnum)){
		return 0;
	}
	////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 0;
	}
	return 1;
}
