// *** GLOBAL Vars ***
var	XmlRequester = null;


// *** Common Startup Code ***
if (document.layers)
{
	if (top.location !=self.location)
	{
		top.location=self.location
	};
} 
else 
{
	if (self != top)
	{
		if (document.images)
		{
			top.location.replace(self.location);
		}
		else
		{
			top.location=self.location;
		}
	}
}

event_attach ("onload",MyPreInit);
event_attach ("onunload",MyPreUnload);

function	MyPreInit	(elemID)
{
	/*****************************
	 * V 1.0.0 22/12/2006 By Bit *
	 *****************************/
	
	AnimateImgButton ("FlagIt");
	AnimateImgButton ("FlagEn");
	AnimateImgButton ("FlagFr");
	AnimateImgButton ("FlagDe");
	MasterInit ();
}

function	MyPreUnload	(elemID)
{
	/*****************************
	 * V 1.0.0 22/12/2006 By Bit *
	 *****************************/
	
	MasterDispose ();
}

// *** Common function ***

function	MyElemID	(elemID)
{
	/*****************************
	 * V 1.0.0 31/12/2004 By Bit *
	 * V 1.0.1 01/01/2006 By Bit *
	 *****************************/
	 
	var obj
	
	if (document.all)
	{
		obj = document.all(elemID)
	}
	else if (document.getElementById)
	{
		obj = document.getElementById(elemID)
	}
	else if (document.layers)
	{
		obj = document.layers[elemID]
	}
	return (obj);
}
	
function ConfirmChoice	(MessageTxt,OKUrl)
{
	/*****************************
	 * V 1.0.0 14/08/2003 By Bit *
	 * V 1.0.1 01/01/2006 By Bit *
	 *****************************/
	
	if (confirm (MessageTxt))
	{
		location.href=OKUrl;
	}
}

function	CenterLay   (LayerName,CurrW,CurrH)
{
	/*****************************
	 * V 1.0.0 15/05/2003 By Bit *
	 *****************************/
	
	xx = MyElemID (LayerName);
	if (xx != null)
	{
		xx.style.left = ((screen.availWidth / 2) - (CurrW / 2))+'px';
		xx.style.top = ((screen.availHeight / 2) - (CurrH / 2))+'px';
	}
}

function	Number_Format		(Num,NumDecimal,DecPoint,ThousandsSep)
{
	/*****************************
	 * V 1.0.0 15/10/2005 By Bit *
	 *****************************/
	
	Num =  (Math.round (Num * Math.pow (10,NumDecimal)) / Math.pow(10,NumDecimal)).toString ();
	
	var DecPosition = Num.indexOf (".");	
	if (DecPosition == -1)
	{
		Num += ".";
		for (var i = 0;i < NumDecimal;i++)
		{
			Num += "0";
		}
	}
	else
	{
		var	DecLocation = Num.substring (DecPosition,Num.length);		
		for (i = 0;i <= NumDecimal - DecLocation.length;i++)
		{
			Num += "0";
		}
	}
	Num = Num.replace (".",DecPoint);
	
	var DecPosition = Num.indexOf (",");	
	var	IntPart = Num.substring (0,DecPosition);
	var	FloatPart = Num.substring (DecPosition,Num.length);
	
	if (IntPart.length > 3)
	{
		var NewIntPart = "";
		var	DCnnt = 0;
		
		for (var i = IntPart.length;i >= 0;i--)
		{
			NewIntPart += IntPart.charAt (i);
			++DCnnt;
			if (DCnnt == 4)
			{
				NewIntPart += ThousandsSep;
				DCnnt = 0;
			}
		}
		
		var DefNum = "";
		for (var i = NewIntPart.length;i >= 0;i--)
		{
			DefNum += NewIntPart.charAt (i);
		}
		Num = DefNum + FloatPart;
	}
	
	return (Num);
}

function	ExtractIntFromStr	(InStr)
{
	/*****************************
	 * V 1.0.0 16/04/2006 By Bit *
	 *****************************/
	
	var RetValue = "";
	var	TempPartStr = "";
	
	for (var i=0; i < InStr.length;i++)
	{
		TempPartStr = InStr.substring (i,i+1);
		if(TempPartStr=="1"||TempPartStr=="2"||TempPartStr=="3"||TempPartStr=="4"||TempPartStr=="5"||TempPartStr=="6"||TempPartStr=="7"||TempPartStr=="8"||TempPartStr=="9"||TempPartStr=="0")
		{
			RetValue += TempPartStr;
		}
	}
	return parseInt (RetValue);	
}

function	RPadInt	(Num)
{
	/*****************************
	 * V 1.0.0 15/09/2006 By Bit *
	 *****************************/
	
	var RetValue = Num;
	
	if (RetValue <= 9)
	{
		RetValue= "0"+RetValue;
	}
	return (RetValue);
}

function	AnimateImgButton	(ButtId)
{
	/*****************************
	 * V 1.0.0 01/01/2006 By Bit *
	 * V 1.0.1 01/03/2006 By Bit *
	 *****************************/
	 
	var	ObjRef = MyElemID (ButtId);
	
	if (ObjRef != null)
	{
		ObjRef.onmouseout = AnimateImgButtonHandler;
		ObjRef.onmouseover = AnimateImgButtonHandler;
		
		if (AnimateImgButton.arguments.length > 1)
		{
			ObjRef.onclick = AnimateImgButton.arguments[1];
		}
	}
}

function AnimateImgButtonHandler (EvtNfo)
{
	/*****************************
	 * V 1.0.0 01/01/2006 By Bit *
	 * V 1.0.1 05/07/2006 By Bit *
	 *****************************/

	var EventType = null;
	var EventSource = null;

	if (window.event == undefined)
	{ // Firefox
		EventType = EvtNfo.type;
		EventSource = EvtNfo.target;  
	}
	else
	{ // IE
		EventType = window.event.type;
		EventSource = window.event.srcElement;
	}

	switch (EventType)
	{
		case "mouseover":
			EventSource.src = EventSource.src.replace ("Normal","Over");
			break;
		case "mouseout":
			EventSource.src = EventSource.src.replace ("Over","Normal");
			break;
	}
}

function    Trim (Message)
{
    return (Message.replace(/\s+$|^\s+/g,""));
}

function	AppendXmlRequest	(Url,Param,ReturnFunction)
{
	/*****************************
	 * V 1.0.0 10/04/2005 By Bit *
	 *****************************/
	 
	if (XmlRequester != null)
	{
		alert ("Rischiesta XML gia' in corso...");
	}
	else
	{
		var	TempParser = null;
		
		if (window.XMLHttpRequest)
		{
			TempParser = new XMLHttpRequest ();
		}
		else
		{
			TempParser = new ActiveXObject ("Microsoft.XMLHTTP");
		}
		
		if (TempParser)
		{
			XmlRequester = {
							Requester:TempParser,
							ReturnFcn:ReturnFunction
						};			
						
			XmlRequester.Requester.open ("GET",Url,true);
			XmlRequester.Requester.onreadystatechange = ProcessXmlResponse;
			//	XmlRequester.setRequestHeader ("Content-Type","multipart/form-data");
			XmlRequester.Requester.send (Param);
			
			//MyElemID ("Loader").style.display = "block";
		}
	}
}

function	RemoveXmlRequest	(ObjName)
{
	/*****************************
	 * V 1.0.0 10/04/2005 By Bit *
	 *****************************/
	;
}

function	ProcessXmlResponse	()
{
	/*****************************
	 * V 1.0.0 10/04/2005 By Bit *
	 *****************************/
	 
	if (XmlRequester.Requester.readyState == 4)
	{
		if (XmlRequester.Requester.status == 200)
		{
			if (XmlRequester.ReturnFcn != "")
			{
				eval (XmlRequester.ReturnFcn (XmlRequester.Requester.responseText));
			}
			//MyElemID ("Loader").style.display = "none";
			XmlRequester = null;
		}
		else
		{
			alert ("Errore nella comunicazione col server: "+XmlRequester.Requester.statusText);
		}
	}	
}

function	event_attach	(event,func)
{
	if (window.attachEvent)
	{
		window.attachEvent (event,func);
	}
	else
	{
		if ((typeof (func)).toLowerCase () != 'function')
		{
			return;
		}
		if ((typeof (document.event_handlers)).toLowerCase () == 'undefined')
		{
			document.event_handlers = new Array ();
		}
		if ((typeof (document.event_handlers[event])).toLowerCase () == 'undefined')
		{
			document.event_handlers[event] = new Array ();
		}
		if ((typeof (eval ('window.'+event))).toLowerCase () != 'function' )
		{
			eval ('window.' + event + ' = function () { if ( ( typeof( document.event_handlers[ \'' + event + '\' ] ) ).toLowerCase() != \'undefined\' ) { for ( var i = document.event_handlers[ \'' + event + '\' ].length - 1 ; i >= 0  ; i-- ) { document.event_handlers[ \'' + event + '\' ][ i ](); } } } ' );
		}
		document.event_handlers[ event ][document.event_handlers[event].length] = func;
	}
}

/* Min Width v1.1.3 by PVII-www.projectseven.com
 * http://www.projectseven.com/tutorials/css/minwidth/index.htm
 *
 * modified for readability and ability to limit application to
 * IE only so CSS min-width property may be used by compliant
 * browsers.
 *
 * NOTE: horizontal spacing (margins, padding, borders) set in
 *       % values may cause IE to crash when using this script.
 */
function	set_min_width	(obj_name,min_width,ieOnly)
{
	if ((typeof (ieOnly)).toLowerCase () == 'undefined')
	{
		ieOnly = true;
	}
	if (ieOnly == false || (document.getElementById && navigator.appVersion.indexOf ( "MSIE" ) > -1 && !window.opera))
	{
		document.min_width_obj_name = obj_name;
		document.min_width_size = min_width;
		document.resizing = false;
		event_attach ('onload',control_min_width);
		event_attach ('onresize',control_min_width);
	}
}

function	control_min_width	()
{
	var cw , w , pl , pr , ml , mr , br , bl , ad , theDiv = document.min_width_obj_name;
	var g = document.getElementById ( theDiv );
	w = parseInt (document.min_width_size);
	if (g && document.body && document.body.clientWidth)
	{
		gs = g.currentStyle;
		cw = parseInt (document.body.clientWidth);
		pl = parseInt (gs.paddingLeft);
		pr = parseInt (gs.paddingRight);
		ml = parseInt (gs.marginLeft);
		mr = parseInt (gs.marginRight);
		bl = parseInt (gs.borderLeftWidth);
		br = parseInt (gs.borderRightWidth);
		ml = ml ? ml : 0;
		mr = mr ? mr : 0;
		pl = pl ? pl : 0;
		pr = pr ? pr : 0;
		bl = bl ? bl : 0;
		br = br ? br : 0;
		ad = pl + pr + ml + mr + bl + br;
		if (cw <= w)
		{
			w -= ad;
			g.style.width = w + "px";
		}
		else
		{
			g.style.width = "auto";
		}
	}
}