function verify() {
	//verifies correct filling out of the contact us form	

	theForm = xGetElementById("contactform");

	//make sure that all the fields are filled in
	for(i=0;i<theForm.elements.length;i++) {
		if(theForm.elements[i].id) {
			if(theForm.elements[i].id == "Message") {
				theForm.elements[i].value = theForm.elements[i].innerHTML;
			}
			if(theForm.elements[i].value == theForm.elements[i].id) {
				showError('Please enter a valid '+theForm.elements[i].id);
				theForm.elements[i].value = "";
				if(theForm.elements[i].innerHTML) {
					theForm.elements[i].innerHTML = "";
				}
				theForm.elements[i].focus();
				return false;
			}
		}
	}


	//verify the e-mail address is acceptable
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(xGetElementById("E-mail").value)) {
		showError('Please enter a valid e-mail');
		xGetElementById("E-mail").focus();
		return false;
	}

	//verify that a subject is selected
	theSelect = xGetElementById("contactsubject");
	if(theSelect.options[theSelect.selectedIndex].value == "Select a Subject") {
		showError('Please select a subject');
		theSelect.focus();
		return false;
	}

	spam = xGetElementById("spam").value;
	name = xGetElementById("Name").value;
	email = xGetElementById("E-mail").value;
	subject = xGetElementById("contactsubject").value;
	message = xGetElementById("Message").value;
	if(message == "") {
		message = xGetElementById("Message").innerHTML;
	}

	//remove all elements in the form, make a "Sending Message" busy sign
	//and then return with a message saying "You're message has been sent"
	while(theForm.hasChildNodes()) {
		theForm.removeChild(theForm.firstChild);
	}

	theLoadingDiv = document.createElement("div");
	theLoadingDiv.id = "sending";
	theLoadingDiv.style.height = "210px";
	theLoadingDiv.style.width = "240px";
		theText = document.createElement("strong");
		theText.innerHTML = "Sending Message...";
		//theText.style.width="100%";
		theText.style.display = "block";
		theText.style.textAlign = "center";
		theText.style.margin = "100px auto 10px auto";
	theLoadingDiv.appendChild(theText);
		theLoadingImg = document.createElement("img");
		theLoadingImg.src = "images/sending.gif";
		theLoadingImg.style.display = "block";
		theLoadingImg.style.margin = "0 auto";
		theLoadingImg.width = "128";
		theLoadingImg.height = "15";
		theLoadingImg.style.borderWidth = "0";
	theLoadingDiv.appendChild(theLoadingImg);
	theForm.appendChild(theLoadingDiv);


	//sleep for a moment
	setTimeout('sendMessage(spam,name,subject,email,message)',4000);

}

function sendMessage(spam,name,subject,email,message) {


	//perform an ajax call to the contact.php script to send the message
	url = "php/contact.php?ajax=true&name="+name+"&subject="+subject+"&email="+email+"&message="+message;
	t = new Date();
	url = url+"&t="+t.getTime();
	sendMsg = GetXmlHttpObject();
	sendMsg.open("GET",url,true)
	sendMsg.onreadystatechange = function() {
		if(sendMsg.readyState == 4 && sendMsg.status == 200) {
			//replace the loading message with a "Message Successfully Sent"
			theLoadingDiv = xGetElementById("sending");
			for(i=0;i<theLoadingDiv.childNodes.length;i++) {
				if(theLoadingDiv.childNodes[i].nodeName == "STRONG") {
					theLoadingDiv.childNodes[i].innerHTML = "Message Successfully Sent";
				} else {
					if(theLoadingDiv.childNodes[i].nodeName == "IMG") {
						theLoadingDiv.childNodes[i].src = "images/email.jpg";
						theLoadingDiv.childNodes[i].width = "65";
						theLoadingDiv.childNodes[i].height = "45";
					}
				}
			}
		}
	}
	sendMsg.send(null);
}

function showError(errorText) {
	//first remove the error span if one is present
	if(xGetElementById("error")) {
		xGetElementById("error").parentNode.removeChild(xGetElementById("error"));
	}	

	//append an span (id = error) immediately before the name field 
	theError = document.createElement("span");
	theError.id = "error";
	theError.innerHTML = errorText;

	xGetElementById("Name").parentNode.parentNode.insertBefore(theError, xGetElementById("Name").parentNode);
}

function checkFocus(theid) {
	formfield = xGetElementById(theid);
	if(theid == "Message") {
		if(formfield.innerHTML == theid) {
			formfield.innerHTML = "";
		}
	} else {
		if(formfield.value == theid) {
			formfield.value = "";
		}
	}
}

function checkBlur(theid) {
	formfield = xGetElementById(theid);
	if(theid == "Message" && formfield.innerHTML == "") {
		formfield.innerHTML = theid;
	} else {
		if(formfield.value == "") {
			formfield.value = theid;
		}
	}
}