﻿// JScript File
var postBackElement
var descrizione_area=""
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()
        document.getElementById("wait_strutture_cont").style.height="700px"
    if ((postBackElement.id == 'ctl00_ContentPlaceHolder1_butStrutturaRicerca')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_lnkOrdCategoria')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_lnkOrdPrezzo')) {
        //AttesaRicercaStrutture(false)        
    }
    if (postBackElement.id.toString().indexOf("_Paginatore1_")>-1) {
        //AttesaRicercaStrutture(false)        
    }
    if ((postBackElement.id == 'ctl00_ContentPlaceHolder1_butCerca')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_butCerca2')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_butAree')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_butAvRicerca')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_butRicercaCodice')) {
        //AttesaRicercaStrutture(false)
        if (postBackElement.id == 'ctl00_ContentPlaceHolder1_butCerca'){
            if(document.getElementById("ctl00_ContentPlaceHolder1_txtDestinazione").value==""){
                alert(ricerca_localita_obb)
                document.getElementById("destinazione_obb").style.visibility="visible"
                args.set_cancel(true);
                return;
            }
            else{
                document.getElementById("destinazione_obb").style.visibility="hidden"
                cartina_desc_load(document.getElementById("ctl00_ContentPlaceHolder1_txtDestinazione").value)
            }
        }
        document.getElementById("ricerca_titolo").style.visibility="hidden"
        elenco_strutture_box_open()
        if(postBackElement.id == 'ctl00_ContentPlaceHolder1_butRicercaCodice')
            ajax_box_close();
    }    
    if ((postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkStoria")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkEventi")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkRistoranti")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkTempoLibero")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkTrasporti")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_cmbAree")) {
        //AttesaAree(false)        
    }
    if (postBackElement.id.toString().indexOf("_Cartina1_")>-1) {
        document.getElementById("wait_strutture_cont").style.height="540px"
        //AttesaCartina(false)      
        //AttesaRicercaStrutture(false)        
        //AttesaAree(false)        
    }
    if(postBackElement.id=='ctl00_ContentPlaceHolder1_Guestbook1_butUpdate'){
        //AttesaGuestBook(false) 
    }
}

function EndRequestHandler(sender, args){
    if ((postBackElement.id == 'ctl00_ContentPlaceHolder1_butStrutturaRicerca')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_lnkOrdCategoria')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_lnkOrdPrezzo')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_butAvRicerca')) {
        //AttesaRicercaStrutture(true)               
    }
    if (postBackElement.id.toString().indexOf("_Paginatore1_")>-1) {
        //AttesaRicercaStrutture(true)        
    }
    if ((postBackElement.id == 'ctl00_ContentPlaceHolder1_butCerca')||(postBackElement.id == 'ctl00_ContentPlaceHolder1_butCerca2')) {
        //AttesaRicercaStrutture(true)        
    }    
    if ((postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkStoria")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkEventi")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkRistoranti")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkTempoLibero")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_lnkTrasporti")||(postBackElement.id.toString()=="ctl00_ContentPlaceHolder1_cmbAree")) {
        AttesaAree(true)        
    }
    if (postBackElement.id.toString().indexOf("_Cartina1_")>-1) {
        AttesaCartina(true)        
        //AttesaRicercaStrutture(true)        
        AttesaAree(true)        
    }
    if(postBackElement.id=='ctl00_ContentPlaceHolder1_Guestbook1_butUpdate'){
        AttesaGuestBook(true) 
    }
    if(document.getElementById("ctl00_ContentPlaceHolder1_Cartina1_hidAreaChiudi").value!=""){
        imposta_area_scelta(document.getElementById("ctl00_ContentPlaceHolder1_Cartina1_hidAreaChiudi").value)
        /*if(document.getElementById("ctl00_ContentPlaceHolder1_Elenco_strutture1_lnkChiudiElenco"))
            document.getElementById("ctl00_ContentPlaceHolder1_Elenco_strutture1_lnkChiudiElenco").innerHTML=msg_torna_mappa+" "+document.getElementById("ctl00_ContentPlaceHolder1_Cartina1_hidAreaChiudi").value*/
    }
}

function AttesaRicercaStrutture(caricato){
/*   var livello=document.getElementById("strutture_risultato")
    if(caricato){
        livello.className=""
        document.getElementById("strutture_wait").style.display="none"
    }
    else{
        livello.className="strutture_wait"
        document.getElementById("strutture_wait").style.display="block"
        elenco_strutture_box_open()
    }
*/
}

function AttesaAree(caricato){
    var livello=document.getElementById("aree_descrizione")
    if(caricato){
        livello.className=""
        document.getElementById("aree_descrizione_wait").style.display="none"
    }
    else{
        livello.className="aree_descrizione_wait"
        document.getElementById("aree_descrizione_wait").style.display="block"
    }
}
function AttesaCartina(caricato){
    var livello=document.getElementById("ricerca_mappa")
    if(caricato){
        livello.className=""
        document.getElementById("mappa_absolute").style.visibility="visible"
    }
    else{
        livello.className="ricerca_mappa_wait"
        document.getElementById("mappa_absolute").style.visibility="hidden"
    }
}
function AttesaGuestBook(caricato){
    var livello=document.getElementById("guestbook")
    var livelloWait=document.getElementById("progress_guestbook")    
    if(caricato){
        livello.style.display="block"
        livelloWait.className=""
        livelloWait.style.display="none"
    }
    else{
        livello.style.display="none"
        livelloWait.className="progress_guestbook"
        livelloWait.style.display="block"
    }
}


function carica_strutture_area(codice,descrizione){
    document.getElementById("ctl00_ContentPlaceHolder1_hidArea").value=codice
    imposta_area_scelta(descrizione)
//    document.getElementById("ctl00_ContentPlaceHolder1_butAree").click();
    __doPostBack('ctl00$ContentPlaceHolder1$butAree','')
}
function imposta_area_scelta(descrizione){
    return
    if(descrizione!="-1"){
        descrizione_area=descrizione
    /*    if(document.getElementById("ctl00_ContentPlaceHolder1_Elenco_strutture1_lnkChiudiElenco"))
            document.getElementById("ctl00_ContentPlaceHolder1_Elenco_strutture1_lnkChiudiElenco").innerHTML=msg_torna_mappa+" "+descrizione*/
        if(document.getElementById("ctl00_ContentPlaceHolder1_Elenco_strutture1_hidTestoChiudi"))
            document.getElementById("ctl00_ContentPlaceHolder1_Elenco_strutture1_hidTestoChiudi").value=msg_torna_mappa+" "+descrizione
    }
}

function cartina_load(codice){
/*    document.getElementById("ctl00_ContentPlaceHolder1_Cartina1_hidCodiceAreaDaCercare").value=codice
    //document.getElementById("ctl00_ContentPlaceHolder1_Cartina1_butCartina").click();
    __doPostBack('ctl00_ContentPlaceHolder1_Cartina1_butCartina','')*/
}

function cartina_desc_load(desc){
/*
    document.getElementById("ctl00_ContentPlaceHolder1_Cartina1_hidCodiceAreaDaCercare").value=desc
    document.getElementById("ctl00_ContentPlaceHolder1_Cartina1_butCartina").click();*/
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();


function CalClose(cal){
    var arrCal=new Array("ctl00_ContentPlaceHolder1_CalendarioDal","ctl00_ContentPlaceHolder1_CalendarioAl","ctl00_ContentPlaceHolder1_calAvDal","ctl00_ContentPlaceHolder1_calAvAl");
    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(),7)),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(),7)),true);	
        //CAL_A.DataMinima=aggiungiGiorni(CAL_Da.GetData(),7)
        CAL_A.DataMinima=aggiungiGiorni(CAL_Da.GetData(),1)
    }
}
function aggiungiGiorni(data,numeroGiorni){
    var millisecondi=3600000*24*numeroGiorni
    data.setTime(data.getTime()+millisecondi)
    return data			
}


function guestbook(id){
    id=17644    // da commentare
    document.getElementById("ctl00_ContentPlaceHolder1_Guestbook1_hidIdRisorsaNew").value=id
    //document.getElementById("ctl00_ContentPlaceHolder1_Guestbook1_butUpdate").click();
    __doPostBack('ctl00_ContentPlaceHolder1_Guestbook1_butUpdate','')
    ajax_box_open()
}
function ricerca_avanzata(){
    document.getElementById("ricerca_avanzata").style.display="block"
    document.getElementById("gruppo").style.display="none"
    document.getElementById("ricerca_codice").style.display="none"
    ajax_box_open(430,590)
}
function ricerca_avanzata_close(){
    document.getElementById("ricerca_avanzata").style.display="none"
    ajax_box_close()
}
function ricerca_avanzata_validate(){
    var risultato=true
    if(document.getElementById("ctl00_ContentPlaceHolder1_txtAvDestinazione").value==""){
        document.getElementById("destinazione_avanzata_obb").style.visibility="visible"        
        risultato=false
    }
    else{
        document.getElementById("destinazione_avanzata_obb").style.visibility="hidden"
        ricerca_avanzata_close();
    }
    return risultato
}

function info_gruppo_elenco_open(IdGruppo,IdRisorsa){
    gruppo_load(IdGruppo,IdRisorsa)
    document.getElementById("ricerca_avanzata").style.display="none"
    document.getElementById("ricerca_codice").style.display="none"
    document.getElementById("gruppo").style.display="block"
    document.getElementById("ctl00_ContentPlaceHolder1_butAggiorna").click();
    ajax_box_open(470,780)
}
function ricerca_codice(){
    document.getElementById("ricerca_avanzata").style.display="none"
    document.getElementById("gruppo").style.display="none"
    document.getElementById("ricerca_codice").style.display="block"    
    ajax_box_open(180,400,300)
}

/*function ajax_box_open(){
    document.getElementById("ajax_box_overlay").style.height=(getPageSize()[1]).toString()+"px"
    document.getElementById("ajax_box").style.top=(140+getScrollY()).toString()+"px"
    document.getElementById("ajax_box").style.display="block"
    document.getElementById("ajax_box_overlay").style.display="block"
}
function ajax_box_close(){
    document.getElementById("ajax_box").style.display="none"
    document.getElementById("ajax_box_overlay").style.display="none"
}
*/
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}


function sub_ricerca(e){
    var keynum
    var keychar
    var numcheck

    if(window.event) // IE
    {
        keynum = e.keyCode
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which
    }
    if (keynum == 13) // Invio
    {
        document.getElementById("ctl00_ContentPlaceHolder1_hidTipoRicerca").value="INVIO"
        AttesaRicercaStrutture(false)
        //document.getElementById("ctl00_ContentPlaceHolder1_butStrutturaRicerca").click();
        //__doPostBack('ctl00_ContentPlaceHolder1_butStrutturaRicerca','')
        // scateni l'evento del pulsante che ti serve
    }
}

function ajax_box_open(altezza,larghezza,top){
/*    if(prima){
        document.getElementById("ajax_box_overlay").style.height=(getPageSize()[1]).toString()+"px"
        document.getElementById("ajax_box").style.top=(140+getScrollY()).toString()+"px"
    }
    prima=false;*/

    document.getElementById("ajax_box_overlay").style.height=(getPageSize()[1]).toString()+"px"
    document.getElementById("ajax_box").style.top=(140+getScrollY()).toString()+"px"
    document.getElementById("ajax_box").style.display="block"
    document.getElementById("ajax_box_overlay").style.display="block"

    if(!altezza)
        altezza=550
    if(!larghezza)
        larghezza=550
    if(!top)
        top=140
    document.getElementById("ajax_box_container").style.height=altezza+"px"
    document.getElementById("ajax_box_container").style.minHeight=altezza+"px"
    document.getElementById("ajax_box_container").style.width=larghezza+"px"
    document.getElementById("ajax_box").style.top=top+"px"
}
function ajax_box_close(){
/*    document.getElementById("mappa").style.display="none";
    document.getElementById("gallery").style.display="none";*/
    document.getElementById("ajax_box").style.display="none"
    document.getElementById("ajax_box_overlay").style.display="none"
}
