//********show/hide*************
function onOff(id, onoff) {
	if (el = document.getElementById(id)) {
		if (null==onoff) onoff = el.style.display=='none';
		el.style.display = (onoff ? '' : 'none');
	}	
}
//*****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.getElementById('formulator').subject.selectedIndex;
if (document.getElementById('formulator').subject.selectedIndex) {
		var subject = document.getElementById('formulator').subject.options[item].value}
	else if (document.getElementById('formulator').subject.value) {
		var subject = document.getElementById('formulator').subject.value};

if (subject=="General Inquiry"||subject=="Information Request"||subject=="Placement Inquiry"||subject=="Contact The Executive Director"||subject=="Contact The Board of Directors"||subject=="- unspecified/other -") SelectRecipient_Special = "paul"
else if (subject=="The AHFC Foundation / Charitable Giving"||subject=="Events Inquiry") SelectRecipient_Special = "mail"
else if (subject == "Employment Inquiry") SelectRecipient_Special = "mail"
else if (subject == "Training Inquiry") SelectRecipient_Special = "mail"
else if (subject == "Library Inquiry") SelectRecipient_Special = "mail"
else if (subject == "Webmaster Inquiry") SelectRecipient_Special = "mail"
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.getElementById('formulator').SelectRecipient_Special.value = SelectRecipient_Special;

  //* Optionally change subject depending on product selected
//  document.getElementById('formulator').subject.value = "Order Form - " + product;

  //* Set the redirect page.
//  document.getElementById('formulator').redirect.value = "confirmation.php";

  //* All good to go, submit the form to the HiQFM script
  writeIts();
  document.getElementById('formulator').submit();
  return(0);
  }
}
//*****end doForm*****************************************************

//*******************************************************************************
// write in elements on page load
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.getElementById('formulator').name.value == "") {
missinginfo += "\n     -  Name";
}
/*if ((document.getElementById('formulator').email.value == "")||(document.getElementById('formulator').email.indexOf('@') == -1)||(document.getElementById('formulator').email.indexOf('.') == -1)) {
missinginfo += "\n     -  Email";
}*/
if (document.getElementById('formulator').email.value == "") {
missinginfo += "\n     -  Email";
}
if (document.getElementById('formulator').phone.value == "") {
missinginfo += "\n     -  Phone";
}
if (document.getElementById('formulator').address.value == "") {
missinginfo += "\n     -  Address";
}
if (document.getElementById('formulator').city.value == "") {
missinginfo += "\n     -  City";
}
if (document.getElementById('formulator').state.value == "") {
missinginfo += "\n     -  State";
}
if (document.getElementById('formulator').zip.value == "") {
missinginfo += "\n     -  Zip";
}
//if (document.getElementById('formulator').payment_method.checked == "") {
//missinginfo += "\n     -  Contact Method";
//}
if (!document.getElementById('formulator').payment_type1.checked &&
	 !document.getElementById('formulator').payment_type2.checked &&
	 !document.getElementById('formulator').payment_type3.checked) {
missinginfo += "\n     -  Contact Method";
}

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, 380);
return false;
}

else {
	doForm(this.form);
	}
}
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

//bbbbbb no double submits bbbbbbbbbbbbbbbbbbbb


//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

//*****theTest********************************************************
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 = "phoneus.php";
		return(false);
	}
	
	if (!(document.getElementById('q2b').checked)){
		alert("Sorry, this form can not be processed \nwith the information you provided.\nPlease contact us by phone or letter.");
		window.location = "phoneus.php";
		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 = "phoneus.php";
		return(false);
	}
	else {
	document.getElementById('questions').innerHTML=""; 
	onOff('questions');
	/* onOff('continue'); */
	document.getElementById('send').innerHTML='<br><span class="required">(Processing can take several seconds &#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=''; */
	checkFields();
//	doForm(this.form); taken out for test
	}
}
//*****end of theTest*************************************************

