﻿/* --------------------------------------------
| Apertura e chiusura del pannello di 
| ricerca avanzata
----------------------------------------------*/

function EspandiRicerca()
{
    if (Panel_Ric_Avanzata.collapsed == true)
    {
        Panel_Ric_Avanzata.expand();
    }else{
        Panel_Ric_Avanzata.collapse();
    }
}

/* --------------------------------------------
| Mostra la windows Informativa privacy 
----------------------------------------------*/

function MostraInformativa() {
    FinestraPrivacy.show();
    
}

/* --------------------------------------------
| Mostra la windows ricevi annunci gratis in
| scheda immobile 
----------------------------------------------*/

function ApriWinRicevi() {
    FinestraRicevi.show();
    
}

/* --------------------------------------------
| Mostra la windows Login 
----------------------------------------------*/
function ShowWindowLogin() 
{
    WndLogin.show();
}

/* --------------------------------------------
| Apertura e chiusura del pannello di 
| invio annuncio ad amico sulla scheda immobile
----------------------------------------------*/

function EspandiInvioAmico()
{
    if (InviaAmico.collapsed == true) {
        // espandi pannello INVIA AMICO
        InviaAmico.expand();
        var bottone = document.getElementById("idamico");
        bottone.className = 'amico-open';
        
        if (PnlSegnalaErrori.collapsed == false) {
            // collassa pannello SEGNALA ERRORI
            PnlSegnalaErrori.collapse();
            var btnerr = document.getElementById("idsegnala");
            btnerr.className = 'segnala';
        }
    }
    else {
        // collassa pannello INVIA AMICO
        InviaAmico.collapse();
        var bottone = document.getElementById("idamico");
        bottone.className = 'amico';
    }
}

/* --------------------------------------------
| Apertura e chiusura del pannello di 
| invio segnalazione errori sulla scheda immobile
----------------------------------------------*/

function EspandiSegnalaErrori()
{
    if (PnlSegnalaErrori.collapsed == true) {
        // espandi pannello SEGNALA ERRORI
        PnlSegnalaErrori.expand();
        var btnerr = document.getElementById("idsegnala");
            btnerr.className = 'segnala-open';
            
        if (InviaAmico.collapsed == false) {
            // collassa pannello INVIA AMICO
            InviaAmico.collapse();
            var bottone = document.getElementById("idamico");
            bottone.className = 'amico';
        }
    }
    else {
        // collassa pannello SEGNALA ERRORI
        PnlSegnalaErrori.collapse();
        var btnerr = document.getElementById("idsegnala");
            btnerr.className = 'segnala';
    }
}

/* --------------------------------------------
| Apertura e chiusura del pannello  
| mappa agenzia sulla scheda immobile
----------------------------------------------*/

function EspandiMapAgency()
{
    if (FormViewDettaglioAgenzia_PnlMapAgency.collapsed == true)
    {
        FormViewDettaglioAgenzia_PnlMapAgency.expand();
    }
    else
    {
        FormViewDettaglioAgenzia_PnlMapAgency.collapse();
    }
}
/* --------------------------------------------
| HOME PAGE
| Cambio le proprietà dello slider in funzione 
| della combo contratto (Affitto/Vendita)
----------------------------------------------*/

function setPrice(contratto)
{
    if (contratto == 'affitto') 
    {
        SldPrezzoMax.minValue = 100;
        SldPrezzoMax.maxValue = 5000;
        SldPrezzoMax.increment = 100;
        TextPrezzoMax.value = 5000;
    }
    else 
    {
        SldPrezzoMax.minValue = 10000;
        SldPrezzoMax.maxValue = 2000000;
        SldPrezzoMax.increment = 2000;
        TextPrezzoMax.value = 2000000;
    }
}

/* --------------------------------------------
| PAGINA DETTAGLIO
| Cambio le proprietà dello slider in funzione 
| della combo contratto (Affitto/Vendita)
----------------------------------------------*/

function setPriceDtt(contratto)
{
    var lbl_pr_mese = document.getElementById('pr_per_mese');
    if (contratto == 'affitto') {
        SldPrezzoMax.minValue = 100;
        SldPrezzoMax.maxValue = 5000;
        SldPrezzoMax.increment = 100;
        SldPrezzoMax.setValue(SldPrezzoMax.maxValue, true);
        lbl_pr_mese.style.display = "";
        SliderPrezzoOnChange(SldPrezzoMax.maxValue); //setta il testo della label in ext 
    }
    else {
        SldPrezzoMax.minValue = 10000;
        SldPrezzoMax.maxValue = 2000000;
        SldPrezzoMax.increment = 2000;
        SldPrezzoMax.setValue(SldPrezzoMax.maxValue, true); // true indica l'animazione dello slider
        lbl_pr_mese.style.display = "none";
        SliderPrezzoOnChange(SldPrezzoMax.maxValue); //setta il testo della label in ext
    }
}

/* --------------------------------------------
| PAGINA DETTAGLIO
| Cambio le proprietà delle label associate allo slider
| prezzo in funzione se e' impostato al max e se 
| la combo contratto e' Affitto
----------------------------------------------*/
function SliderPrezzoOnChange(prezzo)
{
    var lbl_pr_mese = document.getElementById('pr_per_mese');
    if(parseInt(prezzo) != SldPrezzoMax.maxValue)
    {
        LblPrezzo.setText(formatValuta(prezzo),false);
        // visualizzo la label mese se affitto
        if(CmbContratto.getValue() == 'affitto')
        {
            lbl_pr_mese.style.display = "";
        }
    }
    else
    {
        LblPrezzo.setText('Nessun limite',false);
        lbl_pr_mese.style.display='none';
    }
}


/* --------------------------------------------
| PAGINA DETTAGLIO
| Cambio le proprietà dello slider SUPEFICIE in funzione 
| della combo CATEGORIA (TERRENO[6] e COMMERCIALE INDUSTRIALE[5])
----------------------------------------------*/

function setLimitiSuperficie(CategoriaKy)
{
    if (CategoriaKy == '6' || CategoriaKy == '5') {
        SldSuperficie.minValue = 50;
        SldSuperficie.maxValue = 10000;
        SldSuperficie.increment = 150;
        SldSuperficie.setValue(SldSuperficie.maxValue, true);
        SliderOnChangeSuperficie(SldSuperficie.maxValue); //setta il testo della label in ext 
    }
    else {
        SldSuperficie.minValue = 10;
        SldSuperficie.maxValue = 350;
        SldSuperficie.increment = 10;
        SldSuperficie.setValue(SldSuperficie.maxValue, true); // true indica l'animazione dello slider
        SliderOnChangeSuperficie(SldSuperficie.maxValue); //setta il testo della label in ext
    }
}


/* --------------------------------------------
| PAGINA DETTAGLIO
| Cambio le proprietà delle label associate allo slider
| superficie in funzione se e' impostato al max  
----------------------------------------------*/
function SliderOnChangeSuperficie(superficie)
{
    var strSuperficie = superficie;
        
    var lbl_sup_m2 = document.getElementById('lbl_m2');
    var lbl_sup_m22 = document.getElementById('lbl_m22');
    
    if(parseInt(strSuperficie) != SldSuperficie.maxValue)
    {
        lbl_sup_m22.innerHTML = ' di almeno: ';
        LblSuperficie.setText(formatValuta(strSuperficie));
        lbl_sup_m2.style.display='';
        lbl_sup_m22.style.display='';
    }
    else
    {
        LblSuperficie.setText('Nessun limite',false);
        lbl_sup_m2.style.display='none';
        lbl_sup_m22.style.display='none';
    }
}
/* --------------------------------------------
| PAGINA DETTAGLIO
| formatta il num in valuta
----------------------------------------------*/
function formatValuta(num) {
    num = num.toString().replace(/\$|\,/g, '');
    if (isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num * 100 + 0.50000000001);
    cents = num % 100;
    num = Math.floor(num / 100).toString();
    if (cents < 10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + '.' +
    num.substring(num.length - (4 * i + 3));
    return (((sign) ? '' : '-') + num);
    //return (((sign) ? '' : '-') + num + ',' + cents);
}

//Funzione addetta a sostituire un'immagine inesistente con quella di cortesia
function immagine_cortesia(id_foto)
{
    var foto = document.getElementById(id_foto);
    foto.src = "/includes/interface/no-image-annunci.png";
    foto.onmouseover = "";
    foto.onmouseout = "";
}

/* ---------------------------------------------
| PAGINA SCHEDA IMMOBILE                        |
| Apertura del pannello description a full Height
----------------------------------------------*/

function EspandiDescrizione()
{
    if (PnlDescription.autoscroll == true) {
        PnlDescription.autoscroll = false;
    }
    else {
        PnlDescription.autoscroll = true;
    }
}

/* -------------------------------------------------------
| AVVIA LA RICERCA DA FORM  USATO NEI WEB-FRIENDS        |
| Fa comparire i risultati in un iFrame di id "contents" |
--------------------------------------------------------*/

function ImpostaRicerca(Age, cmbCat, cmbCom, cmbCon, txtPre) {

    parent.contents.location.href = "Results.aspx" +
                                    "?from=" + Age +
                                    "&categoria=" + cmbCat +
                                    "&comune=" + (cmbCom == "Qualsiasi comune" ? "" : cmbCom) +
                                    "&contratto=" + cmbCon +
                                    "&prezzo=" + (txtPre == "0" ? "" : txtPre) +
                                    "";
                    
}

/* ---------------------------------------------------
| ESEGUE UN AUTO CLICK SU UN CONTROLLO cross-browser |
----------------------------------------------------*/                
function AutoClick(Controllo) {

    var browsername = navigator.appName;
    if (browsername.indexOf("Microsoft") != -1) {
        // solo per internet explorer
        document.getElementsByTagName(Controllo).click();
    }
    else {
        // metodo hack per bypassare le security policy di FF
        // https://developer.mozilla.org/En/DOM:document.createEvent
        var evt = document.createEvent("MouseEvents");
        evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        var cb = document.getElementsByTagName(Controllo);
        var canceled = !cb.dispatchEvent(evt);
    }
}

/* ---------------------------------------------------
| APRE IL DIV SUL LATO SX DELLA PAG DETTAGLIO        |
----------------------------------------------------*/ 

function espandiRicerche(bottone,livello) 
{
	if (LinkIsAperto(livello)) 
	{
		ChiudiLink(bottone,livello);
	}	
	else
	{
		ChiudiLink("btn_search_area", "div_ricerche_frequenti");
		ChiudiLink("btn_search_zone", "div_ricerche_zone");
		ChiudiLink("btn_search_category", "div_ricerche_category");
		ChiudiLink("btn_search_features", "div_ricerche_features");
		ApriLink(bottone,livello);	
	}
}

function ApriLink(bottone,livello)
{
	var div_ricerche = document.getElementById(livello);
	var btn_ricerche = document.getElementById(bottone);
	if (div_ricerche == null) return;
	div_ricerche.style.display = "";
	// cambio la classe del bottone
	btn_ricerche.className = "btn_ricerche_close";
}

function ChiudiLink(bottone,livello)
{
	var div_ricerche = document.getElementById(livello);
	var btn_ricerche = document.getElementById(bottone);
	if (div_ricerche == null) return;
	div_ricerche.style.display = "none";
	// cambio la classe del bottone
    btn_ricerche.className = "btn_ricerche_open";
}

function LinkIsAperto(livello)
{
	var div_ricerche = document.getElementById(livello);
	if (div_ricerche == null) return 0;
	return (div_ricerche.style.display == "");
}



/* --------------------------------------------
| Apertura e chiusura del pannello in DETTAGLIO 
| AGENZIA della MAPPA GOOGLE
----------------------------------------------*/

function apriMappa()
{
    if (FormViewDettaglioAgenzia_Pnl_Agency_Map.collapsed == true)
    {
        FormViewDettaglioAgenzia_Pnl_Agency_Map.expand();
    }else{
        FormViewDettaglioAgenzia_Pnl_Agency_Map.collapse();
    }
}

/*-------------------------------------------
| RESETTA LO STORE DI UNA COMBO EXT         |
-------------------------------------------*/
function pulisciComboZona(){
    StrCmbZona_home.removeAll();
    CmbZona.reset();
}

/*-------------------------------------------
| CambiaTab in HOME PAGE                    |
-------------------------------------------*/
function switchTab(tab,div){

    var _tab = document.getElementById(tab);
    var _div = document.getElementById(div);
    
    // nascondo entrambi div delle tab
    document.getElementById("AnnunciXCitta").style.display = "none";
    document.getElementById("AnnunciXtipologia").style.display = "none";
    
    // ripristino entrambi i "bottoni" delle tab
    document.getElementById("labelCITTA").style.background = "url(includes/interface/homeNEW/lingua2OFFrett.png)";
    document.getElementById("labelTIPOLOGIA").style.background = "url(includes/interface/homeNEW/lingua2OFFrett.png)";
    
    // imposto il div cliccato a visibile
    _div.style.display = "";
    // imposto la classe della tab cliccata in maniera che sia selezionata
    _tab.style.background = "url(includes/interface/homeNEW/lingua2ONrett.png)";

}

