/*cambio pagine elenco immobili*/
function cambio_pagina_elenco_immobili (pagina)
{
    document.getElementById('elenco_immobili').action = pagina;
    document.getElementById('elenco_immobili').submit();
}

function cambio_pagina_elenco_cantieri (pagina)
{
    document.getElementById('elenco_cantieri').action = pagina;
    document.getElementById('elenco_cantieri').submit();
}

/*seleziona tutte le zona della ricerca*/
function selezionaTutteZone ()
{
    if (document.getElementById('tuttezone').checked == true)
        $('.zone').attr('checked', true);
    else
        $('.zone').attr('checked', false);
}

/*apre e chiude il div delle zone*/
function ZoneRicerca(azione)
{
    if (azione == "open")
    {
        document.getElementById('openZone').style.display = 'none';
        document.getElementById('closeZone').style.display = 'block';
        document.getElementById('elencoZone').style.display = 'block';
    }
    else
    {
        document.getElementById('openZone').style.display = 'block';
        document.getElementById('closeZone').style.display = 'none';
        document.getElementById('elencoZone').style.display = 'none';
    }

}

/*RICHIEDI PROPONI IMMOBILI ABILITA' CAMPI*/
function abilitaCampi(valore)
{
    document.getElementById('PRresidenziali').style.display = "none";
    document.getElementById('PRcommerciali').style.display = "none";
    
    if (valore!="terreni")
        document.getElementById('PR'+valore).style.display = "block";
        
    $("#camere_a").removeClass("required");
    $("#bagni_a").removeClass("required");
    $("#locali_a").removeClass("required");

    if (valore=="residenziali")
    {
        $("#camere_a").addClass("required");
        $("#bagni_a").addClass("required");
    }
    else if (valore=="commerciali")
    {
        $("#locali_a").addClass("required");
    }
}

function carica_localita (valore, campo, nome_campo)
{
    /*controllo x vedere quale campo svuotare e aggiornare*/
    if (nome_campo == 'id_nazione')
    {
        $(".rimuovioption_Regione").remove();
        $(".rimuovioption_Provincia").remove();
        $(".rimuovioption_Comune").remove();
        $(".rimuovioption_frazione").remove();

        if ($("[name='Regione']").length > 0)
            var selectCambio = "Regione";
        else if ($("[name='Provincia']").length > 0)
            var selectCambio = "Provincia";
        else if ($("[name='Comune']").length > 0)
            var selectCambio = "Comune";
        else if ($("#elencoZone").length > 0)
            var selectCambio = "frazione_check";
        else if ($("[name='frazione']").length > 0)
            var selectCambio = "frazione_sel";
    }
    if (nome_campo == 'Regione')
    {
        $(".rimuovioption_Provincia").remove();
        $(".rimuovioption_Comune").remove();
        $(".rimuovioption_frazione").remove();

        if ($("[name='Provincia']").length > 0)
            var selectCambio = "Provincia";
        else if ($("[name='Comune']").length > 0)
            var selectCambio = "Comune";
        else if ($("#elencoZone").length > 0)
            var selectCambio = "frazione_check";
        else if ($("[name='frazione']").length > 0)
            var selectCambio = "frazione_sel";
    }
    if (nome_campo == 'Provincia')
    {
        $(".rimuovioption_Comune").remove();
        $(".rimuovioption_frazione").remove();

        if ($("[name='Comune']").length > 0)
            var selectCambio = "Comune";
        else if ($("#elencoZone").length > 0)
            var selectCambio = "frazione_check";
        else if ($("[name='frazione']").length > 0)
            var selectCambio = "frazione_sel";
    }
    if (nome_campo == 'Comune')
    {
        $(".rimuovioption_frazione").remove();

        if ($("#elencoZone").length > 0)
            var selectCambio = "frazione_check";
        else if ($("[name='frazione']").length > 0)
            var selectCambio = "frazione_sel";
    }
    
    if (valore!=0 && selectCambio!='')
    {
    var url = link+"php/cerca_funzioni.php?selectCambio="+selectCambio+"&campo="+campo+"&nome_campo="+nome_campo+"&valore="+valore;
    jQuery.ajax({
                    scriptCharset: "iso-8859-1" ,
                    type: "GET",
                    url: url,
                    success: function(data){
                        eval(data);
                        //alert(data);
                    },
                    error: function(data) { 
                    alert(data);
                    }
                });
    return false;
    }
}
