<!--
// JavaScript Document
function SubmitForm() {
	/*the lovely little piece will verify that each of the fields are 
	populated.  the only one that isn't much of a concern is the other referral source
	which is only required if they choose other
	*/
	//get our values into some variables
	var thisForm=document.getElementById("infoForm");
	//disable the submit button
	thisForm.cmdSubmit.disabled=true;
	
	var fName = thisForm.firstName.value;
	var	lName = thisForm.lastName.value;
	var jTitle = thisForm.jobTitle.value;
	var theOrg = thisForm.Organization.value;
	var theAddress = thisForm.Address.value;
	var theCity = thisForm.City.value;
	var theState = thisForm.State.value;
	var phoneArea = thisForm.areaCode.value;
	var phonePrefix = thisForm.phoneThree.value;
	var phoneSuffix = thisForm.phoneFour.value;
	var eMail = thisForm.email.value;
	var sendSpeaking = thisForm.speaking.checked;
	var sendTraining = thisForm.training.checked;
	var sendKit = thisForm.press.checked;
	var infoComments = thisForm.userComments.value;
	
	//ok we have everything, basically we aren't going to validate to make sure that each field has a value that isn't all spaces
	fName = removeExtraSpaces(fName, " ");
	fName = removeLeadingAndTrailingChar(fName," ");	
	if (fName == "") {
		alert("Please supply your first name.");
		thisForm.firstName.focus();
		thisForm.firstName.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end fName check
	
	lName = removeExtraSpaces(lName, " ");
	lName = removeLeadingAndTrailingChar(lName, " ");	
	if (lName == "") {
		alert("Please supply your last name.");
		thisForm.lastName.focus();
		thisForm.lastName.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end lName check
	
	jTitle = removeExtraSpaces(jTitle, " ");
	jTitle = removeLeadingAndTrailingChar(jTitle, " ");
	if (jTitle == "") {
		alert ("Please indicate your job title within your organization.");
		thisForm.jobTitle.focus();
		thisForm.jobTitle.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end jTitle check
	
	theOrg = removeExtraSpaces(theOrg, " ");
	theOrg = removeLeadingAndTrailingChar(theOrg, " ");
	if (theOrg == "") {
		alert ("Please supply your organization.");
		thisForm.Organization.focus();
		thisForm.Organization.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end org check
	
	theAddress = removeExtraSpaces(theAddress, " ");
	theAddress = removeLeadingAndTrailingChar(theAddress, " ");
	if (theAddress == "") {
		alert ("Please supply your address.");
		thisForm.Address.focus();
		thisForm.Address.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end addresscheck

	theCity = removeExtraSpaces(theCity, " ");
	theCity = removeLeadingAndTrailingChar(theCity, " ");
	if (theCity == "") {
		alert ("Please supply your city.");
		thisForm.City.focus();
		thisForm.City.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end addresscheck

	theState = removeExtraSpaces(theState, " ");
	theState = removeLeadingAndTrailingChar(theState, " ");
	if (theState == "" || theState.length != 2) {
		alert ("Please supply your state.");
		thisForm.State.focus();
		thisForm.State.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end addresscheck


	phoneArea = removeExtraSpaces(phoneArea, " ");
	phoneArea = removeLeadingAndTrailingChar(phoneArea, " ");
	if (phoneArea.length != 3) {
		alert("Please enter a valid area code.");
		thisForm.areaCode.focus();
		thisForm.areaCode.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end area code check

	//if they get by that, then we need to check to make sure that they are all numeric
	for (x=0; x < phoneArea.length; x++) {
		if (isNaN(parseInt(phoneArea.charAt(x)))) {
			alert ("Please enter a valid area code.");
			thisForm.areaCode.focus();
			thisForm.areaCode.select();
			thisForm.cmdSubmit.disabled=false;
			return
		} //end if
	}//end of
		
	phonePrefix = removeExtraSpaces(phonePrefix, " ");
	phonePrefix = removeLeadingAndTrailingChar(phonePrefix, " ");
	if (phonePrefix.length != 3) {
		alert("Please enter a valid phone prefix.");
		thisForm.phoneThree.focus();
		thisForm.phoneThree.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end phone prefix check

	for (x=0; x < phonePrefix.length; x++) {
		if (isNaN(parseInt(phonePrefix.charAt(x)))) {
			alert ("Please enter a valid phone prefix.");
			thisForm.phoneThree.focus();
			thisForm.phoneThree.select();
			thisForm.cmdSubmit.disabled=false;
			return
		} //end if
	}//end of
	
	phoneSuffix = removeExtraSpaces(phoneSuffix, " ");
	phoneSuffix = removeLeadingAndTrailingChar(phoneSuffix, " ");
	if (phoneSuffix.length != 4) {
		alert("Please enter a valid phone suffix.");
		thisForm.phoneFour.focus();
		thisForm.phoneFour.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end phone suffix check
	
	for (x=0; x < phoneSuffix.length; x++) {
		if (isNaN(parseInt(phoneSuffix.charAt(x)))) {
			alert ("Please enter a valid phone suffix.");
			thisForm.phoneFour.focus();
			thisForm.phoneFour.select();
			thisForm.cmdSubmit.disabled=false;
			return
		} //end if
	}//end of	
	
	eMail = removeExtraSpaces(eMail, " ");
	eMail = removeLeadingAndTrailingChar(eMail, " ");
	if (eMail == "") {
		alert("Please enter a valid Email address.");
		thisForm.email.focus();
		thisForm.email.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end email check
	
	//used to indicate presence of a character
	var isPresent=false;
	
	//verify that the @ symbol is present and that there is a .net/.com/somethign
	for (x=0; x < eMail.length; x++) {
		if (eMail.charAt(x) == "@") {
			isPresent = true;
			break
		} //end if
	} //end for
	
	if (!isPresent) {
		alert ("Please enter a valid Email address.");
		thisForm.email.focus();
		thisForm.email.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}//end @ email check
	
	isPresent=false;

	//find the .
	for (x=0; x < eMail.length; x++) {
		if (eMail.charAt(x) == ".") {
			isPresent=true;
			var dotPosition = x + 1;	//we don't want the dot
			break
		}//end if
	}//end for
	
	if (!isPresent) {
		alert("Please enter a valid Email address.");
		thisForm.email.focus();
		thisForm.email.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}
	else {
		//get the domain extension
		var domainExt = eMail.substring(dotPosition, eMail.length);
		//make sure there is a valid top level domain extension
		switch (domainExt) {
			case "com":
				break;
			case "biz":
				break;
			case "cc":
				break;
			case "org":
				break;
			case "tv":
				break;
			case "net":
				break;
			case "info":
				break;
			case "bz":
				break;
			case "us":
				break;
			default:
				//fired when none of the above are shot off
				alert ("Please enter a valid Email address.");
				thisForm.email.focus();
				thisForm.email.select();
				thisForm.cmdSubmit.disabled=false;
				return
		}//end TLD ext switch
	}//end extension check
	
	//check to make sure one product is selected
	if(!sendSpeaking && !sendTraining && !sendKit) {
		alert("Please select a product or service.");
		thisForm.cmdSubmit.disabled=false;
		return
	}
	
	/*/ last field comments
	infoComments = removeExtraSpaces(infoComments, " ");
	infoComments = removeLeadingAndTrailingChar(infoComments, " ");
	if (infoComments == "") {
		alert("Please provide comments on what information you would be interested in receiving.");
		thisForm.userComments.focus();
		thisForm.userComments.select();
		thisForm.cmdSubmit.disabled=false;
		return
	}/end comments check
	*/
	
	//now prepare the URL for the submission ASP page
	var aspURL = "";
	aspURL = "sendemail.asp?First=" + fName;
	aspURL = aspURL + "&Last=" + lName;
	aspURL = aspURL + "&Title=" + jTitle;
	aspURL = aspURL + "&Org=" + theOrg;
	aspURL = aspURL + "&Add=" + theAddress;
	aspURL = aspURL + "&City=" + theCity;
	aspURL = aspURL + "&State=" + theState;
	aspURL = aspURL + "&Phone=" + phoneArea + "-" + phonePrefix + "-" + phoneSuffix;
	aspURL = aspURL + "&Email=" + eMail;
	aspURL = aspURL + "&Speak=" + sendSpeaking;
	aspURL = aspURL + "&Train=" + sendTraining;
	aspURL = aspURL + "&Kit=" + sendKit;
	aspURL = aspURL + "&Comments=" + infoComments;
	
//	alert(aspURL);
	location.href = aspURL;
	return
}//end submitform function

function removeLeadingAndTrailingChar (inputString, removeChar) 
{
	var returnString = inputString;
	if (removeChar.length)
	{
	  while(''+returnString.charAt(0)==removeChar)
		{
		  returnString=returnString.substring(1,returnString.length);
		}
		while(''+returnString.charAt(returnString.length-1)==removeChar)
	  {
	    returnString=returnString.substring(0,returnString.length-1);
	  }
	}
	return returnString;
}//end removelead... function

function removeExtraSpaces(string, delimiter)
{
  var returnString = "";
  splitstring = string.split(delimiter);
  for(i = 0; i < splitstring.length; i++)
    {
    if (splitstring[i]!="") returnString += splitstring[i] + delimiter;
    }
  return returnString;
}//end removespa... function
//-->
//-->