$(document).ready(function(){
	
	// Submit inside Contact Form
	$(".c_submit").click(function() {
		 $("#l_contact").submit();
		 return false;
	});

	// Clear Form Fields
	$("input.in_ct").focus(function() {
	if( this.value == this.defaultValue ) {
		this.value = "";
	}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	$("textarea.in_ct").focus(function() {
	if( this.value == this.defaultValue ) {
		this.value = "";
	}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	
	// Left Nav Contact Form
	$("#l_contact").submit(function() {
		var dataString = 'the_page=' + $("input#the_page").val() + '&submit=' + $("input#go").val() + '&name=' + $("input#name").val() + '&t_comments=' + $("textarea#t_comments").val() + '&email=' + $("input#email").val() + '&phone=' + $("input#phone").val() + '&goto=' + $("input#goto").val();
		$.ajax({
			beforeSend: function() {
				 $("#c_form").hide();
				 $("img#loader").css("display", "block");
			},
			type: "POST",
			url: "http://www.customprinters.com/wp-content/themes/custom-printers/includes/contact.php",
			data: dataString,
			success: function(html){
				if (html.indexOf('array_subset') != '-1') {
					var brokenstring = html.split("#$%^");
					$("input.in_ct").css("color", "#6c6d6f");
					for (i = 1; i <= brokenstring.length; i++) {
						$("input#" + brokenstring[i]).css("color", "#AA0000");
					}

					$("#loader").hide();
					$("#c_form").fadeIn(1000);
				} else {
					$("#loader").hide();
					$("#c_form").html(html);
					$("#c_form").fadeIn(1000);
				}
			}
		});
		return false;
	});
});


