var Ajax = {
	
	Sock : null,
	Trigger : null,
	Method	: 'GET',
	SyncMode	: true,

	init : function(trigger)
	{
		if (!Ajax.Sock)
		{
			try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e) 
			{
			  	try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
			  	catch (e) { xmlhttp = false; }
			}
			
		  	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
		  	{
		     	try { xmlhttp = new XMLHttpRequest(); }
		     	catch (e) { xmlhttp = false; }
		  	}
		  	
		  	Ajax.Sock = xmlhttp;
		}
		
	  	Ajax.attachEvent(trigger);
	},

	attachEvent : function(trigger)
	{
		if (Ajax.Sock && (typeof trigger == "function")) 
		{
	  		Ajax.Trigger = trigger;
	    	Ajax.Sock.onreadystatechange = function() 
	    	{
	      		if ((Ajax.Sock.readyState == 4) && (Ajax.Sock.status == 200)) 
	      		{
	      			Ajax.Trigger();
	      			Ajax.destroy();
	      		}
	    	}
		}
		else
		{
	  		Ajax.Trigger = trigger;
	    	Ajax.Sock.onreadystatechange = function() 
	    	{
	      		if ((Ajax.Sock.readyState == 4) && (Ajax.Sock.status == 200)) Ajax.destroy();
		    }
		}
	},
	
	setHeaders : function(headers)
	{
		if (Ajax.Sock) 
		{
			for(header in headers) 
				Ajax.Sock.setRequestHeader(header, headers[header]);
		}
	},

	query : function(url, trigger, method, data, login, password, syncmode, headers)
	{
		Ajax.init(trigger);
		
		method = (method)? method : Ajax.Method;
		syncmode = (syncmode)? syncmode : Ajax.SyncMode;
		
		if (login && password)
			Ajax.Sock.open(method, url, syncmode, login, password);
		else
			Ajax.Sock.open(method, url, syncmode);
		
		if (headers) Ajax.setHeaders(headers);

		Ajax.Sock.setRequestHeader('Connection','close');
		Ajax.Sock.setRequestHeader('Proxy-Connection','close');

		if (method == "POST") 
		{
			Ajax.Sock.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			Ajax.Sock.send(data);
		}
		else
			Ajax.Sock.send(null);
		
	},
	
	destroy : function()
	{
		if (Ajax.Sock) 
		{
			delete(Ajax.Sock);
			Ajax.Sock = false;
		}
	}
};