﻿$(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();
		});	
		$("#popupHomeClose").click(function() {
			disablePopup();
		});
		$("#popupMenuClose").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 like 777-777-7777");		
	    
		$("#serviceForm").validate({			
			rules: {
				name:{
					required: true,
					minlength: 2
				},
				lname:{
					required: true,
					minlength: 2
				},				
				phone:{
					required: true,
					phoneUS: true                
				},			
				mail: {
					required: true,
					email: true
				},
				year:{
					required: true,
					number: true,
					minlength: 4				
				},
				make: "required",
				model: "required",
				date: "required",
				time: "required"
			},
			messages: {
				name: "Enter your name",			
				lname: "Enter your last name",
				mail: "Enter a valid email address",
				phone: {
					required: "Fill in num of phone"
					// minlength: "Your area code should be 3 digits long"
				},				
				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 openHomePopup() {
	loadHomePopup();
	centerHomePopup();
}		

function openwindow3() {
	loadPopup2();
	centerPopup2();
}
function openChat(){
	window.open('https://extranet.dealercentric.com/app-templates/LoanApplication/QuickApplication.aspx?AssociateID=3003&AssociateTypeID=4000&htm=1','mywindow','width=800,height=800');
}

function openMap(){
	w = 450;
	h = 400;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left ='+LeftPosition;
	window.open('http://classic.mapquest.com/embed#b/maps/m:map:12:30.45939:-84.354826::::::1:1:::::::::/l:Legacy+Toyota+Of+Tallahassee:3800+West+Tennessee+Street:Tallahassee:FL:32304:US:30.459398:-84.35481:address::1:::4099354/e','mywindow',settings);
}

