//Copyright 2007 www.chatlb.net
//Version 1.0
String.prototype.TrimLeft=function()
{
	return this.replace(/^(\s|\xA0|&nbsp;)*/,"");
};
String.prototype.TrimRight=function()
{
	return this.replace(/(\s|\xA0|&nbsp;)*$/,"");
};
String.prototype.Trim=function()
{
	return this.TrimLeft().TrimRight();
};
String.prototype.Format = function()
{
	var s=this;
	for(var i=0;i<arguments.length;i++)
	{
		var reg = new RegExp("\\\{"+i+"\\\}","g");
		s=s.replace(reg,arguments[i]);
	}
	return s;
}
function Dimension(el)
{
	this.width = el.offsetWidth;
	this.height = el.offsetHeight;
}
function GetPosition(el)
{
	var l=el.offsetLeft,t=el.offsetTop;
	while ((el = el.offsetParent) != null)
	{
		l+=el.offsetLeft;
		t+=el.offsetTop;
	}
	var obj = {
		"top": t, "left": l
	};
	return obj;
};
function HideInfoPopup()
{
	var div = document.getElementById("PopupInfo");
	if(!div)
		return;
	div.style.visibility = "hidden";
}
function InfoPopup(field, text)
{
	var div = document.getElementById("PopupInfo");
	if(!div)
		return;
	
	div.innerHTML = text;
	var pos = GetPosition(field);
	var dim = new Dimension(field);
	
	div.style.top = pos.top - 60 + "px";
	div.style.left = pos.left + dim.width -20 + "px";
	div.style.visibility = "visible";
}
function Trank(str,length)
{
	return str.substring(0, length);
}
function InitFormValue(f, v)
{
	switch(f.type)
	{
		case "file":
			break;
		case "select-one":
			for(var j = 0; j < f.options.length; j++)
			{
				if(f.options[j].value == v)
				{
					f.options[j].selected = true;
					break;
				}
			}
			break;
		case "checkbox":
			f.checked = v;
			break;
		case "radio":
			f.checked = v;
			break;
		default:
			f.value=value;
			break;
	}
}
function REncode(str)
{
	return str.replace(/\(/g, "\\(").replace(/\)/g, "\\)").replace(/\./g, "\\.").replace(/\+/g, "\\+").replace(/\|/g, "\\|").replace(/\\/g, "\\\\").replace(/\"/g, "\\\"").replace(/\^/g, "\\^").replace(/\$/g, "\\$").replace(/\*/g, "\\*").replace(/\?/g, "\\?");
}

function HexToR(h) { return parseInt((cutHex(h)).substring(0,2),16) }
function HexToG(h) { return parseInt((cutHex(h)).substring(2,4),16) }
function HexToB(h) { return parseInt((cutHex(h)).substring(4,6),16) }
function cutHex(h) { return h.replace("#", "")}

function rgb(hex)
{
	return [HexToR(hex), HexToG(hex), HexToB(hex)];
}
