// JavaScript Document

Event.observe(window, 'load',
      function() {
	  	$('name').focus();
		Element.hide('emailResponse');
		
		$('submit').onclick = function () {
			sendData();
		}
		
		$('returnlink').onclick = function () {
			Element.hide('return');
			Element.hide('emailResponse');
			Element.show('emailFormDiv');
		  	//new Rico.Effect.FadeTo( 'emailFormDiv', 1, 200, 10 );
		}
		
	  }
);

	
function sendData() {
	Element.hide('emailFormDiv');
	Element.show('emailWaiting');
	ajaxUpdate();
}


function ajaxUpdate() {
	
	var url = 'contact_us-send.php?dummy=' + new Date().getTime();
	var params = Form.serialize('frm');
	
	var myAjax = new Ajax.Updater( {success: 'emailResponse'},
								  	url,
									{ method: 'post',
									  parameters: params,
									  onFailure: reportError,
									  onComplete:function() {
									  		Element.hide('emailWaiting');
											Element.show('emailResponse');
											Element.show('return');}
									}); 
	
	

}

function reportError(request)
{
	alert('Sorry. There was an error communicating with the server.');
}
