function ajax(urlRequested, method, container, containerType, loaderID, whatToEval)
{
	var xmlHttp;
	this.responseText="";
	this.errorStatus=0;
	this.error="";
	this.urlRequested=urlRequested;
	this.method=method;
  	this.container=container;
	this.containerType=containerType;
	this.loaderID=loaderID;
	this.whatToEval=whatToEval;
	this.visilbe=1;
	this.fillContainer=fillContainer;
	this.sendRequest=sendRequest;
	this.toggleLoader=toggleLoader;
}

function sendRequest()
{
	this.toggleLoader(1);
	try 
	{	// Check Netscape Security Policy
		netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
	}
	catch(e)
	{
		this.errorStatus=1;
		this.error="Permission UniversalBrowserRead denied.";
	}
	
	try
	{ // Firefox, Opera 8.0+, Safari
		this.xmlHttp=new XMLHttpRequest();
	}
	catch(e)
	{ // Internet Explorer
		try
		{
			this.xmlHttp=new ActiveXObject("Msxml2.xmlHttp");
		}
		catch(e)
		{
			try
			{
				this.xmlHttp=new ActiveXObject("Microsoft.xmlHttp");
			}
			catch(e)
			{
				this.errorStatus=2;
				this.error="Your browser does not support AJAX!";
			}
		}
	}
	
	if(this.xmlHttp.overrideMimeType) this.xmlHttp.overrideMimeType('text/xml');

	if(!this.xmlHttp)
	{
		this.errorStatus=3;
		error='Cannot create xmlHttp instance';
	}
	else
	{
		//this.xmlHttp.onreadystatechange=getContent(this);
		with(this)
		{
			xmlHttp.onreadystatechange=function()
			{
				if (xmlHttp.readyState==4)
				{
					if (xmlHttp.status==200)
					{
						responseText=xmlHttp.responseText;
						errorStatus=0;
						error="";
						fillContainer();
						toggleLoader(0);
						if(whatToEval!="") eval(whatToEval);
					}
					else if (xmlHttp.status==404)
					{
						errorStatus=4;
						error="URL doesn't exist!";
					}
					else
					{
						errorStatus=5;
						error="Status is " + xmlHttp.status;
					}
				}
			}
		}
		
		this.xmlHttp.open(this.method,this.urlRequested,true);
		this.xmlHttp.send(null);
	}
}

function fillContainer()
{
	if(this.containerType=="div")
	{
		//document.getElementById(this.container).style.visibility='hidden';
		this.responseText=this.responseText.replace("<form","<body");
		this.responseText=this.responseText.replace("</form","</body");
		document.getElementById(this.container).innerHTML=this.responseText;
	}
}

//function toggleLoader(loaderID, visible)
function toggleLoader(visible)
{
	if(visible!=0 && visible!=1) visibility=0;
    if(document.layers)	   //NN4+
    {
       document.layers[loaderID].visibility = visible ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(this.loaderID);
        obj.style.visibility = visible ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[loaderID].style.visibility = visible ? "visible" : "hidden";
    }	
}