﻿var nineAJAXModuleList = new Array();



function nineAJAX(objID)
{
	this.m_ModuleCore=this.GetModule(null);
	this.objID=objID;
	this.m_ModuleCore.onreadystatechange = new Function(this.objID+".OnReadyStateChange();");
	this.CallBackReadyState="";
	this.m_bAsync=false;
	this.m_CustomParam=null;
	//nineAJAXModuleList.add(this);
}
function nineAJAXUnload()
{
	
	for(var i=0;i<nineAJAXModuleList.length;i++)
	{
		try {
		delete nineAJAXModuleList[i];
		} 
		catch(e)
		{
			//alert(e);
			nineAJAXModuleList[i]=null;
		}
		nineAJAXModuleList[i]=null;
	}
}
function nineAJAXSetUnload()
{
	if(!window.onunload)
	{
		window.onunload=nineAJAXUnload;
		
	}
}
nineAJAX.prototype.GetDOMFromXMLText=function (xmlText)
{
	var obj=null;
	if ( ( document.implementation != null ) && ( typeof document.implementation.createDocument == "function" ) )
	{
		xmlText=xmlText.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
		var parser = new DOMParser();
		obj = parser.parseFromString( xmlText, "text/xml" );
	}
	else
	{
		xmlText=xmlText.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
		try { obj = new ActiveXObject( "MSXML2.DOMDocument" ); }
		catch( ex ) {}

		if ( obj == null )
		{
			try { obj = new ActiveXObject( "Microsoft.XMLDOM" ); }
			catch( ex ) {}
		}

		if ( obj != null )
		{
			obj.async = false;
			obj.validateOnParse = false;
		}

		obj.loadXML( xmlText );
	}
	return obj;
}
nineAJAX.prototype.NoCacheURL = function (uri){return uri.concat(/\?/.test(uri)?"&":"?","noCache=",(new Date).getTime(),".",Math.random()*1234567)};
nineAJAX.prototype.SendXmlhttp=function (url, depth, funcReadyStateName, customParam)
{
	var nineajax_exception
	try
	{
		this.m_CustomParam=customParam;
		this.CallBackReadyState=funcReadyStateName;
		this.m_bAsync=false;
		if(this.CallBackReadyState!="")
			this.m_bAsync=true;
		url=this.NoCacheURL(url);
		this.m_ModuleCore.open("GET", url, this.m_bAsync); 
		this.m_ModuleCore.setRequestHeader("Content-type", "text/xml");
		
		this.m_ModuleCore.setRequestHeader("Cache-Control", "no-cache");
		this.m_ModuleCore.setRequestHeader("Expires", "0");
		this.m_ModuleCore.setRequestHeader("Pragma", "no-cache");
		if (depth != null) { this.m_ModuleCore.setRequestHeader("Depth", depth); }
		
		this.m_ModuleCore.send("");
		
		if(!this.m_bAsync)
		{
			if(this.m_ModuleCore.status == 200)		return this.m_ModuleCore.responseText;
			else						return "ERROR";
		}
		
	}
	catch(nineajax_exception)
	{
		alert("nineajax_SendXmlhttp:"+nineajax_exception.description);
	}
}
nineAJAX.prototype.SendPostXmlhttp=function (url, tdata, depth, funcReadyStateName, customParam)
{
		var nineajax_exception
	try
	{
		this.m_CustomParam=customParam;
		this.CallBackReadyState=funcReadyStateName;
		this.m_bAsync=false;
		if(this.CallBackReadyState!="")
			this.m_bAsync=true;
		this.m_ModuleCore.open("POST", url, this.m_bAsync); 
		//this.m_ModuleCore.setRequestHeader("Content-type", "text/xml");
		this.m_ModuleCore.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.m_ModuleCore.setRequestHeader("Cache-Control", "no-cache");
		this.m_ModuleCore.setRequestHeader("Expires", "0");
		this.m_ModuleCore.setRequestHeader("Pragma", "no-cache");
		if (depth != null) { this.m_ModuleCore.setRequestHeader("Depth", depth); }
		
		this.m_ModuleCore.send(tdata);
		
		if(!this.m_bAsync)
		{
			if(this.m_ModuleCore.status == 200)		return this.m_ModuleCore.responseText;
			else						return "ERROR";
		}
		
	}
	catch(nineajax_exception)
	{
		alert("nineajax_SendPostXmlhttp:"+nineajax_exception.description);
	}
}
nineAJAX.prototype.OnReadyStateChange=function ()
{
	
	var nineajax_strRet	=	null;
	var nineajax_errorcode;
	//try
	//{
		if (this.m_ModuleCore.readyState != 4) return;
		if (this.m_ModuleCore.status == 200)
		{
			nineajax_strRet	=	this.m_ModuleCore.responseText;
			if(this.CallBackReadyState!="")
			{
				eval(this.CallBackReadyState+"(true, nineajax_strRet, 200, this.m_CustomParam)");
			}
		}
		else
		{
			nineajax_errorcode=this.m_ModuleCore.status;
			if(this.CallBackReadyState!="")
			{
				eval(this.CallBackReadyState+"(false, '', nineajax_errorcode, this.m_CustomParam)");
				
			}
		}
		
	//}
	//catch(nineajax_exception)
	//{
		//alert("nineajax_ReadyStateChange:"+nineajax_exception.description);
	//}
	
	return nineajax_strRet;
}
nineAJAX.prototype.ModuleReset=function ()
{
	
	this.m_ModuleCore=this.GetModule(this.m_ModuleCore);
	this.m_ModuleCore.onreadystatechange = new Function(this.objID+".OnReadyStateChange();");
}

nineAJAX.prototype.GetModule=function (oldModule)
{

	var retModule=null;
	for(var i=0;i<nineAJAXModuleList.length;i++)
	{
		if(nineAJAXModuleList[i]==oldModule)
		{
			try{
				delete nineAJAXModuleList[i];
				nineAJAXModuleList[i]=null;
			}catch(e)
			{
				nineAJAXModuleList[i]=null;
			}
		}
	}
	//nineAJAXModuleList[nineAJAXModuleList.length]=this;
	
	try{
	if (window.XMLHttpRequest)
		retModule= new XMLHttpRequest();
	}catch(e)
	{
	}
	
	try{
	if (retModule==null && window.ActiveXObject) 
		retModule= new ActiveXObject('Msxml2.XMLHTTP');
	}catch(e)
	{
	}
		
	try{
	if (retModule==null && window.ActiveXObject) 
		retModule= new ActiveXObject('Microsoft.XMLHTTP');
	}catch(e)
	{
		
	}
	var bfind=false;
	for(var i=0;i<nineAJAXModuleList.length;i++)
	{
		if(nineAJAXModuleList[i]==null)
		{
			nineAJAXModuleList[i]=retModule;
			bfind=true;
		}
	}
	if(!bfind)
	{
		nineAJAXModuleList[nineAJAXModuleList.length]=retModule;
	}
	//alert(nineAJAXModuleList.length);
	return retModule;
}
nineAJAX.prototype.GetNodeText=function (tnode)
{
	if(tnode.textContent)
		return tnode.textContent;
	if(tnode.text)
		return tnode.text;
	return null; 
}
