﻿var Focus=false;
var msg="";
var ObFocus;
function validate_form(thisform)
{
//if(true):alert("1")?alert("2");
ObFocus=null;
Focus=true;
   msg="";
   
  
	//--------------------------------fistName-----------------------------------------------------------------
    var fistName=document.getElementById("firstname").value;
     
	//Firstname
	if(isStringEmpty(fistName))
	{  
	   SetMsg("First name is required \n","firstname");	     
	}
	/*
	else{
		 if(isHaveSpecialChar(fistName))
		{  
		     SetMsg("First name should not contain special characters \n","firstname");		 
		}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","firstname");	    
                                      }
									  
				      }
	}*/
	
	 //++++++++++++++++++++++++++++some++++++++++++++++++++++
 var n=document.getElementById('firstname').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 ","firstname");
//SetMsg("First name should contain only alphabets\n","firstname");	
}

   //+++++++++++++++++++++++++some++++++++++++++++++++++++++++++++++++++

   
	
	//--------------------------------Last Name-----------------------------------------------------------------
	//Last Name
	var lastname=document.getElementById("lastname").value;
	if(isStringEmpty(lastname))
	{
	   
	    SetMsg("Last name is required  \n","lastname");
	}
	else{
		 if(isHaveSpecialChar(lastname))
		{  
		     SetMsg("Last name should not contain special characters \n","lastname");		 
		}
	/*	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","lastname");	    
                                      }
				      }
					  */
	}
	
	  //++++++++++++++++++++++++++++some++++++++++++++++++++++
 var n=document.getElementById('lastname').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 ","lastname");
//SetMsg("First name should contain only alphabets\n","firstname");	
}

   //+++++++++++++++++++++++++some++++++++++++++++++++++++++++++++++++++
   
	
		//--------------------------------address1-----------------------------------------------------------------
	//Last Name
	var address1=document.getElementById("address1").value;
	if(isStringEmpty(address1))
	{	  
	   SetMsg("Address is required \n","address1");
	}
	 
	 
		
		//--------------------------------city-----------------------------------------------------------------
 
	var city=document.getElementById("city").value;
	if(isStringEmpty(city))
	{	 
	  SetMsg("City is required \n","city");
	}
	else{
		 if(isHaveSpecialChar(city))
		{  
			SetMsg("City has special characters  \n","city");
		   	 
		}else{
		var count=0;
	                 //  alert(fistName);
                                 //alert(iChars.indexOf(obj.value.charAt(i)));
                                      if (!isIntegers_ff(city))
                                       {
                                       //  alert("inside");
                                        count++;
                                      }
                                //alert(count);
                                     if(count>0)
                                      {
                                        
                                      	SetMsg("City should not contain integers  \n","city");					
                                      }
				      }
	}
	 
	 
	 		//--------------------------------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");	   
	}
	 
	
	 	//--------------------------------Mobile-----------------------------------------------------------------
 
	var mobile=document.getElementById("mobile").value;
	 
	if(isStringEmpty(mobile))
	{	   
	    SetMsg("Mobile number is required \n","mobile");
	}
	else if(!isMobilenumber(mobile))
	{	 
	    SetMsg("Mobile number is invalid \n","mobile");
	}else{
	   if(isHaveSpecialChar(mobile))
		{  
			SetMsg("Mobile number has special characters  \n","mobile");
		   	 
		}
	}
	 	
	
	 	//--------------------------------Amount-----------------------------------------------------------------
 
	var amount=document.getElementById("amount").value;
	 
	if(isStringEmpty(amount))
	{	   
	    SetMsg("Please Enter Amount \n","amount");
	}
	else{
	  if(isHaveSpecialChar(amount))
		{  
			SetMsg("Amount should not contain special characters \n","amount");
		   	 
		}else{
	
	  	var count=0;
	                 //  alert(fistName);
                                 //alert(iChars.indexOf(obj.value.charAt(i)));
                                      if (isIntegers_ff(amount))
                                       {
                                       //  alert("inside");
                                        count++;
                                      }
                                //alert(count);
                                     if(count>0)
                                      {
                                        
                                        SetMsg("Amount should not contain characters \n","amount");	    
                                      }
			}
		
	}
		
		  //alert(""+document.getElementById("currency").value)
	if(document.getElementById("currency").value=="select")
	{	 
	  SetMsg("Select Currency  \n","currency");
	}


	//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);
		//alert(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);
	//alert(c);
        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;
    }
}
function isHaveSpecialChar_money(name)
{
 var iChars = "`~!@#$%^&*()+=-[]\\\';/{}|\":<>?";
     for (var i = 0; i < name.length; i++) 
         {
            //alert(iChars.indexOf(name.charAt(i)));
  	        if (iChars.indexOf(name.charAt(i))!= -1)
  	         {
  	           
  	          return true;
  	        }
          }
    return false;
         
}

 
 