// AJAX BY FERNYB AT TRIMARK ADVERTISING
function ajaxObject() {
	var ab;
	if (window.XMLHttpRequest) {
		ab = new XMLHttpRequest(); // For Mozilla browsers
	} else if (window.ActiveXObject) {
		ab = new ActiveXObject("Microsoft.XMLHTTP"); // For IE
		if(!ab) {
			ab = new ActiveXObject("Msxml2.XMLHTTP"); // For IE
		}
	} else {
		return false;
	}
	return ab;
}

var httpAjax;
httpAjax = ajaxObject();

function gatherInfo(wform) {
var sndstr;
var f = eval("document."+wform);
for(var x=0; x<parseInt(f.elements.length); x++) {
    if(x<1) {
        sndstr = f.elements[x].name+"="+ encodeURIComponent(f.elements[x].value); 
    } else {
        sndstr += "&"+f.elements[x].name+"="+ encodeURIComponent(f.elements[x].value);     
    }
}
	// sndReq(sndstr); // send the string
	return sndstr;
}

function validateEmailForm() {
	d = document.contactDeli;
	if(d.name.value == "") {
		window.alert("Please enter your name");
		return false;
	}
	if(d.email.value == "" || d.email.value.length < 4) {
		window.alert("Plese enter in your email");
		return false;
	}
	if(d.comments.value == "" || d.comments.value.length < 10) {
		window.alert("Please enter your comments");
		return false;
	}
	return true;
}


function sendMail() {
	httpAjax.abort();
	if(validateEmailForm()) {
		query = gatherInfo("contactDeli");
		submitMail(query);
	}
	return false;
}	

function submitMail(query) {
	requestPage = "php/send.mail.php";
	httpAjax.open("post", requestPage, true);
	httpAjax.onreadystatechange = handleMailResponse;
	httpAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	httpAjax.send(query);
}

function handleMailResponse() {
	if(httpAjax.readyState == 4) {
		if(httpAjax.status == 200) {
			document.getElementById("contactEmailForm").innerHTML = httpAjax.responseText;
		} else {
			document.getElementById("contactEmailForm").innerHTML = "Sorry could not retrive the content. Network Error";
		}
	} else {
		document.getElementById("contactEmailForm").innerHTML = "<div class=\"mailresponseStyle1\"><span style=\"color:#FFFFFF; font-size:1.0em;\">Please wait. Processing Your Message....</span></div>";	
	}
}	




