function AjaxClass(url, data)
{
	/*Private variables*/
	var m_url = url;
	var m_sendMethod = "GET";
	var m_sendData = data;
	var m_counter  = 0;
	

	/*public variables*/
	//this.m_responseText = "";

	/*public functions*/
	this.SetURL = SetURL;
	this.GetURL = GetURL;
	this.SetSendMethod = SetSendMethod;
	this.Send = Send;
	this.LaunchJavascript = LaunchJavascript;
	this.SetRequestData = SetRequestData;
	this.OnAjaxStateChange = OnAjaxStateChange;
	this.OnAjaxDataReceived = OnAjaxDataReceived;
	this.OnConnectionError = OnConnectionError;
	this.OnStatusError = OnStatusError;

	/*private functions*/
	function SetURL(url)
	{
		m_url = url;
	}

	function GetURL()
	{
		return m_url;
	}

	function SetSendMethod(sendMethod)
	{
		m_sendMethod = sendMethod;
	}

	function SetRequestData(data)
	{
		m_sendData = data;
	}

	function OnAjaxStateChange(httpObj, readyState)
	{
	}
	
	function OnAjaxDataReceived(httpObj, responseText)
	{
	}

	function OnConnectionError(e)
	{
	}

	function OnStatusError(status)
	{
	}

	function Send()
	{
		var httpObj = AjaxClass.GetXMLHttpObject();

		//now we got the XmlHttpRequest object, send the request.
		if (httpObj)
		{
			var thisClassObj = this; //Closure will save this local variable (requires in onreadystatechange)s

			httpObj.onreadystatechange = function ()
			{
				if(window.OnAjaxStateChange)
					window.OnAjaxStateChange(thisClassObj, httpObj, httpObj.readyState);

				if(thisClassObj.OnAjaxStateChange)
					thisClassObj.OnAjaxStateChange(httpObj, httpObj.readyState);

				if(httpObj.readyState==4)
				{
					if(httpObj.status == 200)
					{
						if(window.OnAjaxDataReceived)
							window.OnAjaxDataReceived(thisClassObj, httpObj, httpObj.responseText);

						if(thisClassObj.OnAjaxDataReceived)
							thisClassObj.OnAjaxDataReceived(httpObj, httpObj.responseText);
					}
					else
					{
						thisClassObj.OnStatusError(httpObj.status);
					}
				}
			}

			var callingUrl = m_url;

			if(m_sendMethod == "GET")
			{
				var myDate = new Date();
				var myTime = myDate.getTime();

				//todo: find "?". If find then append "&" otherwise append "?"
				var urlAppend = "?";
				if(m_url.indexOf("?") != -1)
					urlAppend = "&";

				callingUrl = callingUrl + urlAppend + "CacheRemover_jsdfhjshfsdf=" + myTime;
			}

			try
			{
				httpObj.open(m_sendMethod, callingUrl, true);

				if(m_sendMethod == "POST")
				{
					httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					httpObj.setRequestHeader("Content-length", m_sendData.length);
					httpObj.setRequestHeader("Connection", "close");
					httpObj.send(m_sendData);
				}
				else
				{ //send get request
					httpObj.send(null);
				}
			}
			catch(e)
			{
				thisClassObj.OnConnectionError(e);
			}

		}		

		return true; //send request successful
	}

	function LaunchJavascript(responseText) 
	{
		var js = '';
		// RegExp from prototype.sonio.net
		//var ScriptFragment = "(?:<script.*?>)((\n|.)*?)(?:</script>)";
		var ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:</script>)'; 

		var match    = new RegExp(ScriptFragment, 'img');
		var scripts  = responseText.match(match);
		
		
		if(scripts) 
		{
			var js = '';
			for(var s = 0; s < scripts.length; s++) 
			{
					var match = new RegExp(ScriptFragment, 'im');

					js += scripts[s].match(match)[1];
			}
			js = js.replace(/<!--/g,'').replace(/\/\/-->/g,'');
			eval(js);
		}
	}
}

/*Static functions*/
AjaxClass.GetXMLHttpObject = function()
{
	var xmlHttpObjName = null;
	try
	{    // Firefox, Opera 8.0+, Safari    
			xmlHttpObjName=new XMLHttpRequest();    
	}
	catch (e)
	{    
			// Internet Explorer    
			try
			{      
				xmlHttpObjName=new ActiveXObject("Msxml2.XMLHTTP");      
			}
			catch (e)
			{      
				try
				{
					xmlHttpObjName=new ActiveXObject("Microsoft.XMLHTTP");        
				}
				catch (e)
				{        
				}      
			}    
	}
	
	return xmlHttpObjName;
}

