//********set js events*************
window.onload = jsEvents;

function jsEvents() {
//	document.getElementById('phonemail').style.display = "none";
	document.getElementById('phonemail').className = "noInd toprule notshowing";
	document.getElementById('phonemailTrigger').onclick = onoffPhonemail;
	document.getElementById('hidephone').onclick = onoffPhonemail;
}

function onoffPhonemail() {
		if (document.getElementById('phonemail').className == "noInd toprule notshowing") {
		document.getElementById('phonemail').className = "noInd toprule showing";
		}
		else {
			document.getElementById('phonemail').className = "noInd toprule notshowing";
			}
}


//*****doForm**************************

function doForm ( form ) {

//*******************************************************************************
// Validate and submit the form.
//*******************************************************************************
var firstmessage="Please provide the following valid information:\n\n ";
var errormessage="";
var SelectRecipient_Special;

//* set recipient based on subject selected
var item = document.formulator.subject.selectedIndex;
if (document.formulator.subject.selectedIndex) {
		var subject = document.formulator.subject.options[item].value}
	else if (document.formulator.subject.value) {
		var subject = document.formulator.subject.value};

if (subject=="General Inquiry"||subject=="Information Request"||subject=="Potential Website Project"||subject=="Our Current Project"||subject=="subject: unspecified/other"||subject=="Webmaster Service Request"||subject=="About This Site") SelectRecipient_Special = "paul"
//else if (subject=="The AHFC Foundation / Donations"||subject=="Website Feedback") SelectRecipient_Special = "foundation"
//else if (subject=="Events Inquiry"||subject=="Mailing List"||subject=="Unsubscribe") SelectRecipient_Special = "events"
else if (subject == "Personal Message") SelectRecipient_Special = "paul"
//else if (subject == "Library Inquiry") SelectRecipient_Special = "library"
//else if (subject == "Webmaster Inquiry") SelectRecipient_Special = "webminder"
else errormessage=errormessage + "subject" + "\n";

//* Display alert dialog if any errors in validation
if (errormessage !="") { alert (firstmessage + errormessage) ; return false; }
else {

  //* Set the value within the form
  document.formulator.SelectRecipient_Special.value = SelectRecipient_Special;

  //* Optionally change subject depending on product selected
//  document.formulator.subject.value = "Order Form - " + product;

  //* Set the redirect page.
//  document.formulator.redirect.value = "confirmation.php";

  //* All good to go, submit the form to the HiQFM script
  document.formulator.submit();
  return(0);
  }
}
//*****end doForm*****************************************************

//*******************************************************************************
// write in elements needed for scripting
function writeIts() {
	document.getElementById('formulator').action="c/writer.php";
}
//*******************************************************************************

//aaaaaaa form check aaaaaaaaaaaaaaaaaaaaaaaaaa
// trigger is return checkFields();

function checkFields() {
// add spacing above and below message text
/* var txt = 'some text';
var tbox = document.getElementById('a_tbox');
if (tbox)
{
tbox.value = txt;
} */

/* var oldvalue = document.getElementById('mssg').value;
var newvalue = \n\n + oldvalue + \n\n;
if (!(document.getElementById('mssg').value=="")) {
	document.getElementById('mssg').value += newvalue;
} */

/* var myTextField = document.getElementById('myText');
	if(myTextField.value != "")
		alert("You entered: " + myTextField.value) */

/* var textArea = document.getElementById('mssg');
if (textArea.value !=""){
	var theMessage = textArea.value; 
	document.getElementById('mssg').value='(\n\n + theMessage + \n\n)';
} */

/* if (!(document.getElementById('mssg').value=="")) {
	var messagetext = document.getElementById('mssg').value;
	document.getElementById('mssg').value="\n\n + messagetext + \n\n";
} */

/* if (!(document.getElementById('mssg').value=="")) {
	var messagetext = document.getElementById('mssg').value;
	document.getElementById('mssg').value += \n\n + messagetext + \n\n;
} */

//---------

var spacedmessage = "";

var origmessage = document.getElementById('mssg').value;

if (!(document.getElementById('mssg').value=="")) {
	spacedmessage += "\n";
	spacedmessage += origmessage;
//	spacedmessage += "\n____________________";
	document.getElementById('mssg').value = spacedmessage;
}

//---------

missinginfo = "";

if(document.getElementById('mssg').value == "") {
missinginfo += "\n     -  Message";
}
if (document.formulator.name.value == "") {
missinginfo += "\n     -  Name";
}
/*if ((document.formulator.email.value == "")||(document.formulator.email.indexOf('@') == -1)||(document.formulator.email.indexOf('.') == -1)) {
missinginfo += "\n     -  Email";
}*/
if (document.formulator.email.value == "") {
missinginfo += "\n     -  Email";
}

if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You didn't fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease enter the information and submit again!";
alert(missinginfo);
window.scrollTo(0, 400);
return false;
}

else {
	doForm(this.form);
	}
}
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

//bbbbbb no double submits bbbbbbbbbbbbbbbbbbbb


//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

//*****theTest********************************************************
//*****checks for a human, passes to javascript validation script*****
//*****triggers php-script location writer****************************
function theTest(){
	if (!(document.getElementById('q1c').checked)){
		alert("Sorry, this form can not be processed \nwith the information you provided.\nPlease contact us by phone or letter.");
		window.location = "reachus.php?by=phone";
		return(false);
	}
	
	if (!(document.getElementById('q2d').checked)){
		alert("Sorry, this form can not be processed \nwith the information you provided.\nPlease contact us by phone or letter.");
		window.location = "reachus.php?by=phone";
		return(false);
	}
	
	if (!(document.getElementById('must_fill').value=="")){
		alert("Sorry, this form can not be processed \nwith the information you provided.\nPlease contact us by phone or letter.");
		window.location = "reachus.php?by=phone";
		return(false);
	}
	else {
	document.getElementById('questions').innerHTML=""; 
	onOff('questions');
	/* onOff('continue'); */
	document.getElementById('send').innerHTML='<br><span class="required">(Processing can take seconds or minutes  &#8212; to send message,<br> please CLICK ONCE ONLY. Thanks!)<br></span>';
	document.getElementById('buttonhole').innerHTML='<input type="button" onClick="doForm(this.form)" value="Send Message" name="button" class="buttons">';
	document.getElementById('spacing').innerHTML='&nbsp;<br><br><br>&nbsp;';
	/* document.getElementById('send').innerHTML=''; */
	writeIts();
	checkFields();
//	doForm(this.form); taken out for test
	}
}
//*****end of theTest*************************************************
