function getElementsByClassName(node, className) {
	var children = node.getElementsByTagName('*');
	var elements = new Array();
	for (var i=0; i<children.length; i++) {
		var child = children[i];
		var classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}

var notspace = /\S/;
cleanWhitespace = function(node){
	for (var x=0; x<node.childNodes.length; x++) {
		var child = node.childNodes[x];
		//if it's a whitespace text node
		if ((child.nodeType == 3) && (!notspace.test(child.nodeValue)))	{
			node.removeChild(node.childNodes[x]);
			//node.childNodes[x].removeNode();
			x--;
		}
		//elements can have text child nodes of their own
		if(child.nodeType == 1) {
			cleanWhitespace(child);
		}
	}
}
String.prototype.isset=function()
	{
	if(typeof this!="undefined" && this.value!="")
		return true;
	return false;
	}
String.prototype.toObj=function()
	{
	var q=this.split("&");
	var obj=new Object();
	for(var i=0;i<q.length;i++)
		{
		var vars=q[i].split("=");
		if(!vars.length && !i)
			return obj;
		var variable=vars[0];
		delete vars[0];
		value=vars.join("=").substr(1);
		obj[decodeURIComponent(variable)]=decodeURIComponent(value);
		}
	return obj;
	}
Object.prototype.toStr=function()
	{
	var str="";
	for(v in this)
		{
		if(typeof this[v]=="function" || v=="")
			continue;
		str+=encodeURIComponent(v)+"="+encodeURIComponent(this[v])+"&";
		}
	return str.substr(0,str.length-1);
	}
String.prototype.str_replace=function(char,char2)
	{
	if(char2==null)
		char2="";
	return this.split(char).join(char2);
	}
String.prototype.trim = function()
	{
	return this.replace(/^\s*|\s*$/g,"");
	};
String.prototype.ToHTML = function()
	{
	return this.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>").replace(/  /g, "&nbsp; ");
	};
String.prototype.ToTEXT = function()
	{
	return this.replace(/\&amp;/g,"&").replace(/\&lt;/g,"<").replace(/&gt;/g,">").replace(/<br>/g,"\n").replace(/\&nbsp;/g, " ");
	};
String.prototype.makeClickable = function()
	{
	var lines = this.split("<br>");
	for(var z=0; z<lines.length; z++)
		{
		var tmp = lines[z].split(" ");
		for(var i=0; i<tmp.length; i++)
			{
			if(tmp[i].indexOf("www.")!=-1 && tmp[i].indexOf("http://")==-1 && tmp[i].indexOf("https://")==-1)
				tmp[i] = "<a href='http://"+tmp[i]+"' target='_blank'>"+tmp[i]+"</a>";
			else if(tmp[i].indexOf("http://")!=-1 || tmp[i].indexOf("ftp://")!=-1 || tmp[i].indexOf("https://")!=-1)
				tmp[i] = "<a href='"+tmp[i]+"' target='_blank'>"+tmp[i]+"</a>";
			else if (tmp[i].indexOf("@") != -1 && tmp[i].charAt(0) != "@" && tmp[i].charAt(tmp[i].length-1) != "@")
				tmp[i] = "<a href='mailto:"+tmp[i]+"'>"+tmp[i]+"</a>";
			}
		lines[z] = tmp.join(" ");
		}
	return lines.join("<br>");
	}
function setCookie(cookie, str,expires)
	{
	document.cookie = cookie+"="+escape(str)+"; path=/;expires=Fri, 01-Jan-2010 00:00:00 GMT";
	}
function getCookie(cookie) {
	var i1 = document.cookie.indexOf(cookie+"=");
	if(i1<0) return "";
	i1 += cookie.length+1;
	var i2 = document.cookie.indexOf(";", i1);
	if(i2<0) i2 = document.cookie.length;
	return unescape(document.cookie.substring(i1, i2));
}

// ========== REQUEST ====================================================================================================

var Request = new Object();

Request.send = function(url, method, callback, data, urlencoded, name)
	{
	var req;
	if (window.XMLHttpRequest)
		req = new XMLHttpRequest();
	else if (window.ActiveXObject)
		req = new ActiveXObject("Microsoft.XMLHTTP");
	if (typeof name == "undefined")
		name = "";
	else
		name += "\n";
	var readychange = function()
		{
		if(req.readyState == 4)
			{// only if req shows "loaded"
			if(req.status < 400)
				{// only if "OK"
				if (method=="POST")
					{
					callback(req,data);
					delete callback;
					}
				else
					{
					callback(req, data);
					delete callback;
					}
				}
			else if(typeof req == "undefined" || typeof req.status == "undefined")
				// don't do anything. user has navigated away
				delete callback;
			else if (req.status == 401)
				{ // unauthorized
				callback(req);
				delete callback;
				}
			else if (req.status == 404)
				{
				callback(req);
				delete callback;
				}
			else
				{
				//if(App.errorShowing) return false;
				//tool.errorShowing = true;
				switch(req.status)
					{
					// windows error codes
					case 12002: // server timeout
					case 12029: case 12030: case 12031: // dropped connection
					case 12152: // connection closed by server
					case 13030:
						alert(name + _("There was a network problem. Please reload the page."));
						break;
					case 500: case 503:
						alert(name + _("There was an internal server error. Please try later."));
						break;
					default:
						alert(_("There was a problem loading data:") + "\nstatus: " + req.status+ "/" + req.statusText + "\n" + url);
					//tool.errorShowing = false;
					}
				delete callback;
				}
			}
		};
	function do_request()
		{
		if (method=="POST")
			{
			req.open("POST", url, true);
			if (urlencoded) req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.onreadystatechange = readychange;
			req.send(data);
			}
		else
			{
			req.open("GET", url, true);
			req.onreadystatechange = readychange;
			req.send(null);
			}
		};
	do_request();
	return req;
	}

Request.sendRawPOST = function(url, data, callback, name)
	{
	Request.send(url, "POST", callback, data, false, name);
	}
Request.sendPOST = function(url, data, callback, name)
	{
	Request.send(url, "POST", callback, data, true, name);
	}
Request.sendGET = function(url, callback, args, name)
	{
	return Request.send(url, "GET", callback, args, name);
	}
function findPosX(obj) {
	var curleft = 0;
	if (obj && obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj && obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj && obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj && obj.y) curtop += obj.y;
	return curtop;
}
function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
