﻿function Sam_Ajax()
{
	this.IsIE		= document.all? true:false;
	this.InProcess  = false;
	this.xmlhttp	= this.GetHttpObject();
}




Sam_Ajax.prototype.GetHttpObject = function()
{
	var xmlhttpObj;
	try
	{
		xmlhttpObj = new ActiveXObject("Msxml2.XMLHTTP.4.0");
	}
	catch (e1)
	{
		try
		{
			xmlhttpObj = new ActiveXObject("Msxml2.XMLHTTP.3.0");
		}
		catch (e2)
		{
			try
			{
				xmlhttpObj = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e3)
			{
				try
				{  
					xmlhttpObj = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e4)
				{
					xmlhttpObj = new XMLHttpRequest();
				}
			}
		}
	}
	return xmlhttpObj;
}



//Sam_Ajax.prototype.Call = function(url,method,callback,arg)
//{
//	this.CallBase(url,method,null,callback,arg)
//}

Sam_Ajax.prototype.Call = function(url,method,callback,arg)
{
	var xmlhttpObj = this.xmlhttp;

	if (this.InProcess)
	{
		xmlhttpObj.abort();
	}
	var bText = false;
	
	if (arguments.length >= 5 && arguments[4] == "text")
	{
		bText = true;
	}


	xmlhttpObj.open(method,url,true);
	xmlhttpObj.onreadystatechange = function()
	{
		if (xmlhttpObj.readyState == 4)
		{
			if(xmlhttpObj.status==200)
			{
				//alert(xmlhttpObj.responseText);
				if (bText)
					callback(true,xmlhttpObj.responseText,arg);
				else
					callback(true,xmlhttpObj.responseXML,arg);
			}
			else
			{
				//alert(xmlhttpObj.responseText);
				callback(false,null,arg);
			}

			this.InProcess	= false;
		}
	}
	this.InProcess	= true;

	if (arguments.length >= 6)
		xmlhttpObj.send(arguments[5]);
	else
		xmlhttpObj.send(null);
}


