function QCAjax(target, script)
{
	this.xmlhttp = null;
	this.xTargetType = null;//self,parent
	this.xTarget = target;
	this.xScript = script;
	this.xPreUrl = null;
	this.xCurUrl = null;

	this.xDone = false;
	this.xDuration = 10000;
	this.xTimeout = null;
}
QCAjax.prototype.getXmlHttpObject = function ()
{
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}
QCAjax.prototype.xCallback = function ()
{
	var self = this;
	return function () {
		if(self.xmlhttp){
			if (self.xmlhttp.readyState==4)
			{
				if (self.xmlhttp.status==200)
				{
					self.xDone = true;
					window.clearTimeout(self.xTimeout);
					if(self.xTargetType == "parent")
					{
						if(self.xTarget && parent.document.getElementById(self.xTarget))
							parent.document.getElementById(self.xTarget).innerHTML=self.xmlhttp.responseText;
					}
					else
					{
						if(self.xTarget && document.getElementById(self.xTarget))
							document.getElementById(self.xTarget).innerHTML=self.xmlhttp.responseText;
					}
					if(self.xScript && document.getElementById(self.xScript))
					{
						var script = document.getElementById(self.xScript).innerText;
						if(!script) script = document.getElementById(self.xScript).textContent;//for FireFox
						document.getElementById(self.xScript).innerHTML = '';
						eval(script);
					}
				}
				else
				{
					//alert("Problem retrieving XML data:" + self.xmlhttp.statusText);
					document.getElementById(self.xTarget).innerHTML="Problem retrieving XML data:" + self.xmlhttp.statusText;
				}
			}
			else
			{
				if(self.xTarget && document.getElementById(self.xTarget))//sometime is null
				{
					document.getElementById(self.xTarget).innerHTML="<table border='0' width='80%' height='200'><tr><td class='smallText' align='center'><img src='loading.gif' /><br/><br/>&nbsp;&nbsp;&nbsp;Loading ...</td></tr></table>";
				}
			}
		}
	}
}
QCAjax.prototype.xSubmit = function (url)
{
	this.xDone = false;
	if(this.xCurUrl != url)
	{
		this.xPreUrl = this.xCurUrl;
		this.xCurUrl = url;
	}
	this.xmlhttp=this.getXmlHttpObject();
	if (this.xmlhttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	//var self = this;
	this.xmlhttp.onreadystatechange=this.xCallback.call(this);/*function(){
		if (self.xmlhttp.readyState==4)
		{
			if (self.xmlhttp.status==200)
			{
				document.getElementById(self.xTarget).innerHTML=self.xmlhttp.responseText;
			}
			else
			{
				alert("Problem retrieving XML data:" + self.xmlhttp.statusText);
			}
		}
		else
		{
			document.getElementById(self.xTarget).innerHTML="<img src='loading.gif' />";
		}
	};*/
	var self = this;
	window.clearTimeout(this.xTimeout);
	this.xTimeout = window.setTimeout(
		function(){
			if(self.xDone == false){
				self.xmlhttp.abort();
				delete self.xmlhttp['onreadystatechange'];//prevent call back after abort
				self.xmlhttp = null;
				try
				{
					document.getElementById(self.xTarget).innerHTML="<div style='width:100%;height:600px;text-align: left'><input class='smallCtrl' type='button' value='load again'/></div>";
					var ins = document.getElementById(self.xTarget).getElementsByTagName("input");
					ins[0].onclick=function(){self.xDuration+=5000;self.xSubmit(self.xCurUrl);};
				}
				catch (ex){}
			}
		},
		this.xDuration);
		
	this.xmlhttp.open("GET",this.xCurUrl,true);
	this.xmlhttp.send(null);
}
