﻿function movement() {
    $("#popUpReglasDeCancelacionTitle").mousedown(function(e) {
    $("#DetalleHotelesBody").mousemove(function(e) {


    $('#popUpReglasDeCancelacionTitle').css("cursor", "move");
            $('#popUpReglasDeCancelacion').css({ left: (e.pageX - ($('#popUpReglasDeCancelacion').width() / 2)), top: e.pageY - (30) });

        });

    });
    $("#popUpReglasDeCancelacionTitle").mouseup(function(e) {

    $('#popUpReglasDeCancelacionTitle').css("cursor", "auto");
    $('#DetalleHotelesBody').unbind('mousemove');
    });





    $("#popUpPrecioDeCadaNocheTitle").mousedown(function(e) {
    $("#DetalleHotelesBody").mousemove(function(e) {

    $('#popUpPrecioDeCadaNocheTitle').css("cursor", "move");

    //$('#popUpPrecioDeCadaNoche').css({ left: (e.pageX - ($('#popUpPrecioDeCadaNoche').width() / 2)), top: (e.pageY /2) - (30) });

    });

    });
    $("#popUpPrecioDeCadaNocheTitle").mouseup(function(e) {

    $('#popUpPrecioDeCadaNocheTitle').css("cursor", "auto");
    $('#DetalleHotelesBody').unbind('mousemove');
});




$("#popUpComodidadesTitle").mousedown(function(e) {

$('#popUpComodidadesTitle').css("cursor", "move");

    $("#DetalleHotelesBody").mousemove(function(e) {


        $('#popUpComodidades').css({ left: (e.pageX - ($('#popUpComodidades').width() / 2)), top: e.pageY - (30) });

    });

});
$("#popUpComodidadesTitle").mouseup(function(e) {

$('#popUpComodidadesTitle').css("cursor", "auto");
$('#DetalleHotelesBody').unbind('mousemove');
});
    
}


function GenerateCalenar(jsonRoom) {
    var checkIn;
    var checkOut;
    var checkInWeekDay;
    var checkOutWeekDay;
    var checkInWeekMonth;
    var checkOutWeekMonth;
    var checkInMonthDay;
    var checkOutMonthDay;
    var result = "";
    var i;
    var count;
    var checkCmpInWeekDay;
    var checkCmpOutWeekDay;
    var j;
    var currentMonth;
    var count = 0;
    var currrency;
    var charges;
    var response = new Date();
    var aux = new Date();
    checkIn = parseDate(jsonRoom.CheckInFormatString);
    checkOut = parseDate(jsonRoom.CheckOutFormatString);
       
    checkInWeekDay = ((((Date.UTC(checkIn.getFullYear(), checkIn.getMonth(), checkIn.getDate()) / 1000) / 60) / 60) / 24);
    checkOutWeekDay = ((((Date.UTC(checkOut.getFullYear(), checkOut.getMonth(), checkOut.getDate()) / 1000) / 60) / 60) / 24);
    aux = checkIn;

    if (varLocalCurrency == "LocalCurrency")
        currrency = $("#lblCurrencySignLocal").text();
    else
        currrency = $("#lblCurrencySignNoLocal").text();
    
    for (i = 0; i < (checkOutWeekDay - checkInWeekDay); i++) {
        if (varLocalCurrency == "LocalCurrency") {

            charges = jsonRoom.LocalDailyCharges[count];
        }
        else {
            charges = jsonRoom.DailyCharges[count];
        }

        if ((aux.getDate() == 1) | (i == 0)) {
            //buid month

            if (i != 0) {

                if (getMonDay(aux) != 1) {
                    for (j = getMonDay(aux); j < 8; j++)
                        result += "<td class=\"fechaNoDisponible\"></td>";
                }
                result += "</tr>";
                result += "</table>";
            }
            result += "<strong class=\"tituloTablaFechas\">" + aMonthNames[aux.getMonth()] + "</strong>";
            result += "<table class=\"tablaFechasCheckin\">";
            result += "<tbody>";
            result += "<tr class=\"titulosDeFechas\">";
            result += "<th class=\"colFechas\">" + $("#lblFechas").text() + "</th>";
            result += "<th>" + aDayWeekNames[1] + "</th>";
            result += "<th>" + aDayWeekNames[2] + "</th>";
            result += "<th>" + aDayWeekNames[3] + "</th>";
            result += "<th>" + aDayWeekNames[4] + "</th>";
            result += "<th>" + aDayWeekNames[5] + "</th>";
            result += "<th class=\"sabYDom\">" + aDayWeekNames[6] + "</th>";
            result += "<th class=\"sabYDom\">" + aDayWeekNames[0] + "</th>";
            result += "</tr>";
            if (getMonDay(aux) != 1) {
                result += "<tr>";
                result += "<td class=\"colFechas\">" + getFromWeek(aux).getDate() + " " + $("#lblAl").text() + " " + getToWeek(aux).getDate() + "</td>";
                for (j = 1; j < getMonDay(aux); j++)
                    result += "<td class=\"fechaNoDisponible\"></td>";
            } //end if buid month

        }

        if (getMonDay(aux) == 1) {
            result += "</tr>";
            result += "<tr>";
            result += "<td class=\"colFechas\">" + getFromWeek(aux).getDate() + " " + $("#lblAl").text() + " " + getToWeek(aux).getDate() + "</td>";
        }

        result += "<td class=\"colFechas\">" + currrency + " " + Math.ceil(charges).toString() + "</td>";
        count++;


        aux.setDate(aux.getDate() + 1);
    } //end for
    aux.setDate(aux.getDate() - 1);
    if (getMonDay(aux) != 7) {
        for (i = getMonDay(aux); i < 7; i++)
            result += "<td class=\"fechaNoDisponible\"></td>";
        result += "</tr>";
        result += "</table>";
    }
    return result;
}


function getMonDay(date) {

    if (date.getDay() == 0)
        return 7;
    else
        return date.getDay();
}

function compareUtc(date1, date2) {
    var result1;
    var result2;
    result1 = ((((Date.UTC(date1.getFullYear(), date1.getMonth(), date1.getDate()) / 1000) / 60) / 60) / 24);
    result2 = ((((Date.UTC(date2.getFullYear(), date2.getMonth(), date2.getDate()) / 1000) / 60) / 60) / 24);
    return (result1 == result2)

}
function getFromWeek(date) {
    var result = new Date(date);
    var monthBeg = new Date(result.getFullYear(), result.getMonth(), 1);

    if (compareUtc(result, monthBeg))
        return result;

    if (date.getDay() == 0)
        result.setDate(date.getDate() - 6);
    else
        result.setDate(date.getDate() - (date.getDay() - 1));
    return result;
}
function getToWeek(date) {
    var result = new Date(date);
    var monthBeg = new Date(result.getFullYear(), result.getMonth() + 1, 1);
    monthBeg.setDate(monthBeg.getDate() - 1);

    if (date.getDay() == 0)
        result.setDate(date.getDate());
    else
        result.setDate(date.getDate() + (7 - date.getDay()));

    if (result > monthBeg)
        return monthBeg;
    else
        return result;

}

function showInfoEstimatedPrice(obj) {
    $('#infoEstimatedTax').css({ top: $(obj).offset().top });
    $("#infoEstimatedTax").show();
}
