$(document).ready(function(){
	//###############   Form focus & default text   ###############
	$("form input.required:not([type=password]), form textarea.required").each(function(i) {
		$ParentForm = $(this).parents("form");
		if ($ParentForm.attr("id") == "search-form" || $ParentForm.attr("id") == "image-search-form")
			DefaultValue = "Enter search term";
		else
			DefaultValue = "required";
		$(this).attr("notequal", DefaultValue);

		if ($(this).val() == "") {$(this).val(DefaultValue).addClass("empty");}

		$(this).focus(function () {
			if ($(this).parents("#search-form").length || $(this).parents("#image-search-form").length)
				DefaultValue = "Enter search term";
			else
				DefaultValue = "required";

			if ($(this).val() == DefaultValue)
				$(this).val("").removeClass("empty");

		}).blur(function () {
			if ($(this).val() == "") {
				if ($(this).parents("#search-form").length || $(this).parents("#image-search-form").length)
					DefaultValue = "Enter search term";
				else
					DefaultValue = "required";

				$(this).val(DefaultValue).addClass("empty");
			}
		});
	});

	$("#contact-form #reason-other").hide().prev().hide();
	$("#contact-form #enquiry-reason").change(function () {
		//###   Dropdown box selection   ###
		if ( $(this).val() == "Other >>" )
			$("#contact-form #reason-other").fadeIn("slow").prev().fadeIn("slow");
		else
			$("#contact-form #reason-other").fadeOut().prev().fadeOut();
	});
});


//###   Add custom method - this requires the value to be the same as the first parameter   ###
$.validator.methods.notequal = function(value, element, param) {
	return value != param;
};

$(document).ready(function() {
	//###   CONTACT US FORM   ###
	$("#contact-form").validate({
		submitHandler: function(form) {
			//###   Disable the Submit button   ###
			$("#contact-form .button").attr("disabled","true").fadeTo("slow", 0.20).addClass("disabled");

			SubmitContactForm();
			return false;
		}
	});

	//###   SEARCHING   ###
	$("#search-form").validate({
		rules: {
			keywords: {
				required: true,
				minlength: 3,
				maxlength: 30
			}
		}
	});
});
