//------------------------Employment Application Validator-------------------------------
function validApp(theForm){
		if (theForm.Position.selectedIndex == 0){
			alert("Please select a position to apply for.");
			theForm.Position.focus();
			return (false);
  		}
		var hoursOption = -1;
		for (i=0; i<theForm.Hours.length; i++) {
			if (theForm.Hours[i].checked) {
				hoursOption = i;
			}
		}
		if (hoursOption == -1) {
			alert("Please select full-time or part-time hours.");
			return (false);;
		}
		var previousOption = -1;
		for (i=0; i<theForm.Previous.length; i++) {
			if (theForm.Previous[i].checked) {
				previousOption = i;
			}
		}
		if (previousOption == -1) {
			alert("Please indicate if you have worked for Select Communications before.");
			return (false);
		}
		if (theForm.Available.value == ""){
			alert("Please indicate when you can begin work.");
			theForm.Available.focus();
			return (false);
  		}
		if (theForm.Name.value == ""){
			alert("Please enter your name.");
			theForm.Name.focus();
			return (false);
  		}
		var Phone=theForm.Phone
		if (Phone.value == ""){
			alert("Please enter your phone number.");
			theForm.Phone.focus();
			return (false);
  		}
		if (checkInternationalPhone(Phone.value)==false){
			alert("Please enter a valid 10 digit phone number");
			Phone.focus();
			return (false);
		}
		if (theForm.Address1.value == ""){
			alert("Please enter your address.");
			theForm.Address1.focus();
			return (false);
  		}
		if (theForm.City.value == ""){
			alert("Please enter your city.");
			theForm.City.focus();
			return (false);
  		}
		if (theForm.Province.value == ""){
			alert("Please enter your province.");
			theForm.Province.focus();
			return (false);
  		}
		if (theForm.Postal.value == ""){
			alert("Please enter your postal code.");
			theForm.Postal.focus();
			return (false);
  		}
		if (theForm.email.value != ""){
			var emailID = theForm.email;
			if (echeck(emailID.value)==false){
				emailID.focus();
				return (false);
			}
		}
		var highschoolOption = -1;
		for (i=0; i<theForm.Highschool.length; i++) {
			if (theForm.Highschool[i].checked) {
				highschoolOption = i;
			}
		}
		if (highschoolOption == -1) {
			alert("Please indicate if you have a high school diploma.");
			return (false);
		}
		return (true);
	}

//------------------------Employment P3 Survey Validator-------------------------------
function validP3(theForm) {
	if (theForm.Name.value == ""){
		alert("Please enter your name.");
		theForm.Name.focus();
		return (false);
	}
	if (theForm.Contact_Information.value == ""){
		alert("Please enter your contact information.");
		theForm.Contact_Information.focus();
		return (false);
	}
	var el = document.forms[0].elements;
	for(var i = 0 ; i < el.length ; ++i) {
		if(el[i].type == "radio") {
			var radiogroup = el[el[i].name];
			var itemchecked = false;
			for(var j = 0 ; j < radiogroup.length ; ++j) {
				if(radiogroup[j].checked) {
					itemchecked = true;
					break;
				}
			}
			if(!itemchecked) {
				alert("Please make a selection");
				if(el[i].focus) el[i].focus();
				return false;
			}
		}
	}
	return true;
} 

//------------------------Phone Number and Numeric Validator-------------------------------
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);
}

//------------------------Email Address Validator-------------------------------
function echeck(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Please enter a valid email address.");
	   return (false);
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Please enter a valid email address.");
	   return (false);
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Please enter a valid email address.");
		return (false);
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Please enter a valid email address.");
		return (false);
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter a valid email address.");
		return (false);
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Please enter a valid email address.");
		return (false);
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Please enter a valid email address.");
		return (false);
	 }
	 return (true);
}

//------------------------Send a Page Validator-------------------------------
function validPage(theForm){
	bValid=true;
	if (theForm.pnum.value == ""){
        alert("You must enter a pager number.");
        theForm.pnum.focus();
		bValid=false;
		return (false);
	}
	if (theForm.pnum.value.length < 7){
        alert("You must enter a valid pager number.");
        theForm.pnum.focus();
		bValid=false;
		return (false);
	}
	if (isInteger(theForm.pnum.value)==false){
			alert("Please enter a valid pager number.");
			theForm.pnum.focus();
			bValid=false;
			return (false);
		}
	if(theForm.message.value==""){
        alert("You must enter a message to send.");
        theForm.message.focus();
        bValid=false;
		return (false);
	}
	if(theForm.message.value.length > 180){
        alert("Your message is too long. Please shorten it.");
        theForm.message.focus();
        bValid=false;
		return (false);
	}
}

//------------------------Start Service Validator-------------------------------
function validStart(theForm){
	if (theForm.companyName.value == ""){
        alert("You must enter your company name.");
        theForm.companyName.focus();
		return (false);
	}
	if (theForm.contactName.value == ""){
        alert("You must enter your name.");
        theForm.contactName.focus();
		return (false);
	}
	var Phone=theForm.contactPhone;
	if (Phone.value == ""){
		alert("Please enter your phone number.");
		Phone.focus();
		return (false);
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please enter a valid 10 digit phone number");
		Phone.focus();
		return (false);
	}
	return (true);
}

//------------------------White Paper Validator-------------------------------
function validPaper(theForm){
	if (theForm.fname.value == ""){
        alert("Please enter your first name.");
        theForm.fname.focus();
		return (false);
	}
	if (theForm.lname.value == ""){
        alert("Please enter your last name.");
        theForm.lname.focus();
		return (false);
	}
	if (theForm.company.value == ""){
        alert("Please enter your company name.");
        theForm.company.focus();
		return (false);
	}
	if (theForm.address.value == ""){
        alert("Please enter your address.");
        theForm.address.focus();
		return (false);
	}
	if (theForm.city.value == ""){
        alert("Please enter your city.");
        theForm.city.focus();
		return (false);
	}
	if (theForm.state.selectedIndex == 0){
        alert("Please select a state.");
        theForm.state.focus();
		return (false);
	}
	if (theForm.zip.value == ""){
        alert("Please enter your postal code/zip.");
        theForm.zip.focus();
		return (false);
	}
	if (theForm.phone1.value == ""){
        alert("Please enter your phone number.");
        theForm.phone1.focus();
		return (false);
	}
	if (theForm.phone2.value == ""){
        alert("Please enter your phone number.");
        theForm.phone2.focus();
		return (false);
	}
	if (theForm.phone3.value == ""){
        alert("Please enter your phone number.");
        theForm.phone3.focus();
		return (false);
	}
	if (theForm.email.value == ""){
        alert("Please enter your email address. The article will be sent to this address.");
        theForm.email.focus();
		return (false);
	}
	return (true);
}