// JavaScript Document

// REQUIRED: 	slidesStack
//				timer
var slidesStack = [];
slidesStack[0] = "freePos";
var effects_timer = 10;
var effects_stop_all = 0;
var effects_end_alarm = 0;
var effects_list = [];

var animazioni = 1;
if ( /MSIE/.test(navigator.userAgent) ) animazioni = 0;

var effects_list_vuoto = [];
effects_list_vuoto[0] = "nome_gruppo";
effects_list_vuoto[1] = []; // Elementi;
effects_list_vuoto[2] = "unico"; // O multiplo

/*
Lista degli effetti:
	vettore -> ogni elemento:
		[0] nome del gruppo degli effetti (un codice è meglio)
		[1] catena degli effetti
		[2] in funzione: assume il valore dell'indice dell'elemento che sta andando
		[3] in funzione si/no
		[4] unico, o ripeti
	catena degli effetti:
		[0]: slideEff (parametri....., codice_lista );
		
	EFFETTI DISPONIBILI:
	(step è sempre facoltativo, direzione è 1 -> o -1 <-)
		ridimensiona ( id , [larghezza,altezza], codice_lista, step )
		muovi ( id, [a_orizzontale,a_verticale,direzione_orizzontale,direzione_verticale], codice_lista, step ) 
		effectAlert (codice_lista);
		assegnaContenuto ( divA, divDa, codice_lista );
		riposizionaOggetto ( id, posizione, codice_lista ) 
		fadeForza ( id, fadeValue, codice_lista )
		fade ( id, fadeFine, codice_lista, step ) 
		aspetta (tempo, codice_lista)
*/


//muovi ( 'provaEffetti', [100,0,1,1], 0 );
//ridimensiona ( 'provaEffetti', [100,100], 1 );
effects_list[0] = [];
effects_list[0][0] = "menu_prodotti";
effects_list[0][1] = [];
	effects_list[0][1][0] = "muovi ( 'provaEffetti', [100,0,-1,1], 0 );";
	effects_list[0][1][1] = "ridimensiona ( 'provaEffetti', [350,350], 0 );";
	effects_list[0][1][2] = "fadeForza('provaEffetti',0,0);";
	effects_list[0][1][3] = "fade('provaEffetti',1,0);";

effects_list[0][2] = -1;
effects_list[0][3] = 0;
effects_list[0][4] = "unico";


function eseguiEffetto ( codice_lista ) {
	if ( codice_lista >= 0 ) {
		// Aumento di 1 l'indice dell'effetto da eseguire, in partenza è -1
		effects_list[codice_lista][2]++;
		
		// Se è minore del totale degli effetti lo eseguo, altrimenti cancello la lista
		if ( effects_list[codice_lista][2] < effects_list[codice_lista][1].length ) {
			effects_list[codice_lista][3] = 1;
			eval ( effects_list[codice_lista][1][effects_list[codice_lista][2]] );		
		} else {
			if ( effects_list[codice_lista][4] == "ripeti" ) {
				effects_list[codice_lista][2] = -1;
				eseguiEffetto ( codice_lista );
			} else {
				effects_list[codice_lista] = [];
				if ( effects_end_alarm == 1 ) 
					window.alert( "Gli effetti della lista " + codice_lista + " sono finiti");
			}
		}
	}
}

// Questa procedura deve essere richiamata ogni volta che finisce un'azione da parte di una
// funzione grafica: impsta a 0 il boolean di movimento ed esegue quello successivo
function terminaEffetto ( codice_lista ) {
	if ( codice_lista >= 0 ) {
		effects_list[codice_lista][3] = 0; 
		eseguiEffetto ( codice_lista );
	}
}
function effectAlert ( codice_lista ) {
	window.alert(" ALERT ");
	terminaEffetto ( codice_lista );
}
function gruppoEffettiToIndex ( nome_gruppo ) {
	var indice = -1;
	for ( var i=0; i<effects_list.length; i++ ) {
		if ( effects_list[i][0] == nome_gruppo ) indice = i;
	}
	return indice;
}
function aggiungiEffetto ( effetto ) {
	var codice_lista = effects_list.length;
	for (var i=0; i<effetto[1].length; i++ ) {
		effetto[1][i] = effetto[1][i].replace ( "'codice_lista'", codice_lista );
	}
	effects_list[codice_lista] = effetto;
	return codice_lista;
}

function creaListaEffetti ( nome_lista, modo_lista ) {
	var codice_lista = effects_list.length;
	effects_list[codice_lista] = [];
	effects_list[codice_lista][0] = nome_lista;
	effects_list[codice_lista][1] = [];
	for ( var i=2; i<arguments.length; i++ ) {
		effects_list[codice_lista][1][i-2] = arguments[i].replace ( "'codice_lista'", codice_lista );
	}
	effects_list[codice_lista][2] = -1;
	effects_list[codice_lista][3] = 0;
	effects_list[codice_lista][4] = modo_lista;
	eseguiEffetto ( codice_lista );
}

var default_center = 'mainCenter';

function disableEffects () {
	effects_stop_all = 1;
}
function enableEffects () {
	effects_stop_all = 0;
}
function allowEffects () {
	var allow = false;
	if ( effects_stop_all == 0 ) allow = true;
	return allow;
}
function executeEffects ( effectsList ) {
	if ( isString ( effectsList ) ) {
		var temp = effectsList;
		effectsList = [[temp,0,0]];
	}
	var effect;
	var nameEffect = ""
	var exclusiveLocal = 0;
	var exclusiveGlobal = 0;
	for ( var i=0; i<effectsList.length; i++ ) {
		effect = effectsList[i];
		nameEffect = effect[0];
		exclusiveLocal = effect[1];
		exclusiveGlobal = effect[2];
	}
	
	startEffect ( nameEffect );
}
function startEffect ( nameEffect ) {
	if ( allowEffects () ) 
		eval ( nameEffect );
}
function stopEffects () {
	disableEffects();
	setTimeout('enableEffects()',1);
}


/////////////////////////////////////////
//		FUNZIONI VELOCI   	         //
/////////////////////////////////////////

function appari (id) {
	var effetto_veloce = [];
	effetto_veloce[0] = "appari_"+id;
	effetto_veloce[1] = [];
		effetto_veloce[1][0] = "fadeForza('" + id + "',0, 'codice_lista' );";
		effetto_veloce[1][1] = "fade('" + id + "',1,'codice_lista');";
	effetto_veloce[2] = -1;
	effetto_veloce[3] = 0;
	effetto_veloce[4] = "unico";
	var codice_lista = aggiungiEffetto(effetto_veloce);
	eseguiEffetto ( codice_lista );
}
function pulsa (id) {
	var effetto_veloce = [];
	effetto_veloce[0] = "appari_"+id;
	effetto_veloce[1] = [];
		effetto_veloce[1][0] = "fadeForza('" + id + "',1, 'codice_lista' );";
		effetto_veloce[1][1] = "fade('" + id + "',0,'codice_lista');";
		effetto_veloce[1][2] = "fade('" + id + "',1,'codice_lista');";
		effetto_veloce[1][3] = "fade('" + id + "',0,'codice_lista');";
		effetto_veloce[1][4] = "fade('" + id + "',1,'codice_lista');";
	effetto_veloce[2] = -1;
	effetto_veloce[3] = 0;
	effetto_veloce[4] = "unico";
	var codice_lista = aggiungiEffetto(effetto_veloce);
	eseguiEffetto ( codice_lista );
}

function espandi ( id, idPadre, minimo, massimo, step, tipoEffetto, margine, onClose ) {
	if ( !margine ) var margine = 0;
	if ( !onClose ) var onClose = "";
	if ( tipoEffetto == "orizzontale" ) {
		if ( minimo == "massimo" ) minimo = document.getElementById ( idPadre ).clientWidth - 2*margine -2;
		if ( massimo == "massimo" ) massimo = document.getElementById ( idPadre ).clientWidth - 2*margine;
	}
	if ( tipoEffetto == "verticale" ) {
		if ( minimo == "massimo" ) minimo = document.getElementById ( idPadre ).clientHeight - 2*margine;
		if ( massimo == "massimo" ) massimo = document.getElementById ( idPadre ).clientHeight - 2*margine;
	}
	document.getElementById ( id ).style.overflow="hidden";
	slideEff ( id, minimo, massimo, step, tipoEffetto, onClose );
}
function slideEff ( id, minH, maxH, step, tipoEffetto, onClose ) {
	var obj = document.getElementById ( id );
	if ( !tipoEffetto ) var tipoEffetto = "verticale";
	// Condizioni di sforamento da parte dello step
	if ( maxH == 0 ) {
		minH = parseInt(minH) - parseInt(step);
		if ( minH <= maxH ) minH = maxH;			
	} else {
		minH = parseInt(minH) + parseInt(step);
		if ( minH >= maxH ) minH = maxH;
	};

	// Assegno l'altezza e mostro gli elementi
	if ( tipoEffetto == "verticale" )
		obj.style.height = minH + 'px'; 		
	if ( tipoEffetto == "orizzontale" )
		obj.style.left = minH + 'px'; 		
	obj.style.overflow='hidden';
	obj.style.display='block';

	if ( minH < 0 ) {
		if ( (minH + step + 5 )*-1 > maxH )
			minH = maxH;
	}

	// Se non sono arrivato al massimo
	if ( minH != maxH ) {
		setTimeout('slideEff("' + id + '",' + minH + ',' + maxH + ',' + step + ', "' + tipoEffetto + '", "' + onClose + '" )',effects_timer);
	} else {
		// Distinguo tra i due casi per determinare se devo mostrare o nascondere l'elemento
		/*
		if ( minH == 0 ) {
			obj.style.display='none';
		} else {
			obj.style.display='block';
		};
		*/
		if ( onClose != "" ) 
			eval ( onClose );
	}
}

function cambiaStatoVisibile ( id, stato, codice_lista ) {
	document.getElementById ( id ).style.display = stato;
	if ( codice_lista || codice_lista == 0 ) 
		terminaEffetto ( codice_lista );
}

/////////////////////////////////////////
//		MODIFICA OGGETTO   	         //
/////////////////////////////////////////

function getL (id) {
	if ( !document.getElementById ( id ) ) window.alert( "Errore GetL: "+id);
	var doc = document.getElementById ( id );
	if ( doc.style.width == "" ) {
		var status = doc.style.display;
		doc.style.display = 'block';
		var width = doc.clientWidth;
		if ( width == 0 || !width ) width = doc.offsetWidth;
		doc.style.display = status;
		doc.style.width = width + 'px';
	}
	return parseInt ( doc.style.width );
}
function getH (id) {
	if ( !document.getElementById ( id ) ) window.alert("getH"+id);
	var doc = document.getElementById ( id );
	if ( doc.style.height == "" ) {
		var status = doc.style.display;
		doc.style.display = 'block';
		var height = doc.clientHeight;
		if ( height == 0 || !height ) height = doc.offsetHeight;
		doc.style.display = status; 
		doc.style.height = height + 'px';
	} 
	return parseInt ( doc.style.height );
}
function getLeft (id) {
	if ( !document.getElementById ( id ) ) window.alert("getLeft: "+id);
	var doc = document.getElementById ( id );
	if ( doc.style.left == "" ) {
		var status = doc.style.display;
		doc.style.display = 'block';
		var left = parseInt ( doc.clientLeft );
		if ( left == 0 || !left ) left = parseInt ( doc.offsetLeft );
		doc.style.display = status;
	} else {
		left = parseInt ( doc.style.left );
	}
	return left;
}
function getTop (id) {
	if ( !document.getElementById ( id ) ) window.alert("getTop: "+id);
	var doc = document.getElementById ( id );
	if ( doc.style.top == "" ) {
		var status = doc.style.display;
		doc.style.display = 'block';
		var top = parseInt ( doc.clientTop );
		if ( top == 0 || !top ) top = parseInt ( doc.offsetTop );
		doc.style.display = status; 
	} else {
		top = parseInt ( doc.style.top );
	}
	return top;
}
function setDimensioni ( id, dimensioni ) {
	obj = document.getElementById ( id );
	if ( dimensioni[0] > -1 ) obj.style.width = dimensioni[0] + 'px';
	if ( dimensioni[1] > -1 ) obj.style.height = dimensioni[1] + 'px';
}
function getDimensioni ( id ) {
	var dimensioni = [];
	dimensioni[0] = parseInt ( getL ( id ) );
	dimensioni[1] = parseInt ( getH ( id ) );
	return dimensioni;
}
function getPosizione (id) {
	var posizione = [];
	posizione[0] = getLeft ( id );
	posizione[1] = getTop ( id );
	return posizione;
}
function posizionaOggetto ( id, posizione ) {
	var obj = document.getElementById ( id );
	if ( posizione[0] >= 0 )
		obj.style.left = posizione[0] + 'px';
	if ( posizione[1] >= 0 )
		obj.style.top = posizione[1] + 'px';
}
function riposizionaOggetto ( id, posizione, codice_lista ) {
	posizionaOggetto ( id, posizione );
	terminaEffetto ( codice_lista );
}

/////////////////////////////////////////
//	  RIDIMENSIONA OGGETTO	         //
/////////////////////////////////////////

/*
	ridimensiona: prende l'id dell'oggetto da ridimensionare e
	dimensioni: un vettore con le dimensioni finali -> [dimensione_larghezza,dimensione_altezza]
	codice_lista: il codice della lista da eseguire quando finisce l'effetto
	step: lo step tra un frame e l'altro
*/
function ridimensiona ( id, dimensioni, codice_lista, step ) {
	if ( !step ) var step = 6;
	if ( !onClose ) var onClose = "";
	var obj = document.getElementById ( id );

	var stepSingolo = [];
	if ( dimensioni[0] >= 0 && dimensioni[1] >= 0 ) {
		var stepProporzionato = step * ((Math.abs(dimensioni[0]/step))/(Math.abs(dimensioni[1]/step))); 
		stepSingolo[0] = step;
		stepSingolo[1] = step;
		if ( Math.abs(dimensioni[0]/step) > Math.abs(dimensioni[1]/step) ) {
			stepSingolo[0] = stepProporzionato;
		} else {
			stepSingolo[1] = stepProporzionato;
		}
	} else {
		stepSingolo[0] = step;
		stepSingolo[1] = step;
	} 
	var dimensioniAttuali = getDimensioni (id );
	if (  dimensioniAttuali[0] > dimensioni[0] && dimensioni[0] >= 0 ) stepSingolo [0] = stepSingolo[0] * -1;
	if (  dimensioniAttuali[1] > dimensioni[1] && dimensioni[1] >= 0 ) stepSingolo [1] = stepSingolo[1] * -1;
	ridimensionaLH ( id, dimensioni[0], dimensioni[1], stepSingolo[0], stepSingolo[1], codice_lista );
}
function ridimensionaLH ( id, maxL, maxH, stepL, stepH , codice_lista ) {
	var obj = document.getElementById ( id );

	var fine = [];
	fine[0] = 0; 
	fine[1] = 0;

	var nuova = [];
	nuova[0] = parseInt ( getL (id) ) + parseInt ( stepL );
	/*
	if ( nuova[0] < 0 ) nuova[0] = 0;
	if (
		(( nuova[0] <= parseInt (maxL) && stepL < 0 ) ||
		 ( nuova[0] >= parseInt (maxL) && stepL > 0 ))
		|| effects_stop_all == 1 ) 
			fine[0] = 1;
	*/
	if ( stepL > 0 ) { 
		if ( nuova[0] > parseInt ( maxL ) && ( nuova[0] - parseInt (stepL) ) >= parseInt ( maxL ) ) fine[0] = 1;
	} else { 
		if ( nuova[0] < maxL && ( nuova[0] - parseInt (stepL) ) <= parseInt ( maxL ) ) fine[0] = 1;
	}
	
	nuova[1] = parseInt ( getH ( id ) ) + parseInt ( stepH );
	/*
	if ( nuova[1] < 0 ) nuova[1] = 0;
	if (
		(( nuova[1] <= parseInt (maxH) && stepH < 0 ) ||
		 ( nuova[1] >= parseInt (maxH) && stepH > 0 ))
		|| effects_stop_all == 1 ) 
			fine[1] = 1;
	*/
	if ( stepH > 0 ) { 
		if ( nuova[1] > parseInt ( maxH ) && ( nuova[1] - parseInt (stepH) ) >= parseInt ( maxH ) ) fine[1] = 1;
	} else { 
		if ( nuova[1] < maxH && ( nuova[1] - parseInt (stepH) ) <= parseInt ( maxH ) ) fine[1] = 1;
	}
	
	// Assegno l'altezza e mostro gli elementi
	if ( fine[0] == 0 )
		setDimensioni ( id, [nuova[0],-1] );
	if ( fine[1] == 0 )
		setDimensioni ( id, [-1,nuova[1]] );
	
	// Se non sono arrivato al massimo
	if ( fine[0] == 0 || fine[1] == 0 ) {
		setTimeout('ridimensionaLH("' + id + '",' + maxL + ', '+ maxH +', ' + stepL + ', ' + stepH + ', ' + codice_lista + ' )',effects_timer);
	} else { 
		if ( maxL == 0 || maxH == 0 ) {	
			obj.style.display = 'none';
		}
		terminaEffetto ( codice_lista );
	}
}

/////////////////////////////////////////
//		MUOVI OGGETTO	         //
/////////////////////////////////////////

//	onClose = "assegnaMenu('" + id + "');muovi('mainCenter',['dimensione',0,-1,1])";
//	muovi ( 'mainCenter', ['dimensione',0,1,1], onClose );

function muovi ( id, posizione, codice_effetto, step ) {
	if ( !step ) var step = 2;
	
	var attuale = [];
	attuale[0] = parseInt ( getLeft ( id ) );
	attuale[1] = parseInt ( getTop ( id ) );
	var obj = document.getElementById ( id );
	if ( posizione[0] == "dimensione" ) {
		posizione[0] = parseInt ( getL ( id ) ); 
	}
	if ( posizione[0] == "attuale" ) {
		posizione[0] = attuale[0]; 
	}
	if ( posizione[1] == "dimensione" ) {
		posizione[1] = parseInt ( getH ( id ) );
	}
	if ( posizione[1] == "attuale" ) {
		posizione[1] = attuale[1]; 
	}

	var aPosizione = [];
	var stepSingolo = [];
	if ( posizione[0] != 0 && posizione[1] != 0 ) {
		var stepProporzionato = step * ((Math.abs(posizione[0]/step))/(Math.abs(posizione[1]/step))); 
		stepSingolo[0] = step;
		stepSingolo[1] = step;
		if ( Math.abs(posizione[0]/step) > Math.abs(posizione[1]/step) ) {
			stepSingolo[0] = stepProporzionato;
		} else {
			stepSingolo[1] = stepProporzionato;
		}
	} else {
		stepSingolo[0] = step;
		stepSingolo[1] = step;
	}
	posizione[0] = attuale[0] + posizione[0]*posizione[2];
	posizione[1] = attuale[1] + posizione[1]*posizione[3];
	muoviHV ( id, attuale[0], posizione[0], attuale[1], posizione[1], stepSingolo[0]*posizione[2], stepSingolo[1]*posizione[3], codice_effetto );
}
function muoviHV ( id, minH, maxH, minV, maxV, stepH, stepV, codice_effetto ) {
	var obj = document.getElementById ( id );
	// Condizioni di sforamento da parte dello step
	minH = parseInt(minH) + parseInt(stepH);
	minV = parseInt(minV) + parseInt(stepV);

	var fine = [];
	fine[0] = 0; fine[1] = 0;
	
	if ( stepH > 0 ) { 
		if ( parseInt(minH) > parseInt ( maxH ) && ( parseInt (minH) - parseInt (stepH) ) >= parseInt ( maxH ) ) fine[0] = 1;
	} else { 
		if ( minH < maxH && ( parseInt (minH) - parseInt (stepH) ) <= parseInt ( maxH ) ) fine[0] = 1;
	}
	if ( stepV > 0 ) { 
		if ( parseInt(minV) > parseInt ( maxV ) && ( parseInt (minV) - parseInt (stepV) ) >= parseInt ( maxV ) ) fine[1] = 1;
	} else { 
		if ( minV < maxV  && ( parseInt (minV) - parseInt (stepV) ) <= parseInt ( maxV ) ) fine[1] = 1;
	}

	// Assegno l'altezza e mostro gli elementi
	if ( fine[0] == 0 ) 
		obj.style.left = minH + 'px'; 		
	if ( fine[1] == 0 ) 
		obj.style.top = minV + 'px'; 		

	obj.style.overflow='hidden';
	obj.style.display='block';
	obj.style.visibility='visible';

	// Se non sono arrivato al massimo
	if ( fine[0] == 0 || fine[1] == 0 ) {
		setTimeout('muoviHV("' + id + '",' + minH + ',' + maxH + ',' + minV + ',' + maxV + ',' + stepH + ',' + stepV + ', ' + codice_effetto + ' )',effects_timer);
	} else {
		terminaEffetto ( codice_effetto );
	}
}

/////////////////////////////////////////
//		FADE OGGETTO		         //
/////////////////////////////////////////

function getOpacity (id) {
	var obj = document.getElementById ( id );
	if ( obj ) {
		var opacity;
		if(/MSIE/.test(navigator.userAgent)) { 
			opacity = obj.style.filter;
			var opacity = opacity.replace('alpha(opacity=',''); opacity = opacity.replace(')','');
			if ( (opacity == "" || opacity == "undefined" || !opacity) && opacity != 0 ) { 
				obj.style.filter = "alpha(opacity=100)";
				opacity = 100;
			} 
		} else {
			opacity = parseFloat ( obj.style.opacity );
			if ( (opacity == "" || opacity == "undefined" || !opacity) && opacity != 0 ) {
				obj.style.opacity = 1;
				opacity = 1;
			} 
		}
	} else {
		if(/MSIE/.test(navigator.userAgent)) { opacity = 100; } else { opacity = 1; };
	}
	return opacity;
}
function setOpacity(idElemento,value) {
	if ( document.getElementById(idElemento) ) {
		document.getElementById(idElemento).style.opacity = value/10;
		document.getElementById(idElemento).style.filter = 'alpha(opacity=' + value*10 + ')';
	} else {
	}
}
function fadeForza ( id, fadeValue, codice_lista ) {
	var obj = document.getElementById ( id );
	if ( !obj ) window.alert("errore su fadeforza: "+id);
	if(/MSIE/.test(navigator.userAgent)) {
		if ( fadeValue <= 1 )
			fadeValue = fadeValue * 100;
		obj.style.filter = "alpha(opacity="+ fadeValue +")"; 
	} else {
		obj.style.opacity = fadeValue;
	}
	if ( !codice_lista && codice_lista != 0 ) var codice_lista = -1;
	if ( codice_lista >= 0 ) {
		terminaEffetto(codice_lista);
	}
}
function fade ( id, fadeFine, codice_lista, step ) {
	if ( id == 0 ) id = default_center;
	var obj = document.getElementById ( id );
	if ( !step ) var step = 0.1;
	var opacity = getOpacity(id);

	if(/MSIE/.test(navigator.userAgent)) { 
		if ( (opacity == "" || opacity == "undefined" || !opacity) && opacity != 0 ) { 
			obj.style.filter = "alpha(opacity=100)";
			opacity = 100;
		}
		step = step * 100;
		fadeFine = fadeFine * 100;
	} else {
		if ( (opacity == "" || opacity == "undefined" || !opacity) && opacity != 0 ) { 
			obj.style.opacity = 1;
			opacity = 1;
		}
	} 
	if ( opacity > fadeFine ) step = step * -1;
	fadeEff ( id, fadeFine, step, codice_lista );
}
function fadeEff ( id, fadeFine, step, codice_lista ) {
	var obj = document.getElementById ( id );
	var fine = 0;
	var opacity = getOpacity(id); 
	//if ( opacity > 1 ) opacity = opacity / 100;
	if ( step > 0 ) {
		if ( ( parseFloat ( opacity ) >= parseFloat( fadeFine ) ) || effects_stop_all == 1) 
			fine = 1;
	} else {
		if ( ( parseFloat ( opacity ) <= parseFloat( fadeFine ) ) || effects_stop_all == 1) 
			fine = 1;
	}
	if ( fine == 0 ) {
		/*
		if(/MSIE/.test(navigator.userAgent)) { 
			var valore = parseInt(opacity) + parseInt(step);
			obj.style.filter = "alpha(opacity=" + valore + ")";
		} else {
			obj.style.opacity = parseFloat(opacity) + parseFloat(step);
		} 
		*/
		fadeForza (id, parseFloat(opacity) + parseFloat(step));
		setTimeout('fadeEff("' + id + '",' + fadeFine + ',' + step + ', "' + codice_lista + '" )',effects_timer*6);
	} else { 
		terminaEffetto ( codice_lista );
	}
}


/////////////////////////////////////////
//		ASSEGNAZIONI		         //
/////////////////////////////////////////

function assegnaContenuto ( divA, divDa, codice_lista ) {
	document.getElementById ( divA ).innerHTML = document.getElementById ( divDa ).innerHTML;
	if ( codice_lista || codice_lista == 0 ) {
		terminaEffetto ( codice_lista );
	}
}

function assegnaContenutoHTML ( divA, contenuto, codice_lista ) {
	document.getElementById ( divA ).innerHTML = contenuto;
	if ( codice_lista || codice_lista == 0 ) {
		terminaEffetto ( codice_lista );
	}
}


/////////////////////////////////////////
//          FUNZIONI PARTICOLARI             //
/////////////////////////////////////////

function getGrossOffsetLeft(elem) {
	var offset = 0;
	while (elem.offsetParent) {
		offset += (elem.offsetParent.tagName != "HTML") ? parseInt(elem.style.left) - parseInt(elem.offsetLeft) : 0;
		elem = elem.offsetParent;
		offset += elem.offsetLeft;
	}
	return offset;
}
function getGrossOffsetTop(elem) {
	var offset = 0;
	while (elem.offsetParent) {
		offset += (elem.offsetParent.tagName != "HTML") ? parseInt(elem.style.top) - parseInt(elem.offsetTop) : 0;
		elem = elem.offsetParent;
		offset += elem.offsetTop;
	}
	return offset;
}
function getGlobalObjPosition (obj) {
	var obj=document.getElementById ( obj );
	var posizione = [getGrossOffsetLeft(obj),getGrossOffsetTop(obj)];
	return posizione;
}

function aspetta ( tempo, codice_lista ) {
	setTimeout('eseguiEffetto(' + codice_lista + ' )',tempo);
}

function impostaBackground ( id, bck, codice_lista ) {
	document.getElementById ( id ).style.background = bck;
	if ( codice_lista || codice_lista == 0 ) 
		terminaEffetto ( codice_lista );
}

function impostaBackgroundImage ( id, bck, codice_lista ) {
	document.getElementById ( id ).style.backgroundImage = bck;
	if ( codice_lista || codice_lista == 0 ) 
		terminaEffetto ( codice_lista );
}

/////////////////////////////////////////
//          FUNZIONI GRAFICHE	         //
/////////////////////////////////////////
function browserSize () {
	var bodyWidth = document.documentElement.clientWidth;
	var bodyHeight = document.documentElement.clientHeight;
	
	var bodyWidth, bodyHeight; 
	if (self.innerHeight){ // all except Explorer 
	 
	   bodyWidth = self.innerWidth; 
	   bodyHeight = self.innerHeight; 
	}  else if (document.documentElement && document.documentElement.clientHeight) {
	   // Explorer 6 Strict Mode 		 
	   bodyWidth = document.documentElement.clientWidth; 
	   bodyHeight = document.documentElement.clientHeight; 
	} else if (document.body) {// other Explorers 		 
	   bodyWidth = document.body.clientWidth; 
	   bodyHeight = document.body.clientHeight; 
	} 
	return [bodyWidth,bodyHeight];		
}

function setPageHeight () {
	var browser = browserSize();
	height = Math.max (browser[1], document.getElementById ( 'divPagina' ).offsetHeight,document.getElementById ( 'divPagina' ).clientHeight,document.getElementById ( 'divPagina' ).style.height);
	
	var heightCenter = Math.min(document.getElementById ( 'mainCenter' ).clientHeight,document.getElementById ( 'mainCenter' ).offsetHeight);
	var border = Math.max(document.getElementById ( 'mainCenter' ).clientHeight,document.getElementById ( 'mainCenter' ).offsetHeight) - Math.min(document.getElementById ( 'mainCenter' ).clientHeight,document.getElementById ( 'mainCenter' ).offsetHeight);
	height = height-border-55;
	var halfBars = Math.max ( 100,((height-Math.max(document.getElementById ( 'mainCenter' ).clientHeight,document.getElementById ( 'mainCenter' ).offsetHeight))/2));
	document.getElementById ( 'horizontalBordersUp' ).style.height = (halfBars-25) + 'px';
	document.getElementById ( 'horizontalBordersDown' ).style.height = (halfBars-30) + 'px';
	
	document.getElementById ( 'divPagina' ).style.height = parseInt(height) + 'px';	
}

function posiziona_finestre () {
	// generali
	var altezza_pagina = getH ( 'divPagina' );
	var larghezza_pagina = getL('divPagina');
	var altezza_bordo = getH ( 'horizontalBordersUp' );
	
	// login
	var altezza_finestra;
	var top_finestra;
	var larghezza_finestra;
	var left_finestra;

	// pannello utente
	altezza_finestra = getH ( 'divPannelloUtente' );
	larghezza_finestra = getL('divPannelloUtente');
	top_finestra = (altezza_pagina/2)-(altezza_finestra/2)-(altezza_bordo)-20;
	left_finestra = larghezza_pagina - larghezza_finestra - 750;
	posizionaOggetto ('divPannelloUtente', [left_finestra,top_finestra]);

	// homepage
	if ( document.getElementById ( 'divHomepage' ).style.display == 'block' || document.getElementById ( 'divHomepage' ).style.display == "" ) {
		altezza_finestra = getH ( 'divHomepage' );
		larghezza_finestra = getL ( 'divHomepage' );
		top_finestra = (altezza_pagina/2)-(altezza_finestra/2)-(altezza_bordo);
		left_finestra = 100;
		posizionaOggetto ('divHomepage', [left_finestra,top_finestra]);
	}
}

/////////////////////////////////////////
//          		POPUP		         //
/////////////////////////////////////////


var pop_up_sized = 0;
var pop_up_by_id = 0;
var pop_up_by_id_value = "";
var pop_up_open = 0;
var pop_up_onclose = "";

function pop_up_max_h () {
	var p_height;
	//var pop_up = document.getElementById ( "div_pop_up" );
	//( pop_up.offsetHeight ) ? p_height = pop_up.offsetHeight : p_height = pop_up.clientHeight;
	//if ( p_height > Math.max(document.body.clientHeight,document.documentElement.clientHeight) )
		p_height = Math.max(document.body.clientHeight,document.documentElement.clientHeight) - 100;
	return p_height;
}

function pop_up_view ( action, contenuto, id_univoco, regole, regole_opzioni, onload, onend, onclose ) {
	if ( onclose ) {
		pop_up_onclose = onclose;
	}
	if ( !onload ) var onload = 'eseguiEffetto(\'codice_lista\')';
	if ( !onend ) var onend = 'eseguiEffetto(\'codice_lista\')';
	// regole: staiblisce se c'è un solo div o se qualcuno deve essere fisso
	if ( regole ) {
		if ( regole != "" ) {
			regole = regole.split ( '@' );
		} else {
			var regole = new Array;
			regole[0] = "default";
		}
	} else {
		var regole = new Array;
		regole[0] = "default";
	}
	if ( !regole_opzioni ) {
		var regole_opzioni = "";
	}
	//var pop_up_old = document.getElementById ( "div_pop_up_old" ).value;

	var pop_up = document.getElementById ( "div_pop_up" );
	var pop_up_shadow = document.getElementById ( "div_pop_up_shadow" );
	var pop_up_chiudi = document.getElementById ( "div_pop_up_chiudi" );
	var pop_up_chiudi_shadow = document.getElementById ( "div_pop_up_chiudi_shadow" );
	var pop_up_oscura = document.getElementById ( "div_oscura" );
	var vecchio_contenuto = pop_up.innerHTML;
	

	if ( action == 1 ) {

		pop_up_open = 1;
		pop_up.style.display = 'block';
		pop_up_chiudi.style.display = 'block';
		var browser_sizes = browserSize ();
		
		// imposto la dimensione orizzontale
		var p_width = Math.max ( browser_sizes[0] - 500, 600 );
		pop_up.style.width = p_width + 'px';
		// calcolo il massimo dell'altezza
		var p_height = pop_up_max_h()-10;
		// calcolo l'altezza del div di chiusura
		var p_chiudi_height;
		( pop_up_chiudi.offsetHeight ) ? p_chiudi_height = pop_up_chiudi.offsetHeight : p_chiudi_height = pop_up_chiudi.clientHeight;
		// ora che ho calcolato le altezze, li nascondo per modificarli
		pop_up.style.display = 'none';
		pop_up_chiudi.style.display = 'none';
		// imposto le dimensioni orizzontali e verticali
		pop_up.style.height = p_height + 'px';
		pop_up_shadow.style.width = p_width + 'px';
		pop_up_shadow.style.height = p_height + 'px';
		pop_up_chiudi.style.width = 35 + 'px';
		pop_up_chiudi_shadow.style.width = 35 + 'px';
		pop_up_chiudi_shadow.style.height = (p_chiudi_height-5) + 'px';
		// imposto la posizione nello spazio
		var p_top = ( browser_sizes[1] / 2 ) - ( p_height / 2 ) -20; 
		if ( p_top < 0 ) p_top = 20;
		var p_left = ( browser_sizes[0] / 2 ) - ( p_width / 2 ) -10;
		p_top = Math.max(document.body.scrollTop,document.documentElement.scrollTop) + 20;
		pop_up.style.top = p_top + 'px';
		pop_up.style.left = p_left + 'px';
		pop_up_shadow.style.top = (p_top+10) + 'px';
		pop_up_shadow.style.left = (p_left+10) + 'px';
		p_top += p_height + 15;
		pop_up_chiudi.style.top = p_top + 'px';
		pop_up_chiudi.style.left = parseInt ( p_left+p_width-35) + 'px';
		pop_up_chiudi_shadow.style.top = (p_top+10) + 'px';
		pop_up_chiudi_shadow.style.left = parseInt ( p_left+p_width-25) + 'px';
		pop_up.style.display = 'none';
		pop_up_chiudi.style.display = 'none';
		pop_up_shadow.style.display = 'none';
		pop_up_chiudi_shadow.style.display = 'none';
		pop_up_oscura.style.display = 'block';
		function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} 
		pop_up_oscura.style.top = 0 + 'px';
		pop_up_oscura.style.left = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + 'px';
		pop_up_oscura.style.width = Math.max(document.body.clientWidth,document.documentElement.clientWidth) + 'px'; // sizes[0] + 'px';
		var maxHeight = ( Math.max ( Math.max(document.body.offsetHeight,document.documentElement.clientHeight),0 ) ) + 'px'; // sizes[1] + 'px';
		maxHeight = document.getElementById ( "container" ).offsetHeight + document.getElementById ( "sinistra" ).offsetHeight + document.getElementById ( "sopra" ).offsetHeight + 20;
		var arrayPageSize = getPageSize();
		pop_up_oscura.style.height = arrayPageSize[1]+'px';
		pop_up_oscura.style.display = 'none';

		select_view ( "hidden" );
		
		creaListaEffetti ( 'popup', 'unico',
			'fadeForza(\'div_oscura\',0, \'codice_lista\')',
			'cambiaStatoVisibile(\'div_oscura\',\'block\', \'codice_lista\')',
			'fade ( \'div_oscura\', 0.7, \'codice_lista\',0.1 )',
			'fadeForza(\'div_pop_up_shadow\',0, \'codice_lista\')',
			'cambiaStatoVisibile(\'div_pop_up_shadow\',\'block\', \'codice_lista\')',
			'fadeForza(\'div_pop_up\',0, \'codice_lista\')',
			'assegnaContenutoHTML ( \'div_pop_up\',unescape(\''+escape(contenuto)+'\'), \'codice_lista\' )',
			onload,
			'cambiaStatoVisibile(\'div_pop_up\',\'block\', \'codice_lista\')',
			'fade ( \'div_pop_up\', 1, \'codice_lista\',0.2 );fade ( \'div_pop_up_shadow\', 0.8, -1,0.2 )',
			'fadeForza(\'div_pop_up_chiudi\',0, \'codice_lista\');fadeForza(\'div_pop_up_chiudi_shadow\',0, -1)',
			'cambiaStatoVisibile(\'div_pop_up_chiudi\',\'block\', \'codice_lista\');cambiaStatoVisibile(\'div_pop_up_chiudi_shadow\',\'block\', -1)',
			'fade ( \'div_pop_up_chiudi\', 1, \'codice_lista\',0.2 );fade ( \'div_pop_up_chiudi_shadow\', 0.8, -1,0.2 )',
			onend
		);
		
	}
	if ( action == 0 ) { 
		if ( pop_up_by_id == 1 ) {
			pop_up_by_id = 0; 			
			//var tt = pop_up_by_id_value.replace ('_full','');
			document.getElementById ( pop_up_by_id_value ).innerHTML = vecchio_contenuto;
			pop_up_by_id_value = "";
		}
		
		creaListaEffetti ( 'popup', 'unico',
			'fade ( \'div_pop_up_chiudi\', 0, \'codice_lista\',0.1 );fade ( \'div_pop_up_chiudi_shadow\', 0, -1,0.2 )',
			'cambiaStatoVisibile(\'div_pop_up_chiudi\',\'none\', \'codice_lista\');cambiaStatoVisibile(\'div_pop_up_chiudi_shadow\',\'none\', -1)',
			'assegnaContenutoHTML ( \'div_pop_up\',unescape(\'\'), \'codice_lista\' )',
			'fade ( \'div_pop_up\', 0, \'codice_lista\',0.2 );fade ( \'div_pop_up_shadow\', 0, -1,0.2 )',
			'cambiaStatoVisibile(\'div_pop_up\',\'none\', \'codice_lista\')',
			'fade ( \'div_oscura\', 0, \'codice_lista\',0.1 )',
			'cambiaStatoVisibile(\'div_oscura\',\'none\', \'codice_lista\');cambiaStatoVisibile(\'div_pop_up_shadow\',\'none\', -1)',
			'international_cambiomenu(1);'
		);

		select_view ( "visible" );
		
		pop_up_open = 0;
		pop_up_regole_altezze = "";
	}

}

function pop_up_view_close () {
	eval ( pop_up_onclose );
	pop_up_view ( 0, "" );
}

function carica_pop_up_id ( id, onload,onend, regole, regole_opzioni, id_univoco ) {

	if ( !onload ) 
		var onload = "";
	onload = onload + "eseguiEffetto(\'codice_lista\');"
	if ( !onend ) 
		var onclose = "";
	if ( !regole ) {
		var regole = "";
	}
	if ( !regole_opzioni ) var regole_opzioni = "";
	if ( !id_univoco ) var id_univoco = "";
	pop_up_by_id = 1;
	pop_up_by_id_value = id; 
	var contenuto = document.getElementById ( id ).innerHTML;
	document.getElementById ( id ).innerHTML = "";
	pop_up_view ( 1, contenuto, id_univoco, regole, regole_opzioni, onload, onend );
}

function carica_pop_up_contenuto ( contenuto, onload, onend, regole, regole_opzioni, id_univoco ) {
	if ( !onload ) 
		var onload = "";
	onload = onload + "eseguiEffetto(\'codice_lista\');"
	if ( !onclose ) 
		var onclose = "";
	if ( !onend ) 
		var onend = "";
	if ( !regole ) {
		var regole = "";
	}
	if ( !regole_opzioni ) var regole_opzioni = "";
	if ( !id_univoco ) var id_univoco = "";

	pop_up_view ( 1, contenuto, id_univoco, regole, regole_opzioni, onload, onclose, onend );
}

var vecchio_contenuto_alert_id = "";
var pop_up_alert_open = 0;
var pop_up_alert_oscura = 0;

function pop_up_alert_view_id ( id, opzioni ) {
	if ( pop_up_alert_open == 0 ) {
		contenuto = document.getElementById ( id ).innerHTML;
		vecchio_contenuto_alert = id;
		pop_up_alert_view ( 1,contenuto,opzioni );
	}
}
function pop_up_alert_view ( action, contenuto, opzioni ) {
	if ( opzioni ) {
		if ( opzioni != "" ) {
			opzioni = opzioni.split ( '@' );
		} else {
			var opzioni = new Array;
			opzioni[0] = "default";
		}
	} else {
		var opzioni = new Array;
		opzioni[0] = "default";
	}
	var pop_up = document.getElementById ( "div_pop_up_alert" );
	var pop_up_chiudi = document.getElementById ( "div_pop_up_alert_chiudi" );
	

	if ( action == 1 && pop_up_alert_open == 0 ) {

		pop_up_alert_open = 1;
		pop_up.style.display = 'block';
		pop_up_chiudi.style.display = 'block';
		pop_up.style.width='';
		pop_up.style.height='';
		pop_up.innerHTML = contenuto;
		
		var browser_sizes = browserSize ();
		
		var p_width = getL("div_pop_up_alert");
		var p_height = getH("div_pop_up_alert");
		if ( p_height > 300 ) {
			pop_up.style.height='300px';
			p_height = 300;
		}
		var p_chiudi_height = getH("div_pop_up_alert_chiudi");;
		
		// ora che ho calcolato le dimensioni, li nascondo per modificarli
		pop_up.style.display = 'none';
		pop_up_chiudi.style.display = 'none';
		// imposto le dimensioni orizzontali e verticali
		pop_up_chiudi.style.width = 35 + 'px';
		// imposto la posizione nello spazio
		var p_top = ( browser_sizes[1] / 2 ) - ( p_height / 2 ) -20; 
		if ( p_top < 0 ) p_top = 20;
		var p_left = ( browser_sizes[0] / 2 ) - ( p_width / 2 ) -10;
		pop_up.style.top = p_top + 'px';
		pop_up.style.left = p_left + 'px';
		p_top += p_height + 15; 
		pop_up_chiudi.style.top = p_top + 'px';
		pop_up_chiudi.style.left = parseInt ( p_left+p_width) + 'px';
		pop_up.style.display = 'none';
		pop_up_chiudi.style.display = 'none';

		select_view ( "hidden" );
		var pop_up_oscura = document.getElementById ( "div_oscura_alert" );
		//if ( pop_up_alert_oscura.style.display == "none" ) {
			pop_up_alert_oscura = 1;
			pop_up_oscura.style.display = 'block';
			pop_up_oscura.style.top = Math.max(document.body.scrollTop,document.documentElement.scrollTop) + 'px';
			pop_up_oscura.style.left = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + 'px';
			pop_up_oscura.style.width = Math.max(document.body.clientWidth,document.documentElement.clientWidth) + 'px'; // sizes[0] + 'px';
			pop_up_oscura.style.height = ( Math.max ( Math.max(document.body.clientHeight,document.documentElement.clientHeight),0 ) ) + 'px'; // sizes[1] + 'px';
			pop_up_oscura.style.display = 'none';

			creaListaEffetti ( 'popup', 'unico',
				'fadeForza(\'div_oscura_alert\',0, \'codice_lista\')',
				'cambiaStatoVisibile(\'div_oscura_alert\',\'block\', \'codice_lista\')',
				'fade ( \'div_oscura_alert\', 0.7, \'codice_lista\',0.1 )',
				'fadeForza(\'div_pop_up_alert\',0, \'codice_lista\')',
				'cambiaStatoVisibile(\'div_pop_up_alert\',\'block\', \'codice_lista\')',
				'fade ( \'div_pop_up_alert\', 1, \'codice_lista\',0.2 );',
				'fadeForza(\'div_pop_up_alert_chiudi\',0, \'codice_lista\');',
				'cambiaStatoVisibile(\'div_pop_up_alert_chiudi\',\'block\', \'codice_lista\');',
				'fade ( \'div_pop_up_alert_chiudi\', 1, \'codice_lista\',0.2 );'
			);
		/*} else {
			creaListaEffetti ( 'popup', 'unico',
				'fadeForza(\'div_pop_up_alert\',0, \'codice_lista\')',
				'cambiaStatoVisibile(\'div_pop_up_alert\',\'block\', \'codice_lista\')',
				'fade ( \'div_pop_up_alert\', 1, \'codice_lista\',0.2 );',
				'fadeForza(\'div_pop_up_alert_chiudi\',0, \'codice_lista\');',
				'cambiaStatoVisibile(\'div_pop_up_alert_chiudi\',\'block\', \'codice_lista\');',
				'fade ( \'div_pop_up_alert_chiudi\', 1, \'codice_lista\',0.2 );'
			);
		}*/
		
	} 
	if ( action == 0 ) { 
		if ( vecchio_contenuto_alert_id != "" ) {
			document.getElementById (  vecchio_contenuto_alert_id ).innerHTML = pop_up.innerHTML;
			 vecchio_contenuto_alert_id = "";
		}
		
		var pop_up_oscura = document.getElementById ( "div_oscura_alert" );
		if ( pop_up_alert_oscura == 1 ) {
			pop_up_alert_oscura = 0;
			creaListaEffetti ( 'popup', 'unico',
				'fade ( \'div_pop_up_alert_chiudi\', 0, \'codice_lista\',0.1 );',
				'cambiaStatoVisibile(\'div_pop_up_alert_chiudi\',\'none\', \'codice_lista\');',
				'assegnaContenutoHTML ( \'div_pop_up_alert\',unescape(\'\'), \'codice_lista\' )',
				'fade ( \'div_pop_up_alert\', 0, \'codice_lista\',0.2 );',
				'cambiaStatoVisibile(\'div_pop_up_alert\',\'none\', \'codice_lista\')',
				'fade ( \'div_oscura_alert\', 0, \'codice_lista\',0.1 )',
				'cambiaStatoVisibile(\'div_oscura_alert\',\'none\', \'codice_lista\');'
			);
		} else {
			creaListaEffetti ( 'popup', 'unico',
				'fade ( \'div_pop_up_alert_chiudi\', 0, \'codice_lista\',0.1 );',
				'cambiaStatoVisibile(\'div_pop_up_alert_chiudi\',\'none\', \'codice_lista\');',
				'assegnaContenutoHTML ( \'div_pop_up_alert\',unescape(\'\'), \'codice_lista\' )',
				'fade ( \'div_pop_up_alert\', 0, \'codice_lista\',0.2 );',
				'cambiaStatoVisibile(\'div_pop_up_alert\',\'none\', \'codice_lista\')'
			);
		}
		select_view ( "visible" );
		
		pop_up_alert_open = 0;
	}
}

function pop_up_alert_view_close () {
	pop_up_alert_view ( 0,"" ); 
}

function select_view ( visibility ) {
	var selects = document.getElementsByTagName('select');
	for(var i = 0; i < selects.length; i++) {
		if ( !selects[i].getAttribute("untochable") ) {
			selects[i].style.visibility = visibility;
		} 
	}
}
