var Ajax = {
	pageContext:new Object(),
	//-----------------------------------------------------------------------------
	displayLoader:function() {
		var body = document.getElementsByTagName("body").item(0);
		if (!Ajax.loaderElement) {
			Ajax.loaderElement = document.createElement("div");
			Ajax.loaderElement.setAttribute("id","ajax-loader");
			Ajax.loaderElement.appendChild(document.createTextNode("loading..."));
		}
                Ajax.loaderElement.displayed=true;
		body.appendChild(Ajax.loaderElement);
	},
	//-----------------------------------------------------------------------------
	hideLoader:function() {
		if (Ajax.loaderElement && Ajax.loaderElement.displayed) {
			var body = document.getElementsByTagName("body").item(0);
			body.removeChild(Ajax.loaderElement);
                        Ajax.loaderElement.displayed=false;
		}
	},
	//----------------------------------------------------------------------------
	getXMLHttpRequest:function() {
		var xmlHttpRequest = false;
	    // branch for native XMLHttpRequest object
	    if(window.XMLHttpRequest) {
	    	try {
				xmlHttpRequest = new XMLHttpRequest();
	        } catch(e) {
				xmlHttpRequest = false;
	        }
	    // branch for IE/Windows ActiveX version
	    } else if(window.ActiveXObject) {
	     	try {
	      	xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	    	} catch(e) { 
		      	try {
		        		xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		      	} catch(e) {
		        		xmlHttpRequest = false;
		      	}
			}
	    }
	    return xmlHttpRequest;
	},
	//----------------------------------------------------------------------------
	loadXMLHttpRequest:function(url) {
		var xmlHttpRequest = Ajax.getXMLHttpRequest();
		if (xmlHttpRequest) {	
			xmlHttpRequest.open("GET", url, false);
			//xmlHttpRequest.setHeader("Cache-Control", "no-cache");
			//xmlHttpRequest.setRequestHeader("Pragma","no-cache");
			xmlHttpRequest.send(null);
			return xmlHttpRequest;
		}
	},
	//----------------------------------------------------------------------------
	loadXMLHttpRequestAsync:function(url, callback, param) {
		var xmlHttpRequest = Ajax.getXMLHttpRequest();
		if (xmlHttpRequest) {	
			xmlHttpRequest.onreadystatechange = function() {
				if (xmlHttpRequest.readyState == 4) {
					callback(xmlHttpRequest, param);
				}
			}
			xmlHttpRequest.open("GET", url, true);
			//xmlHttpRequest.setHeader("Cache-Control", "no-cache");
			//xmlHttpRequest.setRequestHeader("Pragma","no-cache");
			xmlHttpRequest.send("");
		}
	},
	//----------------------------------------------------------------------------
	loadXML:function(url) {
		return Ajax.loadXMLHttpRequest(url).responseXML;
	},
	//----------------------------------------------------------------------------
	postXML:function(url, xmlDoc) {
		var xmlHttpRequest = Ajax.getXMLHttpRequest();
		if (xmlHttpRequest) {	
			xmlHttpRequest.open("POST", url, false);
			//xmlHttpRequest.setRequestHeader("Pragma","no-cache");
			xmlHttpRequest.send(xmlDoc);
			return xmlHttpRequest;
		}
	},
	//----------------------------------------------------------------------------
	postXMLAsync:function(url, xmlDoc, callback, param) {
		var xmlHttpRequest = Ajax.getXMLHttpRequest();
		if (xmlHttpRequest) {	
			xmlHttpRequest.onreadystatechange = function() {
				if (xmlHttpRequest.readyState == 4) {
					callback(xmlHttpRequest, param);
				}
			}
			xmlHttpRequest.open("POST", url, true);
			//xmlHttpRequest.setRequestHeader("Pragma","no-cache");
			xmlHttpRequest.send(xmlDoc);
		}
	},
	//----------------------------------------------------------------------------
	getXMLDocument:function(xmlHttpRequest) {
		//var xmlDocument = xmlHttpRequest.responseXML;
		//if (!xmlDocument.documentElement) {
			xmlDocument = Ajax.parse(xmlHttpRequest.responseText);
		//}
		//
		return xmlDocument;
	},
	//----------------------------------------------------------------------------
	loadText:function(url) {
		return Ajax.loadXMLHttpRequest(url).responseText;
	},
	//----------------------------------------------------------------------------
	getElementById:function(id) {
		var node = this;
		while (node!=null) {
			var node1 = node;
			while (node1!=null) {
				var node2 = node1;
				while (node2!=null) {
					node1 = node2;
					if (node2.nodeType == 1 && node2.getAttribute("id") == id)
						return node1;
					node2 = node2.firstChild;
				}
				node = node1;
				node1 = node1.nextSibling;
			}
			do {
				node = node.parentNode;
			} while (node!=null && node.nextSibling == null);
			if (node!=null)
				node = node.nextSibling;
		}
		return null;
	},
	//----------------------------------------------------------------------------
	getElementsByClassName:function(node, className) {
		var nodeList = new Array();
		nodeList.item = function(i) {return this[i];};
		var index=0;
		while (node!=null) {
			var node1 = node;
			while (node1!=null) {
				var node2 = node1;
				while (node2!=null) {
					node1 = node2;
					if (node2.nodeType == 1 && (node2.getAttribute("class") == className || node2.className == className))
						nodeList[index++] = node1;
					node2 = node2.firstChild;
				}
				node = node1;
				node1 = node1.nextSibling;
			}
			do {
				node = node.parentNode;
			} while (node!=null && node.nextSibling == null);
			if (node!=null)
				node = node.nextSibling;
		}
		return nodeList;
	},
	//----------------------------------------------------------------------------
	getElementsByTagName:function(tagName) {
		var node = this;
		var nodeList = new Array();
		nodeList.item = function(i) {return this[i];};
		var index=0;
		while (node!=null) {
			var node1 = node;
			while (node1!=null) {
				var node2 = node1;
				while (node2!=null) {
					node1 = node2;
					if (node2.nodeType == 1 && node2.nodeName == tagName)
						nodeList[index++] = node1;
					node2 = node2.firstChild;
				}
				node = node1;
				node1 = node1.nextSibling;
			}
			do {
				node = node.parentNode;
			} while (node!=null && node.nextSibling == null);
			if (node!=null)
				node = node.nextSibling;
		}
		return nodeList;
	},
	//--------------------------------------------------------------------------
	importNode:function(node, deep, doc) {
		if (!doc)
			doc = this;
		switch (node.nodeType) {
			case 1:
				var newNode = doc.createElement(node.nodeName);
				var attrList = node.attributes;
				if (attrList != null) {
					var newAttrList = newNode.attributes;
					for (var i=0; i<attrList.length; i++) {
						var attr = doc.createAttribute(attrList.item(i).name);
						attr.value = attrList.item(i).value;
						newAttrList.setNamedItem(attr);
					}
				}
				if (deep) {
					var nodeList = node.childNodes;
					for (var i=0; i<nodeList.length; i++) {
						var node = Ajax.importNode(nodeList.item(i), true, doc);
						if (node!=null)
							newNode.appendChild(node);
					}
				}
				return newNode;
			case 2:
				var attr = doc.createAttribute(node.name);
				attr.value = node.value;
				return attr;
			case 3:
				return doc.createTextNode(node.nodeValue);
			default: 
				return null;
		}
	},
	//--------------------------------------------------------------------------
	parse:function(xmlString) {
		var xmlDocument = false;
		// branch for native XMLHttpRequest object
		if (window.DOMParser) {
			try {
				var parser = new DOMParser();
				xmlDocument = parser.parseFromString(xmlString, "text/xml");
			} catch(e) {
				xmlDocument = false;
			}
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			try {
				xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
				xmlDocument.async = "false";
				xmlDocument.validateOnParse = "false";
				xmlDocument.resolveExternals = "false";
				xmlDocument.loadXML(xmlString);
			} catch(e) {
				try {
					xmlDocument = new ActiveXObject("Msxml2.XMLDOM");
					xmlDocument.async = "false";
					xmlDocument.validateOnParse = "false";
					xmlDocument.resolveExternals = "false";
					xmlDocument.loadXML(xmlString);
				} catch(e) {
					xmlDocument = false;
				}
			}
			if (xmlDocument) {
				var documentElement = xmlDocument.documentElement
				xmlDocument = new Object();
				xmlDocument.nodeName = "#document";
				xmlDocument.nodeType = 9;
				xmlDocument.firstChild = documentElement;
				xmlDocument.documentElement = documentElement;
				xmlDocument.getElementById = Ajax.getElementById;
				xmlDocument.getElementsByTagName = Ajax.getElementsByTagName;
			}
		}
		return xmlDocument;
	},
	loadUrlParameter:function() {
		Ajax.pageContext.param = new Object();
		var queryString = window.location.search.substring(1);
		var params = queryString.split('&');
		for (var i=0; i<params.length; i++) {
			var index = params[i].indexOf('=');
			if (index > 0) {
				var name = params[i].substring(0,index);
				var value = params[i].substring(index+1);
				Ajax.pageContext.param[name] = value;
			}
		}
	},
	//------------------------------------------------------------------------------
	createXMLDocument:function() {
		var xmlDocument = false;
	    // branch for native XMLHttpRequest object
	    if (document.implementation && document.implementation.createDocument) {
	    	try {
				xmlDocument = document.implementation.createDocument("","", null);
	        } catch(e) {
				xmlDocument = false;
	        }
	    // branch for IE/Windows ActiveX version
	    } else if(window.ActiveXObject) {
	       	try {
	        	xmlDocument = new ActiveXObject("Msxml2.XMLDOM");
	      	} catch(e) {
	        	try {
	          		xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
	        	} catch(e) {
	          		xmlDocument = false;
	        	}
			}
	    }
	    return xmlDocument;
	},
	//------------------------------------------------------------------------------
	onload:function() {
		if (!document.importNode)
			document.importNode = Ajax.importNode;
		Ajax.loadUrlParameter();
	}
};
//------------------------------------------------------------------------------
var LoadEvent = {
	functionList: new Array(),
	add:function(event) {
		LoadEvent.functionList[LoadEvent.functionList.length] = event;
	},
	exec:function() {
		for (var i=0; i<LoadEvent.functionList.length; i++) {
			LoadEvent.functionList[i]();
		}
	}
};
LoadEvent.add(Ajax.onload);
window.onload = LoadEvent.exec;
