var nursingPrograms = "NUR";
var nameRegxp = new RegExp("^(([bBcCdDfFgGhHjJkKlLmMnNpPqQrRsStTvVwWxXyYzZ][a-zA-Z\s]*[aeiouAEIOU][a-zA-Z\s]*)|([aeiouAEIOU][a-zA-Z\s]+))$");

function validateStep2(form)
{
	if(!validateSchoolFormCO(form))
	{
		return false;
	}
	with(form)
	{
		if(!validateDropDown(programId))
		{
			alert("Please select a degree program you are interested in.");
			return false;
		}
		
		var prgId = programId.options[programId.selectedIndex].value;
		var progValue = programValues[prgId];
		
		if(workPhone.value == "")
		{
			alert("Work Phone is required.")
			return false;
		}
		if(!validateDropDown(bestCallTime))
		{
			alert("Please select the best time to call(AM or PM).");
			return false;
		}			     
		if(!validateRadioButtonCondition(custom1))
		{
			alert("Please select the best time to call(AM or PM).");
			return false;
		}
		if ( ! validateStartDate123Months ('custom12') ) 
		{
			return false;
		}
		if ( ! validateCommentBox ('comments') ) 
		{
			return false;
		}
		if(progValue.indexOf("EDD.W1EDU.EDU") == 0 || progValue.indexOf("MS.W1EDU.EDU") == 0 || progValue.indexOf("M.E.GN") == 0)
		{
			if(!validateRadioButtonCondition(custom2))
			{
				alert("Please specify if you have a teaching certificate.");
				return false;
			}
		  	if(!validateRadioButton(custom2,0))
		  	{
				alert("We appreciate your interest in Walden University but based on the information you provided, you do not currently meet the admission requirements for this program.");
				return false;
			}
		}
		if(!validateProgramSpecificInputs(form)) 
		{
			return false;
		}			
		
		if(progValue.indexOf(nursingPrograms) >= 0) 
		{
			if(!validateRadioButtonCondition(registeredNurse)) {
				alert('Please specify whether you have a valid RN License');
				return false;
			}
		  	if(!validateRadioButton(registeredNurse,0)){
				alert ("We appreciate your interest in Walden University but based on the Information you provided, you do not currently meet the admission requirements for this program.");
				return false;
			}			
		}
	}
	if ( ! validateStartDate123Months ('custom12') ) {
			return false;
		}
		if ( ! validateCommentBox ('comments') ) {
			return false;
		}
		if(! validateJoiningReason ('reasonForJoining') ) { return false; } if(! validateContactQuestion ('contactForQuality') ) { return false;}if(! validateMotivationQuestion ('motivationForQuality') ) {
				return false;
		}
	return true;
}

function validateStep1(form) 
{
	if(!validateSchoolFormCO(form))
	{
		return false;
	}
	with(form)
	{

		if(!validateDropDown(salutation))
		{
			alert("Please specify your prefix.");
			return false;
		}
		if(!nameRegxp.test(firstName.value))
		{
			alert("Please specify first name in correct format.");
			return false;
		}
		if(!nameRegxp.test(lastName.value))
		{
			alert("Please specify last name in correct format.");
			return false;
		}		
		if(!validateDropDown(startDate))
		{
			alert("Please select your enrollment date.");
			return false;
		}
		if(startDate.options[startDate.selectedIndex].value == "")
		{
			alert("Please select your enrollment date.");
			return false;
		}
		if(!validateDropDown(educationLevel))
		{
			alert("Please select your highest education.");
			return false;
		}
		if(!validateEducationLevel(educationLevel)) 
		{
			return false;
		}	
	}
	return true;
}

function validateThankYou(form) 
{
	with(form)
	{
		if(!validateDropDown(educationLevel))
		{
			alert("Please select your highest education.");
			return false;
		}
		if(!validateEducationLevel(educationLevel))
		{
			return false;
		}
		if(!validateDropDown(programId))
		{
			alert("Please select a degree program you are interested in.");
			return false;
		}
		if(!validateDropDown(salutation))
		{
			alert("Please specify your prefix.");
			return false;
		}
		if(!validateDropDown(startDate))
		{
			alert("Please select your enrollment date.");
			return false;
		}		
		if(startDate.options[startDate.selectedIndex].value == "")
		{
			alert("Please select your enrollment date.");
			return false;
		}
		if(!validateDropDown(bestCallTime))
		{
			alert("Please select the best time to call(AM or PM).");
			return false;
		}			     
		if(!validateRadioButtonCondition(custom1))
		{
			alert("Please select the best time to call(AM or PM).");
			return false;
		}
		
		if(!validateProgramSpecificInputs(form)) {
			return false;
		}		
		
		var progValue = programValues[programId.value];
		if(progValue.indexOf(nursingPrograms) >= 0) 
		{
			if(!validateRadioButtonCondition(registeredNurse)) 
			{
				alert('Please specify whether you have a valid RN License');
				return false;
			}
		  	if(!validateRadioButton(registeredNurse,0))
		  	{
				alert ("We appreciate your interest in Walden University but based on the Information you provided, you do not currently meet the admission requirements for this program.");
				return false;
			}			
		}
		if(progValue.indexOf("EDD.W1EDU.EDU") == 0 || progValue.indexOf("MS.W1EDU.EDU") == 0 || progValue.indexOf("M.E.GN") == 0)
		{
			if(!validateRadioButtonCondition(custom2))
			{
				alert("Please specify if you have a teaching certificate.");
				return false;
			}
		  	if(!validateRadioButton(custom2,0))
		  	{
				alert("We appreciate your interest in Walden University but based on the information you provided, you do not currently meet the admission requirements for this program.");
				return false;
			}			
		}	
	}
	return true;
}

function validateEducationLevel(educationLevel) 
{
	
	if (educationLevel.value == "HS") 
	{
		alert("Based on the information you provided, you do not currently meet the application requirements for Walden University.");
		return false;
	}	
	return true;
}

function validateProgramSpecificInputs(form) 
{
	with(form) 
	{
		var sProgram = programValues[programId.value];
		var sProgramName = programNames[programId.options[programId.selectedIndex].value];
		if(sProgramName == null)
		{
			sProgramName = programNames[programId.selectedIndex-1];
		}
		var sHighestEducation = '';
		if(educationLvl != '')
		{
			sHighestEducation = educationLvl
		} else
		{
			sHighestEducation = educationLevel.options[educationLevel.selectedIndex].value;
		}
		
		if((sProgram.indexOf("M")==0||sProgram.indexOf("T")==0||sProgramName.indexOf("BSN")>0)
				&& (sHighestEducation == "HS")) 
		{
		  	alert("Based on your current education level you do not qualify for the program/degree you have selected. Please select an Associate or Bachelor program from the Program list.");
		    return (false);
		} else if ((sProgram.indexOf("P")==0||sProgram.indexOf("E")==0||sProgram.indexOf("C")==0)
		 			&& (sHighestEducation != "MAST" && sHighestEducation != "DOC" && sHighestEducation != "POSTDOC"))
		{		
		 	if(sHighestEducation == 'BACH')
		 	{
		  		alert("Based on your current education level you do not qualify for the program/degree you have selected. Please select an Associate, Bachelor, or Masters program from the Program list.");
		     	return (false);
		 	}else{
		  		alert("Based on your current education level you do not qualify for the program/degree you have selected. Please select an Associate or Bachelor program from the Program list.");
		     	return (false);
		 	}
		} else if ((sProgramName.indexOf("RN")>0) && (sHighestEducation == "HS"))
		{
		  	alert("Based on your current education level you do not qualify for the program/degree you have selected. Please select an Associate or Bachelor program from the Program list.");
		    return (false);
		} else if (sProgram.indexOf("CRT.W1PSY.PSY") == 0 && (sHighestEducation != "DOC" && sHighestEducation != "POSTDOC")) 
		{
		  	alert("Based on your current education level you do not qualify for the program/degree you have selected. Please select an  Bachelor, Master or Doctorate program from the Program list.");
		    return (false);			
		}
	  }
	return true;
}

function onProgramChange(programId) 
{
	if(programId.selectedIndex == 0) 
	{
		hideLevel('rn');
		hideLevel('teaching');
		return;
	}
	var sProgram = programValues[programId.value];
	var sProgramName = programNames[programId.selectedIndex-1];
	
	if(sProgram.indexOf("NUR") >= 0) 
	{
		showLevel('rn');
	} else 
	{
		hideLevel('rn');
	}
	
	if(sProgramName.indexOf("MS in Education") >= 0 || sProgramName.indexOf("Doctor of Education") >= 0)
	{
		showLevel('teaching');
	}else{
		hideLevel('teaching');		
	}
}

function onProgramChanged(programId) 
{
	if(programId.selectedIndex == 0) 
	{
		hideLevel('rn1');
		hideLevel('rn2');
		hideLevel('teaching1');
		hideLevel('teaching2');
		return;
	}
	var sProgram = programValues[programId.options[programId.selectedIndex].value];
	var sProgramName = programNames[programId.options[programId.selectedIndex].value];
	
	if(sProgram.indexOf("NUR") >= 0) 
	{
		showLevel('rn1');
		showLevel('rn2');
	} else 
	{
		hideLevel('rn1');
		hideLevel('rn2');
	}
	
	if(sProgramName.indexOf("MS in Education") >= 0 || sProgramName.indexOf("Doctor of Education") >= 0)
	{
		showLevel('teaching1');
		showLevel('teaching2');
	} else 
	{
		hideLevel('teaching1');
		hideLevel('teaching2');
	}
}
