richieste = {
    
    esito_KO: function() {
        alert('Attenzione! si sono verificati degli errori');
    },



    esito_OK: function(obj) {
        // alert(obj.responseText);
        // return;
       var dati = eval('(' + obj.responseText + ')');
       if (dati['popola_zona']) {
            // CONTRIBUISCI_TESTO
            var cont = document.getElementById('cont_zone');
            if (!cont) {
                return;
            }
           if (dati['errore']) {
                alert(dati['errore']);
                cont.style.display = '';
                cont.innerHTML = '';
            } else {
                var i = '';
                var check_zone = '';
                if (dati['info']) {
                    check_zone = '<b>Zona</b><div>';
                    for (i in dati['info']) {
                        if (i == 'indexOf') { // bug IE
                            continue;
                        }
                        check_zone += '<span><input type="checkbox" name="zona[]" value="' + i + '" id="chiave_' + i + 
                            '" /><label for="chiave_' + i + '">' +  dati['info'][i] + '</label></span>';
                    }
                    check_zone += '</div>';
                }    
                cont.innerHTML = check_zone;
                cont.style.display = '';
            }
       } 

    },



    cercazona: function(id) {
        if (isNaN(id)) {
            alert('id non valido');
            return;
        }
        if (id==0 || id =='-1') {
            var cont = document.getElementById('cont_zone');
            if (!cont) {
                return;
            }
            cont.style.display = 'none';
            return;
        }
        
        var ar_parameter = new Array(1);
        ar_parameter[0] = id;

        var callback = { success: richieste.esito_OK, failure: richieste.esito_KO, argument: (ar_parameter) };
        YAHOO.util.Connect.asyncRequest('POST', '/ajax/cerca_zona.php', callback, 'id=' + escape(id) );
    },



    getObject: function(obj) {
      var theObj;
      if(document.all) {
        if(typeof obj=="string") {
          return document.all(obj);
        } else {
          return obj.style;
        }
      }
      if(document.getElementById) {
        if(typeof obj=="string") {
          return document.getElementById(obj);
        } else {
          return obj.style;
        }
      }
      return null;
    },



    //Contador de caracteres.
    contar: function(entrada,salida,texto,caracteres) {
        var entradaObj = richieste.getObject(entrada);
        var salidaObj = richieste.getObject(salida);
        var longitud=caracteres - entradaObj.value.length;
        if(longitud < 0) {
            longitud=0;
//            texto='<span class="disable"> '+texto+' </span>';
            entradaObj.value=entradaObj.value.substr(0,caracteres);
        }
        salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
    },



    home_cerca: function() {
        var scelta = document.getElementById('r_citta');
        if (!scelta) {
            return false;
        }
        if (isNaN(scelta.value) || scelta.value<1) {
            alert('Seleziona un citta\'');
            return false;
        }

        return true;
    }

}
function qf_lunghezza_titolo()
{
    var titolo = document.getElementById('r_titolo');
    if (!titolo) {
        return true;
    }
    if (titolo.value.length > 50 || titolo.value.length<10) {
        return false;
    }
    return true;
}
