window.onerror = null;
window.defaultStatus = '';

var N = navigator.appName;
var V = parseInt(navigator.appVersion);
var loaded=0;
var n3 = (N == "Netscape" && V < 4);
var i3 = (N == "Microsoft Internet Explorer" && V < 4);
var n4 = (N == "Netscape" && V >= 4);
var i4 = (N == "Microsoft Internet Explorer" && V >= 4);

var i55=false;

var transNo=12;
var transNoOff=12;

var transNoSub=6;
var transNoSubOff=7;

var timer=1;

i4  = true;
i55 = true;

if (i4)
{
	var test5 = new String (navigator.appVersion);
	var i = test5.indexOf ("MSIE");
	test5 = test5.substring (i+5);
	var subVersion = parseFloat (test5);

	if (subVersion < 5.5)
		i55=false;
	else
		i55=true;
}


if (!i4) window.location = "browser_error.htm";
if (!i55 && firstTime) window.location = "browser_error.htm";

var ActiveLayer="";
var ActiveMenu="";

var ActiveSubLayer="";
var ActiveSubMenu="";

var X=0;
var Y=0;

var loading = true;
var opening = false;
var LastOpen = new Array ();
for (x=0;x < 5;x++)
	LastOpen[x] = -1;

if (n4 || i4)
{
    if (navigator.appName == "Netscape")
    {
		layerStyleRef="layer.";
		layerRef="document.layers";
		styleSwitch="";
    }
    else
    {
        layerStyleRef="";
        layerRef="document.all";
        styleSwitch=".style";
	}
}

function today()
{
	var  d  = new Date ();
	var gs  = d.getDay();
	var gg  = d.getDate();
	var mm  = d.getMonth()+1;
	var aa  = d.getFullYear();
	var hh  = d.getHours();
	var min = d.getMinutes();
	var giorni = new Array("Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato");
	var mesi = new Array("Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto","Settembre","Ottobre","Novembre","Dicembre");
	if (gg < 10) gg = "0"+gg;
	if (mm < 10) mm = "0"+mm;
	if (hh < 10) hh = "0"+hh;
	if (min < 10) min = "0"+min;
	document.write (giorni[gs]+" "+gg+"  "+mesi[mm-1]+"  "+aa);
}




function setClass(obj,style)
{
	obj.className = style;
}


function setClassHover(obj)
{
	obj.className = obj.className+"Hover";
}

function setClassNormal(obj)
{
	s = new String (obj.className);
	obj.className = s.replace("Hover","");
}

function SetMenuLevel (obj,level)
{
	obj.MenuLevel = level;
}

function SetMenuHomePage (obj,address)
{
	obj.MenuHomePage = address;
}

function SetMenuNumber (obj,number)
{
	obj.MenuNumber = number;
}

function SetMenuImageOpen (obj,image)
{
	obj.MenuImaqeOpen = image;
}

function SetMenuImageClose (obj,image)
{
	obj.MenuImaqeClose = image;
}

function SetMenuStyle (obj,style)
{
	obj.MenuStyle = style;
}

function SetMenuClosing (obj,closing)
{
	obj.MenuClosing = closing;
}




function setAddress (address)
{
	if (window.parent != null)
		window.parent.location=address;
	else
		window.top.location=address;
}


function getKey (str)
{
	var s     = new String ("");
        var uStr  = new String (str.toUpperCase());
	var start = uStr.indexOf ("KEY=");

	if (start != -1)
	{
		s = uStr.substr (start);
		var end = s.indexOf ("&");

		if (end != -1)
			s = s.substr (0,end);
	}

	return s.toUpperCase();
}



function MustOpen (oMenu,oItem,address)
{
	var ret = false;
	var level = 0;

	if (oItem == null)
		return ret;


        if (oItem.MenuHomePage != null)
        {

          var address = oItem.MenuHomePage;
          var key = getKey (new String (address));
          var currentKey=getKey (new String (document.location));

          var address = oItem.MenuHomePage;
          currentAddress = new String (document.location);

          if (currentAddress.indexOf (address) != -1 ||
              (currentKey != "" && currentKey == key))
          {
	 	var number = oItem.MenuNumber;

		var nameItem="T"+number;
		var nameButton="B"+number;
		var nameMenu="MT"+number;

		var oItem   = document.all[nameItem];
		var oButton = document.all[nameButton];
		var oMenu   = document.all[nameMenu];


		oMenu.className = oMenu.MenuStyle + "MenuActive";
		oItem.style.display = "block";
		oButton.src = oMenu.MenuImaqeOpen;

		return true;
          }
        }

	var child = oItem.firstChild;

	while (child != null)
	{

		if (child.href != null)
		{
			s = new String (child.href);
			if (s.indexOf ("javascript") == -1 &&
			    s.indexOf (".gif") == -1 &&
			    s.indexOf (".jpg"))
			{
				if (s.indexOf ("key=") == -1)
				{
					var simple_address = new String (child.href);
					var pos = simple_address.indexOf ("?");

					if (pos != -1)
						simple_address = simple_address.substr (0,pos-1);

					if (address.indexOf (simple_address) != -1 )
					{
						oItem.className= oMenu.MenuStyle + "Active";
						child.className= oMenu.MenuStyle + "Active";
						ret=true;
					}
				}
				else
				{
					if (getKey (address) == getKey (child.href))
					{
						oItem.className= oMenu.MenuStyle + "Active";
						child.className= oMenu.MenuStyle + "Active";
						ret=true;
					}
				}
			}
		}

		if (MustOpen (oMenu,child,address))
			ret = true;

		child=child.nextSibling;
	}

	return ret;
}




// ---------------------------
function SetStartup (MaxMenu)
{
	var x;
	var nameItem;
	var nameButton;
	var oItem;
	var oButton;


	address = new String (document.location);


	for (x=0;x < MaxMenu;x++)
	{
		nameItem="T"+x;
		nameButton="B"+x;
		nameMenu="MT"+x;

		oItem   = document.all[nameItem];
		oButton = document.all[nameButton];
		oMenu   = document.all[nameMenu];

		ok = MustOpen (oMenu,oItem,address);

		if (!ok)
		{
			if (oMenu.MenuHomePage != null)
			{
				var address = oMenu.MenuHomePage;
				var key = getKey (new String (address));
				var currentKey=getKey (new String (document.location));

				var address = oMenu.MenuHomePage;
				currentAddress = new String (document.location);

				if (currentAddress.indexOf (address) != -1 ||
				   (key != "" && currentKey == key))
				{
					oMenu.className = oMenu.MenuStyle + "MenuActive";
					oItem.style.display = "block";

					if (oMenu.MenuLevel > 0)
						oButton.src = oMenu.MenuImaqeOpen;

				}
			}

		}
		else
		{
			oMenu.className = oMenu.MenuStyle + "MenuActive";
			oItem.style.display = "block";
			oButton.src = oMenu.MenuImaqeOpen;

			// setta last open
			LastOpen[oMenu.MenuLevel]=x;

		}
	}

}


// ---------------------------
function ToggleDisplay(nMenu,recursing)
{
	if (alertInUse)
	{
		return;
	}

	var SingleMenu = true;

	var nameItem="T"+nMenu;
	var nameButton="B"+nMenu;
	var nameMenu="MT"+nMenu;

	var oItem   = document.all[nameItem];
	var oButton = document.all[nameButton];
	var oMenu   = document.all[nameMenu];


        if (oMenu.MenuHomePage != null)
        {
          var address = oMenu.MenuHomePage;
          currentAddress = new String (document.location);

          if (currentAddress.indexOf (address) == -1)
          {
            document.location=address;
            return;
          }
        }

	if ((oItem.style.display == "") || (oItem.style.display == "none"))
	{

		oItem.style.display = "block";
		oButton.src = oMenu.MenuImaqeOpen;


		// chiude i menù dello stesso livello
		if (LastOpen[oMenu.MenuLevel] != -1)
		  ToggleDisplay (LastOpen[oMenu.MenuLevel],true);

		if (SingleMenu == true)
			LastOpen[oMenu.MenuLevel] = nMenu;

	}
	else
	{
		if (!recursing || oMenu.MenuClosing == false)
		{
			oItem.style.display = "none";
			oButton.src = oMenu.MenuImaqeClose;
			LastOpen[oMenu.MenuLevel] = -1;
		}
	}
}


// ---------------------------
function showLayer(layer)
{
	if (alertInUse)
	{
		return;
	}

	if (n4 || i4)
	{

		if (ActiveLayer != "")
		{
			eval(layerRef+'["'+ActiveLayer+'"]'+styleSwitch+'.visibility="hidden"');
		}

		ActiveLayer = 'L'+ layer;
		ActiveMenu  = 'M'+ layer;

		if (i4)
		{

			var x= window[ActiveMenu].offsetLeft-13;

			if (!i55) x-=21;


			var y= window[ActiveMenu].offsetTop+window[ActiveMenu].offsetHeight+6;
			var parent;

			for (parent=window[ActiveMenu].offsetParent;
				 parent != null;parent=parent.offsetParent)
			{
			   x = x + parent.offsetLeft;
			   y = y + parent.offsetTop;
			}

			document.all[ActiveLayer].style.left=x;
			document.all[ActiveLayer].style.top=y;
			doTransIE(ActiveLayer,transNo,timer,1);
			// document.all[ActiveLayer].style.visibility='visible';

		}
		if (n4)
		{
			x = document.layers[ActiveMenu].pageX;
			y = document.layers[ActiveMenu].pageY + document.layers[ActiveMenu].clip.height+5;

			document.layers[ActiveLayer].left = x;
			document.layers[ActiveLayer].top = y;
			document.layers[ActiveLayer].visibility = true;
		}
	}
}

// ---------------------------
function showSubLayer(layer)
{
	if (alertInUse)
	{
		return;
	}

	if (n4 || i4)
	{
		if (ActiveSubLayer != "")
		{
			eval(layerRef+'["'+ActiveSubLayer+'"]'+styleSwitch+'.visibility="hidden"');
		}

		ActiveSubLayer = 'L'+ layer;
		ActiveSubMenu  = 'M'+ layer;

		if (i4)
		{
			document.all[ActiveSubMenu].style.color='red';

			var x= window[ActiveSubMenu].offsetLeft+window[ActiveSubMenu].offsetWidth;
			var y= window[ActiveSubMenu].offsetTop-1;
			var parent;

			for (parent=window[ActiveSubMenu].offsetParent;
				 parent != null;parent=parent.offsetParent)
				 {
					x = x + parent.offsetLeft;
					y = y + parent.offsetTop;
				 }

			document.all[ActiveSubLayer].style.left=x;
			document.all[ActiveSubLayer].style.top=y;
			doTransIE(ActiveSubLayer,transNoSub,timer,1);
			// document.all[ActiveSubLayer].style.visibility='visible';

		}
		if (n4)
		{
			var parent = document.layers[ActiveLayer];
			var menu = parent.above;

			while (menu)
			{
				if (menu.name == ActiveSubMenu)
					break;
				menu = menu.siblingAbove;
			}

			if (menu)
			{
				x = parent.left + parent.clip.right - 15;
				y = menu.pageY + 2;

				document.layers[ActiveSubLayer].left = x;
				document.layers[ActiveSubLayer].top = y;
				document.layers[ActiveSubLayer].visibility = true;
			}
		}
	}
}


// ---------------------------
function hideThisLayer()
{
	if (n4 || i4)
	{

		if (ActiveSubLayer == "") // can hide only in no submenu open !!
		{
			var element;
			var parent = null;

			if (i4)
			{
				X = window.event.x;
				Y = window.event.y+5;

				element = document.elementFromPoint(X,Y);


				if (element)
				{
					for (parent=element.parentElement;
						 parent!= null;parent=parent.parentElement)
						if (parent.id == ActiveLayer)
							break;
				}
			}

			if (n4)
			{
				Y = Y+5;// shift

				var left   = document.layers[ActiveLayer].left;
				var top    = document.layers[ActiveLayer].top;
				var right  = document.layers[ActiveLayer].left +
							 document.layers[ActiveLayer].clip.right;
				var bottom = document.layers[ActiveLayer].top +
							 document.layers[ActiveLayer].clip.bottom;

				if (X  >= left && X <= right &&
					Y  >= top  && Y <= bottom )
					parent = true;
			}

			if (!parent)
			{
				if (i4)
					doTransIE(ActiveLayer,transNoOff,timer,0);
					//document.all[ActiveLayer].style.visibility='hidden';

				else
					eval(layerRef+'["'+ActiveLayer+'"]'+styleSwitch+'.visibility="hidden"');
				ActiveLayer="";
			}
		}
	}
}

// ---------------------------
function hideThisSubLayer()
{
	if (n4 || i4)
	{
		var element;
		var parent = null;
		var x,y;

		if (i4)
		{
			x = window.event.x;
			y = window.event.y;
			element = document.elementFromPoint(x,y);

			if (element)
			{
				for (parent=element.parentElement;
					 parent!= null;parent=parent.parentElement)
					if (parent.id == ActiveSubLayer)
						break;
			}
		}

		if (n4)
		{

			var left   = document.layers[ActiveSubLayer].left;
			var top    = document.layers[ActiveSubLayer].top;
			var right  = document.layers[ActiveSubLayer].left +
						 document.layers[ActiveSubLayer].clip.right;
			var bottom = document.layers[ActiveSubLayer].top +
						 document.layers[ActiveSubLayer].clip.bottom;

			if (X  >= left && X <= right &&
				Y  >= top  && Y <= bottom )
				parent = true;
		}


		if (!parent)
		{
			if (i4)
				doTransIE(ActiveSubLayer,transNoSubOff,timer,0);
				// document.all[ActiveSubLayer].style.visibility='hidden';

			else
				eval(layerRef+'["'+ActiveSubLayer+'"]'+styleSwitch+'.visibility="hidden"');

			ActiveSubLayer="";
			hideThisLayer ();
		}
	}
}


// ---------------------------
function showThisLayer()
{
	if (n4 || i4 && ActiveLayer != "")
		eval(layerRef+'["'+ActiveLayer+'"]'+styleSwitch+'.visibility="visible"');
}

// ---------------------------
function showThisSubLayer()
{
	if (n4 || i4 && ActiveSubLayer != "")
		eval(layerRef+'["'+ActiveSubLayer+'"]'+styleSwitch+'.visibility="visible"');
}


// --------------------------------------------------
// funzioni popup
// --------------------------------------------------

var oldOnBodyClick=null;
var alertInUse = false;

// <div id=popupDiv STYLE='POSITION: absolute; VISIBILITY: hidden; width:10'></div>

function openNewPopupBrowser (url,xSize,ySize,scrollbars)
{
	if (xSize == null)
		xSize = 419;
	if (ySize == null)
		ySize = 419;
	if (scrollbars == null)
		scrollbars = "yes";

	w = window.open (url,"_tidysoft","location=no,menubar=no,status=no,toolbar=no,scrollbars="+scrollbars+",width="+xSize+",height="+ySize);

	w.focus ();
}

// --------------------------------------------------
function openPopupWindowEx ( strXMLtemplate , strXMLcontent,left,top, divElement,bodyFunction,show)
{
	if (alertInUse)
	{
		return;
	}

	var x = 100;
	var y = 200;
	var recalc = false;

	if (left == null && top == null)
		recalc = true;

	if (window.event != null)
	{
		x = window.event.x + 15;
		y = window.event.y + document.body.scrollTop - 15;
	}


	if (left == null)
		left = x;

	if (top == null)
		top = y;

	opening = true;

	var template = GetXML ( strXMLtemplate );
	if (template)
	{
		divElement.innerHTML = template;
		var content = null;

		if (strXMLcontent)
			content = GetXML ( strXMLcontent );

		if (content)
			insert_cell.innerHTML = content;

		divElement.style.left=left;
		divElement.style.top=top;

		if (show)
		{
			if (recalc)
			{
				var totalx = left + divElement.clientWidth;
				var totaly = top + divElement.clientHeight;

				if (totalx > document.body.clientWidth)
					divElement.style.left = document.body.clientWidth - divElement.clientWidth - 5;

				if (totaly > (document.body.clientHeight + document.body.scrollTop))
				{
					var y = (document.body.clientHeight + document.body.scrollTop) - divElement.clientHeight - 5;
					if (y < 5)
						y = 31;

					divElement.style.top = y;
				}
			}
			divElement.style.visibility='visible';

			if (bodyFunction)
			{
				oldOnBodyClick=document.body.onclick;
				document.body.onclick = bodyFunction;
			}
		}

	}
}

// --------------------------------------------------
function openPopupWindow ( strXMLtemplate , strXMLcontent,left,top )
{
	openPopupWindowEx ( strXMLtemplate , strXMLcontent,left,top,popupDiv,onBodyClick,true);
}

function GetXML ( strXMLSrc , errorMode)
{

    var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM");

    objXMLDoc.async = false;

    objXMLDoc.load( strXMLSrc );

    if (objXMLDoc.parseError.errorCode != 0)
    {
    	if (errorMode == null)
    		alert ("file: " + strXMLSrc + "\n" + objXMLDoc.parseError.reason + "\nline: " + objXMLDoc.parseError.line + "\nlinepos " + objXMLDoc.parseError.linepos);
     	return null;
    }


    return objXMLDoc.xml;

}

function tidyAlert (s)
{
	var message = new String (s);
	openPopupWindowEx ( '/pop_up/alert/standard.htm' ,null,null,null,alertDiv,null,false);

	message_cell.innerHTML
	message=message.replace (new RegExp("\n","g"),"<br>");
	message_cell.innerHTML=message;

	var totalx = alertDiv.clientWidth;
	var totaly = alertDiv.clientHeight;

	var xpos = (document.body.clientWidth  - alertDiv.clientWidth)  / 2;
	var ypos = (document.body.clientHeight - alertDiv.clientHeight) / 2;

	alertDiv.style.left = xpos;
	alertDiv.style.top = ypos;
	alertDiv.style.visibility='visible';

	oldOnBodyClick=document.body.onclick;
	document.body.onclick = onAlertClick;
	alertInUse=true;

}

function tidyAlertClose ()
{
	alertDiv.style.visibility  = 'hidden';
	document.body.onclick  = oldOnBodyClick;
	alertInUse=false;
}

function onBodyClick()
{
	if (popupDiv.style.visibility == 'visible' && !opening)
	{
		popupDiv.style.visibility = 'hidden';
		document.body.onclick     = oldOnBodyClick;
	}
	opening = false;

}

function onAlertClick()
{
	if (event != null)
	{
		element = document.elementFromPoint(event.clientX,event.clientY);
		if (isAlert (element))
		{
			return true;
		}
	}

	event.returnValue = false;
	event.cancelBubble = true;
	return false;
}

function isAlert (element)
{
	if (element != alertDiv)
	{
		var parent = element.offsetParent;
		while (parent != null)
		{
			if (parent == alertDiv)
			{
				element = alertDiv;
				break;
			}

			parent = parent.offsetParent;
		}
	}

	if (element == alertDiv)
	{
		return true;
	}

	return false;

}

function onBodyClickCredits()
{
	if (popupDiv.style.visibility == 'visible' && !opening)
	{
		popupDiv.style.visibility = 'hidden';
		document.body.onclick     = oldOnBodyClick;
		clearTimeout(iTimerID);
		startIntervalFunctions ();
	}
	opening = false;

}

// -----------------------------------------------------------------
// end funzioni popup ----------------------------------------------
// -----------------------------------------------------------------


// -----------------------------------------------------------------
// funzione di scroll del testo ------------------------------------
// -----------------------------------------------------------------

/**********************************************************************
This script is made by and copyrighted to Thomas Brattli
at www.bratta.com and may be used freely as long as this
message is left intact.
Visit www.bratta.com for more great scripts.
**********************************************************************/

//Set these variables:

//The pixel value of where you want the layer to start (from the top)
var lstart;

//Set this to false if you just want it to go one time
var loop;

//Set the speed, lower value gives more speed
var speed;
var pr_step;


//Browsercheck
var n = (document.layers) ? 1:0;
var ie = (document.all) ? 1:0;

var oSlide;
var iTimerID;

//Object constructor
function makeObjEx(obj,nest)
{
	nest=(!nest) ? '':'document.'+nest+'.';
	this.css=(n) ? eval(nest+'document.'+obj):eval(obj+'.style');
	this.scrollHeight=n?this.css.document.height:eval(obj+'.offsetHeight');
	this.up=goUp;
	this.obj = obj + "Object";
	eval(this.obj + "=this");
	return this;
}
function goUp(speed)
{
	if(parseInt(this.css.top)>-this.scrollHeight)
	{
		this.css.top=parseInt(this.css.top)-pr_step;

		if (iTimerID)
			clearTimeout(iTimerID);

		iTimerID = setTimeout(this.obj+".up("+speed+")",speed);
	}
	else if(loop)
	{
		this.css.top=lstart;
		eval(this.obj+".up("+speed+")");
	}
}

function slideInit()
{
	stopIntervalFunctions ();

	lstart=50;
	loop=true;
	speed=60;
	pr_step=1;

	oSlide=makeObjEx('divNewsEx','divContEx');
	oSlide.css.top=lstart;
	oSlide.up(speed);

}

// -------------- timed functions

var intervalIds       = new Array (10);
var intervalFunctions = new Array (10);
var intervalTimeOuts  = new Array (10);

intervalFunctions[0]=null;

function setIntervalFunction (funct,timeout)
{
	var x;
	for (x=0;x < 10; x++)
	if (intervalFunctions[x] == null)
		break;

	intervalFunctions[x]	= funct;
	intervalTimeOuts[x]	= timeout;
	intervalIds[x] 		= setInterval (intervalFunctions[x],intervalTimeOuts[x]);

	intervalFunctions[x+1]	= null;

}

function stopIntervalFunctions ()
{
	var x =0;
	while (intervalFunctions[x] != null)
	{
		clearInterval (intervalIds[x]);
		x++;
	}

}

function startIntervalFunctions ()
{
	var x =0;
	while (intervalFunctions[x] != null)
	{
		intervalIds[x] = setInterval (intervalFunctions[x],intervalTimeOuts[x]);
		x++;
	}
}


// ----------- cookie functions

// --------------------------------------------
function SetCookie (name, value)
{
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + value +
                ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                ((path == null) ? "" : ("; path=" + path)) +
                ((domain == null) ? "" : ("; domain=" + domain)) +
                ((secure == true) ? "; secure" : "");
}

// --------------------------------------------
function getCookieVal(offset)
{
        var endstr = document.cookie.indexOf (";", offset);

        if (endstr == -1)
                endstr = document.cookie.length;

        return unescape(document.cookie.substring(offset, endstr));
}

// --------------------------------------------
function GetCookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;

    while (i < clen)
    {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);

                i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0)
                        break;
    }

    return null;
}
