﻿var postBackElement = null;
function pageLoad() {
    /*PageMethods.SetSessionValue("SessionValue", Date(), 
    OnSucceeded, OnFailed);*/
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}
function InitializeRequest(sender, args) {
    postBackElement = args.get_postBackElement()
    if (postBackElement.id == 'ContentPlaceHolder1_hidTriggerBook') {
        AttesaAlternative(false)
        AttesaBook(false)
        AttesaCalendario(false)
        AttesaImg(true)
    }
    if ((postBackElement.id == 'ContentPlaceHolder1_calendario_disponibilita1_lnkAvanti') || (postBackElement.id == 'ContentPlaceHolder1_calendario_disponibilita1_lnkIndietro')) {
        AttesaAlternative(false)
        AttesaCalendario(false)
        AttesaBook(false)
        AttesaImg(true)
    }
    if ((postBackElement.id == 'ContentPlaceHolder1_butAltAvanti') || (postBackElement.id == 'ContentPlaceHolder1_butAltIndietro')) {
        AttesaAlternative(false)
        AttesaCalendario(false)
        AttesaBook(false)
        AttesaImg(true)
    }
    if ((postBackElement.id.toString().indexOf("lnkVal")>=0)) {
        AttesaAlternative(false)
        AttesaCalendario(false)
        AttesaBook(false)
        AttesaImg(true)
    }
}

function EndRequestHandler(sender, args) {
    if (postBackElement.id == 'ContentPlaceHolder1_hidTriggerBook') {
        AttesaBook(true)
        AttesaAlternative(true)
        AttesaCalendario(true)
        AttesaImg(false)
    }
    if ((postBackElement.id == 'ContentPlaceHolder1_calendario_disponibilita1_lnkAvanti') || (postBackElement.id == 'ContentPlaceHolder1_calendario_disponibilita1_lnkIndietro')) {
        AttesaCalendario(true)
        AttesaAlternative(true)
        AttesaBook(true)
        AttesaImg(false)
    }
    if ((postBackElement.id == 'ContentPlaceHolder1_butAltAvanti') || (postBackElement.id == 'ContentPlaceHolder1_butAltIndietro')) {
        AttesaAlternative(true)
        AttesaCalendario(true)
        AttesaBook(true)
        AttesaImg(false)
    }
    if ((postBackElement.id.toString().indexOf("lnkVal") >= 0)) {
        AttesaAlternative(true)
        AttesaCalendario(true)
        AttesaBook(true)
        AttesaImg(false)
    }
}

function AttesaImg(visibile) {
    var livello = document.getElementById("wait_image")
    if (visibile) {
        livello.style.display = "block"
    }
    else {
        livello.style.display = "none"
    }
    
}

function AttesaCalendario(visibile) {
    var livello=document.getElementById("villa_main_availability")
    if(visibile){
        livello.className = livello.className.replace(" wait", "")
    }
    else{
        livello.className = livello.className + " wait"
    }
}
function AttesaBook(visibile) {
    //var livello = document.getElementById("ctl00_ContentPlaceHolder1_UpdatePanelBook")
    //var livello = document.getElementById("ContentPlaceHolder1_UpdatePanelBook")
    var livello = document.getElementById("tab_UpdatePanelBook")
    if (visibile) {
        livello.className = livello.className.replace(" wait", "")
    }
    else {
        livello.className = livello.className + " wait"
    }
}
function AttesaAlternative(visibile) {
    //var livello = document.getElementById("ctl00_ContentPlaceHolder1_UpdatePanelAlt")
    //var livello = document.getElementById("ContentPlaceHolder1_UpdatePanelAlt")
    var livello = document.getElementById("div_UpdatePanelAlt")
    if (visibile) {
        livello.className = livello.className.replace(" wait", "")
    }
    else {
        livello.className = livello.className + " wait"
    }
}

function gal(path) {
    //document.getElementById("ctl00_ContentPlaceHolder1_imgBig").src = path
    document.getElementById("ContentPlaceHolder1_imgBig").src = path
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function Cal_click(data) {
    var hiddenFieldTriggerBookID = "ContentPlaceHolder1_hidTriggerBook"
    var hiddenFieldAltDataID = "ContentPlaceHolder1_hidAltData"

    var hiddenFieldTriggerBook = $get(hiddenFieldTriggerBookID);
    var hiddenFieldAltData = $get(hiddenFieldAltDataID);
    hiddenFieldTriggerBook.value = data;
    hiddenFieldAltData.value = data;
    __doPostBack(hiddenFieldTriggerBookID, '');
}

function add_comment() {
    document.getElementById("popup_overlay_testimonials").style.height = (getPageSize()[1]).toString() + "px"
    document.getElementById("popup_content_testimonials").style.top = (240 + getScrollY()).toString() + "px"
    document.getElementById("popup_content_testimonials").style.display = "block"
    document.getElementById("popup_overlay_testimonials").style.display = "block"
}
function closeAddGuestbook(){
    document.getElementById("popup_content_testimonials").style.display = "none";
    document.getElementById("popup_overlay_testimonials").style.display = "none";
}

function daily_request(fuoco) {
    if (document.getElementById("cartina"))
        document.getElementById("cartina").style.visibility = "hidden";
    document.getElementById("popup_overlay_daily").style.height = (getPageSize()[1]).toString() + "px"
    document.getElementById("popup_content_daily").style.top = (240 + getScrollY()).toString() + "px"
    document.getElementById("popup_content_daily").style.display = "block"
    document.getElementById("popup_overlay_daily").style.display = "block"
    if (fuoco)
        document.getElementById("ContentPlaceHolder1_richiesta_giornaliera1_txtNome").focus();
}
function close_daily_request() {
    if (document.getElementById("cartina"))
        document.getElementById("cartina").style.visibility = "visible";
    document.getElementById("popup_content_daily").style.display = "none";
    document.getElementById("popup_overlay_daily").style.display = "none";
}

/*function mail_friend(fuoco) {
    if (document.getElementById("cartina"))
        document.getElementById("cartina").style.visibility = "hidden";
    document.getElementById("popup_overlay_mailfriend").style.height = (getPageSize()[1]).toString() + "px"
    document.getElementById("popup_content_mailfriend").style.top = (240 + getScrollY()).toString() + "px"
    document.getElementById("popup_content_mailfriend").style.display = "block"
    document.getElementById("popup_overlay_mailfriend").style.display = "block"
    if ((fuoco)&&(document.getElementById("ctl00_ContentPlaceHolder1_mailfriend1_txtMailAmico")))
        document.getElementById("ctl00_ContentPlaceHolder1_mailfriend1_txtMailAmico").focus();
}
function close_mail_friend() {
    if (document.getElementById("cartina"))
        document.getElementById("cartina").style.visibility = "visible";
    document.getElementById("popup_content_mailfriend").style.display = "none";
    document.getElementById("popup_overlay_mailfriend").style.display = "none";
}*/

function CalClose(cal) {
    var arrCal = new Array("ContentPlaceHolder1_richiesta_giornaliera1_calDataDa", "ctl00_ContentPlaceHolder1_richiesta_giornaliera1_calDataA");
    for (var i = 0; i < arrCal.length; i++) {
        if (arrCal[i] != cal) {            
            //if (document.getElementById(arrCal[i] + "_CAL_txtData"))
                PU_getCalendario(arrCal[i]).Close();
        }
    }
}
function CambioData(CAL_Da, CAL_A) {
    if (CAL_Da.IsDate()) {
        if (CAL_A.IsDate()) {
            if (CAL_A.GetData() <= CAL_Da.GetData()) {
                CAL_A.SelData(dt2dtstr(aggiungiGiorni(CAL_Da.GetData(), 3)), true);
            }
            /*else{
            if(((CAL_A.GetData()-CAL_Da.GetData())/86400000)>28){
            CAL_A.SelData(dt2dtstr(aggiungiGiorni(CAL_Da.GetData(),27)))
            }
            }*/
        }
        else
            CAL_A.SelData(dt2dtstr(aggiungiGiorni(CAL_Da.GetData(), 3)), true);
        //CAL_A.DataMinima=aggiungiGiorni(CAL_Da.GetData(),7)
        CAL_A.DataMinima = aggiungiGiorni(CAL_Da.GetData(), 3)
    }
}
function aggiungiGiorni(data, numeroGiorni) {
    var millisecondi = 3600000 * 24 * numeroGiorni
    data.setTime(data.getTime() + millisecondi)
    return data
}
function valDateRichiestaGiornaliera(source, arguments) {
    var result=false;
    if((CAL_Obj_ctl00_ContentPlaceHolder1_richiesta_giornaliera1_calDataDa.GetData()!=null)&&(CAL_Obj_ctl00_ContentPlaceHolder1_richiesta_giornaliera1_calDataA.GetData()!=null)){
        result=(aggiungiGiorni(CAL_Obj_ctl00_ContentPlaceHolder1_richiesta_giornaliera1_calDataDa.GetData(),2)<CAL_Obj_ctl00_ContentPlaceHolder1_richiesta_giornaliera1_calDataA.GetData())
    }
    arguments.IsValid = result
}

function scroll_prezzi() {
    window.scrollTo(0,600)
}
