﻿function SetCheckOutDate(checkinClientId, checkoutClientId) {
    var inpCheckIn = document.getElementById(checkinClientId);
    var inpCheckOut = document.getElementById(checkoutClientId);
    
    var day = inpCheckIn.value.substring(0, 2) - 0; // -0 is a hack to convert to int. parseInt returns 0 for parseInt('08')! Bug in javascript ?
    var month = inpCheckIn.value.substring(3, 5) - 0;
    var year = parseInt(inpCheckIn.value.substring(6, 10));
    
    var checkInDate = new Date(year, month - 1, day + 1); // Date.Parse does not work with this date format dd-mm-yyyy

    day = (checkInDate.getDate() < 10 ? '0' : '') + checkInDate.getDate();
    month = ((checkInDate.getMonth() + 1) < 10 ? '0' : '') + (checkInDate.getMonth() + 1);

    inpCheckOut.value = day + '-' + month + '-' + checkInDate.getFullYear();
    var checkOutCalendar = $('#' + checkoutClientId);
    checkOutCalendar.datepicker('option', 'minDate', checkInDate);
    //inpCheckOut.focus();
    //inpCheckOut.blur();
}