/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

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 ValidateForm(){
	var homePhone=document.FastTrackForm.homePhone;
	var mobilePhone=document.FastTrackForm.mobilePhone;
	var email=document.FastTrackForm.email;
	var fname=document.FastTrackForm.firstName;
	var lname=document.FastTrackForm.lastName;
	var address=document.FastTrackForm.address;
	var state=document.FastTrackForm.state;
	var city=document.FastTrackForm.city;
	var zip=document.FastTrackForm.zip;
	var country=document.FastTrackForm.country;
	var time=document.FastTrackForm.available;
	var primary = document.FastTrackForm.primaryPosition;
	var rate = document.FastTrackForm.rate;
	var startM = document.FastTrackForm.startMonth;
	var startD = document.FastTrackForm.startDay;
	var startY = document.FastTrackForm.startYear;
	
	
	if (fname.value == ""){
		alert("Please Provide Your First Name")
		fname.focus()
		return false
	}
	
	if (lname.value == ""){
		alert("Please Provide Your Last Name")
		lname.focus()
		return false
	}
	
	//E-mail	
	if (email.value == "" || ((email.value.indexOf ('@',0) == -1 ||	email.value.indexOf ('.',0) == -1) &&	email.value != "")) {
    alert("Please Provide a Valid E-mail Address");
		email.value="";
		email.focus();
		return false;
  }
	
	if (address.value == ""){
		alert("Please Provide Your Address")
		address.focus()
		return false
	}
	
	if (city.value == ""){
		alert("Please Provide Your City")
		city.focus()
		return false
	}

	if (state.value == "" && country.value == "United States"){
		alert("Please Provide Your State")
		state.focus()
		return false
	}
	
	if (zip.value == ""){
		alert("Please Provide Your Zip Code")
		zip.focus()
		return false
	}

	if (country.value == ""){
		alert("Please Provide Your Country")
		country.focus()
		return false
	}
	
	
  	
	//Phone
	if (homePhone.value=="" && mobilePhone.value==""){
		alert("At least one phone number is required")
		homePhone.focus()
		return false
	}
	
	if (homePhone.value!="" && checkInternationalPhone(homePhone.value)==false){
		alert("Please Enter a Valid Phone Number")
		homePhone.value=""
		homePhone.focus()
		return false
	}
	
	if (mobilePhone.value!="" && checkInternationalPhone(mobilePhone.value)==false){
		alert("Please Enter a Valid Phone Number")
		mobilePhone.value=""
		mobilePhone.focus()
		return false
	}
		
	if (time.value == ""){
		alert("Please Provide Your Availability")
		time.focus()
		return false
	}
	
	if(primary.value=="defaultPrimaryPosition") {
		alert("Please Choose a Primary Position");
		primary.focus();
		return false;
	}
	
	if(rate.value=="defaultRate") {
		alert("Please Rate Yourself");
		rate.focus();
		return false;
	}
	
	if(startM.value=="") {
		alert("Please select month");
		startM.focus();
		return false;
	}
	
		if(startD.value=="") {
		alert("Please select day");
		startD.focus();
		return false;
	}
	
		if(startY.value=="") {
		alert("Please select year");
		startY.focus();
		return false;
	}
	
	return true;
 }