var success_func = function(o)
{
	alert(o.responseText);
	resetForm();
}

var fail_func = function(o)
{
	alert(o.responseText);
}

function validate()
{
	/* Validate the form and then send the contents, if correct, to the parent server. */
	errors = new Array();

	if(document.getElementById('firstname').value=="")
	{
		errors.push("Please enter your first name");
	}
	
	if(document.getElementById('lastname').value=="")
	{
		errors.push("Please enter your last name");
	}
	
	if(document.getElementById('message').value=="")
	{
		errors.push("Please enter the message you wish to send");
	}
	
	field = document.getElementById('email').value;
	apos=field.indexOf("@")
	dotpos=field.lastIndexOf(".")
	if (apos<1||dotpos-apos<2) 
	{
		errors.push("Invalid email address");
	}
	
	if(errors.length > 0)
	{
		error_out = "";
		while(error = errors.pop())
		{
			error_out += error+"\n";
		}
		alert(error_out);
		
	}
	else
	{
		var callback =
		{
			success:success_func,
			failure:fail_func
		}

		YAHOO.util.Connect.setForm("contactus");
		var cObj = YAHOO.util.Connect.asyncRequest('POST', 'contact.php', callback);
	}
	return false;
}

function resetForm()
{
	form = document.getElementById('contactus');
	
	if(form != null)
	{
		form.reset();
	}
}

