//********show/hide*************
//-- now in sitescripts.js with slight difference
//function onOff(id, onoff) {
//	if (el = document.getElementById(id)) {
//		if (null==onoff) onoff = el.style.display=='none';
//		el.style.display = (onoff ? '' : 'none');
//	}	
//}

//*****Job Inquiries**************************************************
function jobInquiry(){

var jobmessage = "Thanks for your interest in employment at Astor!\n\n"+
"A list of all of our current job openings is available on line.\n\n"+
"_______________________________________\n\n" +
"To view all current job openings,\n\n"+
"and to apply for any of those positions,\n\n"+
"click *OK* to go to our employment page,\n\n"+
"or click the  * JOBS *  link,\n\n"+
"which is located at the bottom of this page.\n\n"+
"_______________________________________\n"+
"\n\nWe regret that we can not reply to all messages about job inquiries.        \n\n"+
"Would you like to view all of our current job listings now?\n";

if (document.getElementById('formulator').subject.value == "Employment Inquiry") {
	var x = confirm(jobmessage)
	if (x) window.location = "jobs.php";
	}
}

//*****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=="subject: unspecified/other"||subject=="Employment Inquiry") SelectRecipient_Special = "maildesk"
else if (subject=="The AHFC Foundation / Donations"||subject=="Website Feedback"||subject=="Volunteer Opportunities Form") SelectRecipient_Special = "smoorhead"
else if (subject=="Events Inquiry"||subject=="Mailing List"||subject=="Unsubscribe"||subject=="Adopt-A-Family Submission") SelectRecipient_Special = "dvaldez" //events
//else if (subject == "Employment Inquiry") SelectRecipient_Special = "mail"
else if (subject == "Training Inquiry") SelectRecipient_Special = "adrewes" //training
else if (subject == "Library Inquiry") SelectRecipient_Special = "dkeyes" //library; orig dgarofal
else if (subject == "Residential Program Inquiry") SelectRecipient_Special = "bsullivan" 
else if (subject == "Webmaster Inquiry") SelectRecipient_Special = "sitecheck"
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
  alert("Thanks for your message!\n\nForm processing can take a little time, depending on connection speeds.\nPlease do not re-send unless you are prompted for additional information!\n\nThank you.");
  document.getElementById('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.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 (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 = "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 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*************************************************

