//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, 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 displaygallery(i) {
	if (i == liteweb.lastGallery)
		return;
	$(".g-pages a:eq(" + liteweb.lastGallery + ")").removeClass("ac");
	$(liteweb.GalleryList[liteweb.lastGallery]).fadeOut(500);
	$(liteweb.GalleryList[i]).fadeIn(1500);
	liteweb.lastGallery = i;
	$(".g-pages a:eq(" + i + ")").addClass("ac");
}
function addStyle(name, rules) {
	var node = document.createElement("style");
	node.setAttribute("type", "text/css");
	var text = "{0}{{1}}".Format(name, rules);
	var isIE = /msie/i.test(navigator.userAgent);
	if (!isIE)
		node.appendChild(document.createTextNode(text));
	document.getElementsByTagName("head")[0].appendChild(node);
	if (isIE && document.styleSheets && document.styleSheets.length > 0) {
		var lastStyle = document.styleSheets[document.styleSheets.length - 1];
		if (typeof (lastStyle.addRule) == "object")
			lastStyle.addRule(name, rules);
	}
}
function QuickTimeObject(Name, Width, Height, params) {
	return "<EMBED SRC=\"" + Name + "\" WIDTH=\"" + Width + "\" " +
		"HEIGHT=\"" + Height + "\" AUTOPLAY=true CONTROLLER=false LOOP=false HREF=\"" + Name +
		"\" PLUGINSPAGE=\"http://www.apple.com/quicktime/\" />";
}
function displaynews(i) {
	if (i == liteweb.lastNews)
		return;
	$(".n-pages a:eq(" + liteweb.lastNews + ")").removeClass("ac");
	$(liteweb.newsList[liteweb.lastNews]).fadeOut(500);
	$(liteweb.newsList[i]).fadeIn(500);
	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");
}