var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;
var dentist_selection="";
var tech_selection="";
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

var emailFilter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

function checkForm()
{
   var ch_pname, ch_addr, ch_city, ch_ocity, ch_country, ch_email, ch_contact; 
   
   with(window.document.cform)
   {
      ch_pname=name; 
	  ch_addr=addr;
	  ch_city=city;
	  ch_ocity=ocity;
	  ch_country=country;
	  ch_email= email;
	  ch_contact=contact;
	  //ch_dentist=dentist;
	  //ch_tech=tech;
   }
   
		var at="@"
		var dot="."
		var str=ch_email.value
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)		
		var atpos=str.indexOf(at)
		var dotpos=str.indexOf(dot)
		var dname= str.substring(atpos+1, dotpos)
		
		
  if(trim(ch_pname.value) == '')
   {
      alert('Please enter Your Full Name');
      ch_pname.focus();
      return false;	  
   }
   
   else if(trim(ch_addr.value) == '')
   {
      alert('Please enter Your Address');
      ch_addr.focus();
      return false;	  
   }
   /*
   else if(trim(ch_city.value) == '')
   {
      alert('Please enter Your City');
      ch_city.focus();
      return false;	  
   }*/
   
   else if(trim(ch_city.value) == '-')
   {
      alert('Please enter Your City');
      ch_city.focus();
      return false;	  
   }
   
   else if(trim(ch_city.value) == 'other' && trim(ch_ocity.value) == '')
   {
      alert('Please enter Your City');
      ch_ocity.focus();
      return false;	  
   }
   else if(trim(ch_country.value) == '-')
   {
      alert('Please enter Your Country');
      ch_country.focus();
      return false;	  
   }
   
   else if(trim(ch_email.value) == '')
   {
      alert('Please enter Your Email Address');
      ch_email.focus();
      return false;	  
   }
   
	else if (!(emailFilter.test(ch_email.value))) { 
       alert("Please enter a valid Email Address.");
	   ch_email.focus()
	   return false
	}
	else if(trim(ch_contact.value) == '')
   {
      alert('Please enter your Contact Number');
      ch_contact.focus();
      return false;	  
   }  
   else if (checkInternationalPhone(ch_contact.value)==false){
		alert("Please Enter a Valid Phone Number")
		ch_contact.focus()
		return false
	}
	else if(dentist_selection=="")
   {
      alert('Are you Practising Dentist? kindly choose yes or no');
      //ch_changename.focus();
      return false;	  
   }
   else if(tech_selection=="")
   {
      alert('Are you Technician? kindly choose yes or no');
      //ch_changename.focus();
      return false;	  
   }
   else
   {      
   //alert(ch_resume.value);
	 cform.submit();
      return true;	  
   }
}

function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}
