﻿// JScript File

function QueryValidation()
{	
var emailID=document.frmQuery.E_Address

	if (document.frmQuery.Title.value=='')
		{
		alert("Full Name cannot be blank");
		document.frmQuery.Title.focus();
		return false;
		}

	if (document.frmQuery.FullName.value=='')
		{
		alert("Full Name cannot be blank");
		document.frmQuery.FullName.focus();
		return false;
		}
		
		if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
		
		
		
		if (document.frmQuery.Address.value=='')
		{
		alert("Address cannot be blank");
		document.frmQuery.Address.focus();
		return false;
		}
		
		if (document.frmQuery.City.value=='')
		{
		alert("City cannot be blank");
		document.frmQuery.City.focus();
		return false;
		}
		
		if (document.frmQuery.County_State.value=='')
		{
		alert("County/State cannot be blank");
		document.frmQuery.County_State.focus();
		return false;
		}
		
		if (document.frmQuery.Zip_Code.value=='')
		{
		alert("Postal/Zip code cannot be blank");
		document.frmQuery.Zip_Code.focus();
		return false;
		}
		
		if (document.frmQuery.W_Phone.value=='')
		{
		alert("Work Phone code cannot be blank");
		document.frmQuery.W_Phone.focus();
		return false;
		}
		
		if (document.frmQuery.H_Phone.value=='')
		{
		alert("Home Phone code cannot be blank");
		document.frmQuery.H_Phone.focus();
		return false;
		}
		
		if (document.frmQuery.M_Phone.value=='')
		{
		alert("Mobile Phone code cannot be blank");
		document.frmQuery.M_Phone.focus();
		return false;
		}
		
		
		if (document.frmQuery.E_Address.value=='')
		{
		alert("Email Address cannot be blank");
		document.frmQuery.E_Address.focus();
		return false;
		}
}

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					
	}

