﻿function jsClearText(txtPostCode)
{
    if (txtPostCode.value=="Postcode..." || txtPostCode.value=="Zipcode...")
        txtPostCode.value="";
}    

function jsSetRemoveDefaultText(txtPostCode)
{
   if (txtPostCode.value=="" && document.getElementById("ctl00_ContentPlaceHolder1_ddlLocation").value=="United Kingdom")
            txtPostCode.value="Postcode...";
    if (txtPostCode.value=="" && document.getElementById("ctl00_ContentPlaceHolder1_ddlLocation").value=="United States")
            txtPostCode.value="Zipcode...";            
}    

function jsValidateForm()
{

   if (document.getElementById("ctl00_ContentPlaceHolder1_txtUserName").value=="Username...")
    {
        alert("Username cannot be left blank.");
        document.getElementById("ctl00_ContentPlaceHolder1_txtUserName").focus();
        return false;
    }

     if (document.getElementById("ctl00_ContentPlaceHolder1_txtUserName").value.charAt(0)=="@")
    {
        alert("Invalid Username. Username cannot start with '@' symbol.");
        document.getElementById("ctl00_ContentPlaceHolder1_txtUserName").focus();
        return false;
    }
    
    if (document.getElementById("ctl00_ContentPlaceHolder1_txtPassword").value=="Password...")
    {
        alert("Password cannot be left blank.");
        document.getElementById("ctl00_ContentPlaceHolder1_txtPassword").focus();
        return false;
    }
    
    if (document.getElementById("ctl00_ContentPlaceHolder1_txtEmailAddress").value=="" || document.getElementById("ctl00_ContentPlaceHolder1_txtEmailAddress").value=="Email Address...")
    {
        alert("Email Address cannot be left blank.");
        document.getElementById("ctl00_ContentPlaceHolder1_txtEmailAddress").focus();
        return false;
    }
    
     if (!ValidateEmail(document.getElementById("ctl00_ContentPlaceHolder1_txtEmailAddress")))
        return false;
 
   
    
      if (!document.getElementById("ctl00_ContentPlaceHolder1_chkTermsOfUse").checked)
    {
        alert("Please check the Terms Of User check box to register.");
        document.getElementById("ctl00_ContentPlaceHolder1_chkTermsOfUse").focus();
        return false;
    }
    
    
}

function ValidateEmail(em)
{
	var email = em.value;
	if (email.length > 0) 
	{
	// To check the presence of @ and .
		if ((email.indexOf("@") < 0) || (email.indexOf(".") < 0))
			{
				alert ("Invalid email format")
				em.focus();
				return false;
			} 

	// To check the presence of spl chars, space, .. and so on
		var val;
		val=em.value;
		if ((val.indexOf("..") >= 0) || (val.indexOf("'") >= 0) || (val.indexOf("\"") >= 0)||(val.indexOf(",") >= 0) || (val.indexOf("<") >= 0) || (val.indexOf(">") >= 0  || (val.indexOf(" ") >= 0)))
			{
				alert ("Invalid email format")
				em.focus();
				return false;
			}

	// To check the presence of . as last char
		if (val.substring(val.length-1,val.length) == ".")
			{
				alert ("Invalid email format")
				em.focus();
				return false;
			} 

	// To check the presence of @ twice or . not exist
		val1 = val.substring(val.indexOf("@")+1, val.length);
		if ((val1.indexOf("@") >= 0) || (val1.indexOf(".") < 0))
			{
				alert ("Invalid email format")
				em.focus();
				return false;
			} 
			

	// To check the presence of only numbers
		val1 = val.split("@");
		if (( !isNaN(val1[0]) )  || ( !isNaN(val1[1]) ) )
			{
				alert ("Invalid email format")
				em.focus();
				return false;
			}

	// To check the total length ( >1 or <=3) of text after final .
		val1 = val.split(".");
		var pos = val1.length-1;
		if ((val1[pos].length <2) || (val1[pos].length >3))
			{
				alert ("Invalid email format")
				em.focus();
				return false;
			}
	return true;
	}
}

