var theHttpRequestObject; 
var obj; 
var back_url;

// JavaScript Document
/*
Usage: This function used to detect what browser visitor using
Return:
	IE : Browser is Internet Explorer
	Mozilla : Browser is Mozilla Firefox , Netscape
*/

function DetectBrowser()
{
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	{
		return "Mozilla";
	}
	else
	{
		return "IE";
	}
}
/*
Usage: create requrest object
Return: Request object
*/
function getHttpRequestObject()
{
	var theRequestObject;
	var theBrowser;
	
	theBrowser = DetectBrowser();
	
	if (theBrowser == "IE")
	{
		theRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		theRequestObject = new XMLHttpRequest();
	}
	
	return theRequestObject;
}

function setRequestHeader(theMethod , theURL)
{
	if (theMethod == "POST")
	{
		theHttpRequestObject.setRequestHeader("Method", "POST " + theURL + " HTTP/1.1");
		theHttpRequestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
}

function doRequest(theMethod, theURL, theArgs, theHandledFunction)
{
	//this.obj = obj;
	//alert(theURL);
	theHttpRequestObject = getHttpRequestObject();
	theHttpRequestObject.open(theMethod, theURL, true);	
	setRequestHeader(theMethod, theURL);	
	theHttpRequestObject.onreadystatechange = theHandledFunction;	
	theHttpRequestObject.send(theArgs);
}    

/* 
+theMethod : POST or GET
+theURL : url need get information
+theArgs : null if GET or id0=7 &id1=..
+theHandledFunction : function set return value
+obj: La 1 HTML TAG de set noi dung khi goi Ajax
EX :
+ doRequest('GET','<?php echo PATH_CAFE?>' + 'home/get_contact_ajax/' + this.value, null, showFriends);	
+ doRequest('POST','<?php echo PATH_CAFE?>' + 'home/update_blast_ajax', getBlastPostArgs(), saveBlast);
note: add action in array (file url_option.php):
$arrAction	= array("image","get_contact_ajax","get_city_ajax","update_blast_ajax");
*/

//---------------------------------------------------------------------------------------------------//
// Ham nay dung cho 1 so truong hop gan vao the div don gian
// Muc dich la khong phai viet lai ham ShowContentAjax
// obj: La 1 DIV TAG de set noi dung khi goi Ajax
function doNewRequest(theMethod, theURL, theArgs, obj1, back_url1)
{
	//alert(theURL);
	//alert(back_url);
	
	back_url = back_url1; 
	obj = obj1;
	theHttpRequestObject = getHttpRequestObject();
	theHttpRequestObject.open(theMethod, theURL, true);	
	setRequestHeader(theMethod, theURL);	
	theHttpRequestObject.onreadystatechange = ShowContentAjax;	
	theHttpRequestObject.send(theArgs);
}    

function ShowContentAjax() 
{
	if (theHttpRequestObject.readyState==4) 
	{
		if (theHttpRequestObject.status == 200) 
		{		
			if(obj!=null) 
			{
				obj.innerHTML=theHttpRequestObject.responseText;
				obj.style['display'] = '';
				//alert(theHttpRequestObject.responseText);		
			}
			
			if(back_url!=null) document.location.href = back_url;
		}
	}			
}	

//-----------------------------------------------------------------------------------------------------//

