//************
//CAjax
//************

function CAjax()
{
	this.req = null;
	this.responseText = null;
	this.defaultDisplayText = null;
	this.initialize = Initialize;
	this.process = Process;
	this.onDone = null;
	this.sendData = SendData; // this is recommended only for the POST method
	this.url = "";
	// You must set the variables strig for POST method
	this.variables = null;
	this.getXML = false;
	this.method = "POST";
}

function Initialize()
{
	try
	{
		this.req=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			this.req=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			this.req=null;
		}
	}

	if(!this.req && typeof XMLHttpRequest!="undefined")
	{
		this.req=new XMLHttpRequest();
	}
}

function SendData()
{
	var myUrl = this.url;
	
	this.initialize();
	if(this.req!=null)
	{		
		
		oCHttp = this;
		this.req.onreadystatechange = function() { oCHttp.process() };
		
			
		if(this.method == "GET")
		{
			this.req.open(this.method, myUrl+"?"+this.variables, true);
			this.req.send(null);
		}
		else if(this.method == "POST")
		{
			this.req.open(this.method, myUrl, true);
			this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; Charset=utf-8");
        	this.req.send(this.variables);
		}
	}
}

function Process()
{
	if (this.req.readyState == 4) 
    {
		if (this.req.status == 200) 
		{
			//alert(this.req.responseText);
			if(typeof this.onDone == "function")
			{
				
				if(this.getXML)
				{
//					alert(this.req.responseText);
					///--- setting xml from response text ---
					var oXMLDom;
					if (window.ActiveXObject)
					{
						oXMLDom = new ActiveXObject('Microsoft.XMLDOM'); 
						oXMLDom.loadXML(this.req.responseText);
					}
					else
					{
						oXMLDom = new DOMParser().parseFromString(this.req.responseText, 'text/xml');
					}
					this.onDone(oXMLDom);
				}
				else
				{
					this.onDone(this.req.responseText);
				}
			}
			else
			{
//				alert(this.req.responseText);
				eval(this.req.responseText);
			}
		}
    }
}
