function trim(inputString) {
	if (typeof inputString != "string") { return inputString; }
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) {
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	}
	return retValue;
}

function updateMouseLoader(e) {
	mouseCor=mouseCoords(e);
	mouseX = mouseCor.x;
	mouseY = mouseCor.y;
	var indicator = $('indicator');
	indicator.style.left = (mouseX-42)+'px';
	indicator.style.top = (mouseY-30)+'px';
}



function ShowLoader()
{
	
	
	var browseWidth, browseHeight;
	if (self.innerWidth)
	{
		browseWidth = self.innerWidth;
		browseHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		browseWidth = document.documentElement.clientWidth;
		browseHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		browseWidth = document.body.clientWidth;
		browseHeight = document.body.clientHeight;
	}
	if (document.documentElement && document.documentElement.scrollTop)
	{
		theTop = document.documentElement.scrollTop;
	} else	theTop = document.body.scrollTop;
	if (document.documentElement && document.documentElement.scrollLeft)
	{
		theLeft = document.documentElement.scrollLeft;
	} else	theLeft = document.body.scrollLeft;

	var left = (browseWidth-32)/2 + theLeft;
	var top = (browseHeight-32)/2 + theTop;
	var indicator = $('indicator');
	//indicator.style.top = top+'px';
	//indicator.style.left = left+'px';
	indicator.style.zIndex = 100;
	if (indicator.style.display=='none')
	{
		indicator.style.display = 'block';
	}
}

function HideLoader()
{
	var indicator = $('indicator');
	if (indicator.style.display=='block')
	{
		indicator.style.display = 'none';
	}
}

var jsUtils =
{
	addEvent: function(el, evname, func)
	{
		if(el.attachEvent) // IE
			el.attachEvent("on" + evname, func);
		else if(el.addEventListener) // Gecko / W3C
			el.addEventListener(evname, func, false);
		else
			el["on" + evname] = func;
	},

	removeEvent: function(el, evname, func)
	{
		if(el.detachEvent) // IE
			el.detachEvent("on" + evname, func);
		else if(el.removeEventListener) // Gecko / W3C
			el.removeEventListener(evname, func, false);
		else
			el["on" + evname] = null;
	},

	GetRealPos: function(el)
	{
		if(!el || !el.offsetParent)
			return false;
		var res=Array();
		res["left"] = el.offsetLeft;
		res["top"] = el.offsetTop;
		var objParent = el.offsetParent;
		while(objParent.tagName != "BODY")
		{
			res["left"] += objParent.offsetLeft;
			res["top"] += objParent.offsetTop;
			objParent = objParent.offsetParent;
		}
		res["right"]=res["left"] + el.offsetWidth;
		res["bottom"]=res["top"] + el.offsetHeight;

		return res;
	},

	FindChildObject: function(obj, tag_name, class_name)
	{
		if(!obj)
			return null;
		var tag = tag_name.toUpperCase();
		var cl = (class_name? class_name.toLowerCase() : null);
		var n = obj.childNodes.length;
		for(var j=0; j<n; j++)
		{
			var child = obj.childNodes[j];
			if(child.tagName && child.tagName.toUpperCase() == tag)
				if(!class_name || child.className.toLowerCase() == cl)
					return child;
		}
		return null;
	},

	FindNextSibling: function(obj, tag_name)
	{
		var o = obj;
		var tag = tag_name.toUpperCase();
		while(o.nextSibling)
		{
			var sibling = o.nextSibling;
			if(sibling.tagName && sibling.tagName.toUpperCase() == tag)
				return sibling;
			o = sibling;
		}
		return null;
	},

	FindPreviousSibling: function(obj, tag_name)
	{
		var o = obj;
		var tag = tag_name.toUpperCase();
		while(o.previousSibling)
		{
			var sibling = o.previousSibling;
			if(sibling.tagName && sibling.tagName.toUpperCase() == tag)
				return sibling;
			o = sibling;
		}
		return null;
	},

	FindParentObject: function(obj, tag_name)
	{
		var o = obj;
		var tag = tag_name.toUpperCase();
		while(o.parentNode)
		{
			var parent = o.parentNode;
			if(parent.tagName && parent.tagName.toUpperCase() == tag)
				return parent;
			o = parent;
		}
		return null;
	},

	IsIE: function()
	{
		return (document.attachEvent && !this.IsOpera());
	},

	IsOpera: function()
	{
		return (navigator.userAgent.toLowerCase().indexOf('opera') != -1);
	},

	ToggleDiv: function(div)
	{
		var style = document.getElementById(div).style;
		if(style.display!="none")
			style.display = "none";
		else
			style.display = "block";
		return (style.display != "none");
	},

	urlencode: function(s)
	{
		return escape(s).replace(new RegExp('\\+','g'), '%2B');
	},

	OpenWindow: function(url, width, height)
	{
		var w = screen.width, h = screen.height;
		if(this.IsOpera())
		{
			w = document.body.offsetWidth;
			h = document.body.offsetHeight;
		}
		window.open(url, '', 'status=no,scrollbars=yes,resizable=yes,width='+width+',height='+height+',top='+Math.floor((h - height)/2-14)+',left='+Math.floor((w - width)/2-5));
	},
	
	SetPageTitle: function(s)
	{
		document.title = phpVars.titlePrefix+s;
		var h1 = document.getElementsByTagName("H1");
		if(h1)
			h1[0].innerHTML = s;
	},

	LoadPageToDiv: function(url, div_id)
	{
		var div = document.getElementById(div_id);
		if(!div)
			return;
		CHttpRequest.Action = function(result)
		{
			CloseWaitWindow();
			div.innerHTML = result;
		}
		ShowWaitWindow();
		CHttpRequest.Send(url);
	},

	trim: function(s)
	{
		var r, re;
		re = /^[ \r\n]+/g;
		r = s.replace(re, "");
		re = /[ \r\n]+$/g;
		r = r.replace(re, "");
		return r;
	},
	
	Redirect: function(args, url)
	{
		var e = null, bShift = false;
		if(args.length > 0)
			e = args[0];
		if(!e)
			e = window.event;
		if(e) 
			bShift = e.shiftKey;

		if(bShift) 
			window.open(url); 
		else 
		{
			ShowWaitWindow();
			window.location=url;
		}
	},

	False: function(){return false;},

	AlignToPos: function(pos, w, h)
	{
		var x = pos["left"], y = pos["bottom"];

		var body = document.body;
		if((body.clientWidth + body.scrollLeft) - (pos["left"] + w) < 0)
		{
			if(pos["right"] - w >= 0 )
				x = pos["right"] - w;
			else
				x = body.scrollLeft;
		}

		if((body.clientHeight + body.scrollTop) - (pos["bottom"] + h) < 0)
		{
			if(pos["top"] - h >= 0)
				y = pos["top"] - h;
			else
				y = body.scrollTop;
		}
		
		return {'left':x, 'top':y};
	}
}
