function redirect(url){
    window.location = url;
}

function mostral(id){
    obj=document.getElementById(id);
    if(obj.style.display=="block"){
        obj.style.display="none";
    }else{
        obj.style.display="block";
    }
}

function mostraENascondi(m,n){
    mostra=document.getElementById(m);
    nascondi=document.getElementById(n);

    if(mostra.style.display=="block"){
        mostra.style.display="none";
        nascondi.style.display="block";

    }else{
        mostra.style.display="block";
        nascondi.style.display="none";
    }
}

function bo_mostraNascondiElencoHotel(id,etichetta){
	daApp = document.getElementById('daApprovare');
	appr = document.getElementById('approvati');
    switch(id){
		case 'daApprovare':
			daApp.style.display="block";
			appr.style.display = "none";
			document.getElementById('etichettaApprovati').style.backgroundColor = "#880000";
			document.getElementById('etichettaTutti').style.backgroundColor = "#880000";
		break;
		case 'approvati':
			daApp.style.display="none";
			appr.style.display = "block";
			document.getElementById('etichettaDaApprovare').style.backgroundColor = "#880000";
			document.getElementById('etichettaTutti').style.backgroundColor = "#880000";
		break;
		case 'tutti':
			daApp.style.display="block";
			appr.style.display = "block";
			document.getElementById('etichettaDaApprovare').style.backgroundColor = "#880000";
			document.getElementById('etichettaApprovati').style.backgroundColor = "#880000";
		break;
	}
	etichetta.style.backgroundColor = "#ff0000";
	document.getElementById('sezMostrata').value = id;
	
}

boxHotelVisualizzato = 'boxHotelEn';

function mostraBoxHotel(id){
    //it=document.getElementById('boxHotelIt').style.display;
    //en=document.getElementById('boxHotelEn').style.display;
	
    var it = document.getElementById('boxHotelIt');
    var en = document.getElementById('boxHotelEn');
    var tit = document.getElementById('tit');
	
    if(id == 'boxHotelEn'){
        it.style.display = 'none';
        en.style.display = 'block';
        tit.innerHTML = 'HOTEL\'S AREA';
    }else{
        it.style.display  = 'block';
        en.style.display  = 'none';
        tit.innerHTML = 'AREA HOTEL';
    }
}

function verificaBoxRicerca(myform){
    if(myform.city.value == ""){
        alert(eval('messaggi_'+lang+"['riccitta']"));
        return false;
    }
}



// carpeGetElementByID: Cross-browser version of "document.getElementById()"
function carpeGetElementById(element)
{
    if (document.getElementById){
        element = document.getElementById(element);
		
    }else if (document.all){
        element = document.all[element];
    }else{
        element = null;
    }
		
    return element;
}

function elabora(){
	
    oggetto1 = carpeGetElementById('testo_registrazione');
    oggetto2 = carpeGetElementById('file_fla');
	
    oggetto1.style.display = "block";
    oggetto2.style.display = "none";
}


function mostranascondi_daApprovare(){
	
    oggettoscatenante = carpeGetElementById('bot_mostra_nascondi_inv');
    oggetto = carpeGetElementById('div_invisibili');
	
		
    if(oggetto.style.display == "block"){
        oggetto.style.display = "none";
        oggettoscatenante.innerHTML = 'Mostra hotel in attesa di approvazione &gt;&gt;';
		
    }else{
		
        oggetto.style.display = "block";
        oggettoscatenante.innerHTML = 'Nascondi hotel in attesa di approvazione &gt;&gt;';
    }
}


function attivaDisattivaCampo(idcampo){
	
    oggetto = carpeGetElementById(idcampo);

    if(oggetto.disabled == true){
        oggetto.disabled = false;
    }else{
        oggetto.disabled = true;
    }
}


function copiadatihotel(){
    document.getElementById('indirizzoamm').value =  document.getElementById('indirizzo').value;
    document.getElementById('localitaamm').value =  document.getElementById('local').value;
    document.getElementById('capamm').value =  document.getElementById('cap').value;
    document.getElementById('statoamm').value =  document.getElementById('stato').value;
    document.getElementById('telamm').value =  document.getElementById('telefono').value;
    document.getElementById('faxamm').value =  document.getElementById('fax').value;
    document.getElementById('emailamm').value =  document.getElementById('email').value;
}


function confermaCancellazioneHotel(idhotel,nomehotel) {
	
	
    var answer = confirm("Sei sicuro di voler Eliminare l\'hotel "+nomehotel+" ?");
    if (answer){
        window.location = "cancellazioneHotel.php?cancHotel="+idhotel;
    }
    else{
        alert("Cancellazione Annullata!");
    }
}


// BOX NEWS
function scrollUP(shift){
    box=document.getElementById('newscontainer');
    pos = Number(box.style.top.replace("px",""));
    //alert (pos);
    if(pos>=-1*altezzascroll){
        nuovay = (pos-shift);
        box.style.top = nuovay+'px';
    }else{
        clearInterval(st);
        setTimeout("nextnews()",intervallo);
    }
} 

function nextnews(){
    //alert(indice+","+elenconews.length);
    if(indice>0){
        indice--;
    }else{
        indice=elenconews.length-1;
    }
	
    document.getElementById('newscontainer').style.top="0px";
    document.getElementById('contenutonews').innerHTML = '<p align="left"><a href="rassegnastampa.php"><b>'+elenconews[indice]+"</b></a>";
    st = setInterval("scrollUP("+shift+")", velocita_scorrimento);
}

function avviabox(){
    shift=1;//pixel
    velocita_scorrimento = 10;//millisecondi
    intervallo = 3000;//millisecondi
    indice=elenconews.length-1;
    altezzascroll=115;//altezza di #newsviewport
    document.getElementById('newsviewport').style.height = altezzascroll+"px";
    document.getElementById('spaziatore').style.height = altezzascroll+"px";
	
    document.getElementById('contenutonews').innerHTML = '<p align="left"><a href="rassegnastampa.php"><b>'+elenconews[indice]+"</b></a>";
    //document.getElementById('contatore').innerHTML =(indice+1)+"/"+(elenconews.length);
    st = setInterval("scrollUP("+shift+")", velocita_scorrimento);
}

amministrativa = false;
settoreAttivo = '3RK';

function mostrasettore(settore){
	
    nascondisettore(settoreAttivo);
	
    settoreAttivo = settore;
	
    vocemenu = document.getElementById(settore);
    vocemenu.style.backgroundColor = "#888888";
	
    livello = document.getElementById('livello_'+settore);
    livello.style.display = "block";
}

function nascondisettore(settore){
	
    vocemenu = document.getElementById(settore);
    //vocemenu.style.backgroundColor = "#252525";
	
    corpo = document.getElementById('livello_'+settore);
    corpo.style.display = "none";
}

function mostrabox(box){
	
    var boxed =  carpeGetElementById(box);
    // document.getElementById(box);
	
    if(boxed.style.display == "none")
        boxed.style.display = "block";
    else{
		
        if(boxed.style.display == "block")
            boxed.style.display = "none";
		
    }
}

function eseguiRicerca(){
    myform = document.getElementById('formricerca');
    myform.action='ricerca.php';
    myform.submit();
}

function attivacasella(casella){
    casella.style.color="black";
    casella.value="";
}

function sbloccaCampo(caller, campoControllo){
	
    campoChiamante = carpeGetElementById(caller);
    daSbloc = carpeGetElementById(campoControllo);
	
	
    if( campoChiamante.value != "" && campoChiamante.value.length > 1){
		
        daSbloc.readOnly=false;
    }else{
		
        daSbloc.readOnly=true;
    }
	
}


// Controllo se è settato il campo che gli viene passato e se ha un valore
function controlloValoreCampo(campo){
	
    if(elemento = carpeGetElementById(campo)){
        if ( elemento.value != "" ){
			
            return elemento;
			
        }else{
            return false;
        }
		 
    }else{
        return false;
    }

}


/**
* Crea l'elenco dei valori per l'input
* 
* @param string origine L'input Scatenante.
*/
function cambiaElenchi(origine,valore){
    //verifico di quale caso si tratti
    //alert(origine+','+valore);
    switch(origine){
        case 'stato':
            //devo cambiare le regioni e le città
            //lo stato viene da una select, per cui esiste sicuramente
            //viene passato l'id dello stato

            //cancello regione e città
            if(document.getElementById('regione')){
                document.getElementById('regione').value = '';
            }
            if(document.getElementById('localita')){
                document.getElementById('localita').value = '';
            }
           
            //carico l'elenco dei nomi delle regioni di quello stato
            elencoRegioni = new Array();
            elencoCitta = new Array();
            for (var idregione in  arrayStatiRegioniCitta[valore]['regioni']) {
                elencoRegioni.push(arrayStatiRegioniCitta[valore]['regioni'][idregione]['nome']);

                //carico l'elenco dei nome delle città di della regione
                
                for (var idcitta in  arrayStatiRegioniCitta[valore]['regioni'][idregione]['citta']) {
                    elencoCitta.push(arrayStatiRegioniCitta[valore]['regioni'][idregione]['citta'][idcitta]['nome']);
                }
            }
            break;

        case 'regione':
            //devo cambiare le città
            stato = document.getElementById('stato').value;
            regione = getIdByName(stato, 'regione', valore);
            //alert (stato+' '+regione);

            //cancello la città
            document.getElementById('localita').value = '';
            elencoCitta = new Array();
            
            if(regione){    //se regione è già presente
                for (var idcitta in  arrayStatiRegioniCitta[stato]['regioni']['id'+regione]['citta']) {
                    elencoCitta.push(arrayStatiRegioniCitta[stato]['regioni']['id'+regione]['citta'][idcitta]['nome']);
                }
            }else{
                //nuova regione, svuoto l'elenco delle città
                elencoCitta = new Array();
            }
            break;
    }
}

/**
 *Restituisce l'id di una regione o città
 */
function getIdByName(stato,tipo,valore){
    
    switch (tipo){
        case 'regione':
            //scorro l'array delle regioni in cerca di quella passata
            for ( var regione in arrayStatiRegioniCitta[stato]['regioni']){
                if(valore == arrayStatiRegioniCitta[stato]['regioni'][regione]['nome']){
                    return arrayStatiRegioniCitta[stato]['regioni'][regione]['id'];
                }
            }
            //se non lo trova arriva qui
            return false;
            break;

        case 'citta':
            //scorro l'array delle città in cerca di quella passata
            for ( var regione in arrayStatiRegioniCitta[stato]['regioni']){
                for ( var citta in arrayStatiRegioniCitta[stato]['regioni'][regione]['citta']){
                    if(valore == arrayStatiRegioniCitta[stato]['regioni'][regione]['citta'][citta]['nome']){
                        return arrayStatiRegioniCitta[stato]['regioni'][regione]['citta'][citta]['id'];
                    }
                }
            }
            //se non lo trova arriva qui
            return false;
            break;
    }
}


function cambiaElenchiAutoComplete(origine){
    origine = origine||false;
	
    // Sto Caricando il Campo delle Regioni
    statiRicerca = controlloValoreCampo("statoRicerca");
    if( ( origine == "regioneRicerca" && statiRicerca ) || ( origine == "cittaRicerca" && statiRicerca ) )
    //( origine == "ubicazioneRegione" && controlloValoreCampo("ubicazioneStato") ) || )
    {
		
        statoRicerca = statiRicerca.value;
        // Svuoto l'array delle Regioni
        regioniAutoComplete = new Array();
		
        // Svuoto l'array delle Citta
        cittaAutoComplete = new Array();
		
        // DEVO AGGIORNARE IL CAMPO REGIONI
        if ( origine == "regioneRicerca" ){
			
            i=0;
            // Ciclo Sulle Regioni
            for ( k=0; k < arrStati[statoRicerca]["regioni"].length; k++ ){
				
                // Qua Carico le Regioni
                indreg = arrStati[statoRicerca]["regioni"][k];
                regioniAutoComplete[i] = arrRegioni[indreg]["nome"];
				
                i++;
            }
			
            for ( k=0; k < arrStati[statoRicerca]["regioni"].length; k++ ){
				
                // Qua Carico le Regioni
                indreg = arrStati[statoRicerca]["regioni"][k];
                regioniAutoComplete[i] = arrRegioni[indreg]["nomeit"];
				
                i++;
            }
			
								
            AutoComplete_Create('regioneRicerca', regioniAutoComplete);
			
        }else if ( origine == "cittaRicerca" ){ // DEVO AGGIORNARE IL CAMPO DELLE CITTA
			
            i=0;
            j=0;
			
            // Ciclo Sulle Regioni
            for ( k=0; k < arrStati[statoRicerca]["regioni"].length; k++ ){
				
                // CONTROLLO SE C'E' UNA REGIONE SETTATA!
                if ( regioneCercata = controlloValoreCampo( "regioneRicerca" )){
				
                    nomeRegione = regioneCercata.value;
                    indreg = arrStati[statoRicerca]["regioni"][k];
                    // Qua Carico le Regioni
                    if ( arrRegioni[indreg]["nome"] == nomeRegione ){
										
                        // Cambio le città
                        for (l=0; l < arrRegioni[indreg]["citta"].length; l++){
							
                            indcitta = arrRegioni[indreg]["citta"][l];
                            cittaAutoComplete[j] = arrCitta[indcitta]["nome"];
                            j++;
						
                        }
                        i++;
						
                    }else if (arrRegioni[indreg]["nomeit"] == nomeRegione){ // Hanno scelto una regione in italiano
						
                        // Cambio le città
                        for (l=0; l < arrRegioni[indreg]["citta"].length; l++){
							
                            indcitta = arrRegioni[indreg]["citta"][l];
                            cittaAutoComplete[j] = arrCitta[indcitta]["nomeit"];
                            j++;
						
                        }
                        i++;
						
                    }
					
                }else{
					
                    // Qua Carico le Regioni
                    indreg = arrStati[statoRicerca]["regioni"][k];
                    regioniAutoComplete[i] = arrRegioni[indreg]["nome"];
					
                    // Cambio le città
                    for (l=0; l < arrRegioni[indreg]["citta"].length; l++){
						
                        indcitta = arrRegioni[indreg]["citta"][l];
                        cittaAutoComplete[j] = arrCitta[indcitta]["nome"];
                        j++;
					
                    }
					
                    // Cambio le città
                    for (l=0; l < arrRegioni[indreg]["citta"].length; l++){
						
                        indcitta = arrRegioni[indreg]["citta"][l];
                        cittaAutoComplete[j] = arrCitta[indcitta]["nomeit"];
                        j++;
					
                    }
														
                    i++;
                }
				
            }
								
            AutoComplete_Create('cittaRicerca', cittaAutoComplete);
        }
		
        i=0;
        j=0;
				
    // Stanno compiendo una ricerca
    /*if ( origine == "regioneRicerca" ){
			
			
			// Ciclo Sulle Regioni 
			for ( k=0; k < arrStati[statoRicerca]["regioni"].length; k++ ){
				
				// Qua Carico le Regioni
				
				indreg = arrStati[statoRicerca]["regioni"][k];
				regioniAutoComplete[i] = arrRegioni[indreg]["nome"];
				
				// Cambio le città
				for (l=0; l < arrRegioni[indreg]["citta"].length; l++){
					
					indcitta = arrRegioni[indreg]["citta"][l];
					cittaAutoComplete[j] = arrCitta[indcitta]["nome"];
					j++;
				
				}
				i++;
			}
								
			AutoComplete_Create('regioneRicerca', regioniAutoComplete);
			AutoComplete_Create('cittaRicerca', cittaAutoComplete);
				
		}else if ( origine=="ubicazioneStato" ) { 
			
			for (indice in RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"])
			{
				//regioniAutoComplete
				regioniAutoComplete[i] = RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"][indice]["nome"];
			
				i++;
			}
			
			AutoComplete_Create('ubicazioneRegione', regioniAutoComplete);		
		}	*/	 
			
    }else if (
        ( origine == "ubicazioneRegione" && ( statiRegistrazione = controlloValoreCampo("ubicazioneStato") ) ) ||
        ( 	 origine == "ubicazioneLocalita" &&
            ( regioniRegistrazione = controlloValoreCampo("ubicazioneRegione") ) &&
            ( statiRegistrazione = controlloValoreCampo("ubicazioneStato") )
            )
        )
        {
		
		
        statoRegistrazione = statiRegistrazione.value;
			
        // Svuoto l'array delle Citta
        cittaAutoComplete = new Array();
		
        if ( origine == "ubicazioneRegione" ){
			
            // Svuoto l'array delle Regioni
            regioniAutoComplete = new Array();
			
            i=0;
            for (indice in RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"])
            {
                //regioniAutoComplete
                regioniAutoComplete[i] = RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"][indice]["nome"];
			
                i++;
            }
			
            AutoComplete_Create('ubicazioneRegione', regioniAutoComplete);
			
        }else{
			
            regioneSelezionata = regioniRegistrazione.value;
            cittaRegistrazione = carpeGetElementById("ubicazioneLocalita")
            // Cerco l'id della Regione
            for (indice in RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"])
            {
                if(RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"][indice]["nome"] == regioneSelezionata ){
                    regione = RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"][indice]["id"];
					
                    //Pulisco il Campo Citta
                    cittaRegistrazione.value = "";
					
					
                    s = 0;
				
                    for ( indice2 in RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"]["id"+regione]["citta"] )
                    {
										
                        if( RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"]["id"+regione]["citta"][indice2]["nome"] != '' ) {
				   		
                            cittaAutoComplete[s] = RarrStatiRegioniCittaReg[statoRegistrazione]["regioni"]["id"+regione]["citta"][indice2]["nome"];
                        }
				   		
                        s++;
                    }
					
                }
			
            }
            AutoComplete_Create('ubicazioneLocalita', cittaAutoComplete);
        }
	
	
    }else{
        //alert('non ho ancora inserito niente....vediamo se carica');
        j=0;
        r=0;
        s=0;
		
        // Svuoto l'array delle Citta
        regioniAutoComplete = new Array();
		
        // Svuoto l'array delle Citta
        cittaAutoComplete = new Array();
		
        for (idstato in arrStati){
            for ( k=0; k < arrStati[idstato]["regioni"].length; k++ ){
					
                indreg = arrStati[idstato]["regioni"][k];
				
                // Qua Carico le Regioni
                regioniAutoComplete[r] = arrRegioni[indreg]["nome"];
                r++;
                regioniAutoComplete[r] = arrRegioni[indreg]["nomeit"];
                r++;
				
                // Cambio le città
                for (l=0; l < arrRegioni[indreg]["citta"].length; l++){
						
                    indcitta = arrRegioni[indreg]["citta"][l];
                    cittaAutoComplete[j] = arrCitta[indcitta]["nome"];
                    j++;
					
                }
					
                // Cambio le città
                for (l=0; l < arrRegioni[indreg]["citta"].length; l++){
					
                    indcitta = arrRegioni[indreg]["citta"][l];
                    cittaAutoComplete[j] = arrCitta[indcitta]["nomeit"];
                    j++;
				
                }
            }
        }
        AutoComplete_Create('regioneRicerca', regioniAutoComplete);
        AutoComplete_Create('cittaRicerca', cittaAutoComplete);
    }
	
	
	
}

function caricaAutocompleteAreaAmm(origine,stato){
	
    // Svuoto l'Array delle Citta
    cittaAutoComplete = new Array();
	
    for (g=0; g < arrStati[stato]["citta"].length; g++ ) // indice in arrStati[statoRicerca]["regioni"])
    {
        indice = arrStati[stato]["citta"][g];
        cittaAutoComplete[g] = arrCitta[indice]["nome"];
		
    }
    //alert (cittaAutoComplete);
    AutoComplete_Create(origine, cittaAutoComplete);
}



function inviaform(myform){
    f = document.getElementById(myform);
    f.submit();
}

function salvaDatiHotel(dest,hotel,sessid){
    // dest è la sezione di destinazione, non il form da salvare!!!
    //f = document.getElementById("datihotel");
    if(document.datihotel){
        document.datihotel.action="amm_salvaDatiHotel.php?dest="+dest+"&idhotel="+hotel+"&phpsessid="+sessid;
        document.datihotel.submit();
    }else{
	
        window.location = "amm_schedahotel.php?dest="+dest+"&idhotel="+hotel+"&phpsessid="+sessid;
    }
	
}

function salvaDatiCertificazione(dest,hotel,sessid){
    // dest è la sezione di destinazione, non il form da salvare!!!
    //f = document.getElementById("datihotel");
    if(document.datihotel){
        document.datihotel.action="amm_salvaDatiCertificazione.php?dest="+dest+"&idhotel="+hotel+"&phpsessid="+sessid;
        document.datihotel.submit();
    }else{
	
        window.location = "amm_schedahotel.php?dest="+dest+"&idhotel="+hotel+"&phpsessid="+sessid;
    }
	
}

function deleteCampo(nomeCampo){
	
    if( elemento = controlloValoreCampo(nomeCampo)){
        elemento.value = "";
    }

}

/**
* � Copyright 2005 Richard Heyes
*/

/**
    * Global vars
    */
__AutoComplete = new Array();

// Basic UA detection
isIE = document.all ? true : false;
isGecko = navigator.userAgent.toLowerCase().indexOf('gecko') != -1;
isOpera = navigator.userAgent.toLowerCase().indexOf('opera') != -1;


/**
    * Attachs the autocomplete object to a form element. Sets
    * onkeypress event on the form element.
    * 
    * @param string formElement Name of form element to attach to
    * @param array  data        Array of strings of which to use as the autocomplete data
    */
function AutoComplete_Create (id, data)
{
    
	
    __AutoComplete[id] = {
        'data':data,
        'isVisible':false,
        'element':document.getElementById(id),
        'dropdown':null,
        'highlighted':null
    };

    //alert(document.getElementById(id));

    __AutoComplete[id]['element'].setAttribute('autocomplete', 'off');
    __AutoComplete[id]['element'].onkeydown  = function(e) {
        return AutoComplete_KeyDown(this.getAttribute('id'), e);
    }
    __AutoComplete[id]['element'].onkeyup    = function(e) {
        return AutoComplete_KeyUp(this.getAttribute('id'), e);
    }
    __AutoComplete[id]['element'].onkeypress = function(e) {
        if (!e) e = window.event;
        if (e.keyCode == 13 || isOpera) return false;
    }
    __AutoComplete[id]['element'].ondblclick = function() {
        AutoComplete_ShowDropdown(this.getAttribute('id'));
        AutoComplete_Highlight(id, 0);
    }
    __AutoComplete[id]['element'].onclick    = function(e) {
        if (!e) e = window.event;
        e.cancelBubble = true;
        e.returnValue = false;
    }

    // Hides the dropdowns when document clicked
    var docClick = function()
    {
        for (id in __AutoComplete) {
            AutoComplete_HideDropdown(id);
        }
    }

    if (document.addEventListener) {
        document.addEventListener('click', docClick, false);
    } else if (document.attachEvent) {
        document.attachEvent('onclick', docClick, false);
    }


    // Max number of items shown at once
    if (arguments[2] != null) {
        __AutoComplete[id]['maxitems'] = arguments[2];
        __AutoComplete[id]['firstItemShowing'] = 0;
        __AutoComplete[id]['lastItemShowing']  = arguments[2] - 1;
    }
        
    AutoComplete_CreateDropdown(id);
        
    // Prevent select dropdowns showing thru
    if (isIE) {
        __AutoComplete[id]['iframe'] = document.createElement('iframe');
        __AutoComplete[id]['iframe'].id = id +'_iframe';
        __AutoComplete[id]['iframe'].style.position = 'absolute';
        __AutoComplete[id]['iframe'].style.top = '0';
        __AutoComplete[id]['iframe'].style.left = '0';
        __AutoComplete[id]['iframe'].style.width = '0px';
        __AutoComplete[id]['iframe'].style.height = '0px';
        __AutoComplete[id]['iframe'].style.zIndex = '98';
        __AutoComplete[id]['iframe'].style.visibility = 'hidden';
            
        __AutoComplete[id]['element'].parentNode.insertBefore(__AutoComplete[id]['iframe'], __AutoComplete[id]['element']);
    }
}


/**
    * Creates the dropdown layer
    * 
    * @param string id The form elements id. Used to identify the correct dropdown.
    */
function AutoComplete_CreateDropdown(id)
{
    var left  = AutoComplete_GetLeft(__AutoComplete[id]['element']);
    var top   = AutoComplete_GetTop(__AutoComplete[id]['element']) + __AutoComplete[id]['element'].offsetHeight;
    var width = __AutoComplete[id]['element'].offsetWidth;
    
    __AutoComplete[id]['dropdown'] = document.createElement('div');
    __AutoComplete[id]['dropdown'].className = 'autocomplete'; // Don't use setAttribute()
    
    __AutoComplete[id]['element'].parentNode.insertBefore(__AutoComplete[id]['dropdown'], __AutoComplete[id]['element']);
        
    // Position it
    __AutoComplete[id]['dropdown'].style.left       = left + 'px';
    __AutoComplete[id]['dropdown'].style.top        = top + 'px';
    __AutoComplete[id]['dropdown'].style.width      = width + 'px';
    __AutoComplete[id]['dropdown'].style.zIndex     = '99';
    __AutoComplete[id]['dropdown'].style.visibility = 'hidden';
}
    
    
/**
    * Gets left coord of given element
    * 
    * @param object element The element to get the left coord for
    */
function AutoComplete_GetLeft(element)
{
    var curNode = element;
    var left    = 0;

    do {
        left += curNode.offsetLeft;
        curNode = curNode.offsetParent;

    } while(curNode.tagName.toLowerCase() != 'body');

    return left;
}
    
    
/**
    * Gets top coord of given element
    * 
    * @param object element The element to get the top coord for
    */
function AutoComplete_GetTop(element)
{
    var curNode = element;
    var top    = 0;

    do {
        top += curNode.offsetTop;
        curNode = curNode.offsetParent;

    } while(curNode.tagName.toLowerCase() != 'body');

    return top;
}

    
/**
    * Shows the dropdown layer
    * 
    * @param string id The form elements id. Used to identify the correct dropdown.
    */
function AutoComplete_ShowDropdown(id)
{
    AutoComplete_HideAll();

    var value = __AutoComplete[id]['element'].value;
    var toDisplay = new Array();
    var newDiv    = null;
    var text      = null;
    var numItems  = __AutoComplete[id]['dropdown'].childNodes.length;

    // Remove all child nodes from dropdown
    while (__AutoComplete[id]['dropdown'].childNodes.length > 0) {
        __AutoComplete[id]['dropdown'].removeChild(__AutoComplete[id]['dropdown'].childNodes[0]);
    }

    // Go thru data searching for matches
    for (i=0; i<__AutoComplete[id]['data'].length; ++i) {
        if (__AutoComplete[id]['data'][i].substr(0, value.length).toLowerCase() == value.toLowerCase()) {
            toDisplay[toDisplay.length] = __AutoComplete[id]['data'][i];
        }
    }
        
    // No matches?
    if (toDisplay.length == 0) {
        AutoComplete_HideDropdown(id);
        return;
    }



    // Add data to the dropdown layer
    for (i=0; i<toDisplay.length; ++i) {
        newDiv = document.createElement('div');
        newDiv.className = 'autocomplete_item'; // Don't use setAttribute()
        newDiv.setAttribute('id', 'autocomplete_item_' + i);
        newDiv.setAttribute('index', i);
        newDiv.style.zIndex = '99';
            
        // Scrollbars are on display ?
        if (toDisplay.length > __AutoComplete[id]['maxitems'] && navigator.userAgent.indexOf('MSIE') == -1) {
            newDiv.style.width = __AutoComplete[id]['element'].offsetWidth - 22 + 'px';
        }

        newDiv.onmouseover = function() {
            AutoComplete_HighlightItem(__AutoComplete[id]['element'].getAttribute('id'), this.getAttribute('index'));
        };
        newDiv.onclick     = function() {
            AutoComplete_SetValue(__AutoComplete[id]['element'].getAttribute('id'));
            AutoComplete_HideDropdown(__AutoComplete[id]['element'].getAttribute('id'));
					
					
            if(amministrativa){
                assocCitta = 	__AutoComplete[id]['element'].value;
                idhotel   = 	__AutoComplete[id]['element'].getAttribute('idhotel');
                idstato   =		__AutoComplete[id]['element'].getAttribute('idstato');
                idregione  =	__AutoComplete[id]['element'].getAttribute('idregione');
						
                window.location = 'amm_elencohotel.php?assocCitta='+assocCitta+'&idhotel='+idhotel+'&idstato='+idstato+'&idregione='+idregione;
            }
				
        }
            
        text   = document.createTextNode(toDisplay[i]);
        newDiv.appendChild(text);
            
        __AutoComplete[id]['dropdown'].appendChild(newDiv);
    }
        
        
    // Too many items?
    if (toDisplay.length > __AutoComplete[id]['maxitems']) {
        __AutoComplete[id]['dropdown'].style.height = (__AutoComplete[id]['maxitems'] * 15) + 2 + 'px';
        
    } else {
        __AutoComplete[id]['dropdown'].style.height = '';
    }

        
    /**
        * Set left/top in case of document movement/scroll/window resize etc
        */
    __AutoComplete[id]['dropdown'].style.left = AutoComplete_GetLeft(__AutoComplete[id]['element']);
    __AutoComplete[id]['dropdown'].style.top  = AutoComplete_GetTop(__AutoComplete[id]['element']) + __AutoComplete[id]['element'].offsetHeight;


    // Show the iframe for IE
    if (isIE) {
        __AutoComplete[id]['iframe'].style.top    = __AutoComplete[id]['dropdown'].style.top;
        __AutoComplete[id]['iframe'].style.left   = __AutoComplete[id]['dropdown'].style.left;
        __AutoComplete[id]['iframe'].style.width  = __AutoComplete[id]['dropdown'].offsetWidth;
        __AutoComplete[id]['iframe'].style.height = __AutoComplete[id]['dropdown'].offsetHeight;
            
        __AutoComplete[id]['iframe'].style.visibility = 'visible';
    }


    // Show dropdown
    if (!__AutoComplete[id]['isVisible']) {
        __AutoComplete[id]['dropdown'].style.visibility = 'visible';
        __AutoComplete[id]['isVisible'] = true;
    }

        
    // If now showing less items than before, reset the highlighted value
    if (__AutoComplete[id]['dropdown'].childNodes.length != numItems) {
        __AutoComplete[id]['highlighted'] = null;
    }
}
    
    
/**
    * Hides the dropdown layer
    * 
    * @param string id The form elements id. Used to identify the correct dropdown.
    */
function AutoComplete_HideDropdown(id)
{
    if (__AutoComplete[id]['iframe']) {
        __AutoComplete[id]['iframe'].style.visibility = 'hidden';
    }


    __AutoComplete[id]['dropdown'].style.visibility = 'hidden';
    __AutoComplete[id]['highlighted'] = null;
    __AutoComplete[id]['isVisible']   = false;
}
    
    
/**
    * Hides all dropdowns
    */
function AutoComplete_HideAll()
{
    for (id in __AutoComplete) {
        AutoComplete_HideDropdown(id);
    }
}
    
    
/**
    * Highlights a specific item
    * 
    * @param string id    The form elements id. Used to identify the correct dropdown.
    * @param int    index The index of the element in the dropdown to highlight
    */
function AutoComplete_HighlightItem(id, index)
{
    if (__AutoComplete[id]['dropdown'].childNodes[index]) {
        for (var i=0; i<__AutoComplete[id]['dropdown'].childNodes.length; ++i) {
            if (__AutoComplete[id]['dropdown'].childNodes[i].className == 'autocomplete_item_highlighted') {
                __AutoComplete[id]['dropdown'].childNodes[i].className = 'autocomplete_item';
            }
        }
            
        __AutoComplete[id]['dropdown'].childNodes[index].className = 'autocomplete_item_highlighted';
        __AutoComplete[id]['highlighted'] = index;
    }
}


/**
    * Highlights the menu item with the given index
    * 
    * @param string id    The form elements id. Used to identify the correct dropdown.
    * @param int    index The index of the element in the dropdown to highlight
    */
function AutoComplete_Highlight(id, index)
{
    // Out of bounds checking
    if (index == 1 && __AutoComplete[id]['highlighted'] == __AutoComplete[id]['dropdown'].childNodes.length - 1) {
        __AutoComplete[id]['dropdown'].childNodes[__AutoComplete[id]['highlighted']].className = 'autocomplete_item';
        __AutoComplete[id]['highlighted'] = null;
        
    } else if (index == -1 && __AutoComplete[id]['highlighted'] == 0) {
        __AutoComplete[id]['dropdown'].childNodes[0].className = 'autocomplete_item';
        __AutoComplete[id]['highlighted'] = __AutoComplete[id]['dropdown'].childNodes.length;
    }

    // Nothing highlighted at the moment
    if (__AutoComplete[id]['highlighted'] == null) {
        __AutoComplete[id]['dropdown'].childNodes[0].className = 'autocomplete_item_highlighted';
        __AutoComplete[id]['highlighted'] = 0;

    } else {
        if (__AutoComplete[id]['dropdown'].childNodes[__AutoComplete[id]['highlighted']]) {
            __AutoComplete[id]['dropdown'].childNodes[__AutoComplete[id]['highlighted']].className = 'autocomplete_item';
        }

        var newIndex = __AutoComplete[id]['highlighted'] + index;

        if (__AutoComplete[id]['dropdown'].childNodes[newIndex]) {
            __AutoComplete[id]['dropdown'].childNodes[newIndex].className = 'autocomplete_item_highlighted';
                
            __AutoComplete[id]['highlighted'] = newIndex;
        }
    }
}


/**
    * Sets the input to a given value
    * 
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
function AutoComplete_SetValue(id)
{
    //__AutoComplete[id]['element'].focus();
    __AutoComplete[id]['element'].value = __AutoComplete[id]['dropdown'].childNodes[__AutoComplete[id]['highlighted']].innerHTML;
//__AutoComplete[id]['element'].blur();
}
    
    
/**
    * Checks if the dropdown needs scrolling
    * 
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
function AutoComplete_ScrollCheck(id)
{
    // Scroll down, or wrapping around from scroll up
    if (__AutoComplete[id]['highlighted'] > __AutoComplete[id]['lastItemShowing']) {
        __AutoComplete[id]['firstItemShowing'] = __AutoComplete[id]['highlighted'] - (__AutoComplete[id]['maxitems'] - 1);
        __AutoComplete[id]['lastItemShowing']  = __AutoComplete[id]['highlighted'];
    }
        
    // Scroll up, or wrapping around from scroll down
    if (__AutoComplete[id]['highlighted'] < __AutoComplete[id]['firstItemShowing']) {
        __AutoComplete[id]['firstItemShowing'] = __AutoComplete[id]['highlighted'];
        __AutoComplete[id]['lastItemShowing']  = __AutoComplete[id]['highlighted'] + (__AutoComplete[id]['maxitems'] - 1);
    }
        
    __AutoComplete[id]['dropdown'].scrollTop = __AutoComplete[id]['firstItemShowing'] * 15;
}


/**
    * Function which handles the keypress event
    * 
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
function AutoComplete_KeyDown(id)
{
    // Mozilla
    if (arguments[1] != null) {
        event = arguments[1];
    }

    var keyCode = event.keyCode;

    switch (keyCode) {

        // Return/Enter
        case 13:
            if (__AutoComplete[id]['highlighted'] != null) {
                AutoComplete_SetValue(id);
                AutoComplete_HideDropdown(id);
            }
                
            event.returnValue = false;
            event.cancelBubble = true;
            break;

        // Escape
        case 27:
            AutoComplete_HideDropdown(id);
            event.returnValue = false;
            event.cancelBubble = true;
            break;
            
        // Up arrow
        case 38:
            if (!__AutoComplete[id]['isVisible']) {
                AutoComplete_ShowDropdown(id);
                AutoComplete_Highlight(id, 0);
            }
                
            AutoComplete_Highlight(id, -1);
            AutoComplete_ScrollCheck(id, -1);
            return false;
            break;
            
        // Tab
        case 9:
            if (__AutoComplete[id]['isVisible']) {
                AutoComplete_HideDropdown(id);
            }
            return;
            
        // Down arrow
        case 40:
            if (!__AutoComplete[id]['isVisible']) {
                AutoComplete_ShowDropdown(id);
                AutoComplete_Highlight(id, 0);
            }
                
            AutoComplete_Highlight(id, 1);
            AutoComplete_ScrollCheck(id, 1);
            return false;
            break;
    }
}


/**
    * Function which handles the keyup event
    * 
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
function AutoComplete_KeyUp(id)
{
    // Mozilla
    if (arguments[1] != null) {
        event = arguments[1];
    }

    var keyCode = event.keyCode;

    switch (keyCode) {
        case 13:
            event.returnValue = false;
            event.cancelBubble = true;
            break;

        case 27:
            AutoComplete_HideDropdown(id);
            event.returnValue = false;
            event.cancelBubble = true;
            break;
            
        case 38:
        case 40:
            return false;
            break;

        default:
            AutoComplete_ShowDropdown(id);
            AutoComplete_Highlight(id, 0);
            break;
    }
}
    
/**
    * Returns whether the dropdown is visible
    * 
    * @param string id    The form elements id. Used to identify the correct dropdown.
    */
function AutoComplete_isVisible(id)
{
    return __AutoComplete[id]['dropdown'].style.visibility == 'visible';
}


function modificaStoricoNote(){
    document.getElementById('storiconote').style.display='none';
    document.getElementById('modificanote').style.display='block';
}



var cAutocomplete =
{
    sDescription : 'autcomplete class'
}


cAutocomplete.complete = function( hEvent )
{
    if( hEvent == null )
    {
        var hEvent = window.hEvent
    }

    var hElement = ( hEvent.srcElement ) ? hEvent.srcElement : hEvent.originalTarget

    var sAA = hElement.getAttribute( 'autocomplete' ).toString()
    if( sAA.indexOf( 'array:' ) >= 0 )
    {
        hArr = eval( sAA.substring( 6 ) )
    }
    else if(  sAA.indexOf( 'list:' ) >= 0 )
    {
        hArr = sAA.substring( 5 ).split( '|' )
    }



    if( hEvent.keyCode == 16 )
    {
        return
    }
    var sVal = hElement.value.toLowerCase()
    if( hEvent.keyCode == 8 )
    {
        sVal = sVal.substring( 0, sVal.length - 1 )
    }
    if( sVal.length < 1 )
    {
        return
    }
    for( var nI = 0; nI < hArr.length; nI++ )
    {
        sMonth = hArr[ nI ]
        nIdx = sMonth.toLowerCase().indexOf( sVal, 0 )
        if( nIdx == 0 && sMonth.length > sVal.length )
        {
            hElement.value = hArr[ nI ]
            if( hElement.createTextRange )
            {
                hRange = hElement.createTextRange()
                hRange.findText( hArr[ nI ].substr( sVal.length ) )
                hRange.select()
            }
            else
            {
                hElement.setSelectionRange( sVal.length, sMonth.length )
            }
            return
        }
    }
}

cAutocomplete.init = function()
{
    var nI = 0
    var aInputs = document.getElementsByTagName( 'input' )
    for( var nI = 0; nI < aInputs.length; nI ++ )
    {
        if( aInputs[ nI ].type.toLowerCase() == 'text' )
        {
            var sLangAtt = aInputs[ nI ].getAttribute( 'autocomplete' )
            if( sLangAtt )
            {
                if( document.attachEvent )
                {
                    aInputs[ nI ].attachEvent( 'onkeyup', cAutocomplete.complete )
                }
                else if( document.addEventListener )
                {
                    aInputs[ nI ].addEventListener( 'keyup', cAutocomplete.complete, false )
                }
            }
        }
    }
}

if( window.attachEvent )
{
    window.attachEvent( 'onload', cAutocomplete.init )
}
else if( window.addEventListener )
{
    window.addEventListener( 'load', cAutocomplete.init, false )
}

/* verifica completamento form*/
function validaForm(myForm, ling){
	var errore = true;
    for(i=0;i<myForm.elements.length;i++){
        campo = myForm.elements[i];
        if(campo.attributes.getNamedItem("richiesto")){
            if(campo.value==""){
                 campo.style.backgroundColor="yellow";
                errore = errore&false;
            }
        }
    }
	if(errore==0){
		if(ling=="RU"){
			alert('Заполните все обязательные поля!');
		}else{
			alert('Please complete all fields!');
			
		}
		return false;
	}else{
		return true;
	}
}

var MD5 = function (string) {
 
	function RotateLeft(lValue, iShiftBits) {
		return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
	}
 
	function AddUnsigned(lX,lY) {
		var lX4,lY4,lX8,lY8,lResult;
		lX8 = (lX & 0x80000000);
		lY8 = (lY & 0x80000000);
		lX4 = (lX & 0x40000000);
		lY4 = (lY & 0x40000000);
		lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
		if (lX4 & lY4) {
			return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
		}
		if (lX4 | lY4) {
			if (lResult & 0x40000000) {
				return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
			} else {
				return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
			}
		} else {
			return (lResult ^ lX8 ^ lY8);
		}
 	}
 
 	function F(x,y,z) { return (x & y) | ((~x) & z); }
 	function G(x,y,z) { return (x & z) | (y & (~z)); }
 	function H(x,y,z) { return (x ^ y ^ z); }
	function I(x,y,z) { return (y ^ (x | (~z))); }
 
	function FF(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function GG(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function HH(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function II(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function ConvertToWordArray(string) {
		var lWordCount;
		var lMessageLength = string.length;
		var lNumberOfWords_temp1=lMessageLength + 8;
		var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
		var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
		var lWordArray=Array(lNumberOfWords-1);
		var lBytePosition = 0;
		var lByteCount = 0;
		while ( lByteCount < lMessageLength ) {
			lWordCount = (lByteCount-(lByteCount % 4))/4;
			lBytePosition = (lByteCount % 4)*8;
			lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
			lByteCount++;
		}
		lWordCount = (lByteCount-(lByteCount % 4))/4;
		lBytePosition = (lByteCount % 4)*8;
		lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
		lWordArray[lNumberOfWords-2] = lMessageLength<<3;
		lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
		return lWordArray;
	};
 
	function WordToHex(lValue) {
		var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
		for (lCount = 0;lCount<=3;lCount++) {
			lByte = (lValue>>>(lCount*8)) & 255;
			WordToHexValue_temp = "0" + lByte.toString(16);
			WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
		}
		return WordToHexValue;
	};
 
	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	};
 
	var x=Array();
	var k,AA,BB,CC,DD,a,b,c,d;
	var S11=7, S12=12, S13=17, S14=22;
	var S21=5, S22=9 , S23=14, S24=20;
	var S31=4, S32=11, S33=16, S34=23;
	var S41=6, S42=10, S43=15, S44=21;
 
	string = Utf8Encode(string);
 
	x = ConvertToWordArray(string);
 
	a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
 
	for (k=0;k<x.length;k+=16) {
		AA=a; BB=b; CC=c; DD=d;
		a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
		d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
		c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
		b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
		a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
		d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
		c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
		b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
		a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
		d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
		c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
		b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
		a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
		d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
		c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
		b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
		a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
		d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
		c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
		b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
		a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
		d=GG(d,a,b,c,x[k+10],S22,0x2441453);
		c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
		b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
		a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
		d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
		c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
		b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
		a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
		d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
		c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
		b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
		a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
		d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
		c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
		b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
		a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
		d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
		c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
		b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
		a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
		d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
		c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
		b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
		a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
		d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
		c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
		b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
		a=II(a,b,c,d,x[k+0], S41,0xF4292244);
		d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
		c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
		b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
		a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
		d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
		c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
		b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
		a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
		d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
		c=II(c,d,a,b,x[k+6], S43,0xA3014314);
		b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
		a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
		d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
		c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
		b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
		a=AddUnsigned(a,AA);
		b=AddUnsigned(b,BB);
		c=AddUnsigned(c,CC);
		d=AddUnsigned(d,DD);
	}
 
	var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
 
	return temp.toLowerCase();
}
function cripta(form){
	form.user.value= MD5(form.user.value);
	form.password.value = MD5(form.password.value);
	return true;
}

function mostraNascondiElenco(ido,id,n){
    obj=document.getElementById(ido);
	objSrc = document.getElementById(id);
    if(obj.style.display=="block"){
        obj.style.display="none";
		objSrc.innerHTML = '...see all the results ('+n+' more) &gt;&gt;';
    }else{
        obj.style.display="block";
		objSrc.innerHTML = '...hide results &gt;&gt;';
    }
}

function by(i,dir) {
//usata per ordinare array multidimensionali
//dir = -1 z-a; dir=1 a-z
//yourarray.sort(by(2,-1));
	return function(a,b){
		if(a[i]){a = a[i];} else { a=0; }
		if(b[i]){b = b[i];} else { b=0; }
		
		if(isNaN(a)){
			result = a.toLowerCase() == b.toLowerCase() ? 0 : (a.toLowerCase() < b.toLowerCase() ? -1*dir : dir)
		}else{
			result =  (dir == 1 ? a - b : b-a)
		}
		return result;
	}
}

function inArray(array,element) {
	for(var i = 0; i < array.length; i++)
		if(array[i] === element)
		return i;
	return false;
}

function aMultiSort(array,i,dir) {
	array.sort(by(i,dir));
	return array;
}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function clona(object) 
{ 
    var ClonedObject = function(){}; 
    ClonedObject.prototype = object; 
    return new ClonedObject; 
} 
