﻿$(document).ready(
		function() {	
			
			
			// LOADING POPUP
			// Click the button event!
			$("#button_pop").click(function() {
				// centering with css
					centerPopup();
					// load popup
					loadPopup();
				});

			// CLOSING POPUP
			// Click the x event!
			$("#popupLoginClose").click(function() {
				disablePopup();
			});
			$("#popupLoginClose2").click(function() {
				disablePopup();
			});
			$("#popupFormClose").click(function() {
				disablePopup();
			});				
			// Click out event!
			$("#backgroundPopup").click(function() {
				disablePopup();
				//centerPopup();
				//loadPopup();
			});
			// Press Escape event!
			$(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");
		    
			$("#wayne_form").validate({
				rules: {
					first_name:{
						required: true,
						minlength: 2
					},
					last_name:{
						required: true,
						minlength: 2
					},					
					phone:{
						required: true,
						phoneUS: true                
						// minlength: 3
					},			
					email: {
						required: true,
						email: true
					},
					car_info:{
						required: true,
						minlength: 2
					},					
					hear:{
						required: true,
						minlength: 2
					}					
					
				},
				messages: {
					name: "Enter your name",			
					address: "Enter your address",
					city: "Enter your city",
					code: {
							required: "Enter a code",
							minlength: "Code consist min 5 characters",
							number: "Only numbers allowed"			

							},
					phone: {
						required: "Fill in num of phone",
						// minlength: "Your area code should be 3 digits long"
					},
					email: "Enter a valid email address",
					agree: "Please accept our policy"

				}
			});		    

	});

	function openwindow2()
	{	    
	    loadPopup();
	    centerPopup();
	}
	function openwindow3()
	{	    
	    loadPopup2();
	    centerPopup2();
	}
	function openform()
	{	    
	    loadFormPopup();
	    centerFormPopup();
	}	
