// set color
// $Id: selcolor.js,v 1.3 2007/11/21 14:05:27 hightman Exp $
function selectColor()
{
	if (arguments.length < 1) return;
	if (arguments.length == 1)
	{
		var argv = document.clrArguments;
		var color = arguments[0];
		
		for (var i = 0; i < argv.length; i++)
		{
			if (typeof argv[i] == 'function')
			{
				argv[i]();
				continue;
			}
			if (!argv[i].tagName) continue;
			if (argv[i].tagName == 'INPUT') argv[i].value = color;
			else if (argv[i].tagName == 'IMG') argv[i].style.backgroundColor = color;
			else if (argv[i].tagName == 'DIV') argv[i].style.borderColor = color;			
		}
		document.clrDiv.style.display = 'none';
		$('frmcolor').style.display='none';
		
		if (typeof demoTab != "undefined") TOI_update()
		if (typeof demoTab1 != "undefined") TOI_update()
		return;
	}
	document.clrArguments = arguments;
	if (!document.clrDiv)
	{
		var oDiv = document.createElement('DIV');
		oDiv.style.display = 'none';
		oDiv.style.position = 'absolute';
		oDiv.style.zIndex = '99';
		document.body.insertBefore(oDiv, document.body.firstChild);
		document.clrDiv = oDiv;

		var aColors = new Array('00', '33', '66', '99', 'CC', 'FF');
		var cRanges = new Array(0, 0, 3, 0, 0, 3, 3, 3);
		try { var oTable = document.createElement('<TABLE cellspacing=0 cellpadding=0>'); }
		catch (e) { var oTable = document.createElement('TABLE'); }
		oTable.border = 0;
		oTable.width = '216';
		oTable.cellSpacing = '0';
		oTable.cellPadding = '0';
		oTable.style.border = '2px inset';

		for (var i = 0; i < cRanges.length; i += 2)
		{
			for (var j = cRanges[i]; j < cRanges[i] + 3; j++)
			{
				var oRow = oTable.insertRow(-1);
				for (var k = cRanges[i+1]; k < cRanges[i+1] + 3; k++)
				{
					for (var l = 0; l < 6; l++)
					{
						var oCell = oRow.insertCell(-1);
						var color = '#' + aColors[k] + aColors[l] + aColors[j];
						oCell.bgColor = color;
						oCell.title = color;
						oCell.height = '12';
						oCell.width = '12';
						oCell.onclick = function () { selectColor(this.bgColor); };
					}
				}
			}
		}

		// Gray scale colors
		var oRow = oTable.insertRow(-1);
		for (var n = 0; n < 18; n++)
		{
			var oCell = oRow.insertCell(-1);
			var k = n % 6;
			var color = '#' + aColors[k] + aColors[k] + aColors[k];
			oCell.bgColor = color;
			oCell.height = '12';
			oCell.width = '12';
			if (n == 17)
			{
				oCell.title = 'Close the color pannel';
				oCell.onclick = function () { document.clrDiv.style.display = 'none'; $('frmcolor').style.display='none';}
				oCell.innerHTML = '<a href="javascript:void(0)"><font color="#ff0000">X</font></a>';
				oCell.align = 'center';
			}
			else
			{
				oCell.title = color;
				oCell.onclick = function () { selectColor(this.bgColor); };			
			}
		}
		oDiv.appendChild(oTable);	
	}

	var lt = arguments.length - 1;
	var ev = arguments[lt];
	var xpos, ypos;
	if (ev.pageX)
	{
		xpos = ev.pageX;
		ypos = ev.pageY;
	}
	else
	{
		xpos = document.body.scrollLeft + ev.clientX;
		ypos = document.body.scrollTop + ev.clientY;
	}

	document.clrDiv.style.left =  (xpos + 2) + 'px';
	document.clrDiv.style.top =  (ypos + 2) + 'px';
	document.clrDiv.style.display = '';
	
	$('frmcolor').style.pixelLeft=document.clrDiv.style.pixelLeft;
    $('frmcolor').style.pixelTop=document.clrDiv.style.pixelTop;
    $('frmcolor').style.display=document.clrDiv.style.display;
	$('frmcolor').style.width = '216px';
	$('frmcolor').style.height = '162px';
}

