
function getXMLHTTP(){
	var A=null;
	try{
		A=new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			A=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(oc){
			A=null;
		}
	}
	if(!A && typeof XMLHttpRequest != "undefined") {
		A=new XMLHttpRequest();
	}
	return A;
}

function request_xmlHttp(method,url,func){
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTP();
	if(_xmlHttp){
		_xmlHttp.open(method,url,true);
		_xmlHttp.onreadystatechange=function() {
			// if( _xmlHttp.readyState==4 && _xmlHttp.status == 200 && _xmlHttp.responseText ){
			if( _xmlHttp.readyState==4 && _xmlHttp.status == 200 ){
				//func(_xmlHttp.responseText);
				func();
			}
		};
		_xmlHttp.send(null);
	}
}
function httpRequest(){
	this.xmlHttp=null;//getXMLHTTP();
	this.request_list=[];
	this.xmlHttpPrevReadyState="";// for Firefox
}
httpRequest.prototype.request=function(method,url,func,query,additional_value){
	this.request_list.push({
		'method':method,
		'url':url,
		'func':func,
		'query':query,
		'additional_value':additional_value
	});
	if( this.request_list.length==1 ){
		this.do_request();
	}
};
httpRequest.prototype.onload=function(){
	// if( this.xmlHttp.status == 200 && this.xmlHttp.responseText ){
	if( this.xmlHttp && this.xmlHttp.status == 200 ){
		this.request_list[0].func(this.request_list[0].additional_value);
	}
	this.request_list.shift();
	if( this.request_list.length>0 ){ this.do_request(); }
};
httpRequest.prototype.do_request=function(){
	if( ! this.request_list[0] ){ return; }
	if( this.xmlHttp && this.xmlHttp.readyState!=0 ){ this.xmlHttp.abort(); }
	this.xmlHttp=getXMLHTTP();
	if( this.xmlHttp ){
		var self=this;
		var postdata=null;
		// postdata = 'text=' + encodeURIComponent(textbox.value);
		this.xmlHttp.open(this.request_list[0].method,this.request_list[0].url,true);
		if( this.request_list[0].method.toUpperCase()=="POST" ){
			if( this.request_list[0].query ){
				if( typeof(this.request_list[0].query)=="string" ){
					postdata=this.request_list[0].query;
				// }else if( typeof(this.request_list[0].query)=="object" ){
				}
			}
			this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}
		this.xmlHttp.onreadystatechange=function() {
			if( self.xmlHttpPrevReadyState!=self.xmlHttp.readyState ){
				self.xmlHttpPrevReadyState=self.xmlHttp.readyState;
			}else{
				return;
			}
			if( self.xmlHttp.readyState==4 ){
				self.onload();
			}
		};
		this.xmlHttp.send(postdata);
	}
};

var _xmlHttp=null;
var http_request=new httpRequest();
