
/* 2006.11.02 
tom@webstarsltd.com */

var button = document.getElementById('buttons');
var formObject = document.getElementById("iform");
var openConnection;
var dotCounter = 0;

var handleSuccess = function(o){
	if(o.responseText !== undefined){
		button.innerHTML= "<strong>Sent!</strong>";
		formObject.reset();
		alert("The message has been sent successfully!");
	}
};

var handleFailure = function(o){
	if(o.responseText !== undefined){
		alert("The action has failed! Please try again later");
	}
};

var callback =
{
  success:handleSuccess,
  failure:handleFailure,
  scope:this,
  argument:[]
};

function validate() {

	var email_pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/i;
			
	if (formObject.telephone.value == "" && !email_pattern.test(formObject.email.value)) {
		alert( "Please provide either your telephone number or well formatted email address" );
		formObject.telephone.focus();
		return false;
	}
	return true;
}

function importInProgress()
{
	if(YAHOO.util.Connect.isCallInProgress(openConnection))		
	{
		if (dotCounter > 30)
		{
			button.innerHTML= "Sending";
			dotCounter = 0;
		}
		else
		{
			button.innerHTML += ".";	
			dotCounter += 1;
		}
		window.setTimeout('importInProgress()', 1000);
	}
}


function makeRequest() {
	if(!validate()) return false;
	YAHOO.util.Connect.setForm(formObject);
	openConnection = YAHOO.util.Connect.asyncRequest('POST', '../includes/sendmail.php', callback);
	button.innerHTML= "Sending";
	window.setTimeout('importInProgress()', 1000);
}