
var ImageArray = new Array();

function OpenWindow(Url, WindowName, NoToolbar, NoScroll, NoResize, NoStatus, NoTitle, Width, Height, Left, Top, Center)
{
	var sParams = new Array();
	
	sParams[sParams.length] = 'scrollbars=' + !NoToolbar;
	
	sParams[sParams.length] = 'location=' + !NoToolbar;
	sParams[sParams.length] = 'directories=' + !NoToolbar;
	sParams[sParams.length] = 'menuBar=' + !NoToolbar;

	sParams[sParams.length] = 'status=' + !NoStatus;

	sParams[sParams.length] = 'resizable=' + !NoResize;

	sParams[sParams.length] = 'titlebar=' + !NoTitle;

	if (Width > 0)
		sParams[sParams.length] = 'width=' + Width;

	if (Height > 0)
		sParams[sParams.length] = 'height=' + Height;

	if (Center && Width > 0 && Height > 0)
	{
		sParams[sParams.length] = 'left=' + (screen.width - Width) / 2;
		sParams[sParams.length] = 'top=' + (screen.height - Height) / 2;
	}
	else if (Left > 0 && Top > 0)
	{
		sParams[sParams.length] = 'left=' + Left;
		sParams[sParams.length] = 'top=' + Top;
	}

	eval('window.open(Url, WindowName, \'' + sParams.join(',') + '\')');
}

function ChangeFrameUrl(frameName, Url)
{
	if (frameName == '_Top')
	{
		top.location = Url;
	}
	else
	{
		top.frames[frameName].location = Url;
	}
}

function MoveObject(id, posX, posY)
{
	var obj

	obj = GetObjectStyleByID(id);

	obj.left = posX;
	obj.top = posY;
}

function SetCursor(obj, CursorType)
{
	//var obj;
	//alert(id);
	//obj = GetObjectStyleByID(id);

	obj.style.cursor = CursorType;
}

function ChangeCursor(CursorType)
{
	window.cursor = CursorType;
}

function Visible(id, visible)
{
	var obj;

	obj = GetObjectStyleByID(id);

	if (visible)
		obj.visibility = "visible";
	else
		obj.visibility = "hidden";
}

function MoveMenuItem(MenuItemID, ImageID, LeftOffset, TopOffset)
{
	var MenuItem, ImageItem;

	if ((MenuItem = GetObjectStyleByID(MenuItemID)) != null && (ImageItem = GetObjectStyleByID(ImageID)) != null)
	{
		MenuItem.left = (parseInt(ImageItem.left, 10) + parseInt(LeftOffset, 10)) + 'px';
		MenuItem.top = (parseInt(ImageItem.top, 10) + parseInt(TopOffset, 10)) + 'px';
	}
}

function ConvertQuotes(sText)
{
	return sText.replace(/'/g, "''")
}

function GetObjectStyleByID(id) 
{
	if (document.layers) 
		return document.layers[id];
	else if (document.all)
		return document.all(id).style;
	else if (document.getElementById) 
		return document.getElementById(id).style;
	else
	{
		alert("DHTML support not found.");
		return false;
	}
}

function GetObjectByID(id) 
{
	if (document.layers) 
		return document.layers[id];
	else if (document.all)
		return document.all(id);
	else if (document.getElementById) 
		return document.getElementById(id);
	else
	{
		alert("DHTML support not found.");
		return false;
	}
}

function GetInputValue(ID)
{
	var obj;

	obj = GetObjectByID(ID);

	return obj.value;
}

function GetMouseX()
{
	return window.event.x;
}

function GetMouseY()
{
	return window.event.y;
}

function LoadImages()
{
	if (document.images)
	{
		var i,
			args = LoadImages.arguments;

		for (i = 0; i < args.length; i++)
		{
			ImageArray[args[i]] = new Image();
			ImageArray[args[i]].src = args[i + 1];
		}
	}
}

function ChangeImages()
{
	if (document.images)
	{
		var i,
			args = ChangeImages.arguments,
			imgObject;

		for (i = 0; i < args.length - 1; i+=2)
		{
			imgObject = GetObjectByID(args[i]);
			imgObject.src = ImageArray[args[i + 1]].src;
		}
	}
}

/*****************************************************************************************

Parameters:

First:		hRef
Second:		Parameter name
Third:		New value
fourth:		Parameter name 2
fifth:		New value 2
and so on...

Notes:

if new value is set to '' then the parameter is removed

*****************************************************************************************/

function ModifyParams()
{
	var PARAM_SEP = '&';
	var URL_SEP	= '?';
	var VALUE_SEP	= '=';

	var strArray = new Array(),
		strParam = new Array(),
		found = false,
		i,
		j,
		args = ModifyParams.arguments;

	// If there is no URL_SEP, add it to force to have 2 values in the array
	if (args[0].indexOf(URL_SEP) == -1)
		args[0] += URL_SEP;

	strArray = args[0].split(URL_SEP);

	strParam = strArray[1].split(PARAM_SEP);

	// Loop thru each function params
	for (j = 1; j < args.length; j += 2)
	{
		// Loop thru each href params
		for (i = 0; i < strParam.length; i++)
		{
			// If there is nothing is strParam, force to replace the current empty param
			if (strParam[i].length == 0 && i == 0)
				strParam[i] = args[j];

			if (strParam[i].split(VALUE_SEP)[0].toLowerCase() == args[j].toLowerCase())
			{
				found = true;
				break;
			}
		}
		// If the specified param is found in the hRef params
		if (found)
			if (args[j + 1].length == 0)
				strParam = RemoveArrayItem(strParam, i);					// If the New value is '', delete this param
			else
				strParam[i] = args[j] + VALUE_SEP + args[j + 1];			// else replace the param
		else
			strParam[strParam.length] = args[j] + VALUE_SEP + args[j + 1];	// add the param
	}
	// rebuild the href
	strArray[1] = strParam.join(PARAM_SEP);
	return strArray.join(URL_SEP);
}

function RemoveArrayItem(sArray, index)
{
	eval('sArray.splice(' + index + ', 1)');
	return sArray
}