// JavaScript Document
function validate(formval)
{
	var frmvar=formval;
	var message='';
    var fname=trim(formval.fname.value);
    var sname=trim(formval.sname.value);
    var addr1=trim(formval.addr1.value);
	var city=trim(formval.city.value);	
	var county=trim(formval.county.value);	
	var postcode=trim(formval.postcode.value);
	var tel1=trim(formval.tel1.value);
	var emailID=trim(formval.email.value);
	var emailcID=trim(formval.emailc.value);
	var pass=trim(formval.pass.value);
	var passc=trim(formval.passc.value);	
	
	if ((fname==null)||(fname=="") ||(fname=="Enter first name(s)"))
	{
		message="Please Enter your first name\n";
	}	
	if ((sname==null)||(sname=="") ||(sname=="Enter last name"))
	{
		message+="Please Enter last name\n";
	}
	if ((addr1==null)||(addr1=="") ||(addr1=="Enter line one of address"))
	{
		message+="Please Enter line one of address\n";
	}	
	if ((city==null)||(city=="") ||(city=="Enter town/city"))
	{
		message+="Please Enter town/city\n";
	}	
	if ((county==null)||(county=="") ||(county=="Enter county"))
	{
		message+="Please Enter county\n";
	}
	if ((postcode==null)||(postcode=="") ||(postcode=="Enter postcode"))
	{
		message+="Please Enter postcode\n";
	}
	if ((tel1==null)||(tel1=="") ||(tel1=="Enter telephone number"))
	{
		message+="Please Enter telephone number\n";
	}
	if ((emailID==null)||(emailID=="") ||(emailID=="Enter email address"))
	{
		message+="Please Enter your Email ID\n";
		//emailID.focus()
		//return false
	}
	if (echeck(emailID)==false)
	{
		message+="Please Enter Valid Email ID\n";
		//return false
	}
	if (emailID!==emailcID && emailcID!="Confirm e-mail address\n")
	{
		message+="Confirm E-mail is not correct\n";
		//return false
	}	
/////////////////////////////////////////////
   if(pass=='')
   {  
      message+="Please enter valid password.\n";
     //document.form1.pass.focus();
     //return false;
   }
    if(!chkLength(pass))
   {
	 message+="Your password must be 6 to 20 characters with no spaces.\n";
    // document.form1.pass.focus();
    // return false;
   }
 if(pass!=passc)
    {  
     message+="Confirm  password is not correct.\n";
     //document.form1.passc.focus();
    // return false;
     }
   if(formval.agree.checked==false)
    {
	  message+="Please confirm that you have read and agree to the terms and conditions.\n";
	}

////////////////////////////////////////////////////////

	if(message!='')
	{  
		alert("The following form field(s) were incomplete or incorrect:\n\n" + message + "\n\n Please complete or correct the form and submit again.");
		message='';
		return false;
	}
	else
	 {
	   return true;
	 }
}	
function echeck(str) 
		{
		
			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")
				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					
		}
function chkLength(str)
  { 
   if(typeof(str) == "undefined") { return false; }
   else {  
  if(parseInt(str.length)<6 || parseInt(str.length)>20)
   { return false;
   }
  else if(str.indexOf(" ")>0)
   {
	   return false;
   }
   else
   { return true;
   }
   }
   
 }
function trim(str)
{
	
	
   if(typeof(str) != "undefined") 
  {   var len= str.length;
    for (var i=0;i<len;i++)
    {
      if(str.indexOf(" ")==0)
        str=str.substring(1,len);
    }
	for (var i=str.length-1;i>0;i--)
    { 
      if(str.lastIndexOf(" ")==str.length-1)
        str=str.substring(0,str.length-1);
		
    }
    strtrim=str;
	
  }
  else
  {
    strtrim=str;
  }
  
  return strtrim;
}
