// JavaScript Document
function createAjaxObject()
{
	try {
	   xhr = new XMLHttpRequest()
		if (xhr.overrideMimeType) 
		{
			xhr.overrideMimeType('text/xml');
		}

	}
	catch(e)    // Failed 
	{
			   // IE
		 try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
			try {
			   xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		 }
	}
	return xhr;
}

function clsHTTPRequest()
{
	this.params = new Array();
	this.requestURI = '';
	this.response = '';
	this.m_sMimeType = 'text/xml';
	this.onResponse = function() {};
	
	this.post = function()
	{
		var oConn = createAjaxObject();
		oConn.onreadystatechange = function()
		{
			if (oConn.readyState == 4)
			{
				if (oConn.status == 200)
				{
					eval(oConn.responseText);
				}

			}
		}
		var sUrl = this.requestURI;
		var data = this.formatArgs();
		oConn.open("POST", sUrl, true); 
		oConn.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oConn.send(data); 	
	}
	
	this.getHTML = function(p_sTarget)
	{
		var oConn = createAjaxObject();
		this.setHTML();
		if (oConn.overrideMimeType) {
			oConn.overrideMimeType(this.m_sMimeType);
		}
		oConn.onreadystatechange = function()
		{
			if (oConn.readyState == 4)
			{
				if (oConn.status == 200)
				{
					var sHTML = oConn.responseText;
					if (sHTML) {
						document.getElementById(p_sTarget).innerHTML = sHTML;
					}
				}

			}
		}
		var sUrl = this.requestURI;
		var data = this.formatArgs();
		oConn.open("GET", sUrl, true); 
		oConn.send(null); 	
	}
	
	this.postXML = function (p_sLoopback) {
		var oConn = createAjaxObject();
		oConn.onreadystatechange = function()
		{
			if (oConn.readyState == 4)
			{
				if (oConn.status == 200)
				{
					p_sLoopback(oConn.responseXML);
				}

			}
		}
		var sUrl = this.requestURI;
		var data = this.formatArgs();
		oConn.open("POST", sUrl, true); 
		oConn.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oConn.send(data); 	
	}
	
	this.formatArgs = function()
	{	
		var args = "";
		if (this.params.length > 0)
		{
				for(i = 0; i < this.params.length; i++)
				{
						args += this.params[i] + "&";
				}
		}
		return args.substring(0, args.length-1)
	}
	
	this.setRequestURI =  function (p_sRequestURI)
	{
		this.requestURI = p_sRequestURI;
	}
	
	this.addParam = function(param, value)
	{
		this.params[this.params.length] = param + "=" + encodeURI(value);
	}
	
	this.setXML = function() {
		this.m_sMimeType = 'text/xml';
	}
	
	this.setHTML = function() {
		this.m_sMimeType = 'text/html';
	}
}
