Is_NS=window.navigator.appName == "Netscape"
Is_IE=window.navigator.appName == "Microsoft Internet Explorer"

function GetElement(nome){
	if (Is_IE) {
		return document.all[nome];
	} else {
		return document.getElementById(nome);
	}

}

function WinWidth(){
	if (Is_IE) {
		return document.body.clientWidth;
	} else {
		return window.innerWidth;
	}
}

function PopupXY(nome, menuItem, dx, dy, wi, hi){
	PopCloseAll();
	showBox = GetElement(nome);
	mleft = menuItem.offsetLeft + dx;
	mtop  = menuItem.offsetTop + menuItem.offsetHeight + dy;
	parente = menuItem.offsetParent;
	while (parente){
		mtop  += parente.offsetTop; 
		mleft += parente.offsetLeft;
		parente = parente.offsetParent;
	}
	if (wi) {
//		ww = WinWidth();
		out_right = mleft + wi*1.2 - WinWidth();
		if (out_right > 0) mleft = mleft - out_right;
//		alert('New left =' + mleft + ' Window = ' + ww);
	}
	if (wi) showBox.style.width = wi;
	if (hi) showBox.style.height = hi;
	if (mleft < 0) mleft = 0;
	if (mtop < 0) mtop = 0;
	showBox.style.top  = mtop; 
	showBox.style.left = mleft;
	showBox.style.visibility = "visible";
}

function PopupBox(nome, menuItem){
	PopupXY(nome, menuItem, 0, 6)
}

function PopupHint(nome, menuItem, wi){
	PopCloseAllNamed('Hint');
	PopupXY(nome, menuItem, -64, -8, wi)
}

function PopupFoto(image, fnome, padre){
	PopCloseAll();
	showBox = GetElement('Menu0');
	menuItem = GetElement('I0');
	mleft = menuItem.offsetLeft;
	mtop  = menuItem.offsetTop + menuItem.offsetHeight + 8; 
	parente = menuItem.offsetParent;
	while (parente){
		mtop  += parente.offsetTop; 
		mleft += parente.offsetLeft;
		parente = parente.parentElement;
	}
	image.src = fnome;
	showBox.style.visibility = "visible";
	showBox.style.top  = mtop; 
	showBox.style.left = 10;
}

function Popup(nome, padre){
	PopupBox(nome, GetElement('I'+nome));
}

function PopClose(nome){
	showBox = GetElement(nome);
	if (showBox){
		showBox.style.visibility = "hidden";
		return true;
	} else {
		return false;
	}
}

function PopCloseAllNamed(nome){
	conta = 0;
	while (PopClose(nome + conta)) {++conta;}
	return conta;
}

function PopCloseAll(){
	PopCloseAllNamed('Menu');
}

function PopCloseHint(){
	PopCloseAllNamed('Hint');
}

function ScriviUltimaData(){
	var datAgg = new Date(document.lastModified);
	with (datAgg) {	document.writeln(getDate(), '-', getMonth()+1, '-', getFullYear());}
}

