// Contact Form
$(document).ready(function(){

	// Highlighting Current Inputs/Labels
	$("#test2 input,#test2 textarea")
		.focus(function(){
			$(this).parents(".row").addClass('hover');
		})
		.blur(function(){
			$(this).parents(".row").removeClass('hover');
				// Validate Single Form Element
				$(this).valid();
		});
			
	// Main Form Validation/Submit
	$("#test2").validate({
		highlight: function(element, errorClass) {
			$(element).parents(".row").addClass(errorClass);
		},
		unhighlight: function(element, errorClass) {
			$(element).parents(".row").removeClass(errorClass);
		},
		errorElement: "span",
		errorPlacement: function(error, element) {
			error.appendTo(element.parent());
		},
		submitHandler: function(form) {
			// Disable Elements (To prevent double submission)
			$("#test2 input[type='submit']").hide();
			$("#form").val("javascript");		
			// Post Data
			$.post("index.php",$("form").serialize(),function(data){
				// Response Message
				alert(data);
				$("#test2 input,#test2 textarea,#test2 select").removeAttr("disabled");
				$("#test2 input[type='submit']").show();
			});
			$("#test2 input,#test2 textarea,#test2 select").attr("disabled","disabled");
		}
	});

});