
function CheckBusinessRules(oForm) {
	
	var bIsGood = true;
	//we must know what program they want, so as to know which business rules to employ
	switch (oForm.program.options[oForm.program.selectedIndex].value) {
		case '4|CMC':
			//check highest level of education
			if (oForm.cmc_highesteduc.options[oForm.cmc_highesteduc.selectedIndex].value == 'NoEduc'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			//check if enrolled in other program
			if (oForm.cmc_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
			//check profession
			if (oForm.cmc_occupation.options[oForm.cmc_occupation.selectedIndex].value == 'Other'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
		break;
		case '29|GCM':
			//check highest level of education
			if (oForm.gcm_highesteduc.options[oForm.gcm_highesteduc.selectedIndex].value == 'NoEduc'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			//check if enrolled in other program
			if (oForm.gcm_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
			//check profession
			if (oForm.gcm_occupation.options[oForm.cmc_occupation.selectedIndex].value == 'Other'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
		break;
		// end of adding
		//CHANGE 03.may.2004
		//this program is no-longer offered RT# 27202 - Russ
		case '29|LNC':
			//registered nurse?lnc_licensednurse
			if (oForm.lnc_licensednurse[1].checked){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			
			//enrolled elsewhere?
			if (oForm.lnc_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
		break;
		//this program is no-longer offered RT# 27202 - Russ
		case '29|FNC':
			//registered nurse?fn_licensednurse
			if (oForm.fn_licensednurse[1].checked){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			
			//enrolled elsewhere?
			if (oForm.fn_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
		break;
		case '4|LCP':
			//check highest level of education
			if (oForm.lcp_highesteduc.options[oForm.lcp_highesteduc.selectedIndex].value == 'NoEduc'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			//check if enrolled in other program
			if (oForm.lcp_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
			//check profession
			if (oForm.lcp_occupation.options[oForm.lcp_occupation.selectedIndex].value == 'Other'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
		break;
		//END CHANGE 03.may.2004
		case '29|MCC':
			//check highest level of education
			if (oForm.mcc_highesteduc.options[oForm.mcc_highesteduc.selectedIndex].value == 'NoEduc'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			//check if enrolled in other program
			if (oForm.mcc_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
			//check if they have computer
			if (oForm.mcc_havecomputer[1].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
		break;
		case '29|MT':
			//check highest level of education
			if (oForm.mt_highesteduc.options[oForm.mt_highesteduc.selectedIndex].value == 'NoEduc'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			//check if enrolled in other program
			if (oForm.mt_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
			//check if they have computer
			if (oForm.mt_havecomputer[1].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
			if (oForm.mt_canYouType[1].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
		break;
		case '29|PTC':
			//check highest level of education
			if (oForm.ptc_highesteduc.options[oForm.ptc_highesteduc.selectedIndex].value == 'NoEduc'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			//check if enrolled in other program
			if (oForm.ptc_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
			//check if they have computer
			if (oForm.ptc_havecomputer[1].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
		break;
		case '29|MB':
			//check highest level of education
			if (oForm.mb_highesteduc.options[oForm.mb_highesteduc.selectedIndex].value == 'NoEduc'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			//check if enrolled in other program
			if (oForm.mb_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
			//check if they have computer
			if (oForm.mb_havecomputer[1].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
		break;
		case '67|MOS':
			//check highest level of education
			if (oForm.mos_highesteduc.options[oForm.mos_highesteduc.selectedIndex].value == 'NoEduc'){
				oForm.action = "nothankyou.asp";
				bIsGood = false;
			}
			//check if enrolled in other program
			if (oForm.mos_anotherprogram[0].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
			//check if they have computer
			if (oForm.mos_havecomputer[1].checked){
				oForm.action = "enrollnothankyou.asp";
				bIsGood = false;
			}
		break;
	}
		
	//	alert('formaction is = ' + oForm.action);
	if (bIsGood) {
		// when live:
		oForm.action = "/include/SDC_form_submit.asp?sitestate=siteid=398;pageid=0";
		// debugging:
		//oForm.action = 'postbacktester.asp';
	}
}

function CheckFilter(oForm) {
	var w1 = String.fromCharCode(115, 104, 105, 116);
	var w2 = String.fromCharCode(112, 105, 115, 115);
	var w3 = String.fromCharCode(99, 117, 110, 116);
	var w4 = String.fromCharCode(116, 105, 116, 115);
	var w5 = String.fromCharCode(97, 115, 115);
	var arrIW = new Array(w1,w2,w3,w4,w5);
	var w6 = String.fromCharCode(102, 117, 99, 107);
	var w7 = String.fromCharCode(99, 111, 99, 107, 115, 117, 99, 107, 101, 114);
	var w8 = String.fromCharCode(109, 111, 116, 104, 101, 114, 102, 117, 99, 107, 101, 114);
	var w9 = String.fromCharCode(97, 115, 115, 104, 111, 108, 101);
	var arrW = new Array(w6,w7,w8,w9);
	var curW = '';
	var curV = '';
	for(var i=0;i<arrIW.length;i++) {
		curW = arrIW[i];
		for (var f=0;f<oForm.length;f++) {
			if (oForm.elements[f].type == 'text') {
				curV = oForm.elements[f].value;
				curV = curV.toLowerCase();
				if (curV.indexOf(curW) > -1) {
					if (curV.indexOf(' ' + curW + ' ') > -1 || curV.indexOf(curW + ' ') == 0 || curV.indexOf(' ' + curW) == (curV.length - (curW.length + 1))) {
						alert('Form must not contain profane content');
						return false;
					}
				}
			}
		}
	}
	for (var i=0;i<arrW.length;i++) {
		curW = arrW[i];
		for (var f=0;f<oForm.length;f++) {
			if (oForm.elements[f].type == 'text') {
				curV = oForm.elements[f].value;
				curV = curV.toLowerCase();
				if (curV.indexOf(curW) > -1) {
					alert ('Error: Profane content not permitted.');
					return false;
				}
			}
		}
	}
	return true;
}


function phoneIsValid(Obj,sLabel) {
	var sPhone = Obj.value;
	var sPhoneTemp = sPhone;
	sPhone = '';
	var sNumbers = '1234567890';
	for (var i=0;i<sPhoneTemp.length;i++) {
		if (sNumbers.indexOf(sPhoneTemp.charAt(i)) > -1) {
			sPhone += sPhoneTemp.charAt(i);
		}
	}
	if (sPhone.charAt(0) == '1' || sPhone.charAt(0) == 1) {
		sPhone = sPhone.substring(1,(sPhone.length));
	}
	if (sPhone.length != 10) {
		return sLabel + ' must be a 10 digit number\n';
	}
	else { 
		Obj.value = sPhone;
	}
	var sAreaCode = sPhone.substring(0,3);
	var sPrefix = sPhone.substring(3,6);
	var sNumber = sPhone.substring(6,10);
	ary7NotAllowed = new Array('1234567','4567890','0000000','1111111','2222222','3333333','4444444','5555555','6666666','7777777','8888888','9999999')
	ary3NotAllowed = new Array('000','911','555');
	for (var i=0;i<ary7NotAllowed.length;i++) {
		if (sPrefix.toString() + sNumber.toString() == ary7NotAllowed[i])  {
			return sLabel + ' must be a valid phone number\n';
		}
	}
	for (var i=0;i<ary3NotAllowed.length;i++) {
		if (sPrefix.toString() == ary3NotAllowed[i].toString()) {
			return sLabel + ' must be a valid phone number\n';
		}
	}
	return '';
}

//END CHANGE 28.apr.2004



function CountryChange(oCountry) {
	if (oCountry.value != 'United States' && oCountry.value != 'Canada') {
		oCountry.form.kaplan_state.selectedIndex = 0;
		var oState = oCountry.form.state;
		oState.value = 'XX';
	}
}

function SetHiddenState(oKaplanState) {
	var aryStates = new Array('AL','Alabama','AK','Alaska','XX','American Samoa','AZ','Arizona','AR','Arkansas','CA','California','CO','Colorado','CT','Connecticut','DE','Delaware','DC','District of Columbia','XX','Federated States of Micronesia','FL','Florida','GA','Georgia','MS','Mississippi','MO','Missouri','MT','Montana','NE','Nebraska','NV','Nevada','NH','New Hampshire','XX','Guam','HI','Hawaii','ID','Idaho','IL','Illinois','IN','Indiana','IA','Iowa','KS','Kansas','KY','Kentucky','LA','Louisiana','ME','Maine','XX','Marshall Islands','MD','Maryland','MA','Massachusetts','MI','Michigan','MN','Minnesota','NJ','New Jersey','NM','New Mexico','NY','New York','NC','North Carolina','ND','North Dakota','XX','Northern Mariana Islands','OH','Ohio','OK','Oklahoma','OR','Oregon','PW','Palau','PA','Pennsylvania','PR','Puerto Rico','RI','Rhode Island','SC','South Carolina','XX','Armed Forces Europe','XX','Armed Forces Middle East','XX','Armed Forces Pacific','AB','Alberta','SD','South Dakota','TN','Tennessee','TX','Texas','UT','Utah','VT','Vermont','XX','Virgin Islands','VA','Virginia','WA','Washington','WV','West Virgina','WI','Wisconsin','WY','Wyoming','XX','Armed Forces Africa','XX','Armed Forces Americas','XX','Armed Forces Canada','BC','British Columbia','MB','Manitoba','NB','New Brusnwick','NF','Newfoundland','NT','Northwest Territories','NS','Nova Scotia','ON','Ontario','PE','Prince Edward Island','QB','Quebec','SK','Saskatchewan','YT','Yukon Territory')
	var oState = oKaplanState.form.state;
	if (oKaplanState.options[oKaplanState.selectedIndex].value == 'XX') {
		oState.value = 'XX';
	}
	else {
		for (var i=1;i<aryStates.length;i++) {
			if (oKaplanState.options[oKaplanState.selectedIndex].value == aryStates[i]) {
				oState.value = aryStates[i-1];
				break;
			}
		}
	}
}


function validateForm(oForm) {
//	alert('using this validate form');
//	alert(oForm.program.name);
	
	if (!validate('program','Program of Interest',oForm)) { return false; }
	if (!validate('firstname','First Name',oForm)) { return false; }
	if (!validate('lastname','Last Name',oForm)) { return false; }
	if (!validate('email','E-mail Address',oForm)) { return false; }
	if (!checkEmail(oForm.email.value)) {
		alert('Form Error:\nPlease use a valid E-mail address');
		return false;
	}
	if (!validate('address','Address',oForm)) { return false; }
	if (!validate('city','City',oForm)) { return false; }
	if (oForm.country.options[oForm.country.selectedIndex].value == 'United States' || oForm.country.options[oForm.country.selectedIndex].value == 'Canada') 
	{
		if (!validate('kaplan_state','State',oForm)) { return false; }
	}
	if (!validate('zip','Zip Code',oForm)) { return false; }
	if (!validate('country','Country',oForm)) { return false; }
	
	if (!validate('evephone','Home Phone',oForm)) { return false; }
	if (!validate('dayphone','Work or Mobile Phone',oForm)) { return false; }
	//at this point, we have already determined that day and eve phones are non-blank,
	//so just call the phoneIsValid function
	var sevephonePhoneError = phoneIsValid(oForm.evephone,'Home Phone');
	if (sevephonePhoneError.length > 0) {
		alert(sevephonePhoneError);
		return false;
	}

	var sdayphonePhoneError = phoneIsValid(oForm.dayphone,'Work or Mobile Phone');
	if (sdayphonePhoneError.length > 0) {
		alert(sdayphonePhoneError);
		return false;
	}

// validate changing stuff here
	switch (oForm.program.options[oForm.program.selectedIndex].value) {
		//this program is no-longer offered RT# 27202 - Russ
		case '29|LNC':
			if (!validate('lnc_licensednurse','Are you a registered nurse licensed to practice in the U.S.?',oForm)) { return false; }
			if (!validate('lnc_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
		break;
		//this program is no-longer offered RT# 27202 - Russ
		case '29|FNC':
			if (!validate('fn_licensednurse','Are you a registered nurse licensed to practice in the U.S.?',oForm)) { return false; }
			if (!validate('fn_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
		break;
		case '4|LCP':
			if (!validate('lcp_highesteduc','What is the highest level of education that you possess',oForm)) { return false; }
			if (!validate('lcp_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
			if (!validate('lcp_occupation','Please select your profession from the list below',oForm)) { return false; }
		break;
		// CHANGE 28.apr.2004
		case '4|CMC':
			if (!validate('cmc_highesteduc','What is the highest level of education that you possess',oForm)) { return false; }
			if (!validate('cmc_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
			if (!validate('cmc_occupation','Please select your profession from the list below',oForm)) { return false; }
		break;
		// END CHANGE 28.apr.2004
		//added 01-18-2005, Andy
		case '29|GCM':
			if (!validate('gcm_highesteduc','What is the highest level of education that you possess',oForm)) { return false; }
			if (!validate('gcm_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
			if (!validate('gcm_occupation','Please select your profession from the list below',oForm)) { return false; }
		break;
		// end of adding, 01-18-2005
		case '29|MCC':
			if (!validate('mcc_highesteduc','What is the highest level of education that you possess',oForm)) { return false; }
			if (!validate('mcc_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
			if (!validate('mcc_havecomputer','Will you have access to a computer to take your courses',oForm)) { return false; }
		break;
		case '29|PTC':
			if (!validate('ptc_highesteduc','What is the highest level of education that you possess',oForm)) { return false; }
			if (!validate('ptc_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
			if (!validate('ptc_havecomputer','Will you have access to a computer to take your courses',oForm)) { return false; }
		break;
		case '29|MB':
			if (!validate('mb_highesteduc','What is the highest level of education that you possess',oForm)) { return false; }
			if (!validate('mb_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
			if (!validate('mb_havecomputer','Will you have access to a computer to take your courses',oForm)) { return false; }
		break;
		case '29|MT':
			if (!validate('mt_highesteduc','What is the highest level of education that you possess',oForm)) { return false; }
			if (!validate('mt_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
			if (!validate('mt_havecomputer','Will you have access to a computer to take your courses',oForm)) { return false; }
			if (!validate('mt_canYouType','Can you type 50 words per minute?',oForm)) { return false; }
		break;
		case '67|MOS':
			if (!validate('mos_highesteduc','What is the highest level of education that you possess',oForm)) { return false; }
			if (!validate('mos_anotherprogram','Are you currently enrolled in another educational program',oForm)) { return false; }
			if (!validate('mos_havecomputer','Will you have access to a computer to take your courses',oForm)) { return false; }			
		break;
	}
	
	// validate the rest here
	if (!validate('besttime','When is the best time to contact you?',oForm)) { return false; }
	// 12/29/2008 Russ S. This form element doesnt exist
	//if (!validate('timeperday', 'Do you have 1-3 hours a day to devote to your education?', oForm)){ return false;}
	//if (!validate('interest', 'I am interested in', oForm)){ return false;}
	//if (!validate('strength', 'My personal strengths include', oForm)){ return false;}
	
	//end of adding
	
	// CHANGE 28.apr.2004
	CheckBusinessRules(oForm);  
	if (!CheckFilter(oForm)){
		return false;
	}		

	return true;
}

function checkEmail(sEmail) {
	var AtSign = sEmail.indexOf('@');
	var Period = sEmail.lastIndexOf('.');
	if (AtSign > -1 && Period > -1 && AtSign < Period) {
		return true;
	}
	else {
		return false;
	}
}

function validate(sFieldName,sLabelName,oForm) {
	var oField = eval('oForm.' + sFieldName);
	var undefined;
	if (oField != undefined) {
	 	if (CheckRequired(oField) ) {
			return true;
		}
		else {
			if (oField[0] == undefined || oField.type == 'select-one') {
				alert('Form Error:\nPlease complete: ' + sLabelName + '.');
				oField.focus();
				return false;
			}
			else {
				if (!CheckRequired(oField)) {
					alert('Form Error:\nPlease complete: ' + sLabelName + '.');
					oField[0].focus();
					return false;
				}
			}
		}
	}
	else if (oField[0] != undefined) {
		if (!CheckRequired(oField)) {
					alert('Form Error:\nPlease complete: ' + sLabelName + '.');
					oField[0].focus();
					return false;
		}
	}
	else {
		alert('undefined field in form: ' + sFieldName);
		return false;
	}
}

function CheckRequired(Obj) {
	var ObjType;
	var retVal;
	var x = 0;
	var undefined;
	ObjType = Obj.type;
	/* types: password, radio, select-multiple, select-one, text, textarea */
	if (ObjType == undefined) {
		ObjType = Obj[0].type;
	}
	switch(ObjType) {
		case 'hidden':
			if(Obj.value.length < 1) {
				retVal = false;
			}
			else {
				retVal = true;
			}
		break;
		case 'text':
			if(Obj.value.length < 1) {
				retVal = false;
			}
			else {
				retVal = true;
			}
		break;
	
		case 'textarea':
			if(Obj.value.length < 1) {
				retVal = false;
			}
			else {
				retVal = true;
			}
		break;
	
		case 'password':
			if(Obj.value.length < 1) {
				retVal = false;
			}
			else {
				retVal = true;
			}
		break;
		case 'file':
			if(Obj.value.length < 1) {
				retVal = false;
			}
			else {
				retVal = true;
			}
		break;
		case 'select-one':
			if(Obj.selectedIndex > 0) {
				retVal = true;
			}
			else {
				retVal = false;
			}
		break;
		
		case 'select-multiple':
			retVal = false;
			for (var x=0;x<Obj.options.length;x++) {
				if (Obj[x].selected) {
					retVal = true;
				}
			}
		break;
		
		case 'radio':
			retVal = false;
			for(var x=0;x<Obj.length;x++) {
				if (Obj[x].checked) {
					retVal = true;
				}
			}
		break;
		
		case 'checkbox':
		
			if (navigator.appName == 'Netscape' && (navigator.appVersion.toString().substr(0,1) == '4' || navigator.appVersion.toString().substr(0,1) == '3' || navigator.appVersion.toString().substr(0,1) == '2')) {
				var arrNum = Obj.length - 1;
				var cbObj;
				if (Obj[arrNum] == undefined) {
					cbObj = Obj;
				}
				else {
					cbObj = Obj[arrNum];
				}
				var formObj = cbObj.form;
				var cbName = cbObj.name;
				var cbCount = 0;
				var cbFirstChecked = cbObj.checked;
				var cbOtherChecked = false;
				for (var cb=0;cb<formObj.length;cb++) {
					if (formObj.elements[cb].type == 'checkbox' && formObj.elements[cb].name == cbName) {
						cbCount++;
						if (formObj.elements[cb].checked) {
							cbOtherChecked = true;
							}
					}
				}
				if (cbCount > 0) {
					if (cbFirstChecked || cbOtherChecked) {
						retVal = true;
					}
					else {
						retVal = false;
					}
				}
				else {
					if (cbFirstChecked) {
						retVal = true;
					}
					else {
						retVal = false;
					}
				}
			}
			else {
			retVal = false;
			if (Obj.length != undefined) {
				for(var x=0;x<Obj.length;x++) {
					if (Obj[x].checked) {
						retVal = true;
					}
				}
			}
			else {
				if (Obj.checked == true) {
					retVal = true;
				}
			}
		}
		break;
		
		
		default:
			retVal = true;
	}
	return retVal;
}

// end std validation