// JavaScript Document

// stop the click-happy people
var inuse = false;

function ajaxMail(){

// get the data we're going to send
var strname = $('#name').val();
var stremail = $('#email').val();
var strmessage = $('#message').val();

// check to see if a message is being sent or bogus info
if(inuse){ /* ignore the click */ }
else if(strname == "" || stremail == "" || strmessage == "") { alert("Please make sure you fill out the form completely"); } 
else {

// it's in use now, grey out the button
inuse = !inuse;
$("a.submit").css("background","#666").text("sending...");

// do an ajax call to send the info
$.ajax({
type: "POST",
url: "mail.php",
data: "name=" + strname + "&email=" + stremail + "&message=" + strmessage,
success: function(){

// let them know how it's going with the button text
$("a.submit").text("message sent");
setTimeout('$("a.submit").text("thank you!").css("background","#06F");',2000);
setTimeout('$("a.submit").text("submit");$("#name").val("");$("#email").val("");$("#message").val("");txtCount();',5000);

// ok we're done. turn the button back on
inuse = !inuse;

}
});
}
}

function txtCount(){
var maxchars = 500;
var strmessage = $('#message').val();
var strlength = strmessage.length;
if (strlength > maxchars) { // see if it's longer than the max
$('#message').val(strmessage.substring(0, maxchars));
} else {
$('#char').text(maxchars - strlength); // update characters remaining 
}
}// JavaScript Document