/* variabili generali */
var oldmenucolor = "";

/* Funzione per l'effetto bordato del td degli item di menu */
function menuEffect(mnuName, effectColor) {
	var obj = document.getElementById(mnuName);
	oldmenucolor = obj.style.backgroundColor;
	obj.style.backgroundColor= effectColor;
}

/* Funzione per l'effetto bordato del td degli item di menu */
function menuEffectReset(mnuName) {
	var obj = document.getElementById(mnuName);
	obj.style.backgroundColor= oldmenucolor;
}

/* Funzione per l'apparizione o sparizione del layer */
function swapLayer(layer_name, anchor_obj_name, moveX, moveY, align) {
	var ly_obj = document.getElementById(layer_name);
	var anch_obj = null;
	var x = 0;
	var y = 0;
	
	if (anchor_obj_name != '') {
		anch_obj = document.getElementById(anchor_obj_name);
		x = findPosX(document.getElementById(anchor_obj_name)) + moveX;
		y = findPosY(document.getElementById(anchor_obj_name)) + moveY;
		if (align == 'right') {
			x+=anch_obj.width;
		}
	}
	
	if (ly_obj.style.visibility == 'hidden') {
		ly_obj.style.top = y;
		ly_obj.style.left = x;
		ly_obj.style.visibility = 'visible';
	} else {
		ly_obj.style.visibility = 'hidden';
	}
}

/* Funzione per il fadeIn di oggetti (variando l'effetto alpha) 
 * i = percentuale alpha di partenza (esempio 0)
 * j = percentuale alpha di arrivo (esempio 80)
 * fadeObject = oggetto della pagina a cui applicare l'effetto fade in
 * step = scalini di incremento nella quantità di alpha (normalmente 1) */
function fadeIn(i,j,fadeObject,step) {
	var obj = document.getElementById(fadeObject);
	obj.style.filter = 'alpha(opacity="'+i+'")';
	i += step;
	if(i<j) setTimeout("fadeIn("+i+","+j+",'"+fadeObject+"',"+step+")",0);
	if(i>=j && j==100) obj.style.filter = 'alpha(opacity="100")';
}

/* Funzione per il fadeOut di oggetti (variando l'effetto alpha) 
 * i = percentuale alpha di partenza (esempio 80)
 * j = percentuale alpha di arrivo (esempio 0)
 * fadeObject = oggetto della pagina a cui applicare l'effetto fade out
 * step = scalini di decremento nella quantità di alpha (normalmente 1) */
function fadeOut(i,j,fadeObject,step) {
	var obj = document.getElementById(fadeObject);
	obj.style.filter = 'alpha(opacity="'+i+'")';
	i -= step;
	if(i>j) setTimeout("fadeOut("+i+","+j+",'"+fadeObject+"',"+step+")",0);
	if(i<=j) obj.style.filter = 'alpha(opacity="0")';
}

/*
function menuEffect(mnuName) {
	var obj = document.getElementById(mnuName);
	obj.style.borderColor = "#90939E";
	obj.style.borderTopWidth = "1";
	obj.style.borderBottomWidth = "0";
	obj.style.borderLeftWidth = "0";
	obj.style.borderRightWidth = "0";
	obj.style.borderStyle = "solid";
	obj.style.backgroundColor= "#F5F6FD";
}


function menuEffectReset(mnuName) {
	var obj = document.getElementById(mnuName);
	obj.style.borderColor = "#90939E";
	obj.style.borderTopWidth = "1";
	obj.style.borderBottomWidth = "0";
	obj.style.borderLeftWidth = "0";
	obj.style.borderRightWidth = "0";
	obj.style.borderStyle = "solid";
	obj.style.backgroundColor= "#E4E8F8";
}
*/

/* JavaScript per ritorno posizione immagine */
function findPosX(obj) {
	// get X position
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	// get Y position
	var curtop = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}

/* Funzione che apre una finestra  
   ------------------------------- */

// 1 = true
// 0 = False

function OpWindows(adr, tool, loc_box, dir, stat, menu, scroll, resize, width, heigh, scX, scY) {    
	var address = adr;  
	var op_wid  = width;   
	var op_heigh = heigh;                 

	var op_tool  = (tool=='1')  ? 'toolbar=yes' : 'toolbar=no'; 
	var op_loc_box  = (loc_box=='1')  ? ',location=yes' : ',location=no'; 
	var op_dir  = (dir=='1')  ? ',,directories=yes' : ',,directories=no'; 
	var op_stat  = (stat=='1')  ? ',status=yes' : ',status=no'; 
	var op_menu  = (menu=='1')  ? ',menubar=yes' : ',menubar=no'; 
	var op_scroll  = (scroll=='1')  ? ',scrollbars=yes' : ',scrollbars=no'; 
	var op_resize  = (resize=='1')  ? ',resizable=yes' : ',resizable=no'; 
	var op_wid  = ",width="+width;  
	var op_heigh = ",height="+heigh;  
	var op_screenX = ",screenX="+scX;
	var op_screenY = ",screenY="+scY;
	
	var option =op_tool+op_loc_box+op_dir+op_stat+op_menu+op_scroll+op_resize+op_wid+op_heigh+op_screenX+op_screenY;
	window.open(address, "", option);  
}

function OpenWindow(adr, width, height) {    
	// determina la larghezza dello schermo
	var sc_width = screen.width;
	var sc_height = screen.height;
	var wx = 0;
	var wy = 0;
	if (width == 0) {
		if (sc_width > 0) {
			width = sc_width - 40;
			height = sc_height - 80;
		} else {
			width = 600;
			height = 400;
		}
	}
	// centratura
	if (sc_width > 0) {
		wx = Math.floor((sc_width-width)/2);
		wy = Math.floor((sc_height-height)/2);
	}
	// alert("larghezza: " + width + " - altezza: " + height);
	// apre la finestra
	OpWindows(adr, 0, 0, 0, 1, 0, 1, 1, width, height, wx, wy);
}

// --------------------- Funzioni di Roll-Over ------------------------

/* Funzione che ritorna l'immagine originale 
   ----------------------------------------- */
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; 
	for(i=0; a&&i<a.length&&(x=a[i])&&x.oSrc; i++) {
		x.src=x.oSrc;
 	}
}

/* Funzione che precarica le immagini necessarie 
   --------------------------------------------- */
function MM_preloadImages() { //v3.0
	var d=document; 
	if(d.images) {
		if(!d.MM_p) {
			d.MM_p=new Array();
		}
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++) {
			if (a[i].indexOf("#")!=0) {
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
		}
	}	
}

/* Funzione che trova gli oggetti necessari 
   ---------------------------------------- */
function MM_findObj(n, d) { //v3.0
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
    	d=parent.frames[n.substring(p+1)].document;
    	n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0; !x&&i<d.forms.length; i++) {
    	x=d.forms[i][n];
    }
    for(i=0; !x&&d.layers&&i<d.layers.length; i++) {
    	x=MM_findObj(n,d.layers[i].document);
    }
    return x;
}

/* Funzione che sostituisce l'immagine originale con quella di rollover
   -------------------------------------------------------------------- */
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0; i<(a.length-2); i+=3) {
		if ((x=MM_findObj(a[i]))!=null) {
			document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.src;
			x.src=a[i+2];
		}
	}
}

