/**

* AJAX forms

* 

* Author : Hatem B.Y.

*/





var AJAXForms = false;

var LastField = null;

var isIE = false;







// on !IE we only have to initialize it once

if (window.XMLHttpRequest) {



	AJAXForms = new XMLHttpRequest();

	

}





//Function to validate the mailing list form

function validateForm(){



	//initialiase variable

	valid = true;



	//If the user has not entered a name, alert them

	if (document.mailinglistform.realname.value == "") {



		document.getElementById('errorText').innerHTML = "Please enter your name!";

		document.mailinglistform.realname.focus();

		valid = false;



	}





	//If the user hs not entered a valid e-mail address, alert them

	if (document.mailinglistform.email.value == "") {



		document.getElementById('errorText').innerHTML = "Please enter an e-mail address!";

		document.mailinglistform.email.focus();

		valid = false;



	}

	

	//If all is well...

	if (valid != false) {

	

		//..then send the data to the joinMailingList.php

		sendPHPMail();

		

	}





	//Return the status of the valid variable

	//The reason for this is that we don't actually want to submit the form or else the page will refresh

	return false;



}

















function sendPHPMail(form_param) {



	if (window.XMLHttpRequest) {

	

		// branch for IE/Windows ActiveX version

	}

	

	else if (window.ActiveXObject) {

	

		AJAXForms = new ActiveXObject("Microsoft.XMLHTTP");

	}





	AJAXForms.onreadystatechange = processChange;

	AJAXForms.open("GET", "joinMailingList.php?recipient=" + document.mailinglistform.recipient.value +"&subject=" + document.mailinglistform.subject.value + "&realname=" + document.mailinglistform.realname.value + "&email=" + document.mailinglistform.email.value);

	//Send the request

	AJAXForms.send(null);

  

}









//When the state of the AJAX HTTPREQUEST object changes...

function processChange() {



	//Declare constants

	var HTTP_REQUEST_UNINITIALISED = 0;

	var HTTP_REQUEST_LOADING = 1;

	var HTTP_REQUEST_LOADED = 2;

	var HTTP_REQUEST_INTERACTIVE = 3;

	var HTTP_REQUEST_COMPLETE = 4;

	var REQUEST_STATUS_OK = 200;

	var REQUEST_STATUS_NOTFOUND = 404;

	

  	if (AJAXForms.readyState == 4) { 

  

  		//Show welcome message!

  		blendimage(mailingList);

    

  	}  

  

}
