function $include(file) {
	document.write('<script language="javascript" type="text/javascript" src="' + file + '"></script>');
}

function $css(file) {
	document.write('<link rel="stylesheet" type="text/css" href="' + file + '" />');
}

function $() {
	if (arguments.length == 0)
		return false;
	var el = gEBI(arguments[0]);
	var i = 1;
	while (i < arguments.length) {
		if (arguments[i] == "parent") {
			el = el.parentNode;
			i++;
		} else if ((i + 1) == arguments.length) {
			return gEBTN(el, arguments[i++]);
		} else {
			el = gEBTN(el, arguments[i++], arguments[i++]);
		}
	}
	return el;
}

function gEBI(el) {
	if (typeof el == 'string')
		return document.getElementById(el);
	else
		return el;
}

function gEBTN () {
	if (arguments.length < 2) {
		return false;
	} else if (arguments.length == 2) {
		var els = Array();
		var childs = gEBI(arguments[0]).childNodes;
		var mask = arguments[1].toUpperCase();
		for (var i = 0; i < childs.length; i++) {
			if (mask == "*") {
				if (childs[i].nodeType == 1) {
					els.push(childs[i]);
				}
			} else if (mask == childs[i].nodeName) {
				els.push(childs[i]);
			}
		}
		return els;
	} else {
		var childs = gEBI(arguments[0]).childNodes;
		var mask = arguments[1].toUpperCase();
		var num = arguments[2];
		var j = -1;
		for (var i = 0; i < childs.length; i++)
		{
			if (mask == "*") {
				if (childs[i].NodeType == 1) {
					j++;
				}
			} else if (mask == childs[i].nodeName) {
				j++;
			}
			if (j == num) {
				return childs[i];
			}
		}
	}
}

function $c() {
	if (arguments.length == 0)
		return false;
	var el = document.createElement(arguments[0]);
	if (arguments.length > 1)
	{
		var i;
		for (i in arguments[1])
			el[i] = arguments[1][i];
	}
	if (arguments.length > 2)
		el.innerHTML = arguments[2];
	return el;
}

var $browser = new function() {
	this.agent = navigator.userAgent.toLowerCase();
	this.dom = document.getElementById ? true : false;
	this.opera = (this.agent.indexOf("opera") > -1);
	this.mac = (this.agent.indexOf("mac") > -1);
	this.moz = (this.agent.indexOf("gecko") > -1);
	this.ff = (this.agent.indexOf("firefox") > -1);
	this.ns = (this.agent.indexOf("netscape") > -1);
	this.ie = ((navigator.appVersion.toLowerCase().indexOf("msie") > -1) && this.dom && !this.opera);
	var apver = navigator.appVersion;
	this.ver = (this.ie ? parseFloat(apver.substr(apver.toLowerCase().indexOf("msie") + 5)) : parseInt(apver));
}();

var $ajax = {
	init: function () {
			var res;
			try {
				if ($browser.ie) {
					if ($browser.ver >= 6) {
						res = new ActiveXObject("Microsoft.XMLHTTP");
					} else {
						res = new ActiveXObject("Msxml2.XMLHTTP");
					}
				} else {
					res = new XMLHttpRequest();
				}
			} catch (e) {
				return null;
			}
			return res;
		},
	request: function () {
			try {
				if (arguments.length == 0)
					return;
				var url = arguments[0];
				var req = $ajax.init();
				var data = null;
				if (arguments.length > 1)
					data = $ajax.buildData(arguments[1]);
				if (arguments.length > 2) {
					var onsucc = arguments[2];
					req.onreadystatechange = function () {
						if (req.readyState == 4) {
							if (req.status == 200) {
								onsucc($ajax.parseRespond($ajax.ruDecode(req.responseText)));
							}
						}
					}
				}
				var urlCache = '';
				var cache = false;
				if (arguments.length > 3) {
					cache = arguments[3]
				}
				if (!cache)
					urlCache = (url.indexOf('?') == -1 ? '?' : '&') + 'rTime=' + $time();
				req.open("POST", url + urlCache, true);
				req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				req.setRequestHeader("Content-length", data.length);
				req.setRequestHeader("Connection", "close");
				req.send(data);
			} catch (e) { }
		},
	buildData: function (data) {
			var res = '';
			for (var k in data) {
				if (res.length > 0)
					res += '&';
				res += encodeURI(k) + '=' + encodeURI(data[k]);
			}
			return res;
		},
	parseRespond: function (a) {
			try {
				return (Function("return" + a))()
			} catch(e) {
				return null;
			}
		},
	ruDecode: function (a) {
			var tmp;
			var res = "";
			for (var i = 0; i < a.length; i++) {
				if (a.charAt(i) == '|')
				{
					tmp = a.charAt(++i);
					if (tmp == 'a')
						res += '¨';
					else if (tmp == 'b')
						res += '¸';
					else if (tmp == 'c')
						res += '|';
					else
						res += String.fromCharCode(tmp.charCodeAt(0) + 1007);
				}
				else
					res += a.charAt(i);
			}
			return res;
		},
	formRequest: function () {
			if (arguments.length == 0)
				return;
			var form = arguments[0];
			var id = 'ifrm' + $time('z');
			document.body.appendChild($c( 'div', {}, '<iframe style="display: none" src="about:blank" id="' + id + '" name="' + id + '" onload="loaded(\'' + id + '\');"></iframe>' ));
			var ifrm = $(id);
			form.target = id;
			if (arguments.length > 1)
			{
				var onsucc = arguments[1];
				ifrm.onload = function() {
					var ifrmdoc = window.frames[id].document;
					if (ifrmdoc.location.href != "about:blank") {
						onsucc($ajax.parseRespond($ajax.ruDecode(ifrmdoc.body.innerHTML)));
					}
				}
			}
			form.submit();
		}
}

function $time() {
	var sep = '.';
	if (arguments.length > 0)
		sep = arguments[0];
	var date = new Date();
	return date.getFullYear() + sep
		+ date.getMonth() + sep
		+ date.getDate() + sep
		+ date.getHours() + sep
		+ date.getMinutes() + sep
		+ date.getSeconds() + sep
		+ date.getMilliseconds();
}

