
function stripSpaces(fld) {
  var x = fld.value;
  while (x.substring(0,1) == ' ') x = x.substring(1);
  while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
  fld.value = x;
}

function validateForm(form) {
	var returnValue = true;
	var errorMessage = 'The following fields are required but do not contain any information:\n\n';
	var focusField = null;
  var emailRE = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

  stripSpaces(form.first_name);
  stripSpaces(form.last_name);
  stripSpaces(form.title);
  stripSpaces(form.department);
  stripSpaces(form.company);
  stripSpaces(form.street_address);
  stripSpaces(form.city);
  stripSpaces(form.state);
  stripSpaces(form.zip);
  stripSpaces(form.emailfrom);
  stripSpaces(form.phone);
  stripSpaces(form.comments);
  
//	var bandwidthChoice = form.bandwidth.selectedIndex;
//	else if ((!form.Broadcast.checked) &&
//		(!form.Registration.checked) &&
//		(!form.CopySense.checked) &&
//		(!form.RepliCheck.checked) &&
//		(!form.Custom.checked)) {
//		alert('You must check at least one of the Products');
//		if (!focusField)
//			focusField = form.Broadcast;
//		returnValue = false;
//	}
//	else if (form.CopySense.checked && !form.bandwidth[bandwidthChoice].value) {
//		alert("Please select the approx. speed of your primary Internet connection")
//		form.bandwidth.focus()
//		returnValue = false;
//	}

	if (!form.first_name.value) {
		errorMessage += ' - First Name\n';
		if (!focusField)
			focusField = form.first_name;
		returnValue = false;
	}
	if (!form.last_name.value) {
		errorMessage += ' - Last Name\n';
		if (!focusField)
			focusField = form.last_name;
		returnValue = false;
	}
	if (!form.country.value) {
		errorMessage += ' - Country\n';
		if (!focusField)
			focusField = form.country;
		returnValue = false;
	}
	if (!form.zip.value) {
		errorMessage += ' - Postal Code\n';
		if (!focusField)
			focusField = form.zip;
		returnValue = false;
	}
	if (!form.emailfrom.value) {
		errorMessage += ' - Email Address\n';
		if (!focusField)
			focusField = form.emailfrom;
		returnValue = false;
	}
	if (!form.comments.value) {
		errorMessage += ' - Questions/Comments\n';
		if (!focusField)
			focusField = form.comments;
		returnValue = false;
	}
	if (!returnValue) {
		alert(errorMessage);
		if (focusField)
			focusField.focus();
	}
	else if (!validEmail(form.emailfrom.value)) {
		alert('Invalid email address in Email Address field');
		form.emailfrom.focus();
		form.emailfrom.select();
		returnValue = false;
	}
	return returnValue;
}


function validEmail(email) {
	var emailOK = true;
	var invalidChars = ' /:,;';
	var atPos = email.indexOf("@",1);
	var periodPos = email.indexOf(".",atPos);
	if ((email == "") || (atPos == -1) || (email.indexOf("@",atPos+1) != -1) || 
		(periodPos == -1) || (periodPos+3 > email.length)) {
		emailOK = false;
	}
	for (i=0; i<invalidChars.length; i++) {
		var badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			emailOK = false;
		}
	}
	return emailOK;
}