

function isEmailAddr(email)
	{
 	 var result = false
  	var theStr = new String(email)
  	var index = theStr.indexOf("@");
 	 if (index > 0)
  		{
   		 var pindex = theStr.indexOf(".",index);
   		 if ((pindex > index+1) && (theStr.length > pindex+1))
		result = true;
  		}
  		return result;
}





var digits = "0123456789";

var phoneNumberDelimiters = "()- ";

var validWorldPhoneChars = phoneNumberDelimiters + "+";

var minDigitsInIPhoneNumber = 1;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        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);
}

function ValidatePhone(){
	var Phone=document.form1.phone

	
	
	
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please provide Contact Number.")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please provide valid Contact Number.")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }
 
 











function ValidateForm2 (which) {
	//--- validate the register form
	
		var temp = '';
		temp = which.elements['typework'].value;
		if (temp == '') {
			alert ('Please select Type of Locum work you are seeking.');
			which.elements['typework'].focus ();
			return false;
		}
		

		temp = which.elements['aboutus'].value;
		if (temp == '') {
			alert ('Please select How Did you hear about Medic Oncall?');
			which.elements['aboutus'].focus ();
			return false;
		}

		temp = which.elements['fname'].value;
		if (temp == '') {
			alert ('Please enter YOUR NAME.');
			which.elements['fname'].focus ();
			return false;
		}
		
		temp = which.elements['sname'].value;
		if (temp == '') {
			alert ('Please enter YOUR SURNAME.');
			which.elements['sname'].focus ();
			return false;
		}
		temp = which.elements['nationality'].value;
		if (temp == '') {
			alert ('Please select YOUR NATIONALITY.');
			which.elements['nationality'].focus ();
			return false;
		}
		
		temp = which.elements['livein'].value;
		if (temp == '') {
			alert ('Please enter Where you LIVE IN.');
			which.elements['livein'].focus ();
			return false;
		}
		

		
		

		temp = which.elements['phone'].value;
		
	if (!ValidatePhone(temp))
 		 {
   				 which.elements['phone'].focus();
    			 return (false);
	 	 }
		
		
		
		
		
		//--- validate email address
		var temp = '';
		temp = which.elements['email'].value;
		if (!isEmailAddr(temp)) {
			alert ('Please enter an email address.');
			which.elements['email'].focus ();
			return false;
		} else {
			
			temp1 = which.elements['ConfirmEmail'].value;
			Login = which.elements['email'].value;
			if (temp1 != Login) {
				alert ('Your email and confirmed email address are not the same, please re-enter the two values.');
				which.elements['email'].focus ();
				return false;
			}
		}
		
		temp = which.elements['attach1'].value;
		if (temp == '') {
			
			return true;
		} else {
if (!/(\.(doc|pdf))$/i.test(which.elements['attach1'].value)){
alert("Please attach Valid File.");
which.elements['attach1'].focus ();
		
		return false;
			}
		}
		

		 
		
		



	}



		
		



