﻿/* --------------------------------------------
| 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();
    }
}

function MostraInformativa() {
    FinestraPrivacy.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&agrave; 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&agrave; dello slider in funzione 
| della combo contratto (Affitto/Vendita)
----------------------------------------------*/

function setPriceDtt(contratto) {

    if (contratto == 'affitto') {
        SldPrezzoMax.minValue = 100;
        SldPrezzoMax.maxValue = 5000;
        SldPrezzoMax.increment = 100;
        LblPrezzo.setText('5.000',false); //setta il testo della label in ext 
    }
    else {
        SldPrezzoMax.minValue = 10000;
        SldPrezzoMax.maxValue = 2000000;
        SldPrezzoMax.increment = 2000;
        LblPrezzo.setText('2.000.000',false); //setta il testo della label in ext
    }
}

/* --------------------------------------------
| 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() {

    // div ricerche
    var div_ricerche = document.getElementById("div_ricerche_frequenti");
    // bottone apre/chiudi
    var btn_ricerche = document.getElementById("btn_ricerche_frequenti");
    
    if (div_ricerche.style.height == '258px') {
        div_ricerche.style.height = 'auto';
        btn_ricerche.innerHTML = '  nascondi province';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_su.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
    }
    else {
        div_ricerche.style.height = '258px';
        btn_ricerche.innerHTML = '  vedi tutte le province';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_giu.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
    }

}

function espandiRicerche1() {

    // div ricerche
    var div_ricerche = document.getElementById("div_ricerche_frequenti1");
    // bottone apre/chiudi
    var btn_ricerche = document.getElementById("btn_ricerche_frequenti1");
    
    if (div_ricerche.style.height == '0px') {
        div_ricerche.style.height = 'auto';
        btn_ricerche.innerHTML = '  nascondi comuni';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_su.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
		
    }
    else {
        div_ricerche.style.height = '0px';
        btn_ricerche.innerHTML = '  vedi tutti i comuni';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_giu.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
		
    }
}
	
function espandiRicerche2() {

    // div ricerche
    var div_ricerche = document.getElementById("div_ricerche_frequenti2");
    // bottone apre/chiudi
    var btn_ricerche = document.getElementById("btn_ricerche_frequenti2");
    
    if (div_ricerche.style.height == '0px') {
        div_ricerche.style.height = 'auto';
        btn_ricerche.innerHTML = '  nascondi province';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_su.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
		
    }
    else {
        div_ricerche.style.height = '0px';
        btn_ricerche.innerHTML = '  vedi tutti le province';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_giu.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
		
    }
	

}


function espandiRicerche3() {

    // div ricerche
    var div_ricerche = document.getElementById("div_ricerche_frequenti3");
    // bottone apre/chiudi
    var btn_ricerche = document.getElementById("btn_ricerche_frequenti3");
    
    if (div_ricerche.style.height == '0px') {
        div_ricerche.style.height = 'auto';
        btn_ricerche.innerHTML = '  nascondi regioni';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_su.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
		
    }
    else {
        div_ricerche.style.height = '0px';
        btn_ricerche.innerHTML = '  vedi tutti le regioni';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_giu.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
		
    }
	

}


function espandiRicerche4() {

    // div ricerche
    var div_ricerche = document.getElementById("div_ricerche_frequenti4");
    // bottone apre/chiudi
    var btn_ricerche = document.getElementById("btn_ricerche_frequenti4");
    
    if (div_ricerche.style.height == '0px') {
        div_ricerche.style.height = 'auto';
        btn_ricerche.innerHTML = '  nascondi categorie';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_su.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
		
    }
    else {
        div_ricerche.style.height = '0px';
        btn_ricerche.innerHTML = '  vedi tutte le categorie';
        btn_ricerche.style.backgroundImage = 'url(/includes/interface/espandi_giu.jpg)';
        btn_ricerche.style.backgroundPosition = '0px 0px';
		
    }
	

}
