jQuery(document).ready(function() {
	$("#popupClose").click(function() {
		disablePopup();
	});        
	$("#backgroundPopup").click(function() {
		disablePopup();
	});
	/* DATE PICKER */
	$("#datepicker").datepicker({
		showOn: 'button',
		buttonImage: BaseUrl + '/images/form/calendar.jpg',
		buttonImageOnly: true
	});	

	/* FORM VALIDATE */
	
	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");
	
	$("#shedule_form form").validate({		
		rules: {
			fname:{		
				required: true,
				minlength: 2,
				remote: BaseUrl + "/service/jsonfirstname"
			},
			lname:{
				required: true,
				minlength: 2,
				remote: BaseUrl + "/service/jsonlastname"
			},				
/*			phone:{
				required: true,
				phoneUS: true                
			},			
			email: {
				required: true,
				email: true
			},*/
			year:{
				required: true,
				number: true,
				minlength: 4,
				remote: BaseUrl + "/service/jsonyear"
			},
			make:{
				required: true,
				remote: BaseUrl + "/service/jsonmake"
			},
			model:{
				required: true,
				remote: BaseUrl + "/service/jsonmodel"
			}
		},
		messages: {
			fname: "Enter your name",			
			lname: "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"
		}		
	});
	
	$("#subscription_form").validate({		
		rules: {
			fname:{		
				required: true,
				minlength: 2
			},
			lname:{
				required: true,
				minlength: 2
			},				
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			fname: "Enter your name",			
			lname: "Enter your last name",
			email: "Enter a valid email address"
		}
	});
	
	$("#Phone1").attr("checked", "checked");
	$('#Email').attr('class', 'text2');		
	$('#Email').attr('disabled', true);		
	
	$("#Phone1").click(function() {
		$(this).next("input").removeAttr("disabled").attr('class', 'text');		
		$('#Email').attr('class', 'text2');		
		$('#Email').attr('disabled', true);		
	});
	$("#Email1").click(function() {
		$('#Phone').attr('class', 'text2');
		$('#Phone').attr('disabled', true);
		$(this).next("input").removeAttr("disabled").attr('class', 'text');
	});		
		
});  
function openwindow() {
	loadPopup();
	centerPopup();
}
function openCopy(url){	
	window.open(url,'mywindow','width=400,height=200');
}
function openlivetext(){	
	window.open('https://server.iad.liveperson.net/hc/56216877/?cmd=file&file=visitorWantsToChat&site=56216877','mywindow','width=400,height=400');
}
function map(){
	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://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=1545+East+Merritt+Island+Causeway,+Merritt+Island,+FL&aq=0&sll=28.356496,-80.669307&sspn=0.009158,0.016512&ie=UTF8&hq=&hnear=1545+E+Merritt+Island+Causeway,+Merritt+Island,+Brevard,+Florida+32952&t=h&z=14&vpsrc=0&ll=28.356161,-80.669346&output=embed','mywindow',settings);
}

