// JavaScript Document
function chk_frm()
{
	
//You should create the validator only after the definition of the HTML form
 Name=window.document.frm.name.value;
 Email=window.document.frm.email.value;
 Security=window.document.frm.number.value;
 RetVal=IsTextBoxValid("Name",Name,100,1);
 if(!RetVal)
 {
  window.document.frm.name.focus();
  return false;
 }
 RetVal=IsEmailValid("Email-Id",Email,1);
 if(!RetVal)
 {
   window.document.frm.email.focus();
  return false;
 }
  RetVal=IsSecurityCodeValid("Security",Security,100,1);
 if(!RetVal)
 {
  window.document.frm.number.focus();
  return false;
 }
}

function IsEmailValid(Caption,ControlValue,IsCompulsary)
{

  var Email=trim(ControlValue);
  var at="@";
  var dot=".";
  var Length=Email.length;
  var lat=Email.indexOf(at);
  if(IsCompulsary)
  {
    if ((Email==null)||(Email==""))
    {
      alert("Please Enter your Email ID");
      return false;
    }
  }
  if (Email.indexOf(at)==-1 || Email.indexOf(at)==0 || Email.indexOf(at)==Length)
  {
    alert("Invalid E-mail ID");
    return false;
  }
  if (Email.indexOf(dot)==-1 || Email.indexOf(dot)==0 || Email.indexOf(dot)==Length-1)
  {
    alert("Invalid E-mail ID");
    return false;
  }
  if (Email.indexOf(at,(lat+1))!=-1)
  {
    alert("Invalid E-mail ID");
    return false;
  }
  if (Email.substring(lat-1,lat)==dot || Email.substring(lat+1,lat+2)==dot)
  {
    alert("Invalid E-mail ID");
    return false;
  }
  
  if (Email.indexOf(dot,(lat+2))==-1)
  {
    alert("Invalid E-mail ID");
    return false;
  }
  if (Email.indexOf(" ")!=-1)
  {
    alert("Invalid E-mail ID");
    return false;
  }
  return true;
}

 function IsTextBoxValid(Caption,ControlValue,ControlLength,IsCompulsary)   
{   
    var TextFieldValue=trim(ControlValue);
    var intTempVarCondition;
    intTempVarCondition=0;
   	    
    if(IsCompulsary)                                                       
    {
	     if(TextFieldValue.length<1)					                      
	     {
		      alert(Caption +" is  Empty");
		      intTempVarCondition=1;
	     }
    }	
    if(TextFieldValue.length>ControlLength)			                     
    {}
    if (intTempVarCondition==1)
    {	     return false;
    }
    else
    {
	     return true;
    }	
 }	
function IsSecurityCodeValid(Caption,ControlValue,ControlLength,IsCompulsary)   
{  
    var TextFieldValue=trim(ControlValue);
    var intTempVarCondition;
    intTempVarCondition=0;
   	    
    if(IsCompulsary)                                                       
    {
	     if(TextFieldValue.length<1)					                      
	     {
		     //alert(Caption +" is  Empty");
			 alert("Insert security code shown in image");
		      intTempVarCondition=1;
	     }
    }	
    if(TextFieldValue.length>ControlLength)			                     
    {
	     alert(Caption +" Must Be Less Than " +ControlLength +" Characters");
	     intTempVarCondition=1;
    }
    if (intTempVarCondition==1)
    {
	     return false;
    }
    else
    {
	     return true;
    }	
 }	

function trim(s)						                                 
{
   return s.replace( /^\s*/,"").replace( /\s*$/,"");
}

function chk_frm_validation(){
    if(document.getElementById('con_name').value==""){
	   alert("Please enter the name");
	   document.getElementById('con_name').focus();
	   return false;
	 }
	/*if(document.getElementById('con_phone').value==""){
			alert("Please enter the phone number");
			document.getElementById('con_phone').focus();
			return false;
		
		}
		if (isNaN(document.getElementById('con_phone').value)) {
			alert("The phone number contains illegal characters.");
			document.getElementById('con_phone').focus();
			return false;
		
		}
		if (document.getElementById('con_phone').value.length != 10) {
		alert("The phone number is the wrong . Make sure your  10 digit phone number");
			document.getElementById('con_phone').focus();
			return false;
		}	*/
	 if(document.getElementById('con_email').value==""){
	   alert("Please enter the Email-Id");
	   document.getElementById('con_email').focus();
	   return false;
	 }
	  
	 if(document.getElementById('con_email').value.length >0) {
	 i=document.getElementById('con_email').value.indexOf("@")
	 j=document.getElementById('con_email').value.indexOf(".",i)
	 k=document.getElementById('con_email').value.indexOf(",")
	 kk=document.getElementById('con_email').value.indexOf(" ")
	 jj=document.getElementById('con_email').value.lastIndexOf(".")+1
	 len=document.getElementById('con_email').value.length
		}
 	if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
 	}
 	else {
 		alert("Please enter a valid Email address.\n" +
		document.getElementById('con_email').value + " is invalid.");
		document.getElementById('con_email').focus() ;
		return false;
		 } 
		 
		
	  /* if(document.getElementById('comment').value==""){
	   alert("Please enter the subject.");
	   document.getElementById('comment').focus();
	   return false;
	 }*/
	
   return true;
  }

