$(document).ready(function(){
var d = document.forms[0];

$("#security").attr("autocomplete", "off");

$("#myForm").attr("method", "post");
$("#myForm").attr("action", "contact.php");

$(".entry_field").focus(function(){
$(this).css("background", "#f0f8ff");

});

$(".entry_field").blur(function(){
$(this).css("background", "#ffffff");

});

$("#name").focus();
$(":button").click(function(){
if(confirm("Are you sure you want to clear this form? Doing so" +'\n' + "will completely erase your entries. If you do want to" + '\n' + "erase your entries, click OK. If you don't, click Cancel."))
{
for(i=1;i<d.elements.length-2;i++)
{
d.elements[i].value="";
$("#name").focus();
}
}

else
{
return false;
}

});

$(".info1").mouseover(function(){
$("#tip1").css("visibility", "visible");
$("#tip1").html("I promise I won't give or sell your e-mail address to anyone. I take internet privacy very seriously.");
});

$(".info1").mouseout(function(){
$("#tip1").css("visibility", "hidden");
});

$(".info2").mouseover(function(){
$("#tip2").css("visibility", "visible");
$("#tip2").html("This is a security feature to prevent spamming programs called bots from abusing this form.");
});

$(".info2").mouseout(function(){
$("#tip2").css("visibility", "hidden");
});

$(":submit").click(function(){
var reg_exp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/;
var exp = /^j57af$/;
var maxLimit = 400;

if(d.elements[1].value.length < 5 )
{
alert("You didn't include your name.");
d.elements[1].focus();
return false;
}

if(!reg_exp.test(d.elements[2].value))
{
alert("Invalid e-mail address!");
d.elements[2].focus();
return false;
}

if(d.elements[3].value.length < 5 )
{
alert("You didn't make any comments.");
d.elements[3].focus();
return false;
}

if(d.elements[3].value.search(/http/i) > -1)
{
alert("No URLs in the Comments box.");
d.elements[3].focus();
d.elements[3].value="";
return false;
}

if(d.elements[3].value.length > maxLimit)
{
alert("Too many characters were entered in the comments box." + "\n" + "Please shorten your comments.");
d.elements[3].focus();
d.elements[3].value = d.elements[3].value.substring(0, maxLimit);
return false;
}

if(!exp.test(d.elements[4].value))
{
alert("You didn't enter the characters or you didn't enter them correctly. I only" +"\n" +" ask this to keep spammers and scammers from abusing this form. Thanks." +"\n\n" +"- Robert Hughes");
d.elements[4].focus();
d.elements[4].value="";
return false;
}

});

});
