/* This function valides an enrollment form*/

function validateEnrollForm()
{
	getResult = false;
	formPath = document.enroll_application;
	if (formPath.fname.value.replace( /(^\s+)|(\s+$)/g, '') == "" )
	{
		alert("Please complete your First Name to submit this enrollment.");
		formPath.fname.focus();
	}
	else if (formPath.lname.value.replace( /(^\s+)|(\s+$)/g, '') == "" )
	{
		alert("Please complete your Last Name to submit this enrollment.");
		formPath.lname.focus();
	} 
	else if (formPath.email.value.replace( /(^\s+)|(\s+$)/g, '') == "")
	{
		alert("Please complete your E-Mail Address to submit this enrollment.");
		formPath.email.focus();
	}
	else if (checkEmailSymbol(formPath.email.value) == false)
	{
		alert("Your E-Mail Address has an invalid format");
		formPath.email.focus();
	}
	else if (formPath.email_confirm.value.replace( /(^\s+)|(\s+$)/g, '') == "")
	{
		alert("Please complete your Confirm E-Mail Address to submit this enrollment.");
		formPath.email_confirm.focus();
	}
	else if (checkEmailSymbol(formPath.email_confirm.value) == false)
	{
		alert("Your Confirm E-Mail Address has an invalid format");
		formPath.email_confirm.focus();
	}
	else if (formPath.email.value != formPath.email_confirm.value)
	{
		alert("The Confirm E-Mail Address you entered does not match with the above E-mail Address. Please try again.");
		formPath.email_confirm.focus();
	}
	else if (formPath.zip.value.replace( /(^\s+)|(\s+$)/g, '') == "")
	{
		alert("Please complete your Zip Code to submit this enrollment.");
		formPath.zip.focus();
	}
	else
	{
		getResult = true;
	}
	return getResult;
}

function checkEmailSymbol(s)
{
	var RegExEmail = /([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/;

	var getResult = true;
	getResult = RegExEmail.test(s);

	return getResult;
}

function updateCountryInfo()
{
	formPath = document.enroll_application;
	inputObj = eval("formPath." + "state_input");
	selectObj = eval("formPath." + "state_id");
	countryObj = eval("formPath." + "country_id");
	if (countryObj.options[countryObj.selectedIndex].value =="1" || countryObj.options[countryObj.selectedIndex].value =="39") // US Country
	{
		selectObj.style.display = "block";
		inputObj.style.display = "none";
	}
	else
	{
		selectObj.style.display = "none";
		inputObj.style.display = "block";
	}
}
