﻿function datepicker_checkin_init(img_src) {
    btn_img = img_src ? img_src : "/images/btn_cal.gif";
    $j(".check-in-date").datepicker({
        showOn: 'button', 
        buttonImage: btn_img,
        buttonImageOnly: true, 
        minDate: new Date(),
        beforeShow: function() {
            datepicker_before_show();
            var check_out_date = $j(".check-out-date").val();
            if (check_out_date != "") {
                var max_date = new Date(check_out_date);
                max_date.setDate(max_date.getDate() - 1);
                $j(".check-in-date").datepicker('option','maxDate', max_date);
            }
        },
        onClose: function() {
            datepicker_on_close();
        }
    });
}

function datepicker_checkout_init(img_src) {
    btn_img = img_src ? img_src : "/images/btn_cal.gif";
    var min = new Date();
    min.setDate(min.getDate() + 1);
    $j(".check-out-date").datepicker({
        showOn: 'button', 
        buttonImage: btn_img,
        buttonImageOnly: true, 
        minDate: min,
        beforeShow: function() {
            datepicker_before_show();
            var check_in_date = $j(".check-in-date").val();
            if (check_in_date != "") {
                var min_date = new Date(check_in_date);
                min_date.setDate(min_date.getDate() + 1);
                $j(".check-out-date").datepicker('option','minDate', min_date);
            }
            
        },
        onClose: function() {
            datepicker_on_close();
        }
    });
}

function datepicker_before_show() {
    $j("ul.res").parent().addClass("active");
    $j("ul.active, .menu li").unbind();
}

function datepicker_on_close() {
    $j("ul.active, .menu li").hover(function() {
        $j("ul.active").removeClass("active");
     },
     function() {});
     
     $j("ul.active").click(function() {
        $j(this).removeClass("active");
     });
}