var initialize = function() {

	// send contact email
	$('#submitbutton').click(function() {
		var name = $('#contact_form').find('input[@name="yourname"]').val();
		var email = $('#contact_form').find('input[@name="email"]').val();
		var telephone = $('#contact_form').find('input[@name="telephone"]').val();
		var comments = $('#contact_form').find('textarea[@name="comments"]').val();
		// disable submit button
		var submitButton = $('#contact_form').find('input[name="submitbutton"]');
		submitButton.attr("disabled", "true");
		// send mail
		sendMail(name, email, telephone, comments);
		// re-enabled submit button 
		submitButton.removeAttr("disabled");
	});
	
};

$(document).ready(initialize);

function sendMail(name, email, telephone, comments) {
	
	// perform validation
	if (name.length == 0) {
		alert("please enter your name");
		return false;
	} else if (email.length == 0) {
		alert("please enter your email address");
		return false;
	} else if (telephone.length == 0) {
		alert("please enter a telephone number");
		return false;
	} else if (comments.length == 0) {
		alert("please enter comments");
		return false;
	} else {
		$.post(
			"mailer.php", 
			{ name: name, email: email, telephone: telephone, comments: comments },
			function(data){
    			alert("Email was successfully sent!");
  			}
  		);
	}
}
