// ---------------------------------------------------------------------------------------------------------------
// (c) ANBe Designs 2003 (MACB)
// anbedesigns@hotmail.com
// ---------------------------------------------------------------------------------------------------------------

function CenterComponent(aComponent, aContainer, deltaX, deltaY)
{
	var IEBrowser = IsIE();
	var ScrollLeft = IEBrowser ? document.body["scrollLeft"] : window.pageXOffset;
	var ScrollTop  = IEBrowser ? document.body["scrollTop"] : window.pageYOffset;

	var ContainerCX = aContainer.clientWidth >> 1;
	var ContainerCY = aContainer.clientHeight >> 1;
	var ComponentCX = (IEBrowser ? aComponent.clientWidth : aComponent.offsetWidth) >> 1;
	var ComponentCY = (IEBrowser ? aComponent.clientHeight : aComponent.offsetHeight) >> 1;	
	
	if (deltaX != null)	
		aComponent.style.left = ContainerCX - ComponentCX + deltaX + ScrollLeft;
	if (deltaY != null)
		aComponent.style.top = ContainerCY - ComponentCY + deltaY + ScrollTop;		
}

function CenterComponentX(aComponent, aContainer, deltaX)
{
	CenterComponent(aComponent, aContainer, deltaX, null);
}

function CenterComponentY(aComponent, aContainer, deltaY)
{
	CenterComponent(aComponent, aContainer, null, deltaY);
}

// ---------------------------------------------------------------------------------------------------------------

function OpenNewWindow(Document, Name, Params, Maximize)
{
	var NewWindow = window.open(Document, Name, Params);
	if (Maximize)
	{
		NewWindow.moveTo(0, 0);
		NewWindow.resizeTo(screen.availWidth, screen.availHeight);	
	}
	
	return NewWindow;
}

// ---------------------------------------------------------------------------------------------------------------

function DesktopCenter(aWindow)
{	
	var aWindowWidth = IsIE()? GetIEBody(aWindow.document).clientWidth : aWindow.innerWidth;
	var aWindowHeight = IsIE()? GetIEBody(aWindow.document).clientHeight : aWindow.innerHeight;
		
	aWindow.moveTo((screen.width >>> 1) - (aWindowWidth >>> 1), (screen.height >>> 1) - (aWindowHeight >>> 1));	
}

// ---------------------------------------------------------------------------------------------------------------

function OpenImageInNewWindow(aImage, aWindowName, aWindowParams, Maximize)
{
	var ImageWindow = OpenNewWindow("", aWindowName, aWindowParams, Maximize);
	aImage = GetObject(aImage);
	ImageWindow.document.open();
	ImageWindow.document.write("<div align='center'><img border='0' src='" + aImage.src + "'></div>");
	ImageWindow.document.close();
	return ImageWindow;
}

// ---------------------------------------------------------------------------------------------------------------

function PreloadImages(PathImages, ImagesList)
{
	var Images = new Array();	
	for (var i=0; i < ImagesList.length; i++)
	{
		Images[i] = new Image();
		Images[i].src = PathImages + ImagesList[i];
	}	
}

// ----------------------------------------------------------------------------------------------------------------

function _FrameImageResizeWindow(Img)
{
	var WindowAddWidth = 10;
	var WindowAddHeight = 24;
	var Width;
	var Height;
	var ImageWidth = null;
	var ImageHeight = null;
	
	if (Img.offsetWidth >= screen.width)
	{
		Width = screen.width;
		ImageWidth = Width - WindowAddWidth;
	}
	else
		Width = Img.offsetWidth + WindowAddWidth;

	if (Img.offsetHeight >= screen.height)
	{
		Height = screen.height;
		ImageHeight = Height - WindowAddHeight;
	}
	else
		Height = Img.offsetHeight + WindowAddHeight;			

	resizeTo(Width, Height);
	moveTo((screen.width - Width) >>> 1, (screen.height - Height) >>> 1);
	
	
	if (ImageWidth)
		Img.width = ImageWidth;
		
	if (ImageHeight)
		Img.height = ImageHeight;
		
	Img.style.visibility = "visible";
}

function FrameImage(ImgId, ImgSource)
{
	var Img = GetObject(ImgId);
	Img.onload = function(){_FrameImageResizeWindow(Img)};
	Img.src = ImgSource;	
}	

// ----------------------------------------------------------------------------------------------------------------

function IsValidColor(AColor)
{
	var HexDigits = GetHexDigits();
	
	if ((AColor) && (AColor.length == 6))
	{
		for (var i = 0; i < 6; i++)
		{
			if (HexDigits.indexOf(AColor.substr(i, 1).toUpperCase()) == -1)
				return false;
		}
		return true;
	}
	
	return false;	
}

// ----------------------------------------------------------------------------------------------------------------

function GetIEBody(ADocument)
{
	if (typeof ADocument == "undefined") ADocument = document;
	return (ADocument.compatMode && ADocument.compatMode != "BackCompat") ? ADocument.documentElement : ADocument.body;
}

// ----------------------------------------------------------------------------------------------------------------
