var mouse_x = 0;
var mouse_y = 0;

document.onmousemove =
	function (e) {
		if ((e) && (e.target) && (e.target.tagName) && (e.target.tagName.toLowerCase() == 'option')) return;
		if (document.all) {
			mouse_x = event.clientX;
			mouse_y = event.clientY;
			if ((event.srcElement) && (event.srcElement.tagName) && (event.srcElement.tagName.toLowerCase() == 'select')) mouse_y += 30;
		} else if (document.getElementById){
			mouse_x = e.clientX;
			mouse_y = e.clientY;
		} else if (document.layers) {
			mouse_x = e.x;
			mouse_y = e.y;
		} // end if
		if (window.pageXOffset) {
			mouse_x += window.pageXOffset;
			mouse_y += window.pageYOffset;
		} else {
			var html = document.getElementsByTagName('html')[0];
			mouse_x += html.scrollLeft;
			mouse_y += html.scrollTop;
		} // end if
	} // end event

function CheckAsyncRequest(id) {
	var cursor = document.getElementById('hour_glass' + id);
	if (cursor) {
		if (ajax_wait_message) alert(ajax_wait_message);
		return false;
	} else {
		return true;
	} // end if
} // end function

function StartAsyncRequest(id) {
	var cursor = document.getElementById('hour_glass' + id);
	if (cursor) {
		if (ajax_wait_message) alert(ajax_wait_message);
		return false;
	} else {
		cursor = document.createElement('DIV');
		cursor.id = 'hour_glass' + id;
		cursor.className = ajax_cursor_class_name;
		if ((mouse_x) && (mouse_y)) {
			cursor.style.left = (mouse_x + parseInt((cursor_x_shift) ? cursor_x_shift : 0)) + 'px';
			cursor.style.top = (mouse_y + parseInt((cursor_y_shift) ? cursor_y_shift : 0)) + 'px';
		} // end if
		if (ajax_cursor_html) cursor.innerHTML = ajax_cursor_html;
		document.body.appendChild(cursor);
		return true;
	} // end if
} // end function

function FinishAsyncRequest(id) {
	var cursor = document.getElementById('hour_glass' + id);
	if (cursor) {
		document.body.removeChild(cursor);
	} // end if
} // end function

function HttpRequest(url, post_data, id, event, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) {
	var req = null;
    try {
		req = new XMLHttpRequest();
	} catch(e) {
		req = null;
	} // end try
	if (!req) {
	    try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			req = null;
		} // end try
	} // end if
	if (!req) {
	    try {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			req = null;
		} // end try
	} // end if
	if (req) {
		var can_start = (id) ? StartAsyncRequest(id) : true;
		if (can_start) {
			try {
				req.onreadystatechange =
					function () {
						if (req.readyState == 4) {
							if (id) FinishAsyncRequest(id);
							if (req.status == 200) {
								if (event) event(req.responseText, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
							} else {
								//alert("There was a problem retrieving the XML data:\r\n" + req.statusText);
								var win = window.open('about:blank', 'error_window');
								win.document.write(req.responseText);
							} // end if
						} // end if
					} // end event
				if (Math.random) url = url + (url.indexOf('?') < 0 ? '?' : '&') + 'random=' + escape(Math.random() * 100000);
				if (post_data) {
					req.open("POST", url, true);
					req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					req.send(post_data);
				} else {
					req.open("GET", url, true);
					req.send("");
				} // end if
			} catch(e) {
				if (id) FinishAsyncRequest(id);
			} // end try
		} // end if
	} else {
		alert("XML component not found on your computer.");
	} // end if
} // end function

function XmlRootByText(text) {
	var dom = null;
	try {
		dom = new DOMParser();
		if (dom) dom = dom.parseFromString(text, "text/xml");
		if (dom) dom = dom.documentElement;
	} catch(e) {
		dom = null;
	} // end try
	if (!dom) {
	    try {
			dom = new ActiveXObject("Msxml2.DOMDocument");
			if (!dom.loadXML(text)) dom = null;
			if (dom) dom = dom.firstChild;
		} catch(e) {
			dom = null;
		} // end try
	} // end if
	if (!dom) {
	    try {
			dom = new ActiveXObject("Microsoft.DOMDocument");
			if (!dom.loadXML(text)) dom = null;
			if (dom) dom = dom.firstChild;
		} catch(e) {
			dom = null;
		} // end try
	} // end if
	return dom;
} // end function

function GetXmlAttributeValue(node, attrName) {
	var attr;
	if ((node) && (attr = node.attributes.getNamedItem(attrName))) {
		return attr.value;
	} else {
		return "";
	} // end if
} // end function

function GetXmlNodeValue(node) {
	if ((node) && (node.text)) {
		return node.text;
	} else if ((node) && (node.firstChild) && (node.firstChild.nodeValue)) {
		return node.firstChild.nodeValue;
	} else {
		return "";
	} // end if
} // end function

function GetXmlNodeByTagName(parent, tagName) {
	if ((parent) && (parent.childNodes)) {
		var i;
		for (i = 0; i < parent.childNodes.length; i++) {
			if (parent.childNodes[i].tagName == tagName) return parent.childNodes[i];
		} // end for
	} // end if
	return null;
} // end function

function GetXmlNodesByTagName(parent, tagName) {
	if ((parent) && (parent.childNodes)) {
		return parent.getElementsByTagName(tagName);
	} else {
		return new Array();
	} // end if
} // end function

