
function ajax (_method, _url) {
	var request=(window.XMLHttpRequest)? new XMLHttpRequest : new ActiveXObject("MSXML2.XMLHTTP");
	request.onreadystatechange=onReadyStateChange;
	var updater=null;
	var url=_url;
	var method=_method;
	var thisObj=this;
	
	
	thisObj.targetelementid=null;
	
	
	this.onLoaded=function(){}
	this.onInteractive=function(){}
	
	this.onLoading=function () {
		createUpdater();
	}
	
	this.processResult=function () {
		if (thisObj.targetelementid!=null) {
			document.getElementById(thisObj.targetelementid).innerHTML=thisObj.getResponse();
		}
	}

	this.onComplete=function () {
		if (updater!=null) updater.style.display='none';
		this.processResult();
	}

	this.onError=function () {
		alert('error');
	}

	
	function createUpdater() {
		if (thisObj.targetelementid==null) return;
		var te=document.getElementById(thisObj.targetelementid);
	
		if (updater==null) {
			updater=icore.createElement('div',{id:thisObj.targetelementid+'updater',className:'updater'});
			updater.style.position='absolute';
			if (te!=null) {
				updater.style.top=icore.getElYPos(te)+'px';
				updater.style.left=icore.getElXPos(te)+'px';
				updater.style.width=te.offsetWidth+'px';
				updater.style.height=te.offsetHeight+'px';
			} else {
				updater.style.top=0+'px';
				updater.style.left=0+'px';
				updater.style.width=document.body.clientWidth+'px';
				updater.style.height=screen.availHeight+'px';
			}
			icore.changeOpacity(updater, 80);
		} else updater.style.display='block';
		
		updater.innerHTML='Loading...';
		document.body.appendChild(updater);
	}

	function onReadyStateChange() {
		switch(request.readyState) {
			case 0:break;
			case 1:thisObj.onLoading();break;
			case 2:thisObj.onLoaded();break;
			case 3:thisObj.onInteractive();break;
			case 4:thisObj.onComplete();break;
			default:thisObj.onError();break;
		}
	}
	
	this.update=function () {
		var urlparams='';
		if (this.update.arguments[0]!=null) {
			urlparams=this.update.arguments[0];
		}

		request.open(method, url+urlparams, true);
		request.send(null);
	}


	this.getResponse=function () {
		if (request.getResponseHeader('Content-Type').indexOf('xml')!=-1) {
			return request.responseXML.documentElement;
		} else {
			return request.responseText;
		}
	}
}

