var httpObjsHolder = {
	mailhttp: {
		o: ( ie ? new ActiveXObject("Msxml2.XMLHTTP") : new XMLHttpRequest() )
	}
};

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function processVerifyContact(oXml) {
	if (oXml.selectSingleNode("//data/mail")) {
		document.getElementById("formBody").style.visibility='hidden';
		document.getElementById("displayMsg").firstChild.nodeValue = 'Your message was sent successfully. Thank you for contacting OptionsHouse.';
	}
	else{
		document.getElementById("displayMsg").firstChild.nodeValue = 'There was an error with your message. Please ensure that all required fields have been populated and re-submit.';
	}
}

function checkReqForm () {
	if (trim(document.Form1.firstname.value) == "") {
		document.getElementById("displayMsg").firstChild.nodeValue="Please enter your first name";
		document.Form1.firstname.focus();
		return false;
	}
	else if (trim(document.Form1.lastname.value) == "") {
		document.getElementById("displayMsg").firstChild.nodeValue="Please enter your last name";
		document.Form1.lastname.focus();
		return false;
	}
	else if (trim(document.Form1.email.value) == "") {
		document.getElementById("displayMsg").firstChild.nodeValue="Please enter your email address";
		document.Form1.email.focus();
		return false;
	}
	else if (! (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.Form1.email.value)) ) {
		document.getElementById("displayMsg").firstChild.nodeValue="Invalid Email Address! Please re-enter.";
		document.Form1.email.focus();
		return false;
	}
	else if (document.Form1.email.value!=document.Form1.email2.value) {
		document.getElementById("displayMsg").firstChild.nodeValue="Please verify your Email adress.";
		document.Form1.email2.focus();
		return false;
	}
	else if (trim(document.Form1.comments.value) == "") {
		document.getElementById("displayMsg").firstChild.nodeValue="Please specify a question/comment";
		document.Form1.comments.focus();
		return false;
	}
	else {
		return true;
	}
}

function submitForm() {
	var checker = checkReqForm();

	if ( checker ) {
		var act = "<EZMessage action='mail.contactus'><data>"
			+ "<firstName>"+ replaceSpecials(document.getElementById("firstname").value) +"</firstName>"
			+ "<lastName>"+ replaceSpecials(document.getElementById("lastname").value) +"</lastName>"
			+ "<emailAddress>"+ replaceSpecials(document.getElementById("email").value) +"</emailAddress>"
			+ "<phoneNumber>"+ replaceSpecials(document.getElementById("phone").value) +"</phoneNumber>"
			+ "<companyName>"+ replaceSpecials(document.getElementById("company").value) +"</companyName>"
			+ "<department>"+ replaceSpecials(document.getElementById("department").value) +"</department>"
			+ "<how>"+ replaceSpecials(document.getElementById("hear").value) +"</how>"
			+ "<howSpecific>"+ replaceSpecials(document.getElementById("specify").value) +"</howSpecific>"
			+ "<question>"+ replaceSpecials(document.getElementById("comments").value) +"</question>"
			+ "</data></EZMessage>"
		;

		getHttpXMLReq(act, processVerifyContact)
	}
}
