$(document).ready(function(){
	//standard AJAX mail form submission (requires mail2_plus.php, and captcha)
	//add form name to selector for submit event, the rest will take care of itself!
	$("input[type=submit]").removeAttr("disabled");
	$("#contactf").submit(function(e){
		e.preventDefault();
		var form = $(this);
		var btn = $(this).find("input[type=submit]");
		btn.attr("disabled","disabled");
		$.post("ajax/simple-mail.php",form.serialize(),function(data){
			var err = data.split("|");
			if (err[0] == "error") {
				alert(err[1]);
				btn.removeAttr("disabled");
			} else {
				//if a redirect is specified, use that. Else replace the form with a message.
				if (form.find("input[name=redirect]").length && form.find("input[name=redirect]").val() != "") {
					window.location = form.find("input[name=redirect]").val();
				} else {
					form.html("<p class='sent'>Your message has been sent.</p>");
				}
			}
		});
	});
	
	$("#contactf input,#contactf textarea,#searchf input").focus(function(){
		var v = $(this).val();
		if (v == "Search" || v == "Name" || v == "Phone" || v == "Email" || v == "Comments/Questions" || v == "<< Copy the code") {
			$(this).val("");
		}
	});
	$("#contactf input,#contactf textarea,#searchf input").blur(function(){
		var n = $(this).attr("name");
		var v = $(this).val();
		if (n == "search" && v == "") {
			$(this).val("Search");
		} else if (n == "name" && v == "") {
			$(this).val("Name");
		} else if (n == "phone" && v == "") {
			$(this).val("Phone");
		} else if (n == "email" && v == "") {
			$(this).val("Email");
		} else if (n == "comments" && v == "") {
			$(this).val("Comments/Questions");
		} else if (n == "code" && v == "") {
			$(this).val("<< Copy the code");
		}
	});
	
	$("#searchInput").keyup(function(){
		var searchfor = $(this).val();
		$.post("ajax/search.php",{"search":searchfor},function(data){
			$("#autocomplete").html(data).show();
		});
	});
	
	$("#searchInput").blur(function(){
		$("#autocomplete").hide();
	});
});
