

if(window.ActiveXObject&&!window.XMLHttpRequest)
{
	window.XMLHttpRequest=function()
	{
		return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf("msie 5")!=-1)?"Microsoft.XMLHTTP":"Msxml2.XMLHTTP");
	};
}

global_fakeOperaXMLHttpRequestSupport=false;

if(window.opera&&(!window.XMLHttpRequest||!(new window.XMLHttpRequest()).setRequestHeader))
{
	global_fakeOperaXMLHttpRequestSupport=true;
	window.XMLHttpRequest=function()
	{
		this.readyState=0;
		this.status=0;
		this.statusText="";
		this._headers=[];
		this._aborted=false;
		this._async=true;
		this.abort=function()
		{
			this._aborted=true;
		};
		this.getAllResponseHeaders=function()
		{
			return this.getAllResponseHeader("*");
		};
		this.getAllResponseHeader=function(_1)
		{
			var _2="";
			for(var i=0;i<this._headers.length;i++)
			{
				if(_1=="*"||this._headers[i].h==_1)
				{
					_2+=this._headers[i].h+": "+this._headers[i].v+"\n";
				}
			}
			return _2;
		};
		this.setRequestHeader=function(_4,_5)
		{
			this._headers[this._headers.length]={h:_4,v:_5};
		};
		this.open=function(_6,_7,_8,_9,_10)
		{
			this.method=_6;
			this.url=_7;
			this._async=true;
			this._aborted=false;
			if(arguments.length>=3)
			{
				this._async=_8;
			}
			if(arguments.length>3)
			{
				opera.postError("XMLHttpRequest.open() - user/password not supported");
			}
			this._headers=[];
			this.readyState=1;
			if(this.onreadystatechange)
			{
				this.onreadystatechange();
			}
		};
		this.send=function(_11)
		{
			if(!navigator.javaEnabled())
			{
				alert("XMLHttpRequest.send() - Java must be installed and enabled.");
				return;
			}
			if(this._async)
			{
				setTimeout(this._sendasync,0,this,_11);
			}
			else
			{
				this._sendsync(_11);
			}
		};
		this._sendasync=function(req,_13)
		{
			if(!req._aborted)
			{
				req._sendsync(_13);
			}
		};
		this._sendsync=function(_14)
		{
			this.readyState=2;
			if(this.onreadystatechange)
			{
				this.onreadystatechange();
			}
			var url=new java.net.URL(new java.net.URL(window.location.href),this.url);
			var _16=url.openConnection();
			for(var i=0;i<this._headers.length;i++)
			{
				_16.setRequestProperty(this._headers[i].h,this._headers[i].v);
			}
			this._headers=[];
			if(this.method=="POST")
			{
				_16.setDoOutput(true);
				var wr=new java.io.OutputStreamWriter(_16.getOutputStream());
				wr.write(_14);
				wr.flush();
				wr.close();
			}
			var _18=false;
			var _19=false;
			var _20=false;
			var _21=false;
			var _22=false;
			var _23=false;
			for(var i=0;;i++)
			{
				var _24=_16.getHeaderFieldKey(i);
				var _25=_16.getHeaderField(i);
				if(_24==null&&_25==null)
				{
					break;
				}
				if(_24!=null)
				{
					this._headers[this._headers.length]={h:_24,v:_25};
					switch(_24.toLowerCase())
					{
						case "content-encoding":_18=true;
							break;
						case "content-length":_19=true;
							break;
						case "content-type":_20=true;
							break;
						case "date":_21=true;
							break;
						case "expires":_22=true;
							break;
						case "last-modified":_23=true;
							break;
					}
				}
			}
			var val;
			val=_16.getContentEncoding();
			if(val!=null&&!_18)
			{
				this._headers[this._headers.length]={h:"Content-encoding",v:val};
			}
			val=_16.getContentLength();
			if(val!=-1&&!_19)
			{
				this._headers[this._headers.length]={h:"Content-length",v:val};
			}
			val=_16.getContentType();
			if(val!=null&&!_20)
			{
				this._headers[this._headers.length]={h:"Content-type",v:val};
			}
			val=_16.getDate();
			if(val!=0&&!_21)
			{
				this._headers[this._headers.length]={h:"Date",v:(new Date(val)).toUTCString()};
			}
			val=_16.getExpiration();
			if(val!=0&&!_22)
			{
				this._headers[this._headers.length]={h:"Expires",v:(new Date(val)).toUTCString()};
			}
			val=_16.getLastModified();
			if(val!=0&&!_23)
			{
				this._headers[this._headers.length]={h:"Last-modified",v:(new Date(val)).toUTCString()};
			}
			var _27="";
			var _28=_16.getInputStream();
			if(_28)
			{
				var _29=new java.io.BufferedReader(new java.io.InputStreamReader(_28));
				var _30;
				while((_30=_29.readLine())!=null)
				{
					if(this.readyState==2)
					{
						this.readyState=3;
						if(this.onreadystatechange)
						{
							this.onreadystatechange();
						}
					}
					_27+=_30+"\n";
				}
				_29.close();
				this.status=200;
				this.statusText="OK";
				this.responseText=_27;
				this.readyState=4;
				if(this.onreadystatechange)
				{
					this.onreadystatechange();
				}
				if(this.onload)
				{
					this.onload();
				}
			}
			else
			{
				this.status=404;
				this.statusText="Not Found";
				this.responseText="";
				this.readyState=4;
				if(this.onreadystatechange)
				{
					this.onreadystatechange();
				}
				if(this.onerror)
				{
					this.onerror();
				}
			}
		};
	};
}

if(!window.ActiveXObject&&window.XMLHttpRequest)
{
	window.ActiveXObject=function(_31)
	{
		switch(_31.toLowerCase())
		{
			case "microsoft.xmlhttp":
			case "msxml2.xmlhttp":
				return new XMLHttpRequest();
		}
		return null;
	};
}

// Create HttpRequest Object
function MakeHttpRequest(progId)
{
	if(!progId)
		progId = "microsoft.xmlhttp";
	var xmlhttp;
	xmlhttp = new ActiveXObject(progId);
	return xmlhttp;
}

function PostRequest(url, postXml)
{
	xmlhttp = MakeHttpRequest();
	xmlhttp.open("POST", url, false);
	if(!postXml)
		xmlhttp.send("");
	else if(typeof(postXml) == "object")
		xmlhttp.send(postXml.xml);
	else
		xmlhttp.send(postXml);
	if(CheckRequestReturn(xmlhttp) != false)
		return xmlhttp.responseText;
	else
		return null;
}

function AjaxRequest(url, postXml, callBackFunction, infoToCallBack, bRetDOM)
{
	xmlhttp = MakeHttpRequest();
	xmlhttp.open("POST", url, true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(CheckRequestReturn(xmlhttp) != false)
			{
				if(callBackFunction)
				{
					if(bRetDOM)
						callBackFunction(xmlhttp, infoToCallBack, true);
					else
						callBackFunction(xmlhttp.responseText, infoToCallBack, true);
				}
			}
			xmlhttp = null;
		}
	};
	if(!postXml)
		xmlhttp.send("");
	else if(typeof(postXml) == "object")
		xmlhttp.send(postXml.xml);
	else
		xmlhttp.send(postXml);
}

function AjaxRequestObject(url, postXml, callBackFunction, infoToCallBack, bRetDOM)
{
	var xmlhttp = null;
	xmlhttp = MakeHttpRequest();
	xmlhttp.open("POST", url, true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
			if(CheckRequestReturn(xmlhttp) != false)
			{
				if(callBackFunction)
				{
					if(bRetDOM)
						callBackFunction(xmlhttp.responseXML, infoToCallBack, true);
					else
						callBackFunction(xmlhttp.responseText, infoToCallBack, true);
				}
			}
			xmlhttp = null;
		}
	};
	this.Load = function()
	{
		if(!postXml)
			xmlhttp.send("");
		else if(typeof(postXml) == "object")
			xmlhttp.send(postXml.xml);
		else
			xmlhttp.send(postXml);
	};
}

function CheckRequestReturn(xmlhttp)
{
	return true;
}

//////////////////////////////////////////////////////////////////////////// XML DOM Document Part

function MakeDOM(progId)
{
	var dom = null;
	try
		{dom = document.implementation.createDocument("","",null);}
	catch(e)
		{try
			{dom = document.implementation.createHTMLDocument("");}
		catch(e)
			{if(!progId) progId = "msxml2.DOMDocument.3.0";
				dom = new ActiveXObject(progId);}}
	dom.async = false;
	dom.validateOnParse = false;
	dom.resolveExternals = false;
	return dom;
}

function LoadDOMXml(xmlStr)
{
	var dom = null;
	try
	{
		dom = (new DOMParser()).parseFromString(xmlStr, 'text/xml');
	}
	catch(e)
	{
		dom = MakeDOM();
		dom.loadXML(xmlStr);
	}
	return dom;
}

function GetNodeValue(xml, nodeName)
{
	var ret = false;
	try
	{
		ret = xml.selectSingleNode("//"+nodeName);
		if(ret)
			ret = ret.text;
		else
			ret = "";
	}
	catch(e)
	{
		ret = xml.evaluate("//"+nodeName,xml,null,XPathResult.STRING_TYPE,null);
		if(ret)
			ret = ret.stringValue;
		else
			ret = "";
	}
	return ret;
}

//To handle missing attribute and XPath starts with "//"
function SetNodeValue(xmlDoc, path, newVal)
{
	g_currFunction = "1501";
	newVal = trim(newVal);
	var node = xmlDoc.selectSingleNode(path);
	if (node != null)
	{
		node.text = newVal;
	}
	else if(path.charAt(0) == '@')
	{
		xmlDoc.setAttribute(path.substring(1),newVal);
	}
	else
	{        
		var currentPath = "";
		var nodesArray = path.split("/");
		
		for(var i=0; i<nodesArray.length; i++)
		{
			if(nodesArray[i]=="") {
				currentPath += "/";
				continue;
			}
			var parentNode = (currentPath == "/" || currentPath == "//")? xmlDoc: xmlDoc.selectSingleNode(currentPath);
		    
			currentPath += currentPath.charAt(currentPath.length-1)=='/'? nodesArray[i]: "/" + nodesArray[i];
			var selNode = xmlDoc.selectSingleNode(currentPath);
			if (selNode == null)
			{
				if(nodesArray[i].charAt(0) == '@') {
					parentNode.setAttribute(nodesArray[i].substring(1), newVal);
					node = parentNode;
					break;
				}    
				else {
					var newNode;
					if(xmlDoc.ownerDocument == null)
						newNode = xmlDoc.createElement(nodesArray[i]);
					else
						newNode = xmlDoc.ownerDocument.createElement(nodesArray[i]);
		                
					parentNode.appendChild(newNode);
					if(i == nodesArray.length-1) {
						newNode.text = newVal;
						node = newNode;
					}
				}
			}
		}
	}
	return node;
}