Array.prototype.removeItem = function removeItem(item) {
	for (var j = 0; j < this.length; ) if (this[j] == item) this.splice(j, 1); else j++;
};

ujf = {};
ujf.event = {
	_loaded: false,
	_onLoad: new Array(),
	_onUnload: new Array(),
	_onResize: new Array(),
	addOnLoad: function(f, late) {
		this._onLoad.push(f);
		if (this._loaded && (late || late == null)) f();
	},
	addOnUnload: function(f) { this._onUnload.push(f); },
	addOnResize: function(f) { this._onResize.push(f); },
	removeOnLoad: function(f) { this._onLoad.removeItem(f); },
	removeOnUnload: function(f) { this._onUnload.removeItem(f); },
	removeOnResize: function(f) { this._onResize.removeItem(f); },
	callOnLoad: function() { ujf.event._loaded = true; ujf.event.callEach(ujf.event._onLoad); },
	callOnUnload: function() { ujf.event.callEach(ujf.event._onUnload); },
	callOnResize: function() { ujf.event.callEach(ujf.event._onResize); },
	callEach: function(a) { for (var i = 0; i < a.length; i++) a[i](); }
};
window.onload = ujf.event.callOnLoad;
window.onunload = ujf.event.callOnUnload;
window.onresize = ujf.event.callOnResize;

ujf.json = {
	decode: function(str) {
		return eval('(' + str + ')');
	}
};

ujf.ajax = {
	_xmlHttp: null,
	_currentCall: null,
	_pendingCalls: Array(),
	_isIE: false,
	
	_getXmlHttpObject: function() {
		try { return new XMLHttpRequest(); } catch (e) { }
		this._isIE = true;
		try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { }
		try { return new ActiveXObject("MSXML2.XMLHTTP.5.0"); } catch (e) { }
		try { return new ActiveXObject("MSXML2.XMLHTTP.4.0"); } catch (e) { }
		try { return new ActiveXObject("MSXML2.XMLHTTP.3.0"); } catch (e) { }
		try { return new ActiveXObject("MSXML2.XMLHTTP"); } catch (e) { }
		return null;
	},
	_encodeFormToURI: function(form) {
		var Fields = new Array();
		for (var i = 0; i < Form.length; i++) {
			var Element = Form.elements[i];
			var Value = null;
			switch (Element.type) {
				case 'checkbox':
					if (Element.checked) Value = Element.value ? Element.value : 1;
					break;
				default:
					Value = Element.value;
			}
			if (Value && Element.name) Fields[i] = encodeURIComponent(Element.name) + "=" + encodeURIComponent(Value);
		}
		return Fields.join('&');
	},
	_request: function(url, opt) {
		var req = {url: url, opt: opt};
	},
	_execRequest: function() {
		var req;
		try {
			if (this._xmlHttp == null || this._isIE) this._xmlHttp = Ajax_GetXmlHttpObject();
			if (this._xmlHttp == null) {
				alert("Your browser does not support AJAX!");
				return false;
			}
			//xmlHttp.overrideMimeType('text/html');
			xmlHttp.abort();
			xmlHttp.onreadystatechange = this._stateChangedCallback;
			xmlHttp.open(req.Method, req.URI, true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			if (req.Post) xmlHttp.setRequestHeader("Content-length", req.Post.length);
			xmlHttp.send(req.Post);
		} catch (e) {
			Target.innerHTML = e;
		}
		return false;
	},
	_stateChangedCallback: function()  {
		if (xmlHttp.readyState == 3) {
		} else if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				//xmlHttp.responseText;
			} else {
				/*if (AJAXTarget != null) {
					AJAXTarget.innerHTML = "There was a problem while retrieving the XML data: " + xmlHttp.status + "<br>\n" + xmlHttp.statusText;
				} else {*/
				alert("There was a problem while retrieving the XML data:\n" + xmlHttp.status + " " + xmlHttp.statusText);
			}
		}
	}
};

ujf.html = {};
ujf.html.htmlentities = function(text) {
	if (text == null) return '';
	return text.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
};