if(!window['zw']) window['zw'] = {};

zw.Ajax=function(sUrl, oProcess)
{
	this.url=sUrl;
	this.target=null;
	this.method='POST';
	this.tag=null;
	this.parameters='';
	this.info=null;
	this.req=null;
	this.call=zw.ajaxCall;
	this.cancel=zw.ajaxCancel;
	this.callBack=zw.ajaxCallBack;
	this.process=oProcess;
	this.postProcess=false;
	this.sending=zw.jslng.loading;
	this.tag=false;
	this.working=false;
}

zw.Ahah=function(sUrl, oTarget)
{
	var oAhah=new zw.Ajax(sUrl, null);
	oAhah.target=oTarget;

	return oAhah;
}

zw.ajaxCancel=function()
{

}

zw.ajaxCall=function()
{
	if(this.info)
	{
		this.info.innerHTML=this.sending;
		this.info.style.display='block';
	}

//	if(this.working && this.req)
//		this.req.abort();

	if(window.XMLHttpRequest)
	{
		this.req=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		this.req=new ActiveXObject('Microsoft.XMLHTTP');
	}

	if(this.req)
	{
		var oAjax=this.req;
		var oFunc=this.callBack;
		this.req.obj=this;
		this.req.onreadystatechange=function () { oFunc.call(oAjax); };
		this.req.open(this.method, this.url, true);
		this.working=true;
		if(this.method.toLowerCase()=='post')
		{
			//this.req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			this.req.send(this.parameters);
		} else {
			this.req.send('');
		}
	} else {
		if(this.info) this.info.innerHTML = azw.jslng.reqerr;
	}
}

zw.ajaxCallBack=function(r)
{
	var o;
	if(!r) r=this;

	switch(r.readyState)
	{
		case 3:

			break;
		case 4:
			o=r.obj;
			if (r.status==200)
			{
				o.working=false;
				if(o.info) o.info.innerHTML = '';
				if(o.process) o.process.call(o, r);
				if(o.target) o.target.innerHTML = (r.responseText==undefined?'':r.responseText);
				if(o.postProcess) o.postProcess.call(o, r);
			} else {
				if(o.info) o.info.innerHTML = zw.jslng.errtext+': '+r.statusText;
			}
			break;
	}
}

function zw.ajaxXMLToArray(oXML)
{
	var oResult=new Array();

	if(oXML) for(i=0;i<oXML.childNodes.length;i++)
		if(oXML.childNodes[i].nodeType==1)
			oResult[i]=oXML.childNodes[i].text;

	return oResult;
}

if(document.implementation.hasFeature("XPath", "3.0")){
	if( typeof XMLDocument == "undefined" ){ XMLDocument = Document; }
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode){
	if( !xNode ) { xNode = this; }
		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++){aResult[i] =  aItems.snapshotItem(i);	}
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode){
		if( !xNode ) { xNode = this; }
		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 ){return xItems[0];	}
		else{return null;	}
	}
	Element.prototype.selectNodes = function(cXPathString){
		if(this.ownerDocument.selectNodes){	return this.ownerDocument.selectNodes(cXPathString, this);}
		else{throw "For XML Elements Only";}
	}
	Element.prototype.selectSingleNode = function(cXPathString){
		if(this.ownerDocument.selectSingleNode){return this.ownerDocument.selectSingleNode(cXPathString, this);	}
		else{throw "For XML Elements Only";}
	}
}