var NE4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 4))
var IE4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
var NE5 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 5))
var dialogWin = new Object();
var ebt = new Array();
var ptf = new Array(), ptv = new Array(), pts = 0;


function Init(arglst)
{
	var i;
	var args = new Array();

	ebt["CBHTZVAL1"] = true;
	ebt["CBHTZVAL2"] = true;
	ebt["CBHTZVAL3"] = true;
	ebt["CBHTZVAL4"] = true;
	ebt["CBHTZVAL5"] = true;
	args = arglst.split(",");
	for (i = 0; i < args.length; i+=2)
	{
		ptv[pts] = args[i];
		ptf[pts] = args[i + 1];
		++pts;
	}
	for (i = 0; i < HTZTLB1.elements.length; i++)
	{
		if (HTZTLB1.elements[i].name.substring(0,6) == "HTZFLD")
		{
			DispButt(HTZTLB1.elements[i], true);
		}
	}
}

function PopupMenu(bt)
{
	var prop, fld, s, url, i, sel;

	s = GetId(bt.name);
	sel = HTZTLB1.elements["HTZFLD" + s];
	s = "HTZVAL" + s;
	fld = HTZTLB1.elements[s];
	s = "CB" + s;
	for (i = 0; i < pts; i++)
	{
		if (ptv[i] == sel.options[sel.selectedIndex].value)
		{
			url = ptf[i];
			break;
		}
	}
	if (IE4 || NE5)
	{
		prop = "dialogWidth:400px;dialogHeight:300px;center:1;help:0";
		fld.value = window.showModalDialog(url + "ie.htm", fld.value, prop);
	}
	else if (NE4)
	{
		if (ebt[bt.name] == true) return false;
		if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed))
		{
			dialogWin.returnedValue = "";
			dialogWin.args = fld.value;
			dialogWin.field = fld;
			dialogWin.url = url + "ne.htm";
			dialogWin.width = 400;
			dialogWin.height = 300;
			dialogWin.name = (new Date()).getSeconds().toString();
			dialogWin.left = window.screenX + ((window.outerWidth - dialogWin.width) / 2);
			dialogWin.top = window.screenY + ((window.outerHeight - dialogWin.height) / 2);
			prop = "screenX=" + dialogWin.left + ",screenY=" + dialogWin.top + 
				",resizable=no,width=" + dialogWin.width + ",height=" + 
				dialogWin.height;
			dialogWin.win=window.open(dialogWin.url, dialogWin.name, prop);
			dialogWin.win.focus();
		} 
		else
		{
			dialogWin.win.focus();
		}
	}
	else
	{
	 	alert("Funzione non disponibile");
	}
	return false;
}


function blockEvents() 
{
	window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
	window.onclick = deadend;
	window.onfocus = checkModal;
}
function unblockEvents() 
{
	window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
	window.onclick = null;
	window.onfocus = null;
}

function deadend()
{
	if (dialogWin.win && !dialogWin.win.closed) 
	{
		dialogWin.win.focus();
		return false;
	}
}

function checkModal() 
{
	if (dialogWin.win && !dialogWin.win.closed) 
	{
		dialogWin.win.focus()	
	}
}

function GetId(name)
{
	var i = 0, l;

	l = name.length;
	while(i < l)
	{
		if (name.charAt(i) >= "0" && name.charAt(i) <= "9")
			break;
		++i;
	}
	return name.substr(i);
}

function DispButt(sel, ndef)
{
	var s, bt, i;

	s = GetId(sel.name);
	s = "HTZVAL" + s;
	bt = "CB" + s;
	HTZTLB1.elements[bt].disabled = true;
	ebt[bt] = true;
	for (i = 0; i < pts; i++)
	{
		if (sel.options[sel.selectedIndex].value == ptv[i])
		{
			HTZTLB1.elements[bt].disabled = false;
			ebt[bt] = false;
			if (!ndef && HTZTLB1.elements[s].value.length == 0)
			{
				PopupMenu(HTZTLB1.elements[bt]);
			}
		}
	}
}
