//-------------------------------------------------------------------------
//function ValidateWizardPage(intPage)
//Usage:	Checks required input areas for valid data
//			Submits the form if all fields were entered correctly, or alerts an error message
//
//-------------------------------------------------------------------------
function ValidateWizardPage(intPage)
{
	var objForm = document.frmRegWizard
	
	switch(intPage)
	{
		case 2:
		{
			if(trim(objForm.txtFirstName.value) == "")
			{
				incTextArea_Invalid(objForm.txtFirstName, "Please enter your first name.", true)
			}
			else if(trim(objForm.txtLastName.value) == "")
			{
				incTextArea_Invalid(objForm.txtLastName, "Please enter your last name.", true)
			}
			else if(trim(objForm.txtEmail.value) == "")
			{
				incTextArea_Invalid(objForm.txtEmail, "Please enter your e-mail address.", true)
			}
			else if(!CheckEmail(trim(objForm.txtEmail.value)))
			{
				objForm.txtEmail.value = trim(objForm.txtEmail.value)
				objForm.txtEmail.focus();
			}
			else
			{	
				objForm.submit()
			}
			
			break;
		}
		case 3:
		{
			if(trim(objForm.txtSchoolName.value) == "")
			{
				incTextArea_Invalid(objForm.txtSchoolName, "Please enter a school name.", true)
			}
			/*else if(objForm.txtDistrictNumber.value) == "")
			{
				incTextArea_Invalid(objForm.txtDistrictNumber, "Please enter a district number.", true)
			}*/
			else if(trim(objForm.txtStreetAddress.value) == "")
			{
				incTextArea_Invalid(objForm.txtStreetAddress, "Please enter a street address.", true)
			}
			else if(trim(objForm.txtCity.value) == "")
			{
				incTextArea_Invalid(objForm.txtCity, "Please enter a City", true)
			}
			else if(trim(objForm.txtPostalZipCode.value) == "")
			{
				incTextArea_Invalid(objForm.txtPostalZipCode, "Please enter a postal or zip code.", true)
			}
			else if(objForm.selCountry.selectedIndex == 0)
			{
				alert("Please choose a Country");
				objForm.selCountry.focus();
			}
			else if(objForm.selProvinceState.selectedIndex == 0)
			{
				alert("Please choose a Province or State.");
				objForm.selProvinceState.focus();
			}
			else if(!IsValidProvince(objForm.selProvinceState, objForm.selCountry))
			{
				if(objForm.selCountry.value == "CA")
				{
					alert("Please select a Province!");
					objForm.selProvinceState.focus();
				}
				else if(objForm.selCountry.value == "US")
				{
					alert("Please select a State!");
					objForm.selProvinceState.focus();
				}
			}
			else if(trim(objForm.txtSchoolPhone.value) == "")
			{
				incTextArea_Invalid(objForm.txtSchoolPhone, "Please enter the school phone number.", true)
			}
			else if((trim(objForm.txtSchoolEmail.value) != "") && (!CheckEmail(trim(objForm.txtSchoolEmail.value))))
			{
				objForm.txtSchoolEmail.value = trim(objForm.txtSchoolEmail.value)
				objForm.txtSchoolEmail.focus();
			}
			else
			{	
				objForm.submit();
			}
			break;
		}
		case 4:
		{
			if(trim(objForm.txtUserName.value) == "")
			{
				incTextArea_Invalid(objForm.txtUserName, "Please enter your user name.", true)
			}
			else if(trim(objForm.txtPassword.value) == "")
			{
				incTextArea_Invalid(objForm.txtPassword, "Please enter your password.", true)
			}
			else if(trim(objForm.txtPassword.value).length<5)
			{
				incTextArea_Invalid(objForm.txtPassword, "Your password must be at least 5 characters!", true);
				objForm.txtReEnterPassword.value=""
			}
			else if(trim(objForm.txtReEnterPassword.value) != trim(objForm.txtPassword.value))
			{
				incTextArea_Invalid(objForm.txtReEnterPassword, "", true)
				incTextArea_Invalid(objForm.txtPassword, "Passwords do not match! Please re-enter your password.", true)
				
			}
			else
			{	
				objForm.submit();
			}
			
			break;
		}
		default:
			break;
			
	}
}

function IsValidProvince(objSel, objSelCountry)
{
	var blnValid = true;
	
	if(objSel.selectedIndex != 0)
	{
		if(objSelCountry.selectedIndex != 0)
		{
			if((objSelCountry.value == "CA") && (objSel.selectedIndex > 13))
				blnValid = false;
			else if((objSelCountry.value == "US") && (objSel.selectedIndex < 14))
				blnValid = false;
		}
	}
	
	return blnValid;
}

function OnSubmitLogIn()
{
	var f=document.frmLogIn;
		
	if (trim(f.txtUserName.value) == "")
	{
		incTextArea_Invalid(f.txtUserName, 'Please enter your username!', true);
		return;		   
	}   			
	else if (trim(f.txtPassword.value) == "")
	{
		incTextArea_Invalid(f.txtPassword, 'Please enter your password', true);
		return;		   
	}   	
	  
	f.submit();
}

/* function OnSubmitLostPassword()
		Validate the lost password field.
		Submit the lost password form if all fields are valid.
*/
function OnSubmitLostPassword()
{
	var f = document.frmLostPassword;

	if (trim(f.Email.value) == "")
	{
		incTextArea_Invalid(f.Email, 'Please enter your e-mail address!', true);
	}  
	else if ((f.Email.value.indexOf('@') == -1) || (f.Email.value.indexOf('.') == -1) || (trim(f.Email.value).indexOf(" ") != -1))
	{//Check for @ and . and spaces.
		incTextArea_Invalid(f.Email, 'Please enter a valid e-mail address!', true);
		f.Email.focus();
		return;
	} 
	else
	{
		f.submit();
	}
}
