// JavaScript Document

function setFields() {
	if (document.customForm.plAreas_of_Interest.value=="Expense Management") {
			setDisplayOn('expfields');
			setDisplayOff('wfmfields');
		}
	else {
		if (document.customForm.plAreas_of_Interest.value=="Workforce Management") {
			setDisplayOn('wfmfields');
			setDisplayOff('expfields');
		}
		else {
			if (document.customForm.plAreas_of_Interest.value=="Both Products") {
			setDisplayOn('wfmfields');
			setDisplayOn('expfields');
			}
		}
	}
		
}
function setCountryFields() {
	if (document.customForm.Country.value=="USA") {
			setDisplayOn('usfields');
			setDisplayOff('gbfields');
			setDisplayOff('nonusfields');
		}
	else if (document.customForm.Country.value=="United Kingdom") {
			setDisplayOff('usfields');
			setDisplayOn('gbfields');
			setDisplayOff('nonusfields');
		}
	else {
			setDisplayOff('usfields');
			setDisplayOff('gbfields');
			setDisplayOn('nonusfields');
		}
		
}
function setPurchasingFields() {
	if (document.customForm.plActively_Evaluating_Systems.value=="Yes") {
			setDisplayOn('timeframe');
		}
	else {
			setDisplayOff('timeframe');
		}
		
}
function setDisplayOn(currMenu) {
	if (document.getElementById) {
		thisMenu = document.getElementById(currMenu).style
		if (thisMenu.display == "block") {
			thisMenu.display = "block"
			}
		else {
			thisMenu.display = "block"
			}
		return true
		}
	else {
		return true
		}
}

function setDisplayOff(currMenu) {
	if (document.getElementById) {
		thisMenu = document.getElementById(currMenu).style
		if (thisMenu.display == "block") {
			thisMenu.display = "none"
			}
		else {
			thisMenu.display = "none"
			}
		return true
		}
	else {
		return true
		}
}

function isNotEmpty(String) {
   // Return false if "string" is empty or all blank
  if (String.length == 0) {return (false);}
  for (var i=0; i < String.length; i++) {
    if (String.substring(i) != " ") {return (true);}
  }
  return (false);
}

function submitRegistration(regform) {
	var strFirstName=regform.LeadFirstName.value,
	 	strLastName=regform.LeadLastName.value,
		strTitle=regform.JobTitle.value,
		strAccountName=regform.Company.value,
		strWorkPhone=regform.PrimaryPhone.value,
		strPhoneExt=regform.PhoneExt.value,
		strEMail=regform.LeadEmail.value,
		strConfirmEMail=regform.confirmEmail.value,
//		strAreaInterest=regform.plAreas_of_Interest.value,
//		strDescriptionofBus=regform.Description.value,
		strNumberOfEmployees=regform.NumberEmployees.value,
//		strNumberOfExpRpts=regform.nExpense_Reports_Per_Month.value,
		strAddress1=regform.StreetAddress.value,
		strCity=regform.City.value,
		strStateProvName=regform.StateProvince.value,
		strPostalCode=regform.ZipCode.value,
		strCountryName=regform.Country.value,
		strActivelyEvaluating=regform.plActively_Evaluating_Systems.value,
		strPurchasingTimeframe=regform.plPurchasing_Timeframe.value,
		strInfoRequested='',
		errors='';

	var normalizedWorkPhone = stripCharsInBag(strWorkPhone, phoneNumberDelimiters);

	if (regform.ltInformation_Requested[0].checked) {
//		regform.Account_InfoRequested.value+='Call Me Now;';
		strInfoRequested+='Workforce Scheduling Paper;';
		}
	if (regform.ltInformation_Requested[1].checked) {
//		regform.Account_InfoRequested.value+='Call Me Now;';
		strInfoRequested+='Call Me Now;';
		}
	if (regform.ltInformation_Requested[2].checked) {
//		regform.Account_InfoRequested.value+='Send Information;';
		strInfoRequested+='Send Product Information;';
		}
	if (regform.ltInformation_Requested[3].checked) {
//		regform.Account_InfoRequested.value+='Request a Demo;';
		strInfoRequested+='Request a Demo;';
		}
	if (regform.ltInformation_Requested[4].checked) {
//		regform.Account_InfoRequested.value+='Request a Brochure;';
		strInfoRequested+='Request a Brochure,';
		}
	if (!isNotEmpty(strFirstName)) { 
		errors+='First Name is required\n';
		}
	if (!isNotEmpty(strLastName)) { 
		errors+='Last Name is required\n';
		}
	if (!isNotEmpty(strTitle)) { 
		errors+='Your Title is required\n';
		}
	if (!isNotEmpty(strAccountName)) { 
		errors+='Company Name is required\n';
		}
	if (!isUSPhoneNumber(normalizedWorkPhone)) { 
		if (!isInternationalPhoneNumber(normalizedWorkPhone)) {
			errors+='A valid Business Phone number is required\n';
			}
		}		
	if (!isEmail(strEMail, false))  {
		errors+='The Email address entered is invalid\n';
		}
	else {
		if (!(strEMail==strConfirmEMail)) {
			errors+='The Email address does not match the Confirm Email address\n';
			}
		}
//	if (strAreaInterest=="") {
//		errors+='Please select the Products you are interested in\n';
//		}
//	if (!isNotEmpty(strDescriptionofBus)) { 
//		errors+='Please select a Business Description\n';
//		}
	if (!isNotEmpty(strNumberOfEmployees)) { 
		errors+='Number of Employees is required\n';
		}
//	if ((strAreaInterest=="Expense Management") || (strAreaInterest=="Both Products")) {
//		if (!isNotEmpty(strNumberOfExpRpts)) { 
//			errors+='Number of Expense Reports per month is required\n';
//			}		
//		}
	if (!isNotEmpty(strAddress1)) { 
		errors+='Street Address is required\n';
		}
	if (!isNotEmpty(strCity)) { 
		errors+='City is required\n';
		}	
	if (!isNotEmpty(strPostalCode)) { 
		errors+='Zip/Postal Code is required\n';
		}
	if (!isNotEmpty(strCountryName)) { 
		errors+='Please select a Country\n';
		}	
	if (strCountryName=='USA') {
		if (!isNotEmpty(strStateProvName)) { 
			errors+='State is required\n';
		}	
	}
	if (strActivelyEvaluating=='none') {
		errors+='Please tell us if you are actively evaluating systems\n';
		}
	if (strActivelyEvaluating=='Yes') {
		if (strPurchasingTimeframe=='none') {
			errors+='Please tell us your purchasing timeframe\n';
			}
		}	
//	if (!isNotEmpty(strInfoRequested)) { 
//		errors+='Please check the appropriate box(es) to let us know what type of information you are requesting \n';
//		}	
	if (isNotEmpty(errors)) {		
		alert('The following error(s) occurred:\n'+errors);
		return (false);
		}
//	alert('info requested = '+strInfoRequested);
	regform.ltInformation_Requested.value=strInfoRequested;
	if (isNotEmpty(strPhoneExt)) {
		regform.PrimaryPhone.value=strWorkPhone+' #'+strPhoneExt;
	}
	
//	alert('account_inforequested = '+regform.Account_InfoRequested.value);
	return (true); 
}

//
