<!--

var ie = document.all    != null;
var ns = document.layers != null;

////////////////////////////////////////////////////////////////////////////////////////////////
/// PUNTO //////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////

function point(iX, iY)
{
	this.x = iX;
	this.y = iY;

//------------------------------------------//

	this.copy = function(oPt)
	{
		this.x = oPt.x;
		this.y = oPt.y;
	}
	
	this.add = function(oPt)
	{
		this.x += oPt.x;
		this.y += oPt.y;
	}

	this.subtract = function(oPt)
	{
		this.x -= oPt.x;
		this.y -= oPt.y;
	}

	this.toString = function() { return this.x + "," + this.y;  }
	this.alert    = function() { window.alert(this.toString()); }
}


////////////////////////////////////////////////////////////////////////////////////////////////
/// RETTANGOLO /////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////


function rectangle(iLeft, iTop, iRight, iBottom)
{
	this.left   = iLeft;
	this.top    = iTop;
	this.right  = iRight;
	this.bottom = iBottom;
	
	this.pt1    = new point(this.left,  this.top);
	this.pt2    = new point(this.right, this.bottom);

	this.toString = function() { return this.left + "," + this.top + ";" + this.right + "," + this.bottom; }
	this.alert    = function() { window.alert(this.toString()); }

//------------------------------------------//
	
	this.copy = function(oRect)
	{
		this.left   = oRect.left;
		this.top    = oRect.top;
		this.right  = oRect.right;
		this.bottom = oRect.bottom;
	}
	
	this.containsPoint = function(oPt)
	{
		return oPt.x >= this.left && oPt.x <= this.right &&
			   oPt.y >= this.top  && oPt.y <= this.bottom;
	}

	this.containsRect = function(oRect)
	{
		return this.containsPoint(new point(oRect.left,  oRect.top))    &&
			   this.containsPoint(new point(oRect.right, oRect.top))    &&
			   this.containsPoint(new point(oRect.right, oRect.bottom)) &&
			   this.containsPoint(new point(oRect.left,  oRect.bottom));
	}


	this.intersectRect = function(oRect)
	{
		return this.containsRect(oRect) ||
			   this.containsPoint(new point(oRect.left,  oRect.top))    ||
			   this.containsPoint(new point(oRect.right, oRect.top))    ||
			   this.containsPoint(new point(oRect.right, oRect.bottom)) ||
			   this.containsPoint(new point(oRect.left,  oRect.bottom));
	}


	this.normalize = function()
	{
		if(this.left > this.right)
		{
			var iTemp  = this.left;
			this.left  = this.right;
			this.right = iTemp;
		}

		if(this.top > this.bottom)
		{
			var iTemp   = this.top;
			this.top    = this.bottom;
			this.bottom = iTemp;
		}

		this.pt1 = new point(this.left,  this.top);
		this.pt2 = new point(this.right, this.bottom);
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////
/// VARIE //////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////

function getOwnerIframe(oElement)
{
	if(oElement == null || oElement.parentNode == null)
		return null;
		
	while(oElement.nodeName != "HTML")
	{
		oElement = oElement.parentNode;
		if(oElement == null)
			return null;
	}

	var oDocument = oElement.ownerDocument;
	if(oDocument == null)
		return null;
	
	var oWindow = oDocument.parentWindow;
	if(oWindow == null || oWindow == top)
		return null;
	
	var oParentWindow = oWindow.parent;
	if(oParentWindow == null)
		return null;
	
	var oParentDocument = oParentWindow.document;
	if(oParentDocument == null)
		return null;

	var oColl = oParentDocument.getElementsByTagName("IFRAME");
	if(oColl == null)
		return null;
		
	var oIframe = null;
	for(var i = 0; i < oColl.length; i++)
	{
		if(oColl[i].contentWindow == oWindow)
		{
			oIframe = oColl[i];
			break;
		}
	}
	
	return oIframe;
}


function getGlobalPosition(oObject, oOwner)
{
	var oRect = null;
	
	if(typeof(oOwner) == "undefined") 
		oOwner = document.body;

	try
	{
		if(oObject == null)
			throw { message:"Argomento NULLO!!" }

		var iX = oObject.offsetLeft - oObject.scrollLeft;
		var iY = oObject.offsetTop  - oObject.scrollTop;
		var iW = oObject.offsetWidth;
		var iH = oObject.offsetHeight;

		oObject = oObject.offsetParent;

		while(oObject != oOwner)
		{
			iX += oObject.offsetLeft - oObject.scrollLeft;
			iY += oObject.offsetTop  - oObject.scrollTop;

		// se HTML significa che siamo in un frame
			if(oObject.parentNode && oObject.parentNode.tagName == "HTML")
			{
				oObject = getOwnerIframe(oObject.parentNode);
				if(oObject == null)
					break;
		
				var iFrameBorder = (oObject.frameBorder == "") ? 2 : parseFloat(oObject.frameBorder);

				var oIframeRect = getGlobalPosition(oObject);
				iX += oIframeRect.left + iFrameBorder;
				iY += oIframeRect.top  + iFrameBorder;
				break;
			}
			else
			{
				oObject = oObject.offsetParent;
			}
		}
		
		oRect = new rectangle(iX, iY, iX + iW, iY + iH);
	}
	catch(e)
	{
		alert("** ERRORE ** in 'getGlobalPosition()':\n" + e.message);
	}	

	return oRect;
}

function checkOutOfBodyPosition(oRect)
{
	var iDeltaX = document.body.clientWidth  - oRect.right;
	var iDeltaY = document.body.clientHeight - oRect.height;
	
	if(iDeltaX < 0)	oRect.moveBy(iDeltaX, 0);
	if(iDeltaY < 0)	oRect.moveBy(0, iDeltaY);

	if(oRect.left < 0)	oRect.moveBy(oRect.left, 0);
	if(oRect.top  < 0)	oRect.moveBy(0, oRect.top);
	
	return oRect;
}

//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------

function getCollection(sId, oOwner)
{
	oOwner = (oOwner == null) ? document : oOwner;
	
	var oColl = oOwner.all[sId];
	if(oColl != null && oColl.length == null)
		oColl = new Array(oColl);
	
	return oColl;
}

function getCollectionByName(sId, oOwner)
{
	oOwner = (oOwner == null) ? document : oOwner;
	
	var oColl = oOwner.all[sId];
	if(     oColl == null)	oColl = new Array();
	else if(!oColl.length)	oColl = new Array(oColl);
	
	return oColl;
}

//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------

function trim(strValue)
{
    strValue = trimLeft(strValue);
    strValue = trimRight(strValue);
    
    return strValue;
}


function trimLeft(strValue)
{
    if(strValue == null || strValue == "" || typeof(strValue) != 'string')
        return strValue;
        
    while(strValue && strValue.charAt(0) == ' ')
        strValue = strValue.substring(1);
        
    return strValue == null ? "" : strValue;
}


function trimRight(strValue)
{
    if(strValue == null || strValue == "" || typeof(strValue) != 'string')
        return strValue;
                
    while(strValue && strValue.charAt(strValue.length-1) == ' ')
        strValue = strValue.substring(0, strValue.length-1);
        
    return strValue == null ? "" : strValue;
}


function replaceChar(strString, cFind, cReplaceWidth)
{
	var strNewString = "";
	for(var i = 0; i < strString.length; i++)
	{
		var c = strString.charAt(i);
		strNewString += (c == cFind) ? cReplaceWidth : c;
	}

	return strNewString;
}

-->
