﻿var Focus=false;
var msg="";
var ObFocus;
function validate_online_form(thisform)
{
 
ObFocus=null;
Focus=true;
   msg="";
	//--------------------------------fistName-----------------------------------------------------------------
    var fistName=document.getElementById("fname").value; 
	if(isStringEmpty(fistName))
	{  
	   SetMsg("Name is required \n","fname");	     
	}
/*	else{
		 if(isHaveSpecialChar(fistName))
		{  
		     SetMsg("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("Name should not contain integers \n","fname");	    
                                      }
				      }
	}
	*/
	 //++++++++++++++++++++++++++++space first name++++++++++++++++++++++
 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("Name only allow characters and allowed only single space between two words \n ","fname");
//SetMsg("First name should contain only alphabets\n","firstname");	
}

   //+++++++++++++++++++++++++spaces first name++++++++++++++++++++++++++++++++++++++
	
	//--------------------------------Shipping address-----------------------------------------------------------------
	 
	var shipaddress=document.getElementById("saddress").value;
	if(isStringEmpty(shipaddress))
	{
	   
	    SetMsg("Shipping Address is required  \n","saddress");
	}
		
		
			
	//--------------------------------town/city address-----------------------------------------------------------------
	 
	var town=document.getElementById("townorcity").value;
	if(isStringEmpty(town))
	{
	   
	    SetMsg("Town/City is required  \n","townorcity");
	}else{
		 if(isHaveSpecialChar(town))
		{  
			SetMsg("Town/City has special characters  \n","townorcity");
		   	 
		}else{
		var count=0;
	                 //  alert(fistName);
                                 //alert(iChars.indexOf(obj.value.charAt(i)));
                                      if (!isIntegers_ff(town))
                                       {
                                       //  alert("inside");
                                        count++;
                                      }
                                //alert(count);
                                     if(count>0)
                                      {
                                        
                                      	SetMsg("Town/City should not contain integers  \n","townorcity");					
                                      }
				      }
	}
	
	//--------------------------------town/city address-----------------------------------------------------------------
	 
	var stateorprovince=document.getElementById("b_state").value;
	if(isStringEmpty(stateorprovince))
	{  
	   SetMsg("State is required \n","b_state");	     
	}
	else{
		 if(isHaveSpecialChar(stateorprovince))
		{  
		     SetMsg("State has special characters \n","b_state");		 
		}else{
		var count=0;
	                 //  alert(fistName);
                                 //alert(iChars.indexOf(obj.value.charAt(i)));
                                      if (!isIntegers_ff(stateorprovince))
                                       {
                                       //  alert("inside");
                                        count++;
                                      }
                                //alert(count);
                                     if(count>0)
                                      {
                                        
                                        SetMsg("State should not contain integers \n","b_state");	    
                                      }
				      }
	}
	
		
			 		//--------------------------------address1-----------------------------------------------------------------
	//Last Name
var zipcode=document.getElementById("zipcode").value;
	if(isStringEmpty(zipcode))
	{	  
	   SetMsg("Pin/Post/Zip code is required \n","zipcode");
	}else{
		 if(isHaveSpecialChar(zipcode))
		{  
			SetMsg("Pin/Post/Zip code has special characters \n","zipcode");
		   	 
		}else{
		var count=0;
	                 //  alert(fistName);
                                 //alert(iChars.indexOf(obj.value.charAt(i)));
                                      if (!isIntegers_pin(zipcode))
                                       {
                                       //  alert("inside");
                                        count++;
                                      }
                                //alert(count);
                                     if(count>0)
                                      {
                                        
                                        SetMsg("Pin/Post/Zip code should contain only integers \n","zipcode");	    
                                      }
				      }
	}
	 
	 
	 	//--------------------------------country-----------------------------------------------------------------
  
	 //alert(""+document.getElementById("country").value)
	if(document.getElementById("country").value=="select")
	{
	 	  SetMsg("Select country \n","country");
	}
	 
	

	
		//--------------------------------email-----------------------------------------------------------------
	//Last Name
	var Email=document.getElementById("email").value; 
	
	if(isStringEmpty(Email))
	{	  
	   SetMsg("Email is required \n","email");	   
	}
	else if(isEmail(Email))
	{
	SetMsg("Email invalid \n","email");	   
	}
	 
	 //--------------------------------confirm email-----------------------------------------------------------------
	 
	 
	  	//--------------------------------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");
		   	 
		}
	}
	 	
	 
	//Last Name
	var chqnumber=document.getElementById("chq").value;
	if(isStringEmpty(chqnumber))
	{	  
	   SetMsg("Cheque number is required \n","chq");
	}
	else if(!isInteger(chqnumber))
	{	 
	    SetMsg("Provide correct cheque number  \n","chq");
	}
	 
	 
	 

	//if msg does not contian any message
	 if(msg.length==0)
	 {
	  //alert("No erroes");
	    var quantity=document.getElementById("textfield").value;
	  if(quantity>0)
	  {
	    return true;
	    }else
	    {
	      alert("Please select the quantity");
	      return false;
	    }
	 }
	 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 isIntegers_pin(s)
{
//alert(s);
var count=0;
   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is not a number.
        var c = s.charAt(i);
	//alert(c);
        if ((c >= "0") && (c <= "9") && (c != "."))
	{
	
	}else{
	  count++;
	}
    }
    // All characters are numbers.
    if(count>0)
    {
    return false;
    }else{
    return true;
    }
}

 
 
 
 
 
 
 
  







 