// JavaScript Document

//FormCustomerDetails validation - validate all fields
function FormValidation(PasswordIgnore)
{
	if (document.FormCustomerDetails.Password.value!="") {PasswordIgnore=false;}
	ec = EmailCheck()
	if (ec==true)
	{
		if (document.FormCustomerDetails.Password.value=="" && PasswordIgnore!=true)
		{
			alert('You have not entered a Password');
		}
		else
		{
			if(document.FormCustomerDetails.Password.value.length<6 && PasswordIgnore!=true)
			{
					alert('Your password must be a minimum of 6 characters');
			}
			else
			{
				if (document.FormCustomerDetails.Password.value==document.FormCustomerDetails.PasswordConfirm.value)
				{
					if (document.FormCustomerDetails.PasswordHintA.value=="")
					{
						alert('You have not entered an answer for your Password Hint question');
					}
					else
					{	
						if (document.FormCustomerDetails.MarketingSource.value=='Blank')
						{
							alert('Please tell us how you found out about us');
						}
						else
						{
							if (document.FormCustomerDetails.State.value=="Other" && document.FormCustomerDetails.StateOther.value=="") {alert("You have not entered a state");return;}
							document.FormCustomerDetails.submit();
						}
					}
				}
				else
					{
						alert('The passwords you entered do not match');
						document.FormCustomerDetails.Password.value="";
						document.FormCustomerDetails.PasswordConfirm.value="";
					}
				}
			}
		}
}

//Email address validation
function EmailCheck() {
		str = document.FormCustomerDetails.Email.value
		emailerror = "The email address you have entered is not valid"
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert(emailerror)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(emailerror)
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(emailerror)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(emailerror)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(emailerror)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(emailerror)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(emailerror)
		    return false
		 }
 		 return true					
}
function StateBox() {
	if (document.FormCustomerDetails.State.value=="Other")
		{
			document.FormCustomerDetails.StateOther.style.visibility="visible";
			document.FormCustomerDetails.StateOther.focus();
		}
	else
		{
			document.FormCustomerDetails.StateOther.value=""
			document.FormCustomerDetails.StateOther.style.visibility="hidden";
		}
}