//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({
		top: -400
	}, {
		duration: 1000
	});
	_popupVisible = false;
}
function InfoPopup(field, text)
{
	var div = document.getElementById("PopupInfo");
	if(!div)
		return;
	
	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  + liteweb.popupHeight + 60,
			left: pos.left - $div.height() - 20,
			height: 0,
			visibility: "visible"
		});
	}
	$div.animate({
		height: liteweb.popupHeight,
		top: pos.top - liteweb.popupHeight - 30,
		left: pos.left - $div.width()
	},	{
		duration: 1000
	});
	_popupVisible = true;
}
function Trank(str,len)
{
	return str.length > len? str.substring(0, len) + (len > 3? "...": ""): str;
}
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 displaynews(i)
{
	if(i == liteweb.lastNews)
		return;
	$(".n-pages a:eq(" + liteweb.lastNews + ")").removeClass("ac");
	$(liteweb.newsList[liteweb.lastNews]).hide("slow");
	$(liteweb.newsList[i]).show("slow");
	liteweb.lastNews = i;
	$(".n-pages a:eq(" + i + ")").addClass("ac");
}
function displaytesti(i)
{
	if(i == liteweb.lastTesti)
		return;
	$(".nav a:eq(" + liteweb.lastTesti + ")").removeClass("ac");
	$(liteweb.testiList[liteweb.lastTesti]).fadeOut("slow");
	$(liteweb.testiList[i]).fadeIn("slow");
	liteweb.lastTesti = i;
	$(".nav a:eq(" + i + ")").addClass("ac");
}
