// Copyright 2006-2007 Morose Media

imageprefetch(basepath + 'images/layout/contactform-send-over.v' + versions.contact + '.png');
imageprefetch(basepath + 'images/layout/contactform-send-down.v' + versions.contact + '.png');

function messageBoxVisible(visibility) {
	if (visibility) {
		document.getElementById('messagebox').style.visibility = 'visible';
	} else {
		document.getElementById('messagebox').style.visibility = 'hidden';		
	}
}

function messageBoxContent(title, message) {
	document.getElementById('messageboxcaption').innerHTML = title;
	var elm = document.getElementById('messageboxmessage');
	elm.innerHTML = message;
	elm.style.marginTop = (0 - Math.round(elm.offsetHeight / 2)) + 'px';
}

function submitContactForm_Response(xmlhttp) {
	messageBoxVisible(false);
	
	var data = xmlhttp.responseText.split('|');
	if ((data.length > 0) && (data[0] == 'OK')) {
		messageBoxContent('Message sent!', 'Thank you for contacting us!<br />We will reply shortly.');
	} else if ((data.length > 1) && (data[0] == 'ERROR')) {
		messageBoxContent('Error', data[1]);
	} else {
		messageBoxContent('Error', 'An unknown error has occured. Please try again.');
	}

	messageBoxVisible(true);
}

function submitContactForm() {
	messageBoxContent('Sending message...', 'Contacting server...');
	messageBoxVisible(true);
	
	var dataCompany = escape(document.getElementById('fieldcontactcompany').value);
	var dataName = escape(document.getElementById('fieldcontactname').value);
	var dataEmail = escape(document.getElementById('fieldcontactemail').value);
	var dataContent = escape(document.getElementById('fieldcontactcontent').value);
	
	xml = new xmlconn;
  xml.connect(basepath + 'contact/xml/', "GET", 'company=' + dataCompany + '&name=' + dataName + '&email=' + dataEmail + '&content=' + dataContent, submitContactForm_Response);
}

document.getElementById('fieldcontactsubmit').onclick = submitContactForm;
document.getElementById('messageboxclose').onmouseover = function(event) { document.getElementById('messageboxclose').className = 'closeover'; }
document.getElementById('messageboxclose').onmouseout = function(event) { document.getElementById('messageboxclose').className = 'closenormal'; }
document.getElementById('messageboxclose').onmousedown = function(event) { messageBoxVisible(false); }
document.getElementById('messageboxcloseimg').onmouseover = function(event) { document.getElementById('messageboxclose').className = 'closeover'; }
document.getElementById('messageboxcloseimg').onmouseout = function(event) { document.getElementById('messageboxclose').className = 'closenormal'; }