function XmlHttp(id)
{
	this.Init = function() {
	    var req = null;
		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();
		}
		return this.xmlHttp = req;
	}
	this.xmlHttp = null;
	this.url = "";
	this.waitImage = "images/load.gif";
	this.responseXML = null;
	this.refesh = false;
	this.firstLoad = false;
	this.id = id;
	
	this.onLoad = function() {
		var cURL=window.location.href;
		cURL=cURL.split('#');
		if( cURL[1] != null && cURL[1] != "a"){
			this.url = "./?id="+cURL[1];
			this.refesh = true;
		} else {
			this.url = "./?id=index";
		}
		this.firstLoad = true;
	}
	
	this.sendRequest = function(url,callbackFunction,method,cache,request) {		
	    var req = this.Init();
		if ( req==null ) return;
		req.onreadystatechange = function() {
            // only if req shows "complete" & only if "OK"
            if ( req.readyState == 4 &&
                 req.status == 200) {
                // Process
                eval(callbackFunction);
            }
        };		
		url += "&rand="+parseInt(Math.random()*999999999999999);
		// 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 , true);
			req.send(null);
		}
		return req;
	}
	
	this.isPost = function(request) {
		return (request != null && request != "");
	}
	
	this.sendOnly = function(url,request) {
	    if(request == null) this.sendRequest(url,null,"POST",0,request);	
		else this.sendRequest(url);
	}
	
	this.waiting = function(tag) {
        obj = document.getElementById(tag);
        obj.innerHTML = "<center><img border=0 src='"+this.waitImage+"' align='absbottom'></center><br>";
    }
    
    this.displayXml = function(array_tag) {
		alert(this.xmlHttp.responseText);
        for(i=0; i<array_tag.length-1; i++) {
			xmlObj = this.xmlHttp.responseXML.getElementsByTagName(array_tag[i]);
			htmlObj = document.getElementById(array_tag[i]);
			htmlCode = "";
			for(i=0; i<xmlObj[0].childNodes.length; i++) htmlCode += xmlObj[0].childNodes[i].xml;
			htmlObj.innerHTML = htmlCode;
		}
    } 
	
	this.displayUrl = function(tag, url, request, wait) {
		
		if(wait != false) this.waiting(tag);
		if( this.isPost(request) )
			this.sendRequest(url,this.id+".display('"+tag+"')","POST",0,request);	
		else this.sendRequest(url,this.id+".display('"+tag+"')");
	}
	
	this.multiDisplay = function(array_tag, url, request) {
	    var display = this.id + ".displayXml(new Array(";
	    for(i in array_tag) {
	        display += "'"+array_tag[i]+"',";
	    }
		display += "''))";
		alert(display);
	    if( this.isPost(request) )
			this.sendRequest(url,display,"POST",0,request);	
		else this.sendRequest(url,display);
	}
	
	this.multiSend = function(array_id, url, callback, method, wait) {
	    var request = "";
	    for(i in array_id) {
	        obj = document.getElementById(array_id[i]);
	        request += "&"+array_id[i]+"="+encodeURIComponent(obj.value);
	    }
	    
	    if( method == "POST")
			this.sendRequest(url,callback,"POST",0,request);	
		else this.sendRequest(url+request,callback);
	}
	
	this.submit = function(tag, url, array_id, wait) {
	    this.multiSend(array_id, url, this.id+".display('"+tag+"')", "POST", true);
	}
	
	this.submitOnly = function(url, array_id) {
	    this.multiSend(array_id, url);
	}
	
	this.display = function(tag)
	{
		obj = document.getElementById(tag);
		obj.innerHTML = this.xmlHttp.responseText;
	}
}

var bee = new XmlHttp("bee");
var bee1 = new XmlHttp("bee1");
var bee2 = new XmlHttp("bee2");

bee.onLoad();


//dung khi load sites lan dau tien
window.onload = function() {
	bee2.displayUrl("nhanxet","index.php?id=nhanxet");
	bee1.displayUrl("media", "index.php?id=media");
	ck = getCookie("mnu");
	if(ck != null && ck != "") {
		cks = ck.split(":");
		mnu = parseInt(cks[0]);
		submnu = parseInt(cks[1]);
		if( mnu != 0 ) SelectMenu(0, mnu-1);
		SelectMenu(mnu, submnu);
	}
}

function ajaxClick(tag, url, id) {
	bee.displayUrl(tag, url + id);
	document.location.href = "#"+id;
}