﻿function openDetail(t) {
    var sUrl = "/104/App/dettaglioImmobile.aspx?t=" + t;
    var b = (getWindowWidth()) / 2;
    createUtilityFrame(sUrl, 100, b - 330, 660, 680, true);
}
function getDispo() {
    //hideForm();
    WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(preIds + "btnShowDispo", "", true, "", "", false, true))
}
function hideForm() {
    try {
        $get("checkButton").style.display = "";
        $get("formDati").style.display = "none";
        $get(preId + "displayDispo").style.display = "none";
        $get(preId + "tNrPersone").style.display = "none";
        $get(preId + "fNrPersone").style.display = "none";
    } catch (e) { }
}
function checkDates(val, args) {
    if (PickerDataA.getSelectedDate() == PickerDataDa.getSelectedDate()) {
        alert(strDateErr);
        $get("dt1").className = "tdError";
        $get("dt2").className = "tdError";
        return (false);
    }
    else {
        return (true);
    }
}
function calcolo() {
    var gg = $get(preId + "totGiorni").value;
    var amount = $get(preId + "totStanza").value;
    var addAmount = 0;
    if ($get(preId + "tLettiAggiuntivi3Anni").value > 0) {
        addAmount = gg*(15 * parseInt($get(preId + "tLettiAggiuntivi3Anni").value));
    }
    if ($get(preId + "tLettiAggiuntivi").value > 0) {
        addAmount += gg*(50 * parseInt($get(preId + "tLettiAggiuntivi").value));
    }
    $get("totalAmount").innerHTML = parseInt(amount) + parseInt(addAmount);

    if ($get(preId + "tTipoAlloggio").value == "STD") {
        $get(preId + "tLettiAggiuntivi3Anni").disabled = true;
        $get(preId + "tLettiAggiuntivi").disabled = true;
    }
    else {
        $get(preId + "tLettiAggiuntivi3Anni").disabled = false;
        $get(preId + "tLettiAggiuntivi").disabled = false;
    }

    //Carrello
    $get("totaleAlloggio").innerHTML = $get("totalAmount").innerHTML + ",00";
    $get("totaleProdotti").innerHTML = $get(preId + "totCart").value;
    //alert(parseFloat($get("totalAmount").innerHTML) + parseFloat($get(preId+"totCart").value.replace(",",".")));
    var stayCost = roundNumber(parseFloat($get("totaleAlloggio").innerHTML.replace(",", ".")) + parseFloat($get(preId + "totCart").value.replace(",", ".")));
    $get("totaleVacanza").innerHTML = String.format("{0:n2}",stayCost);
    $get("stayCost").innerHTML = $get("totaleVacanza").innerHTML + " EUR";
    $get("mediumCost").innerHTML = String.format("{0:n2}",roundNumber((stayCost / gg))) + " EUR";

}
function roundNumber(num, dec) {
    return Math.round(num * 100) / 100;
}
function PickerDataDa_OnDateChange(sender, eventArgs) {
    var fromDate = PickerDataDa.getSelectedDate();
    CalendarDataDa.setSelectedDate(fromDate);
    if (PickerDataA.getSelectedDate() < fromDate) {
        var newDate = new Date(fromDate);
        newDate.setDate(fromDate.getDate() + 1);
        CalendarDataA.setSelectedDate(newDate);
        PickerDataA.setSelectedDate(newDate);
    }
    getDispo();
}
function CalendarDataDa_OnChange(sender, eventArgs) {
    var fromDate = CalendarDataDa.getSelectedDate();
    PickerDataDa.setSelectedDate(fromDate);
    if (PickerDataA.getSelectedDate() < fromDate) {
        var newDate = new Date(fromDate);
        newDate.setDate(fromDate.getDate() + 1);
        CalendarDataA.setSelectedDate(newDate);
        PickerDataA.setSelectedDate(newDate);
    }
    getDispo();
}
function ButtonDataDa_OnClick(event) {
    if (CalendarDataDa.get_popUpShowing()) {
        CalendarDataDa.hide();
    }
    else {
        CalendarDataDa.setSelectedDate(PickerDataDa.getSelectedDate());
        CalendarDataDa.show();
    }
}
function ButtonDataDa_OnMouseUp(event) {
    if (CalendarDataDa.get_popUpShowing()) {
        event.cancelBubble = true;
        event.returnValue = false;
        return false;
    }
    else {
        return true;
    }
}


//Picker DataA
function PickerDataA_OnDateChange(sender, eventArgs) {
    var fromDate = PickerDataA.getSelectedDate();
    CalendarDataA.setSelectedDate(fromDate);
    if (PickerDataDa.getSelectedDate() > fromDate) {
        var newDate = new Date(fromDate);
        newDate.setDate(fromDate.getDate() - 1);
        CalendarDataDa.setSelectedDate(newDate);
        PickerDataDa.setSelectedDate(newDate);
    }
    getDispo();
}
function CalendarDataA_OnChange(sender, eventArgs) {
    var fromDate = CalendarDataA.getSelectedDate();
    PickerDataA.setSelectedDate(fromDate);
    if (PickerDataDa.getSelectedDate() > fromDate) {
        var newDate = new Date(fromDate);
        newDate.setDate(fromDate.getDate() - 1);
        CalendarDataDa.setSelectedDate(newDate);
        PickerDataDa.setSelectedDate(newDate);
    }
    getDispo();
}
function ButtonDataA_OnClick(event) {
    if (CalendarDataA.get_popUpShowing()) {
        CalendarDataA.hide();
    }
    else {
        CalendarDataA.setSelectedDate(PickerDataA.getSelectedDate());
        CalendarDataA.show();
    }
}
function ButtonDataA_OnMouseUp(event) {
    if (CalendarDataA.get_popUpShowing()) {
        event.cancelBubble = true;
        event.returnValue = false;
        return false;
    }
    else {
        return true;
    }
}
function showOptions(id, ctl) {
    var sUrl = "/104/app/productslist.aspx?id=" + id;
    var b = Sys.UI.DomElement.getBounds($get("prenotazione"));
    if (id == 4) {
        switch (UIc) {
            case "it":
                sUrl = "http://www.dolomitisuperski.com/altabadia/it-IT/calcolatore-prezzo-skipass-alta-badia-dolomiti-superski-583IT.html";
                break;
            case "de":
                sUrl = "http://www.dolomitisuperski.com/altabadia/de-DE/preise-kalkulator-skipass-alta-badia-dolomiti-superski-583DE.html";
                break;
            case "en":
                sUrl = "http://www.dolomitisuperski.com/altabadia/en-US/price-calculator-skipass-alta-badia-dolomiti-superski-583EN.html";
                break;
        }
        window.open(sUrl);
    }
    else {
        createUtilityFramePR(sUrl, b.y - 40, b.x + 85, 400, 670, ctl);
    }
}
function showCart(ctl) {
    var sUrl = "/104/app/shoppingCart.aspx";
    var b = Sys.UI.DomElement.getBounds($get("prenotazione"));
    createUtilityFramePR(sUrl, b.y, b.x + 85, 400, 670, ctl);
}

function createUtilityFramePR(sUrl, _top, _left, _height, _width, ctl) {
    var ifr = $get("iUty")
    if (ifr != undefined) {
        document.body.removeChild($get("iUty"))
        document.body.removeChild($get("iUtyB"))
    }
    var b = document.createElement("DIV");
    b.id = "iUtyB";
    b.style.width = _width + 4 + "px";
    b.style.height = _height + 24 + "px";
    b.style.top = _top - 22 + "px";
    b.style.left = _left - 2 + "px";
    b.style.position = "absolute";
    b.style.marginTop = "2px";
    b.style.zIndex = "10000";
    b.style.backgroundColor = "#ffffff";
    b.innerHTML = "<img src='/Common/UI/Administration/Images/_closeMini.png' style='float:right;cursor:pointer;margin-top:1px;margin-right:2px;' onclick='wclosePR();' alt='close'/>&nbsp;<b style='font-size:12pt;'>" + ctl.innerHTML + "</b>";

    var i = document.createElement("IFRAME");
    i.id = "iUty";
    i.style.width = _width + "px";
    i.style.height = _height + "px";
    i.style.top = _top + "px";
    i.style.left = _left + "px";
    i.style.position = "absolute";
    i.style.zIndex = "10001";
    i.className = "utilityFrame";
    i.frameBorder = "0";
    i.src = sUrl;
    document.body.appendChild(b);
    document.body.appendChild(i);
}

function wclosePR() {
    try {
        document.body.removeChild($get("iUty"))
        document.body.removeChild($get("iUtyB"))
    } catch (e) { }
}
function addToCartP(id, qty) {
    
    var b = Sys.UI.DomElement.getBounds($get("iUtyB"));
    var s = $get("shopper");
    s.style.width = b.width + "px";
    s.style.height = b.height + "px";
    s.style.top = b.y + "px";
    s.style.left = b.x + "px";

    $get("ctl00_ctl02_idProductToAdd").value = id;
    $get("ctl00_ctl02_QtyToAdd").value = qty;
    __doPostBack('ctl00$ctl02$updateCart', '');

    var bd = Sys.UI.DomElement.getBounds($get("shopperTgt"));
    $("#shopper").toggle();
    $("#shopper").animate({
        width: bd.width - 8,
        height: bd.height,
        top: bd.y,
        left: bd.x + 8
    }, { duration: 450 });
    //window.setTimeout("$('#shopper').toggle()",500);
    window.setTimeout("$('#shopper').fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(4000)", 500);


}

function goDatiUtente() {
    //$get('formDatiUtente').style.display = ''
    //$get("dispoBlock").style.display = "none";
    //$get("cartButtons").style.display = "none";

    //var altc = $get("dispoHTML").outerHTML;
    //var intIndexOfMatch = altc.indexOf("ctl00");
    //while (intIndexOfMatch != -1) {
    //    altc = altc.replace("ctl00", "t")
    //    intIndexOfMatch = altc.indexOf("ctl00");
    //}

    //$get("altContent").innerHTML = altc;
    $get("addToCartButtonsF").innerHTML = $get("addToCartButtons").outerHTML;

    var b = Sys.UI.DomElement.getBounds($get("prenotazione"));
    $get("ctl00_center").style.height = b.height + 100 + "px";
    sanityCheck()

}

function movP(ctl) { ctl.style.backgroundColor = "#ffff00" }
function mouP(ctl) { ctl.style.backgroundColor = "" }

function movP2(ctl) { ctl.style.backgroundColor = "#ffffff" }
function mouP2(ctl) { ctl.style.backgroundColor = "#ffff00" }

//*********************************************************************************
//                           UpdatePanel  gestore eventi elenco
//
function callBackhandler() {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endCb);
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginCb);
}
function beginCb(sender, args) {
    $get("spinner").style.display = "";
}
function endCb(sender, args) {
    $get("spinner").style.display = "none";
    if ($get(preId + "available").value == "ok") {
        $get("formDati").style.display = "";
        $get("checkButton").style.display = "none";
        //window.setTimeout("sanityCheck();", 200);
    }
    else {
        $get("formDati").style.display = "none";
    }
    calcolo();

    var b = Sys.UI.DomElement.getBounds($get("tdLeft"));
    //$get("ctl00_right").style.height = b.height + "px";
    $get("ctl00_center").style.height = b.height + 100 + "px";
    sanityCheck()

}

