function enableElement(what) {
	document.getElementById(what).disabled = false;
}

function disableElement(what) {
	document.getElementById(what).disabled = true;
}

function replaceAll(str,from,to) {
    var idx = str.indexOf(from);
    while (idx > -1) {
        str = str.replace(from,to); 
        idx = str.indexOf(from);
    }
    return str;
}

function checkZipForm(str) {
	if('0123456789'.indexOf(str.charAt(0))<0) {return false;}
	if('0123456789'.indexOf(str.charAt(1))<0) {return false;}
	if('0123456789'.indexOf(str.charAt(2))<0) {return false;}
	if('0123456789'.indexOf(str.charAt(3))<0) {return false;}
	if('0123456789'.indexOf(str.charAt(4))<0) {return false;}	
	return true;	
}

function checkPostalForm(str) {
	//Letters and numbers alternate
	//Certain letters never occur(I AND O)
	//The first character is even more restricted as it designates region. Regions are(from east to west, then north): A,B,C,E,G,H,J,K,L,M,N,P,R,S,T,V,X,Y 
	if('ABCEGHJKLMNPRSTVXY'.indexOf(str.charAt(0))<0) {return false;}
	if('0123456789'.indexOf(str.charAt(1))<0) {return false;}
	if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(str.charAt(2))<0) {return false;}
	if('0123456789'.indexOf(str.charAt(3))<0) {return false;}
	if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(str.charAt(4))<0) {return false;}
	if('0123456789'.indexOf(str.charAt(5))<0) {return false;}
	return true;	
}

function checkZip() {
	var zipcode = document.getElementById('code').value;
	var f = document.getElementById('code');

	zipcode = replaceAll(zipcode," ","");
	zipcode = replaceAll(zipcode,"-","");
	zipcode = zipcode.toUpperCase();  

	if ((zipcode.length < 5) || (zipcode.length > 6 || zipcode == "")) {
		alert('Please enter a valid ZIP or Postal Code');
		document.getElementById('code').value = "";
		ShowStep('code');
		f.focus();
		return false;
	} else {
		if (zipcode.length == 5 && checkZipForm(zipcode)) { // us zipcode
			document.getElementById('country').value = "USA";
			return true;
		} else {
			if (zipcode.length == 6 && checkPostalForm(zipcode)) { // can postalcode
				document.getElementById('country').value = "Canada";
				return true;
			} else {
				alert('Please enter a valid Postal Code');
				document.getElementById('code').value = "";
				ShowStep('code');
				f.focus();
				return false;
			}
		}
	}
}

function warning() {
	var p = document.getElementById('program').value;
	var e = document.getElementById('education').value;

	tmp = p.split('|');
	sid = tmp[0];
	pcode = tmp[2];
	
	//warning popup only
	if(pcode == "SNC") {
		alert("In order to qualify for this program, you must be a Registered Nurse with a bachelor's degree in nursing or healthcare. If you do not meet these requirements, please choose an alternate program.");
	}
	if(pcode == "BSN") {
		alert("To enter the RN to BSN program, you must have a valid, unrestricted, unencumbered RN license from the United States and one year of full-time, post-high school work experience in the health care industry.");
	}
	
	//text display
	if(sid == '1014') {
		document.getElementById('campus_text').style.display = 'none';
		document.getElementById('online_text').style.display = 'block';
		document.getElementById('info_text').style.display = 'block';
	} else {
		document.getElementById('campus_text').style.display = 'block';
		document.getElementById('online_text').style.display = 'none';
		document.getElementById('info_text').style.display = 'none';
	}
	
	//education check
	//		1 - Do not have / not pursuing High School diploma
	//		2 - Have High School Diploma / GED
	//		3 - Completed 0-23 credits (1 year) of College
	//		4 - Completed 24-47 credits (2 years) of College</option>
	//		5 - Completed 48 or more credits (3+ years) of College
	//		6 - Earned Bachelor's Degree
	//		7 - Earned Master's Degree
/*	this education <=> program check is not being done anymore since we have an extra lookup in the DB

	var cert_prgs = new Array("CCP","HRM","PM","ND");
	var assoc_prgs = new Array("AAGS");
	var bach_prgs = new Array("BSB/ACC","BSB/A","BSB/EB","BSB/F","BSB/HM","BSB/ISCOM","BSB/M","BSB/MKT","BSB/PA","BSM","BSB/RM","BSB/IS","BSIT","BSIT/VC","BSCJA","BSHA","BSHS/M","BSN");
	var mast_prgs = new Array("MBA","MBA/ACC","MBA/GM","MBA/HCM","MBA/HRM","MBA/MKT","MBA/PA","MBA/TM","MM","MM-I","MM/HRM","MM/PA","MIS","MIS/M","MS/AJS","MHA","CONT-ED","MAED/ADM","MAED/CI","MAED/CI-CE","MAED/CI-AE","MAED/CIESL","MAED/ECH","MAED/SPE","MAED/TED-E","MAED/TED-S","MSN","MSN/IH","MSN/ED","MSN/MHA","MSN/MBA/HC","MSCIS","MSN/FNP","RN/MSN/MSN/FNP","MSN/N/HCE","NHCE","MAED/CIMTH","MAED/CI-LA","MS/P","MAED/AET");
	var doct_prgs = new Array("DBA","DM","DM/IST","EDD","EDD/CI","DHA","EDD/ET");

	if((e == "2" || e == "3" || e == "4") && (mast_prgs.indexOf(pcode) != -1 || doct_prgs.indexOf(pcode) != -1)){
		alert("You must have a higher education level to apply for this program.");
		document.getElementById('education').value = "";
		document.getElementById('program').value = "";
	}
	if((e == "5" || e == "6") && doct_prgs.indexOf(pcode) != -1){
		alert("You must have a higher education level to apply for this program.");
		document.getElementById('education').value = "";
		document.getElementById('program').value = "";
	}
	// School Nurse Certificate only allows Bachelor's and Master's
	if(pcode == "SNC" && (e == '2' || e == '3' || e == '4' || e == '5')) {
		alert("You must have a higher education level to apply for this program.");
		document.getElementById('education').value = "";
		document.getElementById('program').value = "";
	}
*/

}

function limitZIP(str) {
	var allowed = " -0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (i=0; i < str.length; i++) {
		x = str.charAt(i);
		if(allowed.indexOf(x,0) != -1) {
			return true;
		}
	}
	return false;
}

function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >=4) { win.window.focus(); }
}

function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
	 return true;
}
