
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 + "/index/jsonfirstname"
            },
            lname:{
                required: true,
                minlength: 2,
                remote: BaseUrl + "/index/jsonlastname"
            },
            /*			phone:{
				required: true,
				phoneUS: true                
			},			
			email: {
				required: true,
				email: true
			},*/
            year:{
                required: true,
                number: true,
                minlength: 4,
                remote: BaseUrl + "/index/jsonyear"
            },
            make:{
                required: true,
                remote: BaseUrl + "/index/jsonmake"
            },
            model:{
                required: true,
                remote: BaseUrl + "/index/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"
        }
    });
	
    $("#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/22101221/?cmd=file&file=visitorWantsToChat&site=22101221','mywindow','width=600,height=600');
}
function openLink(name, server){
    var yourname = name;
    var server = server;    
    var emailE=(name + '@' + server);
    var mailto_link ='mailto:' + emailE;    
    window.document.location.href = mailto_link;
   // if (win && win.open &&!win.closed) win.close();
}
