 $(document).ready(function(){
	$("#sendmail").click(function(){
		var valid = '';
		var isr = ' is required.';
		var name = $("#name").val();
		var mail = $("#mail").val();
		var subject = $("#subject").val();
		var text = $("#text").val();
		var phone = $("#phone").val();
		var address = $("#address").val();
		var company = $("#company").val();
		if (name.length<1) {
			valid += '<br />Name'+isr;
		}
		if (company.length<1) {
			valid += '<br />Company'+isr;
		}
		if (address.length<1) {
			valid += '<br />Address'+isr;
		}
		if (phone.length<1) {
			valid += '<br />Phone number'+isr;
		}
		if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += '<br />An valid email addres'+isr;
		}
		if (subject.length<1) {
			valid += '<br />Subject'+isr;
		}
		if (text.length<1) {
			valid += '<br />Message'+isr;
		}
		if (valid!='') {
			$("#response").fadeIn("slow");
			$("#response").html("Error:"+valid);
		}
		else {
			var datastr ='name=' + name + '&company=' + company+ '&address=' + address+ '&phone=' + phone+ '&mail=' + mail + '&subject=' + subject + '&text=' + text;
			$("#response").css("display", "block");
			$("#response").html("Sending message .... ");
			$("#response").fadeIn("slow");
			setTimeout("send('"+datastr+"')",2000);
			alert("Thank you for your request." + "\n" + "A MO.S.T. representative will get back to you shortly")
			$("#name").val() ="";
			$("#mail").val() ="";
			$("#subject").val() ="";
			$("#text").val() ="";
			$("#phone").val() ="";
			$("#address").val() ="";
			$("#company").val() ="";
		}
		return false;
	});
});
function send(datastr){
	$.ajax({	
		type: "POST",
		url: "scripts/email.php",
		data: datastr,
		cache: false,
		success: function(html){
		$("#response").fadeIn("slow");
		$("#response").html(html);
		setTimeout('$("#response").fadeOut("slow")',2000);
	}
	});
}

$(function(){
	var spt = $('span.mailme');
	var at = / at /;
	var dot = / dot /g;
	var addr = $(spt).text().replace(at,"@").replace(dot,".");
	$(spt).after('<a href="mailto:'+addr+'" title="Send email!">'+ addr +'</a>')
	.hover(function(){window.status="Send email!";}, function(){window.status="";});
	$(spt).remove();
});
