//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;
}
var __popCurrentFade = 0;
var __popCurrentZoom = 0;
var __ZoomStartX, __ZoomStartY;
var __ZoomStartW, __ZoomStartH;
function ZoomoutPopup() {
	var div = document.getElementById("PopupInfo");
	if (!div)
		return;
	__popCurrentZoom -= 10;
	div.style.zoom = __popCurrentZoom + "%";
	if (__popCurrentZoom < 10) {
		div.style.visibility = "hidden";
		return;
	}
	div.style.top = parseInt(__ZoomStartY) + 20 + "px";
	div.style.left = (parseInt(__ZoomStartX) + parseInt(__ZoomStartW) - 35 - parseInt(__ZoomStartW) * __popCurrentZoom / 100) + "px";

	setTimeout(ZoomoutPopup, 10);
}
function ZoominPopup() {
	var div = document.getElementById("PopupInfo");
	if (!div)
		return;

	if (__popCurrentZoom >= 100)
		return;

	if (__popCurrentZoom == 0)
		div.style.visibility = "visible";

	__popCurrentZoom += 10;
	div.style.zoom = __popCurrentZoom + "%";

	div.style.top = (parseInt(__ZoomStartY) + parseInt(__ZoomStartH) - parseInt(div.offsetHeight) + (120 - 120 * __popCurrentZoom / 100)) + "px";
	div.style.left = (parseInt(__ZoomStartX) + parseInt(__ZoomStartW) - parseInt(__ZoomStartW) * __popCurrentZoom / 100) + "px";

	setTimeout(ZoominPopup, 10);
}
function FadeInPopup() {
	var div = document.getElementById("PopupInfo");
	if (!div)
		return;

	if (__popCurrentFade > 100) {
		if ("string" == typeof div.style.filter)
			div.style.filter = "";
		return;
	}
	if (__popCurrentFade == 0)
		div.style.visibility = "visible";

	if ("string" == typeof div.style.filter) {
		__popCurrentFade += 10;
		div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity={0})".Format(__popCurrentFade);
	}
	else {
		__popCurrentFade += 2;
		div.style.opacity = __popCurrentFade / 100;
	}
	setTimeout(FadeInPopup, 10);
}
function FadeOutPopup() {
	var div = document.getElementById("PopupInfo");
	if (!div)
		return;

	if (__popCurrentFade < 0) {
		div.style.visibility = "hidden";
		__popCurrentFade = 0;
		return;
	}

	if ("string" == typeof div.style.filter) {
		__popCurrentFade -= 10;
		div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=2,opacity={0})".Format(__popCurrentFade);
	}
	else {
		__popCurrentFade -= 2;
		div.style.opacity = __popCurrentFade / 100;
	}


	setTimeout(FadeOutPopup, 10);
}
function HideInfoPopup() {

	var div = document.getElementById("PopupInfo");
	if (!div)
		return;

	if ("string" == typeof div.style.filter) {
		__ZoomStartX = div.style.left;
		__ZoomStartY = div.style.top;
		__ZoomStartW = parseInt(div.offsetWidth);
		__ZoomStartH = div.offsetHeight;
		ZoomoutPopup();
	}
	else
		FadeOutPopup();
	return;
	var div = document.getElementById("PopupInfo");
	if (!div)
		return;
	div.style.visibility = "hidden";
}
function InfoPopup(field, text) {
	__popCurrentFade = 0;
	var div = document.getElementById("PopupInfo");
	if (!div)
		return;

	div.innerHTML = text;
	var pos = GetPosition(field);
	var dim = new Dimension(field);

	div.style.top = (parseInt(pos.top) - 130) + "px";
	div.style.left = pos.left + dim.width - 75 - 225 + "px";
	if ("string" == typeof div.style.filter) {
		__ZoomStartX = div.style.left;
		__ZoomStartY = parseInt(div.style.top);
		__ZoomStartW = parseInt(div.offsetWidth);
		__ZoomStartH = div.offsetHeight;
		ZoominPopup();
	}
	else
		FadeInPopup();
	//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 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]";
};