// PRESS BUTTON
function buttonDown (thisBtn) {
	thisObj = document.getElementById(thisBtn);
	if (thisObj)
		thisObj.src = "images/" + thisBtn + "DOWN.gif";
}

// RELEASE BUTTON
function buttonUp (thisBtn) {
	thisObj = document.getElementById(thisBtn);
	if (thisObj)
		thisObj.src = "images/" + thisBtn + "UP.gif";
}

// CLEAR FORM DATA
function resetData(formId) {
	formId=document.getElementById(formId);
	formId.reset();
}

// CREATE A BROWSER SPECIFIC AJAX OBJECT
function getXmlHttpObject() {
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

// POST COMMENT MESSAGE USING AJAX
function postData(formId) {
	formId=document.getElementById(formId);
	var formData= '';
	for (i = 0; i < formId.elements.length; i++) {
		formElem = formId.elements[i];
		switch (formElem.type) {
			case 'text':
			case 'select-one':
			case 'hidden':
			case 'password':
			case 'textarea':
				formData += formElem.name + '=' + escape(formElem.value) + '&';
				break;
			case 'checkbox':
				if (formElem.checked)
					formData += formElem.name + '=YES&';
				break;
		}
	}

	var xmlHttp = getXmlHttpObject();
	if (!xmlHttp) {
		alert("Your browser does not support AJAX functionality.\nWe are unable to process your message.\n\nPlease email us at j.calovic@wedding-clergy.com.");
	}
	else {
		// SYNCHRONOUS INVOCATION
		xmlHttp.open("POST", "sendmail.php", false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.send(formData);
	}

	if (xmlHttp.status == 200) {
		response = xmlHttp.responseText;
		alert(response);
		if (response.indexOf("Thank-you") >= 0) {
			document.forms[0].reset();
		}
	}
	else {
		alert("There was a server error while processing message.\nSENDMAIL INVOCATION");
	}
}


