//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 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($(document).width(), $(window).width()) : $(window).width();
}

function GetViewHeight(full)
{
	if(!jQuery)
		return null;
	return full ? Math.max($(document).height(), $(window).height()) : $(window).height();
}
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) + "px";
	div.style.left = (parseInt(__ZoomStartX) +  parseInt(__ZoomStartW) - parseInt(__ZoomStartW)*__popCurrentZoom/100) + "px";
	
	setTimeout(ZoominPopup, 10);
}
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 HideInfoPopup()
{
	FadeOutPopup();
}
function InfoPopup(field, text)
{
	__popCurrentFade = 0;
	var div = document.getElementById("PopupInfo");
	if(!div)
		return;

	div.innerHTML = text;
	var $field = $(field);
	var pos = $field.offset();
	var dim = {
		width: $field.width(),
		height: $field.height()
	};
	
	div.style.top = pos.top + "px";
	div.style.left = pos.left + dim.width - 20 - 326 + "px";
	FadeInPopup();
}
function Trank(str, l, end)
{
	str = str.replace(/<[^>]+>/g, "");
	if (str.Length > l){
		str = str.substring(0, l - 3);
		var regex = /\s([a-z_0-9.])*$/;
		return regex.Replace(str, end);
	}
	return str.substring(0, l);
}
function FadeInPopup()
{
	var div = $("#PopupInfo");
	div.css({visibility: "visible", display: "none"});
	div.fadeIn(600);
}
function FadeOutPopup()
{
	var div = $("#PopupInfo");
	div.fadeOut(600);
}