
   function validate_form(name) {
      k=0;
       
      name_length=name.length;
    
      for(i=0;i<name_length;i++) {
         if(document.getElementById(name[i]).value==""){	
          k++;
          alert("please enter "+name[i]);
          break;
       }
      else if(name[i]=="email"){
        if(!checkMail(name[i])) {
           k++;
          break;
        }
      }
     else if(name[i]=="home phone"||name[i]=="cell phone"||name[i]=="work phone"||name[i]=="phone"||name[i]=="zip code") {
       k=validate_phone(name[i]);
       
     }
    }
    if(k!=0)
    {
      return false;
     }
    else
     return true;
     
  } 


/***************** Email Validation*************/
  function checkMail(email) {
     var str=document.getElementById(email).value;
     var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
     if (filter.test(str))
       return true;
     else {
       alert("Please input a valid email address!")
       document.getElementById("email").focus();
       return false;
     }
  }
/*********************************************************/



  function validate_phone(phone_no) {
   pno=document.getElementById(phone_no).value;
 
   c=pno.indexOf('-');
 

 if(c!=-1)
 {
 
 ph_no=pno.split("-");
 plength=ph_no.length;
 country_code=ph_no[0];
 acode=ph_no[1];
 /******** Finds the length of country,area and phonenumber*********/
 alength=acode.length;
 c_length=country_code.length;
 
if (plength<3) {
 
 k++;
 alert("Invalid "+phone_no+" number\n Eg :- 919-333-3344");
 }
 else {
 p_no=ph_no[2];
 p_length=p_no.length;
  if(alength!=3||c_length!=3||p_length<4)
 {
 k++;
 alert("Invalid "+phone_no+" number \n Eg :- 919-333-3344");
 }
 
 else if(isNaN(acode)||isNaN(p_no)||isNaN(country_code)) {
   k++;
   alert(phone_no+" number must be a number\n Eg :- 919-333-3344");
  }
 } 
 } 
  else if(isNaN(pno)) {
     k++;
     if(phone_no=="zip code")
          alert(phone_no+"  must be a  Number");
     else
     alert(phone_no+" number must be a  Number");
   }
  if(k>0)
   k=1;
  else
   k=0;

 return k;
  
 }

