var response= new Array();
var fields	= new Array();

response['error'] = "* Please complete all fields correctly";
response['success'] = "Thanks for contacting us. We'll respond to your message as soon as possible.";
response['failed']	= "Send email failed. Please try again in a few minutes.";

fields['name']	= "Name";
fields['email'] = "Email";
fields['subject']	= "Subject",
fields['message']	= "Your message ...";



$(function() {
	$(":input").each(function(){
		var n = $(this).attr('name');
		defaultText(this, n);
		$(this).blur(function(){
			defaultText(this, n);
		});
		$(this).focus(function(){
			if ($(this).val() == fields[n]) {
				$(this).val('');
			}
		});
	});
});
defaultText = function(el, n) {
	if($(el).val() == "" && fields[n]) {
		$(el).val(fields[n]);
	}
};



Submit = function(f){
	var valid	= true;
        $("#alert").hide();
	$(':input', f).each(function() {
		var name = $(this).attr("name");
		var val = $(this).val();

		if("" == val || fields[name] == val) {
			valid = false;
		}
	});
	
	if(false === valid) {

		$("#alert").html(response['error']);
                $("#alert").show("slow");
	}
		
	if(valid){
		$.ajax({
			type: "POST",
			url: "sendmail.php",
			data: $(f).serialize(),
			success: function(msg){
                            
				switch(msg){
					case "error": $("#alert").html(response['error']);
                                            $("#alert").show("slow");
						break;
					case "success": $(f).html(response['success']);
						break;
					default: alert(response['failed']);
						break;
				}
			}
		});
	}
	return false;
};