//Copyright 2007 www.liteweb.info
//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 = 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 GetMousePosition(f)
{
	var top = event.y + window.document.body.scrollTop;
	var left = event.x + window.document.body.scrollLeft;
	if(f)
	{
		var pos = GetPosition(f.frameElement);
		top += pos.top;
		left += pos.left;
	}
	var obj = {
		"top": top, "left": left
	};
	return obj;
}
_popupVisible = false;
function HideInfoPopup() {
	var div = document.getElementById("PopupInfo");
	if (!div)
		return;
	$(div).animate({
		height: 1
	}, {
		duration: 300,
		easing: "easeOutCubic",
		complete: function() {
			$(div).css("display", "none");
		}
	});
	_popupVisible = false;
}
function InfoPopup(field, text) {
	var div = document.getElementById("PopupInfo");
	if (!div) {
		div = document.createElement("div");
		div.id = "PopupInfo";
		document.body.insertBefore(div, null);
	}
	div.innerHTML = text;

	var $div = $(div);
	var $field = $(field);
	var pos = $field.offset();

	if (!liteweb.popupHeight)
		liteweb.popupHeight = $div.height();

	if (!_popupVisible) {
		$div.css({
			top: pos.top,
			left: pos.left - $div.width(),
			height: 1,
			visibility: "visible"
		});
	}
	$div.animate({
		height: liteweb.popupHeight,
		top: pos.top,
		left: pos.left - $div.width()
	}
	, {
		duration: 200,
		easing: "easeInCubic"
	});
	_popupVisible = true;
}
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 defined(a)
{
	var ret = (typeof(a)=="undefined");
	if (ret == true) 
	   return false;
	if (typeof(a) == "string" && a=="")
	   return false;
	return (a!=null);
}
function GetViewWidth(full)
{
	if(!jQuery)
		return null;
	return full ? Math.max(jQuery(document).width(), jQuery(window).width()) : jQuery(window).width();
}

function GetViewHeight(full)
{
	if(!jQuery)
		return null;
	return full ? Math.max(jQuery(document).height(), jQuery(window).height()) : jQuery(window).height();
}


function GetAjaxObject(obj)
{
	if(obj.responseXML != null && obj.responseXML.xml != null && obj.responseXML.xml != '')
		return obj.responseXML;
	
	var r = null;
	try
	{
		eval("r=" + obj.responseText + ";");
	}
	catch(e)
	{
		return request.obj.responseText;
	}
	return r;
};
function ToString(obj){
	try{
		var ar = [];
		for(i in obj){
			ar.push(i + ": " + obj[i]);
		}
		return ar.join("\n");
	}catch(e){};
	return "[Object]";
};