/****************************************************/
/***  Following are functions used by phpList to generate
      forms and checks for the subscribe form
	 
	 
/****************************************************/
var fieldstocheck = new Array();
fieldnames = new Array();



function checkContactForm(theform,where) {
	if (theform.nospam.value!="315") {alert ("Please type three hundred fifteen (the number) into the no spam box"); return false; }

	for (i=0;i<fieldstocheck.length;i++) {
    if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") {
      alert("Please enter your "+fieldnames[i]);
      eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
      return false;
    }
  }

  return submitForm(theform,where); // !!! MOD !!! this will return the return from the AjaxRequest function
}

/**************************************************/

function addFieldToCheck(value,name) {
  fieldstocheck[fieldstocheck.length] = value;
  fieldnames[fieldnames.length] = name;
}

function compareEmail()
{
  return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}

/**************************************************/


function submitForm(theform,where) {  //from AjaxRequest demo page on how to submit a form in the background
 
  switch (where)
  {
  	case "contactus":
		var message="<p>Thank you.  Your email has been sent.</p>";
	break;
	
  }
  var status = AjaxRequest.submit(
    theform
    ,{
      //'onSuccess':function(req){ document.forms['form2'].submitResults.value = req.responseText; }
	  'onSuccess':
	  
	  function(req){
		  document.getElementById(where).innerHTML=message;
		  document.forms['contactusform'].name.value="";
		  document.forms['contactusform'].email.value="";
		  document.forms['contactusform'].text.value="";
		}
	  ,'onLoading':function(req){document.getElementById(where).innerHTML="<p>Sending...</p>";}
    }
  );
  return status;

}


