var msHttpVer = null;

function RequestPostFunc(url, id, property, func)
{
	var a = new Ajax("POST", url, id, property, func);
	a.Call();
}


function RequestPost(url, id, property)
{
	var a = new Ajax("POST", url, id, property, null);
	a.Call();
}

/*function Request(url, id, property)
{
	var a = new Ajax("GET", url, id, property, null);
	a.Call();
}*/

function Request(url, id, property, callback)
{
	var a = new Ajax("GET", url, id, property, callback);
	a.Call();
}

function Ajax(method, url, id, property, callback)
{
	var me = this;

	me.url = url;
	me.id =id;
	me.property = property;
	me.xmlHttp = null;
	me.method = method;

	if (window.XMLHttpRequest)
	{
		me.xmlHttp = new XMLHttpRequest();
	}
	/*else if (msHttpVer)
	{
		me.xmlHttp = new ActiveXObject(msHttpVer);
	}*/
	else if (window.ActiveXObject)
	{
		var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		for (var i = 0; i < versions.length ; i++) 
		{
			try 
			{
				me.xmlHttp = new ActiveXObject(versions[i]);
				if (me.xmlHttp) 
				{
					msHttpVer = versions[i];
					break;
        }
			}
			catch (objException) {
			};
		};
	}
	
	if (me.xmlHttp)
	{
		me.xmlHttp.onreadystatechange=	function() 
		{ 
		/*
		readyState =
			(0) UNINITIALIZED 
						The object has been created, but not initialized (open method has not been called). 
			(1) LOADING 
						The object has been created, but the send method has not been called. 
			(2) LOADED 
						The send method has been called and the status and headers are available, but the response is not yet available. 
			(3) INTERACTIVE 
						Some data has been received. You can call responseBody and responseText to get the current partial results. 
			(4) COMPLETED 
						All the data has been received, and the complete data is available in responseBody and responseText. 
		*/
		
			if (me.xmlHttp.readyState==4 || me.xmlHttp.readyState=="complete")
			{ 
			
				try 
				{
					var responseText = me.xmlHttp.responseText;
				
					if (callback)
					{
						//arr = responseText.split('$');
						//responseText = arr[0];
						callback(me.id, responseText);
					}
					else
					{
						var id = me.id;
						var elem = document.getElementById(id);
						if (elem)
						{
							var st = "elem."+me.property+" = '"+responseText+"';";
							if (st) 	eval(st);
						}
					}
				}
				catch (e)
				{
					alert(e);
				}
			}
			
			if (me.xmlHttp.readyState==4) delete me;
		} 
		
		me.Call = function()
		{
			me.xmlHttp.open(method, url, true);
			if (method=="GET")
				me.xmlHttp.send(null);
			else
				me.xmlHttp.send(url);		
		}
		
		//alert(url);
		/*me.xmlHttp.open(method, url, true);
		if (method=="GET")
			me.xmlHttp.send(null);
		else
			me.xmlHttp.send(url);*/
			
	} // end if
	
}


