// JavaScript Document
//////Form validation////////////////////////////////
function echeck(str) {
/* 
DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
/* The return true statement at the bottom of this function is removed by Kasun Rajapaksha (kasun.rajapaksha@yahoo.com ) to 
prevent form submission as soon as the correct email address
*/
	
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   document.getElementById("email").value=='';
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
	//	return true	
	
	}

/* 
DHTML form validation script. by Kasun Rajapaksha (kasun.rajapaksha@yahoo.com)
 */
function fmvalid()
{
var mess='';

if(document.getElementById("email").value=='')
{
mess=mess + " E-mail \n";
}

if(document.getElementById("reemail").value=='')
{
mess=mess + " Re E-mail \n";
}

if(document.getElementById("lname").value=='')
{
mess=mess + " Last Name \n";
}

if(document.getElementById("fname").value=='')
{
mess=mess + " First Name \n";
}

if(document.getElementById("Phone").value=='')
{
mess=mess + " Phone Number \n";
}

if(document.getElementById("Address1").value=='')
{
mess=mess + " Address \n";
}

if(document.getElementById("City").value=='')
{
mess=mess + " City \n";
}

if(document.getElementById("CSState").value=='')
{
mess=mess + " State \n";
}

if(document.getElementById("zip").value=='')
{
mess=mess + " Zip Code \n";
}


if(mess !='')
{
mess=mess + " \n Cannot be blank ";
alert(mess);
return (false);
}


if(mess=='')
{

var emailID1=document.getElementById("email");
var paswd=document.getElementById("Password").value.length;
	
	if (echeck(emailID1.value)!=false)
	{
					if(document.getElementById("reemail").value!=document.getElementById("email").value)
					{
					alert("Email and Re Email does not match please enter again");
					document.getElementById("reemail").value="";
					document.getElementById("reemail").focus();
					return (false);
					}
					if(document.getElementById("reemail").value==document.getElementById("email").value)
					{
						if(document.getElementById("Password").value!="")
						{
							if(document.getElementById("Confirm_Password").value!="")
							{
								if(paswd>7)
								{
									if(document.getElementById("Confirm_Password").value==document.getElementById("Password").value)
									{
									if(document.getElementById("Agreetick").checked==false)
										{
											alert("You have to agree to the terms and conditions and subscriber agreement to proceed");
											return (false);
										}
									else
										{
											return (true);
										}	
									}
									else
									{
									alert("Password and Confirm Password should match");
									document.getElementById("Confirm_Password").value="";
									return(false);
									}
								}
								else
								{
								alert("Password should contain minimun of 8 characters");
								return(false);
								}
								
								
							}
							else
							{
							alert("Confirm Password field cannot be blank");	
							return (false);
							}
						}
						else
						{
							alert("Password field cannot be blank");
							return (false);
						}
					}
	return (false);
	}
return (false);
}
}
///////////////////////////////End of the form validation////////////////////////////////