// Script Source: banvetau.com
// Copyright 2007
// Do not remove this notice.
// JavaScript Document for Ajax
function HTTPReq() {

	var theAJAX;

	if(window.XMLHttpRequest) {
		theAJAX = new XMLHttpRequest();
		if(theAJAX.overrideMimeType) {
			theAJAX.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject) {
		try {
			theAJAX = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e){ 
			try {
				theAJAX = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				theAJAX = false;
			}
		}
	}
	if(!theAJAX){
		alert('Giving up :( Cannot create an XMLHTTP instance');
	}
	return theAJAX;
}

function doAjaxPost(paramList,url,onsuccess,onfail) {

	var ajax = HTTPReq();
	if (!ajax) return;

	var paramArr = [];
	for (var item in paramList) {
		// don't handle arrays, objects, functions, etc
		if (typeof paramList[item] == "string" || typeof paramList[item] == "number") {
			paramArr.push(encodeURIComponent(item) + "=" + encodeURIComponent(paramList[item]));
		}
	}
	var params = paramArr.join("&");

	ajax.open("POST", url, true);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			if (ajax.status == 200 || ajax.status == 0) {
				onsuccess(ajax.responseText);
			} else {
				onfail(ajax.status);
			}
		}
	}
	ajax.send(params);			
}

function loadPage(refreshURL) {
	doAjaxPost({},refreshURL,
		function (ajaxText) {
			document.getElementById("refreshMe").innerHTML = ajaxText;
		}, 
		function (statusCode) {
			alert("Loi trong viec lay du lieu . Trang thai la: " + statusCode);
		}
	);
}

