var _aAJAXInstances=new Array(),_aAJAXNames=new Array();
function NTR_AJAXFunctions(oFrame,sObjectName)
{
	this.id=Math.random();
	this.name=new String();
	if(typeof(sObjectName)!='undefined')
		this.name=sObjectName;
	this.oHttp=getHTTPObject();
	this.async=true;
	this.URL=new String();
	this.stringPost=new String();
	this.method=new String();
	this.onReadyFunction=function(){};
	this.onErrorFunction=function(){};
	this.statusNumber=statusNumber;
	this.statusMessage=statusMessage;
	this.inProcess=false;
	this.call=call;
	this.responseText=responseText;
	this.stringFormPost=stringFormPost;
	this.evalHTML=evalHTML;
	this.evalScripts=evalScripts;
	this.destroy=destroy;
	this.addInstanceInProcess=addInstanceInProcess;
	this.getInstancesInProcess=getInstancesInProcess;
	this.deleteInstanceInProcess=deleteInstanceInProcess;
	this.debug=false;
	this.debugObject=new String();

	function getHTTPObject()
	{
		var oXmlHttp;
		/*@cc_on
		@if(@_jscript_version>=5)
			try
			{
				oXmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
			}
			catch(e)
			{
				try
				{
					oXmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
				}
				catch(e)
				{
					oXmlHttp=false;
				}
			}
		@else
			oXmlHttp=false;
		@end@*/
		if(!oXmlHttp&&typeof XMLHttpRequest!='undefined')
		{
			try
			{
				oXmlHttp=new XMLHttpRequest();
			}
			catch(e)
			{
				oXmlHttp=false;
			}
		}
		return oXmlHttp;
	}
	function call()
	{
		if(!this.inProcess&&this.oHttp)
		{
			this.inProcess=true;
			var oAJAX=this;
			var nMethod=(this.method.toUpperCase()=='GET')?0:1;
			if(!this.async)
				this.onReadyFunction=function(){};
			else
				this.addInstanceInProcess();
			this.oHttp.open(this.method,this.URL,this.async);
			if(nMethod==1)
				this.oHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			this.oHttp.onreadystatechange=function(){responseFunction(oAJAX);};
			this.oHttp.send((nMethod==1)?this.stringPost:null);
			if(!this.async)
			{
				this.inProcess=false;
				return this.oHttp.responseText;
			}
		}
		
	}
	function responseFunction(oAJAX)
	{
		if(oAJAX.debug)
			oFrame.d(oAJAX.debugObject).innerHTML=oAJAX.oHttp.responseText;
		if(oAJAX.oHttp.readyState==4)
		{
			oAJAX.oHttp.onreadystatechange=function(){};
			oAJAX.inProcess=false;
			deleteInstanceInProcess(oAJAX);
			if(oAJAX.oHttp.status==200)
				oAJAX.onReadyFunction();
			else
			  oAJAX.onErrorFunction();
		}
	}
	function responseText()
	{
		return this.oHttp.responseText;
	}
	function statusNumber()
	{
	  return this.oHttp.status;
	}
	function statusMessage()
	{
	  return this.oHttp.statusText;
	}
	function stringFormPost(oForm)
	{
		var sGenericInput='',sRadios='',sChecks='',sSelects='';
		var aChecks=new Array(oForm.length);
		var nChecks=-1;
		for(var x=0;x<oForm.length;x++)
		{
			var chkOptions='',selOptions='';
			var bReady=false;
			with(oForm.elements[x])
			{
				if(type=='text'||type=='password'||type=='hidden'||type=='hidden'||type=='file'||type=='select-one'||type=='textarea')
					sGenericInput+=name+'='+value.stringUTF8()+'&';
				if(type=='radio')
					if(checked)
						sRadios+=name+'='+value.stringUTF8()+'&';
				if(type=='checkbox')
				{
					for(var i=0;i<aChecks.length;i++)
						if(aChecks[i]==name)
							bReady=true;
					if(!bReady)
					{
						nChecks++;
						aChecks[nChecks]=name;
						for(var y=0;y<n(name).length;y++)
							if(n(name)[y].checked)
								chkOptions+=n(name)[y].value.stringUTF8()+',';
						if(chkOptions.length>0)
							chkOptions=chkOptions.substring(0,chkOptions.length-1);
						sChecks+=name+'='+chkOptions+'&';
					}
				}
				if(type=='select-multiple')
				{
					for(y=0;y<options.length;y++)
						if(options[y].selected)
							selOptions+=(options[y].value).stringUTF8()+',';
					if(selOptions.length>0)
						selOptions=selOptions.substring(0,selOptions.length-1);
					sSelects+=name+'='+selOptions+'&';
				}
			}
		}
		//alert(sGenericInput+sRadios+sChecks+sSelects);
		return sGenericInput+sRadios+sChecks+sSelects+'&';
	}
	var sPatternEval=eval('/<scr'+'ipt((.|\\r|\\n)*?)>((.|\\r|\\n)*?)<\\/scr'+'ipt>/gi');
	var aFunctionsAJAX=new Array();
	function evalHTML(sText)
	{
		aFunctionsAJAX=sText.match(sPatternEval);
		return sText.replace(sPatternEval,'');
	}
	function evalScripts()
	{
		if(aFunctionsAJAX!=null)
		{
			for(var x=0;x<aFunctionsAJAX.length;x++)
			{
				var sFunction=aFunctionsAJAX[x].replace(sPatternEval,'$3').replace(/\/\/(.*?)\r\n/gi,'').replace(/\/\*(.*?)\*\//gi,'');
				if(navigator.userAgent.toUpperCase().indexOf('MSIE')>=0)
					oFrame.execScript(sFunction.toString(),'javascript');
				else if(navigator.userAgent.toUpperCase().indexOf('KHTML')>=0)
					oFrame.setTimeout('eval(\''+sFunction.toString().replace(/\t|\r|\n/g,'').replace(/'/g,'\\\'')+'\')',0);
				else {
					oFrame.eval(sFunction.toString());
				}
			}
			aFunctionsAJAX.splice(0,aFunctionsAJAX.length);
		}
	}
	function destroy()
	{
		delete(this.oHttp);
	}
	function addInstanceInProcess()
	{
		top._aAJAXInstances.push(this.id);
		top._aAJAXNames.push(this.name);
	}
	function getInstancesInProcess()
	{
		return top._aAJAXNames;
	}
	function deleteInstanceInProcess(oAJAX)
	{
		for(var i=0;i<top._aAJAXInstances.length;i++)
		{
			if(top._aAJAXInstances[i]==oAJAX.id)
			{
				top._aAJAXInstances.splice(i,1);
				top._aAJAXNames.splice(i,1);
				i=top._aAJAXInstances.length;
			}
		}
	}
}
