function ajaxFunction() {
	var honeypot = document.getElementById('url').value;
	var personNom = document.getElementById('personNom').value;
	var personCtct = document.getElementById('personCtct').value;
	var personMsg = document.getElementById('personMsg').value;
	var personList = document.getElementById('personList').value;
	
	var qString = "?url="+honeypot+"&personNom="+personNom+"&personCtct="+personCtct+"&personMsg="+personMsg+"&personList="+personList;
	
	var goAhead = true;
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				goAhead = false;
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			var returnedText = xmlHttp.responseText;
			if(returnedText == 'noname') {
				alert("Please enter your name.");
				document.getElementById('personNom').focus();
			} else if(returnedText == 'honeypot') {
				alert("Please leave the Website Address field blank.");
				document.getElementById('url').focus();
			} else if(returnedText == 'fail') {
				alert("We were unable to send your message at this time, please try again later.");
			} else {
				thankYou();
			}
		}
	}
	xmlHttp.open("GET","sendMessageAJAXGala.php"+qString,true);
	xmlHttp.send(null);
	return false;
}

function thankYou() {
	hideParagraphs();
	var fortyYearForm = document.getElementById('fortyYearForm');
	var fyfFieldset = fortyYearForm.getElementsByTagName('fieldset')[0];
	var newImg = document.createElement('img');
	newImg.src = 'thankyouGala.jpg';
	newImg.id = 'thankYouImage';
	newImg.alt = "Thank you. We will be in touch soon to answer your question.";
	fyfFieldset.appendChild(newImg);
	newImg.style.cursor = 'pointer';
	newImg['onclick'] = new Function('showParagraphs();');
}
function hideParagraphs() {
	var fortyYearForm = document.getElementById('fortyYearForm');
	var thePs = fortyYearForm.getElementsByTagName('p');
	var thePsL = thePs.length;
	for(var i=0; i<thePsL; i++) {
		thePs[i].style.display = 'none';
	}
}
function showParagraphs() {
	var fortyYearForm = document.getElementById('fortyYearForm');
	var tyImage = document.getElementById('thankYouImage');
	tyImage.parentNode.removeChild(tyImage);
	var thePs = fortyYearForm.getElementsByTagName('p');
	var thePsL = thePs.length;
	for(var i=0; i<thePsL; i++) {
		if(thePs[i].className.indexOf('hide') == -1) {
			thePs[i].style.display = 'block';
		}
	}
	var theTextArea = document.getElementById('personMsg');
	theTextArea.value = '';
	theTextArea.focus();
}

function setAjaxForm() {
	var fortyYearForm = document.getElementById('fortyYearForm');
	fortyYearForm["onsubmit"] = new Function('return ajaxFunction();');
	var tyPic = new createElement('img');
	tyPic.src = 'thankyouGala.jpg';
	tyPic.style.display = 'none';
	document.getElementsByTagName('body')[0].appendchild(tyPic);
}
if(window.addEventListener) window.addEventListener("load",setAjaxForm,false);
else if(window.attachEvent) window.attachEvent("onload",setAjaxForm);
else window.onload = runFirst;