<!--
var page = "";
$(function(){
	if (!jQuery.support.leadingWhitespace) { $('body').addClass("ie-fix"); }
		   
	$('#quick_contact:not(body.request #quick_contact)').hide();
	//$('body.request #quick_contact').show();
	$('#contact_more').removeClass('hide');
	if($("a[rel*='request']").length) {
		$("a[rel*='request']").click(function(){
			page = $("body").hasClass("repair_services") ? unescape(getUrlVar("product",$(this).attr('href'))) : $("#breadcrumbs").text() ;
			$('#requesttype').text(page);
			$("#quick_contact")
					.append($('<p class="close"><span class="simplemodal-close">Close</span></p>'))
					.modal({close: false, onClose: closeModal, onOpen: openModal, persist: false, onShow: onshowModal});
			return false;
		});
	}
		   });

function closeModal (dialog) {
	dialog.data.fadeOut('slow', function () {
		dialog.container.fadeOut('slow', function () {
			dialog.overlay.slideUp('slow', function () {
				$.modal.close();
				$('.close').remove();
			});
		});
	});
}
function openModal (dialog) {
	dialog.overlay.fadeIn('slow', function () {
		dialog.container.fadeIn('slow', function () {
			dialog.data.hide().slideDown('slow');	 
		});
	});
}
function onshowModal (dialog) {
	$(document).keypress(function(e){
	  var key  = (window.event) ?  event.keyCode : e.keyCode;
 	 if( key == 27 ) $.modal.close();
	});	
	if($("#quick_contact").length) {

		$("#quick_contact input:not(.optional), #quick_contact textarea:not(.optional)").blur(function(){
			if ($(this).val() == "") $(this).addClass("form_error"); else $(this).removeClass("form_error");
		});

		$("#quick_contact input[name='phone']").change(function(){
			var self = $("#quick_contact input[name='phone']");
			$('.contact_error1').remove();
				var regex = /^[0-9ext,.\s-()\+]+$/;
				if (!regex.test($(this).val())) {
					$(self).addClass("form_error");
					$(self).after($("<p class='contact_error1 form_error'>Phone numbers cannot contain letters (with the exception of 'ext'). Please correct.</p>"));
				} else {
					$(self).removeClass("form_error");
				}
		});

		$("#quick_contact input[name='email']").change(function(){
			var self = $("#quick_contact input[name='email']");
			$('.contact_error').remove();

				var regex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/;
				if (!regex.test($(self).val())) {
					$(self).addClass("form_error");
					$(self).after($("<p class='contact_error form_error'>Invalid email format. Please correct.</p>"));
				} else {
					$(self).removeClass("form_error");
				}
		});


		$("#quick_contact button[name='contact_send'],#quick_contact button[name='repair_send']").click(function(){
			var repair = $(this).attr('name')=="repair_send" ? "true" : "false";
			$("#quick_contact input:not(.optional), #quick_contact textarea:not(.optional)").each(function(){
				if ($(this).val() == "")	$(this).addClass("form_error"); else $(this).removeClass("form_error");
			});
					var self = $("#quick_contact input[name='phone']");
				$('.contact_error1').remove();
					var regex = /^[0-9ext,.\s-()\+]+$/;
					if (!regex.test($(self).val())) {
						$(self).addClass("form_error");
						$(self).after($("<p class='contact_error1 form_error'>Phone numbers cannot contain letters (with the exception of 'ext'). Please correct.</p>"));
					} else {
						$(self).removeClass("form_error");
					}
				 self = $("#quick_contact input[name='email']");
				$('.contact_error').remove();
	
					var regex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/;
					if (!regex.test($(self).val())) {
						$(self).addClass("form_error");
						$(self).after($("<p class='contact_error form_error'>Invalid email format. Please correct.</p>"));
					} else {
						$(self).removeClass("form_error");
					}
					
			if ($("#quick_contact input, #quick_contact textarea").hasClass('form_error')) {
				alert("Please complete all fields.");
			} else { 
				var submitbutton = $(this);
					submitbutton.attr("disabled", "true");
					$("#quick_contact form").append($('<p class="sending" id="send_notice">Please wait while we send your message...</p>'));
					name = $("#quick_contact input[name='name']").val();			
					data_string = $("#quick_contact form").serialize();
					$('#quick_contact').fadeTo(500,.5);
					$.ajax({
					   type: "POST",
					   url: "/scripts/ajax/contactprocess.php",
					   data: data_string+"&page="+page+"&repair="+repair+"&ajax=true",
					   async: false,
					   success: function(msg){
						//DEBUG							alert(msg);						
							$("#quick_contact h2").after(
								$("<p class='success column span-4 last'>Hello, <strong>"
									+ name	+"</strong>:<br />" + 
									"Thank you for your interest. You'll hear back from us within 1 business day.</p>")); 
							
							$("#quick_contact form").remove();
				
						},
					   error: function(obj,text,error) {
						
						if (obj.status == "400") {
							$("#send_notice").remove();
							submitbutton.removeAttr("disabled");
							Recaptcha.reload();
           					alert("Invalid captcha response. Please try again.");	
       					 } else {

						$("#quick_contact h2").after(
							$("<p class='error column span-4 last'>Hello, <strong>"
								+ name	+ "</strong>:<br />" + 
								"Something went wrong when we tried to send your message. You can try again later "
								+ "or contact us another way: by phone at 800-225-6642 or by e-mail at "
								+ "<a href='info@mohawkltd.com'>info@mohawkltd.com</a>.</p>")); 
						//alert(obj.responseText);
						
						$("#quick_contact form").remove();
						 }
					   }
					 });
					$('#quick_contact').fadeTo(500,1);
					
			}
			return false; // We don't want to submit the form since AJAX handled it
		});
	}
}
function getUrlVar(varname, link){  var href = link ? link : window.location.href; 
	varname = varname.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS = "[\\?&]"+varname+"=([^&#]*)"; 
	var regex = new RegExp(regexS); var results = regex.exec(href); 
	return results == null ? "" : results[1];
}
