var domainName="http://www.yeuthethao.com/dudoan/imgs.bongda";
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.XMLHttpRequest)//window.navigator.appName.toLowerCase().indexOf("netscape") > -1
	{
		return "Mozilla"; //For Firefox, Safari, Opera
	}
	else if(window.ActiveXObject)
	{
		return "IE";
	}
	else{
		//Error for an old browser
		alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
		}
}
/*
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, theArgs)
{
	
	if (theMethod == "POST")
	{
		//alert(theArgs);
		theHttpRequestObject.setRequestHeader("Method", "POST " + theURL + " HTTP/1.1");
		theHttpRequestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		theHttpRequestObject.setRequestHeader("Content-length", theURL.length);
	}
}

function doRequest(theMethod, theURL, theArgs, theHandledFunction)
{
	theHttpRequestObject = getHttpRequestObject();
	theHttpRequestObject.open(theMethod, theURL, true);	
	//setRequestHeader(theMethod, theURL);	
	setRequestHeader(theMethod, encodeURI(theURL), theArgs);	
	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, theArgs);	
	theHttpRequestObject.onreadystatechange = ShowContentAjax;	
	theHttpRequestObject.send(theArgs);
}    
function doNewRequest2(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, theArgs);	
	theHttpRequestObject.onreadystatechange = ShowContentAjax2;	
	theHttpRequestObject.send(theArgs);
}    

function ShowContentAjax() 
{
	if (theHttpRequestObject.readyState==4) 
	{
		if (theHttpRequestObject.status == 200) 
		{		
			if(obj!=null) 
			{		
				//alert(theHttpRequestObject.responseText);
				if(obj!=null) obj.innerHTML=theHttpRequestObject.responseText;
				if(obj.id=="div_message") 
				{
					var msg = obj.innerHTML;
					alert(Trim(msg));
				}
			}
			
			if(back_url!=null) document.location.href = back_url;
		}
	}
	else
		if(obj!=null) 
		{	
			obj.innerHTML = '<p align=center><img src="'+ domainName +'/images/spinner.gif" alt="" border="0" align="absmiddle"> Loading...</p>';		
		}		
}	
function ShowContentAjax2() 
{
	if (theHttpRequestObject.readyState==4) 
	{
		if (theHttpRequestObject.status == 200) 
		{		
			if(obj!=null) 
			{		
				//alert(theHttpRequestObject.responseText);
				if(obj!=null) obj.innerHTML=theHttpRequestObject.responseText;
				if(obj.id=="div_message") 
				{
					var msg = obj.innerHTML;
					alert(Trim(msg));
				}
			}
			
			if(back_url!=null) document.location.href = back_url;
		}
	}
	else
		if(obj!=null) 
		{	
			//obj.innerHTML = '<p align=center><img src="images/spinner.gif" alt="" border="0" align="absmiddle"> Loading...</p>';		
		}		
}	

//-----------------------------------------------------------------------------------------------------//

