// JavaScript Document

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 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,
		strCompany=regform.Company.value,
		strPhone=regform.PrimaryPhone.value,
		strPhoneExt=regform.PhoneExt.value,
		strEmail=regform.LeadEmail.value,
		strConfirmEmail=regform.ConfirmEmail.value,
		strAddress1=regform.StreetAddress.value,
		strCity=regform.City.value,
		strStateProvName=regform.StateProvince.value,
		strPostalCode=regform.ZipCode.value,
		strCountry=regform.Country.value,
		strAreaInterest=regform.plAreas_of_Interest.value,
		strDescriptionofBus=regform.Description.value,
		strNumberOfEmployees=regform.NumberEmployees.value,
		strActivelyEvaluating=regform.plActively_Evaluating_Systems.value,
		numWebcasts=regform.numofwebcasts.value,
		errors='';
	var normalizedWorkPhone = stripCharsInBag(strPhone, phoneNumberDelimiters);
	
	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(strCompany)) { 
		errors+='Company Name is required\n';
		}
	if (!isUSPhoneNumber(normalizedWorkPhone)) { 
		if (!isInternationalPhoneNumber(normalizedWorkPhone)) {
			errors+='A valid Work 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 (!isNotEmpty(strAddress1)) { 
		errors+='Street Address is required\n';
		}
	if (!isNotEmpty(strCity)) { 
		errors+='City is required\n';
		}	
	if (!isNotEmpty(strPostalCode)) { 
		errors+='Zip or Postal Code is required\n';
		}
	if (!isNotEmpty(strCountry)) { 
		errors+='Please select a Country\n';
		}
	if (strCountry=='USA') {
		if (!isNotEmpty(strStateProvName)) { 
			errors+='State is required\n';
			}	
		}
	if (strAreaInterest=='none') {
		errors+='Please select the Products you are interested in\n';
		}
	if (strActivelyEvaluating=='none') {
		errors+='Please tell us if you are actively evaluating systems\n';
		}

	if (!isNotEmpty(strDescriptionofBus)) { 
		errors+='Please select a Business Description\n';
		}
	if (!isNotEmpty(strNumberOfEmployees)) { 
		errors+='Number of Employees is required\n';
		}			
	if (numWebcasts=='1') {		
		var strWebcastID1=regform.WebcastID1.value;
		if (strWebcastID1=='None') {
			errors+='Please select a Webinar\n';
			}
		}
	if (numWebcasts=='2') {		
		var strWebcastID1=regform.WebcastID1.value;
		var strWebcastID2=regform.WebcastID2.value;
		if ((strWebcastID1=='None') && (strWebcastID2=='None')) {
			errors+='Please select a Webinar\n';
			}
		}
	if (isNotEmpty(errors)) {
		alert('The following error(s) occurred:\n'+errors);
		return (false);
		}
		
	if (isNotEmpty(strPhoneExt)) {
		regform.PrimaryPhone.value=strPhone+' #'+strPhoneExt;
	}
	regform.ltWebcast_Registration_Date.value=strWebcastID1+'; '+strWebcastID2;
	return (true); 
}

