//*********************************************************************
//
//	Submit request_info.html or request_account.html
//
//	Author: William H. Cloward
//	Copyright 2003 by WIlliam H. Cloward  All Rights Reserved
//
//*********************************************************************

//	user has pressed Submit button
//	if active page is request_info.html then "rfi" will be true, else false
function my_onsubmit(rfi) {
	var error_found = 0;
	
	//	validate the required fields: First Name, Last Name,
	//	Company, Phone and Email
	if (F_FirstName.value.length == 0) {
		document.all.item("P_FirstName").color = "red";
		if (error_found == 0) {
			F_FirstName.focus();	
			error_found = 1;
		}
	}
	else { document.all.item("P_FirstName").color = "#8E8E8E"; }
	
	if (F_LastName.value.length == 0) {
		document.all.item("P_LastName").color = "red";	
		if (error_found == 0) {
			F_LastName.focus();	
			error_found = 1;
		}
	}
	else { document.all.item("P_LastName").color = "#8E8E8E"; }	
	
	if (F_Company.value.length == 0) {
		document.all.item("P_Company").color = "red";	
		if (error_found == 0) {
			F_Company.focus();	
			error_found = 1;
		}		
	}
	else { document.all.item("P_Company").color = "#8E8E8E"; }	
	
	if (F_Phone.value.length == 0) {
		document.all.item("P_Phone").color = "red";	
		if (error_found == 0) {
			F_Phone.focus();	
			error_found = 1;
		}		
	}
	else { document.all.item("P_Phone").color = "#8E8E8E"; }	
	
	if (F_Email.value.length == 0) {
		document.all.item("P_Email").color = "red";	
		if (error_found == 0) {
			F_Email.focus();	
			error_found = 1;
		}		
	}
	else { document.all.item("P_Email").color = "#8E8E8E"; }	

	//	any errors found?
	if (error_found != 0) {
		document.all.item("R_ErrorMessage").style.display = "inline";
		alert("Please provide us with all the information in the fields marked in red, so we will be able to act on your request promptly.");
		return false;				
	}
	else {
		//	probably unnecessary, but make error message disappear
		document.all.item("R_ErrorMessage").style.display = "none";

		//	allow submission to proceed
		my_sendForm(rfi);

		//	choose the appropriate after-page
		if (rfi == true)
			window.location.href = "request_info_response.html";
		else
			window.location.href = "request_account_response.html";
		return true;
	}
}


//	compose and send an email via "mailto:" protocol
function my_sendForm(rfi) {
	var	MsgBody, MsgSubject;
	var	Optional1, Optional2, Optional3;

	//	control checkbox values
	updateCbox(F_Using_Reservationless);
	updateCbox(F_Using_Assisted);
	updateCbox(F_Using_Video);
	updateCbox(F_Using_Web);
	updateCbox(F_Using_Equipment);
	updateCbox(F_Want_Reservationless);
	updateCbox(F_Want_Assisted);
	updateCbox(F_Want_Video);
	updateCbox(F_Want_Web);
	updateCbox(F_Want_Equipment);
	if (rfi == true) {
		updateCbox(C_SignUp);
		updateCbox(C_Quote);
	}

	//	prepare the strings which aren't present in both forms
	if (rfi == true) {
		Optional1 = "\nTimeframe:\t\t" + F_Timeframe.value;
		Optional2 = "\nOpen an Account:\t" + C_SignUp.value;
		Optional3 = "\nRequest a Quote:\t" + C_Quote.value;
	}
	else {
		Optional1 = "";
		Optional2 = "";
		Optional3 = "";
	}

	//	use the contents of the user-input fields to construct the message's body
	MsgBody = 
	  "\nName:\t\t" + F_FirstName.value + " " + F_LastName.value +
	  "\nTitle:\t\t" + F_Title.value +
	  "\nCompany:\t" + F_Company.value +
	  "\nAddress:\t" + F_Address_1.value +
	  "\n\t\t" + F_Address_2.value +
	  "\nCity:\t\t" + F_City.value +
	  "\nState:\t\t" + F_State.value +
	  "\nZip:\t\t" + F_Zip.value +
	  "\nPhone:\t" + F_Phone.value +
	  "\nEmail:\t\t" + F_Email.value +
	  "\nFax:\t\t" + F_Fax.value +
	  "\n\nEmployees:\t" + F_Employees.value + 
	  "\nLocations:\t" + F_Sites.value + 
	  "\nUsing:" +
	  "\n_Reservationless:\t" + F_Using_Reservationless.value +
	  "\n_Operator Assisted:\t" + F_Using_Assisted.value +
	  "\n_Video:\t\t" + F_Using_Video.value +
	  "\n_Web Collaboration:\t" + F_Using_Web.value +
	  "\n_Equipment:\t\t" + F_Using_Equipment.value +
	  "\nInterested In:" +
	  "\n_Reservationless:\t" + F_Want_Reservationless.value +
	  "\n_Operator Assisted:\t" + F_Want_Assisted.value +
	  "\n_Video:\t\t" + F_Want_Video.value +
	  "\n_Web Collaboration:\t" + F_Want_Web.value +
	  "\n_Equipment:\t\t" + F_Want_Equipment.value +
	  Optional1 + 
	  "\n\nService Provider:\t" + F_CurrentServiceProvider.value + 
	  Optional2 + 
	  Optional3 +
	  "\nBest Time(s):\t\t" + F_WhenContact.value + 
	  "\nTime Zone:\t\t" + F_TimeZone.value + 
	  "\nReferred Via:\t\t" + F_ReferredVia.value + 
	  "\n\t\t\t" + F_Medium.value +
	  "\n\nComments:\t\t" + F_Comments.value;

	  //	select the appropriate Subject line
	  if (rfi == true)
	  	MsgSubject = "Request for Information";
	  else
	  	MsgSubject = "Request New Account";

	//	replace the "mailto:", then invoke it
	FormMailTo.href = "mailto:" + "sales@copperriverinc.com" + "?subject=" + MsgSubject + "&body=" + escape(MsgBody);
	FormMailTo.click();
}


//	update a checkbox's value based on whether it's checked
function updateCbox(cbox) {
	if (cbox.checked == true)
		cbox.value = "Yes";
	else
		cbox.value = "";
}
