var IE = 1;
var MOZILLA = 2;
var OTHER = 3;
var g_objResponseCache = new Object();

function CAjax()
{
	this.m_objHttp = null;	
	this.m_bCreated = false;
	this.m_iType = 0;
	this.m_strErrorMessage = "";
	this.m_strLastResponse = "";
	this.m_strLastCacheName = "";
}

CAjax.prototype.create = function()
{
	try 
	{
 		this.m_objHttp = new ActiveXObject("Msxml2.XMLHTTP");
		this.m_bCreated = true;
		this.m_iType = IE;
 	} 
	catch (e) 
	{
  		try 
		{
   			this.m_objHttp = new ActiveXObject("Microsoft.XMLHTTP");
			this.m_bCreated = true;
			this.m_iType = IE;
  		}
  		catch (e) 
		{
			this.m_bCreated = false;
		}

	}
	
	
	if (!this.m_bCreated && typeof XMLHttpRequest != 'undefined') 
	{
		try 
		{
			this.m_objHttp = new XMLHttpRequest();
			this.m_bCreated = true;
			this.m_iType = MOZILLA;
		} 
		catch (e) 
		{
			this.m_bCreated = false;
		}
	}
	
	if (!this.m_bCreated && window.createRequest) 
	{
		try 
		{
			this.m_objHttp = window.createRequest();
			this.m_iType = OTHER;
		} 
		catch (e) 
		{
			this.m_bCreated = false;
		}
	}
	
	return this.m_bCreated;
}


CAjax.prototype.open = function(strUrl, bSend, strCacheName)
{
	this.m_strLastResponse = "";
	this.m_strLastCacheName = strCacheName;

	/*try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
	} catch (e) {
		alert("Permission UniversalBrowserRead denied.");
	}*/

	var d = new Date ();

	if ( strUrl.indexOf ( "?" ) == -1 )
		strUrl = strUrl + "?dummy=" + d.getTime ();
	else
		strUrl = strUrl + "&dummy=" + d.getTime ();

	if (!this.m_strLastCacheName || !g_objResponseCache[this.m_strLastCacheName])
	{
		try
		{
			this.m_objHttp.open("POST", strUrl, false);
			
			if (bSend)
			{
				this.m_objHttp.send("");
				this.m_strLastResponse = this.m_objHttp.responseText;
				g_objResponseCache[this.m_strLastCacheName] = this.m_strLastResponse;
			}
		}
		catch(e)
		{
			this.m_strErrorMessage = e.name + " - " + e.message;
			return false;
		}
	}
	else
	{
		this.m_strLastResponse = g_objResponseCache[this.m_strLastCacheName];
	}
	
	return true;
}

CAjax.prototype.send = function(strContent)
{
	if (!this.m_strLastCacheName || !g_objResponseCache[this.m_strCacheName])
	{
		try
		{
			this.m_objHttp.send(strContent);
			this.m_strLastResponse = this.m_objHttp.responseText;
			g_objResponseCache[this.m_strLastCacheName] = this.m_strLastResponse;
		}
		catch(e)
		{
			this.m_strErrorMessage = e.name + " - " + e.message;
			return false;
		}
	}
	
	
	return true;
}

CAjax.prototype.getError = function()
{
	return this.m_strErrorMessage;
}

CAjax.prototype.getResponse = function()
{
	// look for the login page
	if ( this.m_strLastResponse.indexOf ( "javascript:createUser" ) != -1 ) {
		setTimeout ( "launchApplication()", 1500 );
	}

	return this.m_strLastResponse;
}

