function checkForm() { 

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;//January is 0!
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd}
if(mm<10){mm='0'+mm}
var formDate = mm + "/" + dd + "/" + yyyy;
document.subscribeForm.elements['Date Entered'].value=formDate;

if (isEmpty(document.subscribeForm.elements['First Name'].value))
{
document.subscribeForm.elements['First Name'].style.backgroundColor='yellow';
alert("Please enter your First Name!");
document.subscribeForm.elements['First Name'].select();
document.subscribeForm.elements['First Name'].focus();
return false;
} else {
document.subscribeForm.elements['First Name'].style.backgroundColor='white';
}

if (isEmpty(document.subscribeForm.elements['Last Name'].value))
{
document.subscribeForm.elements['Last Name'].style.backgroundColor='yellow';
alert("Please enter your Last Name!");
document.subscribeForm.elements['Last Name'].select();
document.subscribeForm.elements['Last Name'].focus();
return false;
} else {
document.subscribeForm.elements['Last Name'].style.backgroundColor='white';
}

if ((document.subscribeForm.elements['Preferred Method of Contact'].options[0].selected) && (isEmpty(document.subscribeForm.elements['Email Address'].value)))
{
document.subscribeForm.elements['Email Address'].style.backgroundColor='yellow';
alert("Please enter your Email Address!");
document.subscribeForm.elements['Email Address'].select();
document.subscribeForm.elements['Email Address'].focus();
return false;
} else {
document.subscribeForm.elements['Email Address'].style.backgroundColor='white';
}

if ((document.subscribeForm.elements['Preferred Method of Contact'].options[1].selected) && (isEmpty(document.subscribeForm.elements['Email Address'].value)))
{
document.subscribeForm.elements['Email Address'].style.backgroundColor='yellow';
alert("Please enter your Email Address!");
document.subscribeForm.elements['Email Address'].select();
document.subscribeForm.elements['Email Address'].focus();
return false;
} else {
document.subscribeForm.elements['Email Address'].style.backgroundColor='white';
}

if (!isEmpty(document.subscribeForm.elements['Email Address'].value))
{
if (!isValidEmail(document.subscribeForm.elements['Email Address'].value)) {
	document.subscribeForm.elements['Email Address'].style.backgroundColor='yellow';
	alert("Please enter a valid Email Address. (name@host.com)");
	document.subscribeForm.elements['Email Address'].focus();
	return false;
} else {
document.subscribeForm.elements['Email Address'].style.backgroundColor='white';
}
}

if ((document.subscribeForm.elements['Preferred Method of Contact'].options[0].selected) && (isEmpty(document.subscribeForm.elements['Mobile Phone'].value)))
{
document.subscribeForm.elements['Mobile Phone'].style.backgroundColor='yellow';
alert("Please enter your Mobile Phone Number!");
document.subscribeForm.elements['Mobile Phone'].select();
document.subscribeForm.elements['Mobile Phone'].focus();
return false;
} else {
document.subscribeForm.elements['Mobile Phone'].style.backgroundColor='white';
}

if ((document.subscribeForm.elements['Preferred Method of Contact'].options[2].selected) && (isEmpty(document.subscribeForm.elements['Mobile Phone'].value)))
{
document.subscribeForm.elements['Mobile Phone'].style.backgroundColor='yellow';
alert("Please enter your Mobile Phone Number!");
document.subscribeForm.elements['Mobile Phone'].select();
document.subscribeForm.elements['Mobile Phone'].focus();
return false;
} else {
document.subscribeForm.elements['Mobile Phone'].style.backgroundColor='white';
}

if (!isEmpty(document.subscribeForm.elements['Mobile Phone'].value))
{
if (checkInternationalPhone(document.subscribeForm.elements['Mobile Phone'].value)==false){
document.subscribeForm.elements['Mobile Phone'].style.backgroundColor='yellow';
alert("Please enter a valid Mobile Phone number!");
document.subscribeForm.elements['Mobile Phone'].focus();
return false;
} else {
document.subscribeForm.elements['Mobile Phone'].style.backgroundColor='white';
document.subscribeForm.elements['Mobile Phone'].value=stripCharsInBag(document.subscribeForm.elements['Mobile Phone'].value,validWorldPhoneChars);
}
}

if (document.subscribeForm.elements['Country'].options[document.subscribeForm.elements['Country'].selectedIndex].value=="")
{
alert("Please select your Country!");
document.subscribeForm.elements['Country'].focus();
return false;
} 

if (document.subscribeForm.elements['State or Province'].options[document.subscribeForm.elements['State or Province'].selectedIndex].value=="")
{
alert("Please select your State or Province!");
document.subscribeForm.elements['State or Province'].focus();
return false;
} 

if (isEmpty(document.subscribeForm.elements['Zip or Postal Code'].value))
{
document.subscribeForm.elements['Zip or Postal Code'].style.backgroundColor='yellow';
alert("Please enter your Zip or Postal Code!");
document.subscribeForm.elements['Zip or Postal Code'].select();
document.subscribeForm.elements['Zip or Postal Code'].focus();
return false;
} else {
document.subscribeForm.elements['Zip or Postal Code'].style.backgroundColor='white';
}

if (!isValidZip(document.subscribeForm.elements['Zip or Postal Code'].value)) 
{
document.subscribeForm.elements['Zip or Postal Code'].style.backgroundColor='yellow';
alert("Please enter a valid Zip or Postal Code!");
document.subscribeForm.elements['Zip or Postal Code'].select();
document.subscribeForm.elements['Zip or Postal Code'].focus();
return false;
} else {
document.subscribeForm.elements['Zip or Postal Code'].style.backgroundColor='white';
}
	

if (document.subscribeForm.elements['Preferred Method of Contact'].options[1].selected)
{
document.subscribeForm.action="http://cl.s4.exct.net/subscribe.aspx";
}

if (document.subscribeForm.elements['Preferred Method of Contact'].options[2].selected)
{
document.subscribeForm.SubscriberKey.value=document.subscribeForm.elements['Mobile Phone'].value;
document.subscribeForm.elements['State'].value=document.subscribeForm.elements['State or Province'].value;
document.subscribeForm.elements['Zip'].value=document.subscribeForm.elements['Zip or Postal Code'].value;
document.subscribeForm.Phone.value=document.subscribeForm.elements['Mobile Phone'].value;
document.subscribeForm.action="http://cl.s4.exct.net/DEManager.aspx";
}

if (document.subscribeForm.elements['Preferred Method of Contact'].options[0].selected)
{
SubscriberKey=document.subscribeForm.elements['Email Address'].value;
var myCountry=document.subscribeForm.elements['Country'].value;
var myState=document.subscribeForm.elements['State or Province'].value;
var myZip=document.subscribeForm.elements['Zip or Postal Code'].value;
var myAddress=document.subscribeForm.elements['Address'].value;
var myCity=document.subscribeForm.elements['City'].value;
var myPhone=document.subscribeForm.elements['Mobile Phone'].value;
var myDateEntered=document.subscribeForm.elements['Date Entered'].value;
var myFirstName=document.subscribeForm.elements['First Name'].value;
var myLastName=document.subscribeForm.elements['Last Name'].value;
var mySource=document.subscribeForm.elements['Source'].value;
var myCD=getSelectedRadioValue(document.subscribeForm.elements['Company Driver']);
var myDedicated=getSelectedCheckboxValue(document.subscribeForm.Dedicated);
var myIntermodal=getSelectedCheckboxValue(document.subscribeForm.Intermodal);
var myOO=getSelectedRadioValue(document.subscribeForm.elements['Owner Operator']);
var myOTR=getSelectedCheckboxValue(document.subscribeForm.elements['Over The Road']);
var myPortDray=getSelectedCheckboxValue(document.subscribeForm.elements['Port Dray']);
var myRegional=getSelectedCheckboxValue(document.subscribeForm.Regional);
var myTanker=getSelectedCheckboxValue(document.subscribeForm.Tanker);
var myTeam=getSelectedCheckboxValue(document.subscribeForm.Team);
document.subscribeForm.thx.value="http://www.schneiderjobs.com/cgi-bin/etform.cgi?&_deExternalKey=SMS_Website_Subscribers&_action=add&_returnXML=0&_successURL=http://www.schneiderjobs.com/ThankYou&_errorURL=http://www.schneiderjobs.com/cgi-bin/eterror.cgi&_clientID=1001334&SubscriberKey="+document.subscribeForm.elements['Email Address'].value+"&Country="+myCountry+"&State="+myState+"&Zip="+myZip+"&Address="+myAddress+"&City="+myCity+"&Phone="+myPhone+"&Date%20Entered="+myDateEntered+"&First%20Name="+myFirstName+"&Last%20Name="+myLastName+"&Preferred%20Method%20of%20Contact=Both&Source="+mySource+"&Company%20Driver="+myCD+"&Owner%20Operator="+myOO+"&Dedicated="+myDedicated+"&Team="+myTeam+"&Intermodal="+myIntermodal+"&Regional="+myRegional+"&Port%20Dray="+myPortDray+"&Tanker="+myTanker+"&Over%20The%20Road="+myOTR;
document.subscribeForm.action="http://cl.s4.exct.net/subscribe.aspx";
}
}

// isEmail (STRING s [, BOOLEAN emptyOK])
// whitespace characters
var whitespace = " \t\n\r";

// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
function isValidEmail(s)
{   
	if (isEmpty(s)) return false;
   
	// is s whitespace?
	if (isWhitespace(s)) return false;
	    
	// there must be >= 1 character before @, so we
	// start looking at character position 1 
	// (i.e. second character)
	var i = 1;
	var sLength = s.length;

	// look for @
	while ((i < sLength) && (s.charAt(i) != "@"))
	{ i++
	}

	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;

	// look for .
	while ((i < sLength) && (s.charAt(i) != "."))
	{ i++
	}

	// there must be at least one character after the .
	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}

// Check whether string s is empty.
function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace(s)
{   
	var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);

		if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}

// 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 trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}

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){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function


function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function                                                                                          
                                                                                                                  

function isValidZip(s)
{
if (s.match(/^[0-9]{5}$/)) {
return true;
}
s=s.toUpperCase();
if (s.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/)) {
return true;
}
if (s.match(/^[A-Z][0-9][A-Z].[0-9][A-Z][0-9]$/)) {
return true;
}
return false;
} 

function fillCountry(){ 
 // this function is used to fill the country list on load
addOption(document.subscribeForm.Country, "USA", "USA", "");
addOption(document.subscribeForm.Country, "Canada", "Canada", "");
}

function SelectState(){
// ON selection of category this function will work

removeAllOptions(document.subscribeForm.elements['State or Province']);
addOption(document.subscribeForm.elements['State or Province'], "", "State or Province", "");

if(document.subscribeForm.Country.value == 'USA'){
addOption(document.subscribeForm.elements['State or Province'],"AL","AL");
addOption(document.subscribeForm.elements['State or Province'],"AK","AK");
addOption(document.subscribeForm.elements['State or Province'],"AZ","AZ");
addOption(document.subscribeForm.elements['State or Province'],"AR","AR");
addOption(document.subscribeForm.elements['State or Province'],"CA","CA");
addOption(document.subscribeForm.elements['State or Province'],"CO","CO");
addOption(document.subscribeForm.elements['State or Province'],"CT","CT");
addOption(document.subscribeForm.elements['State or Province'],"DE","DE");
addOption(document.subscribeForm.elements['State or Province'],"DC","DC");
addOption(document.subscribeForm.elements['State or Province'],"FL","FL");
addOption(document.subscribeForm.elements['State or Province'],"GA","GA");
addOption(document.subscribeForm.elements['State or Province'],"HI","HI");
addOption(document.subscribeForm.elements['State or Province'],"ID","ID");
addOption(document.subscribeForm.elements['State or Province'],"IL","IL");
addOption(document.subscribeForm.elements['State or Province'],"IN","IN");
addOption(document.subscribeForm.elements['State or Province'],"IA","IA");
addOption(document.subscribeForm.elements['State or Province'],"KS","KS");
addOption(document.subscribeForm.elements['State or Province'],"KY","KY");
addOption(document.subscribeForm.elements['State or Province'],"LA","LA");
addOption(document.subscribeForm.elements['State or Province'],"ME","ME");
addOption(document.subscribeForm.elements['State or Province'],"MD","MD");
addOption(document.subscribeForm.elements['State or Province'],"MA","MA");
addOption(document.subscribeForm.elements['State or Province'],"MI","MI");
addOption(document.subscribeForm.elements['State or Province'],"MN","MN");
addOption(document.subscribeForm.elements['State or Province'],"MS","MS");
addOption(document.subscribeForm.elements['State or Province'],"MO","MO");
addOption(document.subscribeForm.elements['State or Province'],"MT","MT");
addOption(document.subscribeForm.elements['State or Province'],"NE","NE");
addOption(document.subscribeForm.elements['State or Province'],"NV","NV");
addOption(document.subscribeForm.elements['State or Province'],"NH","NH");
addOption(document.subscribeForm.elements['State or Province'],"NJ","NJ");
addOption(document.subscribeForm.elements['State or Province'],"NM","NM");
addOption(document.subscribeForm.elements['State or Province'],"NY","NY");
addOption(document.subscribeForm.elements['State or Province'],"NC","NC");
addOption(document.subscribeForm.elements['State or Province'],"ND","ND");
addOption(document.subscribeForm.elements['State or Province'],"OH","OH");
addOption(document.subscribeForm.elements['State or Province'],"OK","OK");
addOption(document.subscribeForm.elements['State or Province'],"OR","OR");
addOption(document.subscribeForm.elements['State or Province'],"PA","PA");
addOption(document.subscribeForm.elements['State or Province'],"RI","RI");
addOption(document.subscribeForm.elements['State or Province'],"SC","SC");
addOption(document.subscribeForm.elements['State or Province'],"SD","SD");
addOption(document.subscribeForm.elements['State or Province'],"TN","TN");
addOption(document.subscribeForm.elements['State or Province'],"TX","TX");
addOption(document.subscribeForm.elements['State or Province'],"UT","UT");
addOption(document.subscribeForm.elements['State or Province'],"VT","VT");
addOption(document.subscribeForm.elements['State or Province'],"VA","VA");
addOption(document.subscribeForm.elements['State or Province'],"WA","WA");
addOption(document.subscribeForm.elements['State or Province'],"WV","WV");
addOption(document.subscribeForm.elements['State or Province'],"WI","WI");
addOption(document.subscribeForm.elements['State or Province'],"WY","WY");
}
if(document.subscribeForm.Country.value == 'Canada'){
addOption(document.subscribeForm.elements['State or Province'],"AB", "AB");
addOption(document.subscribeForm.elements['State or Province'],"BC", "BC");
addOption(document.subscribeForm.elements['State or Province'],"MB", "MB");
addOption(document.subscribeForm.elements['State or Province'],"NB", "NB");
addOption(document.subscribeForm.elements['State or Province'],"NL", "NL");
addOption(document.subscribeForm.elements['State or Province'],"NS", "NS");
addOption(document.subscribeForm.elements['State or Province'],"NU", "NU");
addOption(document.subscribeForm.elements['State or Province'],"ON", "ON");
addOption(document.subscribeForm.elements['State or Province'],"PE", "PE");
addOption(document.subscribeForm.elements['State or Province'],"QC", "QC");
addOption(document.subscribeForm.elements['State or Province'],"SK", "SK");
addOption(document.subscribeForm.elements['State or Province'],"YT", "YT");
}


}
////////////////// 

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}


