//	Project            	:  	Portal
//	Nguoi tao          	:   GiangNM (02/04/2009)
//	Sua doi            	:   
//	Chuc nang chinh  	: 	Xu ly AJax

var req;
var url="http://pinsac.vn/XMLHTTP.php";

function Initialize()
{
	try
	{
		req=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			req=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			req=null;
		}
	}

	if(!req&&typeof XMLHttpRequest!="undefined")
	{
		req=new XMLHttpRequest();
	}

}

function SendQuery(request,method,callbackFunction,cache)
{
	// Init Object
	Initialize();
	
	if ( (req!=null) )
	{		
		req.onreadystatechange = function()
			{
				// only if req shows "complete"
				if (req.readyState == 4)
				{
					// only if "OK"
					if (req.status == 200)
					{
						// Process
						eval(callbackFunction);
					}
				}
			};
		// Cache data or not								
		if ( cache==0 )
		{
			request += "&rand="+Math.random()*100;
		}
		
		// Use POST or GET method , default is GET
		if ( method == 'POST' )
		{
	        req.open("POST", url, true);
	        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	        req.send(request);
		}
		else
		{						
			req.open("GET",url+"?"+request, true);
			req.send(null);
		}
	}
}
