﻿var dateformat;
var locale;
var nights;

Date.prototype.addDays = function (days) {
    this.setDate(this.getDate() + days);
}

$(document).ready(function () {

    dateformat = $('#dateformat').val();
    locale = $('#locale').val();
    nights = parseInt($('#nights').val());
    $.datepicker.setDefaults($.datepicker.regional[locale]);

    $("#checkin").datepicker({
        changeMonth: true,
        changeYear: true,
        minDate: 0,
        dateFormat: dateformat,
        onSelect: function (dateText, inst) {
            sDate = $("#checkin").datepicker("getDate");
            sDate.addDays(nights);
            $("#checkout").datepicker("setDate", sDate);
        }
    });
    $("#checkin").datepicker($.datepicker.regional[locale]).datepicker("setDate", "+0d");

    $("#checkout").datepicker({
              changeMonth: true,
        minDate: 1,
        changeYear: true,
        dateFormat: dateformat
    });
    $("#checkout").datepicker($.datepicker.regional[locale]).datepicker("setDate", "+" + nights + "d");

    $("#search").click(function () {
        var id = $('#id').val();
        var lid = $('#lid').val();
        var interface = $('#interface').val();
        var theme = $('#theme').val();
        var ci = $('#checkin').val();
        var co = $('#checkout').val();
        var a = $('#adults').val();
        var c = $('#children').val();
        var windowname = "geobooking" + id;
        window.open(interface + '?id=' + id + '&ci=' + ci + '&co=' + co + "&th=" + theme + "&l=" + lid + "&a=" + a + "&c=" + c, windowname, 'width=996,height=718,scrollbars=no,status=yes,resizable=no');
    });

});
