
function ajax (_method, _url) {
	var request=(window.XMLHttpRequest)? new XMLHttpRequest : new ActiveXObject("MSXML2.XMLHTTP");
	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) {
			var response=thisObj.getResponse();
			document.getElementById(thisObj.targetelementid).innerHTML=response;
			re=/<script type="text\/javascript">(.*)<\/script>/g;
			var scriptsArray = response.match(/<script type="text\/javascript">(.*)<\/script>/g);
			if (scriptsArray != null) {
				var scriptexe='';
				for ( i = 0; i < scriptsArray.length; i++ ) {
					scriptexe+=scriptsArray[i].replace(/<(\/?)script([^>]*)>/g, '');
				}
				eval(scriptexe);
			}
		}
	}

	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 content=null;
		if (this.update.arguments[0]!=null) {
			content=this.update.arguments[0];
		}

		request.open(method, url, true);
		request.onreadystatechange=onReadyStateChange;
		if (method.toLowerCase()=='post') request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		request.send(content);
	}


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