﻿var Focus=false;
var msg="";
var ObFocus;
function validate_contact_form(thisform)
{
 
ObFocus=null;
Focus=true;
   msg="";
	//--------------------------------fistName-----------------------------------------------------------------
    var fistName=document.getElementById("fname").value; 
	if(isStringEmpty(fistName))
	{  
	   SetMsg("First name is required \n","fname");	     
	}
	/*else{
		 if(ishave(fistName))
		{  
		     SetMsg("First name has special characters \n","fname");		 
		}else{
		var count=0;
	                 //  alert(fistName);
                                 //alert(iChars.indexOf(obj.value.charAt(i)));
                                      if (!isIntegers_ff(fistName))
                                       {
                                       //  alert("inside");
                                        count++;
                                      }
                                //alert(count);
                                     if(count>0)
                                      {
                                        
                                        SetMsg("First name should not contain integers \n","fname");	    
                                      }
				      }
	}*/
	 //++++++++++++++++++++++++++++some++++++++++++++++++++++
 var n=document.getElementById('fname').value;
   var countfirst=0;
  // var cnt=0;
   //var countfr=0;
var reg=/([A-Za-z])/;
var s=1;
for(var i=0;i<n.length;i++)
{
	if(n[0]==' ') 
	{
		//SetMsg("more than one space Not validee \n","firstname");
	//return false;
	countfirst++;
	}

	if(reg.test(n[i]))
		s=1;
	if(reg.test(n[i])==false && n[i]==' '&&s<=1)
		s++;
	else if	(reg.test(n[i])==false||s>1)
	{
	//SetMsg("more than one space Not valide \n","firstname");
			//alert('not valid');
			//return false;
			countfirst++;
	}	

}

if(countfirst>0)
{
SetMsg("First name only allow characters and allowed only single space between two words \n ","fname");
//SetMsg("First name should contain only alphabets\n","firstname");	
}

   //+++++++++++++++++++++++++some++++++++++++++++++++++++++++++++++++++
	
	//--------------------------------Last Name-----------------------------------------------------------------
	 
	var lastname=document.getElementById("lname").value;
	if(isStringEmpty(lastname))
	{
	   
	    SetMsg("Last name is required  \n","lname");
	}
/*	else{
		 if(ishave(lastname))
		{  
		     SetMsg("Last name has special characters \n","lname");		 
		}else{
		var count=0;
	                 //  alert(fistName);
                                 //alert(iChars.indexOf(obj.value.charAt(i)));
                                      if (!isIntegers_ff(lastname))
                                       {
                                       //  alert("inside");
                                        count++;
                                      }
                                //alert(count);
                                     if(count>0)
                                      {
                                        
                                        SetMsg("Last name should not contain integers \n","lname");	    
                                      }
				      }
	}
		*/
		 //++++++++++++++++++++++++++++Last name space++++++++++++++++++++++
 var n=document.getElementById('lname').value;
   var countlast=0;
  // var cnt=0;
   //var countfr=0;
var reg=/([A-Za-z])/;
var s=1;
for(var i=0;i<n.length;i++)
{
	if(n[0]==' ') 
	{
		//SetMsg("more than one space Not validee \n","firstname");
	//return false;
	countlast++;
	}

	if(reg.test(n[i]))
		s=1;
	if(reg.test(n[i])==false && n[i]==' '&&s<=1)
		s++;
	else if	(reg.test(n[i])==false||s>1)
	{
	//SetMsg("more than one space Not valide \n","firstname");
			//alert('not valid');
			//return false;
			countlast++;
	}	

}

if(countlast>0)
{
SetMsg("Last name only allow characters and allowed only single space between two words \n ","lname");
//SetMsg("First name should contain only alphabets\n","firstname");	
}

  
   
	
	//--------------------------------email-----------------------------------------------------------------
	 
	var Email=document.getElementById("temail").value; 	
	if(isStringEmpty(Email))
	{	  
	   SetMsg("Email is required \n","temail");	   
	}
	else if(isEmail(Email))
	{
	SetMsg("Invalid email  \n","temail");	   
	}
	 
	 //--------------------------------confirm email-----------------------------------------------------------------
	 
	var cmail=document.getElementById("cemail").value; 	
	if(isStringEmpty(cmail))
	{	  
	   SetMsg("Enter confirm email \n","cemail");	   
	}
	
	if(Email!=cmail)
	{	   
	    SetMsg("Email and confirm email mismatched \n","cemail");		   
	}
	 
	  	//--------------------------------Mobile-----------------------------------------------------------------
 
	var mobile=document.getElementById("telephone").value;	 
	if(isStringEmpty(mobile))
	{	   
	    SetMsg("Mobile number is required \n","telephone");
	}
	else if(!isMobilenumber(mobile))
	{	 
	    SetMsg("Invalid mobile number  \n","telephone");
	}else{
	   if(isHaveSpecialChar(mobile))
		{  
			SetMsg("Mobile number has special characters  \n","mobile");
		   	 
		}
	}
	 	
	 
	
	 
	//--------------------------------rating-----------------------------------------------------------------	 
	if(document.getElementById("rating").value=="select")
	{
	 	  SetMsg("Select your rating  \n","rating");
	}
	 
	 //--------------------------------about this-----------------------------------------------------------------		
	 
	if(document.getElementById("aboutus").value=="select")
	{	 
	  SetMsg("Select how did you learn about us  \n","aboutus");
	}


	//if msg does not contian any message
	 if(msg.length==0)
	 {
	  //alert("No erroes");
	    return true;
	 }
	 else
	 {
	  alert(msg);
	  
	  try{  ObFocus.focus();  }catch(e){}
	  
	   return false;
	 }
	 return false;
 
}
function SetMsg(newmsg,id)
{ 
     msg=msg+newmsg;	  
	if(Focus)
	{    
	    Focus=false;
		ObFocus=document.getElementById(id);
		
	}     
}

function isIntegers_ff(s)
{
//alert(s);
   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is not a number.
        var c = s.charAt(i);
	
        if ((c >= "0") && (c <= "9") && (c != ".")) return false;
    }
    // All characters are numbers.
    return true;
}

 
 
 
 
 
 
 
  










/*function validate_email(field,alerttxt)
{
 

 if(field=="")
 {
 alert('Please enter email address');
 return true;
 }else{
apos=field.indexOf("@");
dotpos=field.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {
   //alert(alerttxt);
   return true;
  }

}
 
}

function validate_firstname(field,alerttxt)
{
with (field)
{
 if(value.length==0)

 {alert(alerttxt);return false;}
 }
 }

 



function validate_form(thisform)
{
with (thisform)
{
 var mesg=0;
 if (validate_firstname(firstname,"Please enter first name!")==false)
  {firstname.focus();return false;
  mesg=1;
  }
  
 
  
if (validate_email(document.getElementById("email").value,"Not a valid e-mail address!"))

  {email.focus();return false;
   mesg=1;
  }
 if(mesg==0)
 { 
   return true;
 }else{
 
   return false;
 }
 
}
}*/