//===========================================//
// Ajax Library 
//              Coded by Vichraje @ Sep.2007
//____________vicrry@yahoo.com.hk____________
//===========================================//

var Ajax = {
	
	//===========================================
	//.. Public members -:
	//-------------------------------------------
		
		Request : function(URL, Params, SyncFunc)
		{
			if( typeof SyncFunc == 'function' )
				Ajax.RequestRAW(URL, Params, function( response ) {
					return SyncFunc( eval('(' + response + ')') );
				} );
			else
				return eval('(' + Ajax.RequestRAW(URL, Params) + ')');
		}, 
		
		RequestRAW : function (URL, Params, SyncFunc)
		{
			var ReqObj = this._getReqObject();
			
			if ( SyncFunc ) 
				ReqObj.onreadystatechange = function()
				{
					if(ReqObj.readyState!=4) return;
					
					SyncFunc( ReqObj.responseText );
				};
			
			try
			{
				ReqObj.open('POST', URL, !!SyncFunc);
				
				ReqObj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;');
				ReqObj.setRequestHeader('Content-length', (Params?String(Params).length:0) );
				ReqObj.setRequestHeader('Connection', 'close');
				
				ReqObj.send(Params);
			}
			catch (Exception) { alert('Ajax request error : ' + Exception); }
			
			if( !SyncFunc )
				return ReqObj.responseText;
		}, 
		
	//===========================================
	//.. internal functions -:
	//-------------------------------------------
	/* You don't need to read the following lines in most cases. */
		
		_getReqObject : function() {
			if(/MSIE/.exec(navigator.userAgent))
			{
				try			{ return new ActiveXObject("Msxml2.XMLHTTP"); }
				catch(e)	{ return new ActiveXObject("Microsoft.XMLHTTP"); }
			}
			else { return new XMLHttpRequest(); }
		}
		
	//===========================================
};