﻿$(document).ready(
		function() {	
			
			$("#button_pop").click(function() {
					centerPopup();
					loadPopup();
				});
			
			$("#popupLoginClose").click(function() {
				disablePopup();
			});
			$("#popupLoginClose2").click(function() {
				disablePopup();
			});
			$("#popupFormClose").click(function() {
				disablePopup();
			});	
			$("#couponPopupClose").click(function() {
				disablePopup();
			});				
			$("#backgroundPopup").click(function() {
				disablePopup();
			});
			
			$(document).keypress(function(e) {
				if (e.keyCode == 27 && popupStatus == 1) {
					disablePopup();
				}
			});
			
		    jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
		        phone_number = phone_number.replace(/\s+/g, ""); 
		        return this.optional(element) || phone_number.length > 9 &&
		            phone_number.match(/^(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
		    }, "Enter a valid phone number");
		    
			jQuery.validator.addMethod(
					  "selectNone",
					  function(value, element) {
					    if (element.value == "none")
					    {
					      return false;
					    }
					    else return true;
					  },
					  "Please select an option."
					);		    
		    
			$("#wayne_form").validate({
				rules: {							
					service:"required",				
					first_name:{
						required: true,
						minlength: 2
					},
					last_name:{
						required: true,
						minlength: 2
					},					
					phone:{
						required: true,
						phoneUS: true                
					},			
					email: {
						required: true,
						email: true
					},
					car_info:{
						required: true,
						minlength: 2
					},
					year:{
						required: true,
						number: true,
						minlength: 4				
					},
					make: "required",
					model: "required",
					date: "required",
					time: "required",					
					hear:{
						required: true,
						minlength: 2
					}					
				},
				messages: {
					first_name: "Enter your name",			
					last_name: "Enter your last name",
					email: "Enter a valid email address",
					phone: {
						required: "Fill in num of phone"
					},				
					year: {
							required: "Enter a year",
							minlength: "Code consist min 4 characters",
							number: "Only numbers allowed"
					},				
					make: "Enter make",
					model: "Enter model",
					date: "Enter date",
					time: "Enter time"
				}
			});	    
	});
	function openwindow()
	{
	    window.open("https://server.iad.liveperson.net/hc/45300888/?cmd=file&file=visitorWantsToChat&site=45300888&imageUrl=http://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/English/General/2a","mywindow","resizable=1,width=475,height=400");
	}
	function openwindow2()
	{	    
	    loadPopup();
	    centerPopup();
	}
	function openwindow3()
	{	    
	    loadPopup2();
	    centerPopup2();
	}
	function openform()
	{	    
	    loadFormPopup();
	    centerFormPopup();
	}
	function openCoupon()
	{	    
	    loadCouponPopup();
	    centerCouponPopup();
	}	
function openChat(){
	window.open('https://server.iad.liveperson.net/hc/45300888/?cmd=file&file=visitorWantsToChat&site=45300888&imageUrl=http://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/English/General/2a','mywindow','width=800,height=800');
}
function zoom(){	window.open('http://mapq.st/pzlA7F','mywindow','width=800,height=800');}
