
//////////////////////////////////////////////////////////////////////////////
// Apre/chiude le sottocategorie della categoria

function toggleMenu(nome) {
    var id = nome+ "_menu";
    if (document.getElementById(id).style.display == 'inline') {
	document.getElementById(id).style.display = 'none';
	document.getElementById('img_'+nome).src ='immagini/plus.gif';
    }
    else {
	document.getElementById(id).style.display = 'inline';
	document.getElementById('img_'+nome).src ='immagini/minus.gif';
    }
}

//////////////////////////////////////////////////////////////////////////////
// Pulisce i campi testo della data esatta

function pulisciDataEsatta() {
    document.ricerca.data_dal.value = '';
    document.ricerca.data_al.value  = '';
}

//////////////////////////////////////////////////////////////////////////////

function pulisciCampoCosa() {
    if ((document.ricerca.cosa.value=='titolo,artista') || (document.ricerca.cosa.value=='title,artist'))
	document.ricerca.cosa.value = '';
}

//////////////////////////////////////////////////////////////////////////////

function pulisciCampoDove() {
    if ((document.ricerca.dove.value=='sede,citta\'') || (document.ricerca.dove.value=='venue,city')) {
	document.ricerca.dove.value = '';
	document.ricerca.dove_hidden.value = '';
    }
}

//////////////////////////////////////////////////////////////////////////////

function effettuaRicerca(eng) {
    
    if (document.ricerca.dataprecisa.checked) { 
	if (!document.ricerca.data_dal.value || !document.ricerca.data_al.value) {
	    alert(eng == 1? 'To make an exact search you must insert both dates' : 'Per fare la ricerca esatta devi inserire entrambe le date');
	    return;
	}
	// Controllo che la data "dal" sia minore uguale della data "al"
	var reg = /(\d{2})\/(\d{2})\/(\d{4})/;
	var dal = parseInt(document.ricerca.data_dal.value.replace(reg,"$3$2$1"));
	var  al = parseInt(document.ricerca.data_al.value.replace(reg,"$3$2$1"));
	if (dal>al) {			
	    alert(eng == 1? 'The start date is after the final one: the search cannot give results' : 'La data di inizio ricerca č maggiore di quella della fine: la ricerca non puņ produrre risultati');
	    return;
	}
    }
    submitForm();
}

//////////////////////////////////////////////////////////////////////////////

function submitForm() {
    pulisciCampoCosa();
    pulisciCampoDove();
    document.ricerca.submit();
}

//////////////////////////////////////////////////////////////////////////////

function toggleCategoria(padre,tipo) {
    for (var i=0;i<document.ricerca.elements.length;i++) {			
	var elemento = document.ricerca.elements[i];
	if (elemento.getAttribute('tipo') == tipo) 
	    elemento.checked = (padre.checked) ? true : false;			   
    }
}

//////////////////////////////////////////////////////////////////////////////

function toggleSottoCategoria(elemento,idPadre) {
    var trovato = false;
    for (var i=0;i<document.ricerca.elements.length;i++) {
	var tmp = document.ricerca.elements[i];
	if (tmp.getAttribute('tipo') == elemento.getAttribute('tipo') && 
	    elemento.value != tmp.value && !tmp.checked) 
	    trovato = true;			
    }
    
    if (!trovato) 
	document.getElementById(idPadre).checked  = elemento.checked;
}

//////////////////////////////////////////////////////////////////////////////

function changePage(valore) {
    document.ricerca.page.value = valore;
    submitForm();
}

//////////////////////////////////////////////////////////////////////////////

function changeLink(nome,valore,testo) {
    document.ricerca.dove_hidden.value = document.ricerca.dove.value = testo;
    document.getElementById('link_hidden').name     = nome;
    document.getElementById('link_hidden').value    = valore;
    if (document.getElementById('select_op_dove'))
	document.getElementById('select_op_dove').value = 'esatta';

    submitForm();
}

