function ajaxLoad(method,URL,data,displayId){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("บราวเซอร์ของคุณไม่รองรับ !");
				return false;
			}
		}
	}


var nonewait = data.indexOf("div=nonewait");

method = method.toLowerCase();
URL += "?ajax=" + (new Date()).getTime();

if(method.toLowerCase() == "get"){
URL += "&" + data;
data = null;
} 

ajaxRequest.open(method,URL);

 if(method.toLowerCase() == "post"){
ajaxRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ctype = ajaxRequest.getResponseHeader("Content-Type");
		ctype = ctype.toLowerCase();
		ajaxCallback(ctype,displayId ,ajaxRequest.responseText);
		delete ajaxRequest;
		ajaxRequest=null;
			}else{
		if(nonewait != 0){
		ajaxCallwait(displayId );
		}
			}
	}
ajaxRequest.send(data);
}

function ajaxCallback(contentType,displayId,responseText){
if(contentType.match("text/javascript")){
eval(responseText);
}else{
 document.getElementById(displayId).innerHTML = responseText;
}}

function ajaxCallwait(displayId ){
document.getElementById(displayId).innerHTML= "<div width='100' align='center'><BR><img src=\"images/AjaxLoading.gif\" alt=\"Loading...\"/><BR><" + "/" + "div>";
}

function ajaxError(displayId){
document.getElementById(displayId).innerHTML= "<div width='100' align='center'><font size=\"2\" color=\"#ff0000\" face=\"MS Sans Serif\">ผิดพลาด ลองใหม่อีกครั้ง !<" + "/" + "font> <" + "/" + "div>";
}
