// JavaScript Document

//
// ** trimming functions
//
function Trim(szString)
{
  value = szString;

  while (value.charAt(value.length-1) == " "){value = value.substring(0,value.length-1);} 
  while(value.substring(0,1) ==" "){value = value.substring(1,value.length);}

  return value;
}

function TrimText(pitem,pvalue)
{
	pitem.value = Trim(pvalue);
}
//
// ** input validation function
//
function StoreValue(pname,pobject)
{
	TrimText(pobject,pobject.value);
	
	pname.value = pobject.value;

}



function ProcessForm()
{
	var RegForm 		= document.form1
	var FirstName 		= RegForm.firstname.value;
	var LastName 		= RegForm.lastname.value ;
	var Organization 	= RegForm.organization.value;
	var Address 		= RegForm.address.value ;
	var City			= RegForm.city.value;
	var State			= RegForm.state.value;
	var Zip				= RegForm.zipcode.value;
	var EmailAddress 	= RegForm.emailaddress.value ;
	var PhoneNumber 	= RegForm.phonenumber.value ;
	var FaxNumber 		= RegForm.faxnumber.value ;
	var Comments 		= RegForm.comments.value ;
	var Contact1 		= RegForm.contact1.checked;
	var Contact2 		= RegForm.contact2.checked;
	var Contact3 		= RegForm.contact3.checked;
	var Contact4 		= RegForm.contact4.checked;
	var TimeFrame 		= RegForm.timeframe.value;
	var Authority1 		= RegForm.authority1.checked;
	var Authority2 		= RegForm.authority2.checked;
	var Authority3 		= RegForm.authority3.checked;
	var Type1 			= RegForm.usertype1.checked;
	var Type2 			= RegForm.usertype2.checked;
	var Type3 			= RegForm.usertype3.checked;
	var Type4			= RegForm.usertype4.value
	var Size			= RegForm.size.value;
	var errormsg 		= "";
	var RESPONSE		= false;
	
	
	if ( FirstName == "") {
		errormsg = "The following information must be provided:\nPlease enter a first name";
	}

	if ( LastName == "") {
		errormsg += "\nPlease enter a last name";
	}
	
	if ( Organization == "") {
		errormsg += "\nPlease enter a company or organization name";
	}

	if ( Address == "") {
		errormsg += "\nPlease enter an address";
	}
	
	if ( City == "") {
		errormsg += "\nPlease enter a city";
	}
	
	if ( State == "") {
		errormsg += "\nPlease enter a state";
	}

	if ( Zip == "") {
		errormsg += "\nPlease enter a zipcode";
	}
	
	if ( EmailAddress == "" ) {
		errormsg += "\nPlease enter an email address";
	}
	else {
		if ( EmailAddress.indexOf("@",0) < "1" ) {
			errormsg += "\nPlease enter a valid email address";
		}
	}

	if ( PhoneNumber == "" ) {
		errormsg += "\nPlease enter a phone number";
	}

	if ( FaxNumber == "" ) {
  		RegForm.faxnumber.value = "none";
	}
	
	if (Contact1) RESPONSE = true;	
	if (Contact2) RESPONSE = true;	
	if (Contact3) RESPONSE = true;	
	if (Contact4) RESPONSE = true;	
	if (!RESPONSE) {
		errormsg += "\nPlease select a contact type";
	}
	
	if (TimeFrame == "") {
		errormsg += "\nPlease select a time frame";
	}
	
	if (Authority1) RESPONSE = true;
	if (Authority2) RESPONSE = true;
	if (Authority3) RESPONSE = true;
	if (!RESPONSE) {
		errormsg += "\nPlease select a purchasing authority";
		RESPONSE = false;
	}
	
	if (Type1) RESPONSE = true;
	if (Type2) RESPONSE = true;
	if (Type3) RESPONSE = true;
	if (Type4 != "") RESPONSE = true;
	if (!RESPONSE) {
		errormsg += "\nPlease select a type of work";
		RESPONSE = false;
	}
	
	if (Size == "") {
		errormsg += "\nPlease select a company size";
	}
	
	
	if (errormsg == "") return true;
	
	alert(errormsg);
	return false;

}
