/***************************************************************************
 *													     functions.js
 *														-------------------
 *	 begin								: Wednesday, August 23, 2006
 *	 copyright						: (C) 2006 alcaeus
 *	 email								: alcaeus@infler.de
 *
 *   Some codes in this file are (C) Daniel R. Wolf of www.delphipraxis.net
 *   All codes used with the author's permission
 *
 ***************************************************************************/

var base_hex = "0123456789ABCDEF";

function convert_rgbcolor(rgb)
{
	var r = 0;
	var g = 0;
	var b = 0;
	var colors = '';
	var pos = 0;
	
	if (rgb.charAt(0) == '#')
	{
		return rgb.toUpperCase();
	}
	
	rgb = rgb.replace(/\s/g, '');
	var len = rgb.length;
	colors = rgb.slice(4, len-1);
	
	pos = colors.indexOf(',');
	if (pos > -1)
	{
		r = colors.slice(0, pos);
		colors = colors.slice(pos+1);
	}
	
	pos = colors.indexOf(',');
	if (pos > -1)
	{
		g = colors.slice(0, pos);
		colors = colors.slice(pos+1);
	}
	
	if (colors != '')
	{
		b = colors;
	}
	
	return RGB2Hex(r, g, b);
}


function dec2Hex(number)
{
	return base_hex.charAt(Math.floor(number / 16)) + base_hex.charAt(number % 16);
}


function openWindow(docURL, wndName, wndWidth, wndHeight, posLeft, posTop)
{
	if (!posLeft)
	{
		var posLeft = (screen.width - wndWidth) / 2;
	}
	if (!posTop)
	{
		var posTop = ((screen.height - wndHeight) / 2)-20;
	}

	var parameters = "width="+wndWidth+",height="+wndHeight+",left="+posLeft+",top="+posTop+",dependent=no,menubar=no,location=no,resizable=yes,scrollbars=yes,status=no";
	window.open(docURL, wndName, parameters);
}


function RGB2Hex(TR, TG, TB)
{
	return '#' + dec2Hex(TR) + dec2Hex(TG) + dec2Hex(TB);
}


function setCheckboxes(theForm, elementName, isChecked)
{
	if (elementName != '')
	{
		var chkboxes = document.forms[theForm].elements[elementName];
	}
	else
	{
		var chkboxes = document.forms[theForm].elements;
	}

	var count = chkboxes.length;
	if (count) 
	{
		for (var i = 0; i < count; i++) 
		{
			chkboxes[i].checked = isChecked;
    }
	} 
	else 
	{
		chkboxes.checked = isChecked;
	} 
	
	return false;
} 


