// JavaScript Document
/**
 *  Ajax Class
 *  Designer:	Stephen Liang
**/
var AjaxKtClass = function()
{
	this.xmlHttp = false;
	this.url = "";
	this.updateFun = null;

	this.Create = function(url, updateFun)
	{
		this.xmlHttp=createXMLHttpRequest();
		this.url = url;
		this.updateFun = updateFun;
	}

	this.Open = function()
	{
		this.xmlHttp.open("GET", this.url+'?cachebuster='+CacheBuster(), true);
		this.xmlHttp.onreadystatechange = this.updateFun;
		this.xmlHttp.send(null);
	}
	this.OpenSync = function()
	{
		this.xmlHttp.open("GET", this.url, false);
		this.xmlHttp.send(null);
	}
	
	this.Open2 = function(url)
	{
		this.xmlHttp.open("GET", url+'?cachebuster='+CacheBuster(), true);
		this.xmlHttp.onreadystatechange = this.updateFun;
		this.xmlHttp.send(null);
	}
	
	this.Open3 = function(param)
	{
		this.xmlHttp.open("GET", this.url + param+'&cachebuster='+CacheBuster(), true);
		this.xmlHttp.onreadystatechange = this.updateFun;
		this.xmlHttp.send(null);
	}
	
	this.GetData = function()
	{
		if(this.xmlHttp.readyState == 4){
			return this.xmlHttp.responseText;
		}
		return null;
	}
	this.GetXML = function()
	{
		return this.xmlHttp.responseXML;
	}

	this.GetState = function()
	{
		return (this.xmlHttp.readyState);
	}
	this.GetErrorCode=function()
	{
		var xmlDoc=this.xmlHttp.responseXML.documentElement;

		return (xmlDoc.getElementsByTagName('error')[0].childNodes[0].nodeValue);

	}
	this.GetErrorDescription=function()
	{
		var strRet='';
		var xmlDoc=this.xmlHttp.responseXML.documentElement;

		try {strRet=xmlDoc.getElementsByTagName('errordesc')[0].childNodes[0].nodeValue;}
		catch(err) {strRet='Error Decription is missing';}
		return (strRet);

	}
	this.GetReturnValue=function(strElem)
	{
		var strRet='';

		var xmlDoc=this.xmlHttp.responseXML.documentElement;
		try {strRet=xmlDoc.getElementsByTagName(strElem)[0].childNodes[0].nodeValue;}
		catch(err) {strRet='';}
		return (strRet);

	}
	this.GetRecordValue=function(intRecNum,strElem)
	{
		var xmlDoc=this.xmlHttp.responseXML.documentElement;
		//alert('1');
		var recRecs=xmlDoc.getElementsByTagName('records')[0];
		//alert('2');
		var recRec=recRecs.getElementsByTagName('record'+intRecNum)[0];
		//alert('3');
		return recRec.getElementsByTagName(strElem)[0].childNodes[0].nodeValue;
	
	}

	this.GetNodeValue=function(objNode,strElem)
	{
		var strRet='';;

		try {strRet=objNode.getElementsByTagName(strElem)[0].childNodes[0].nodeValue;}
		catch(err) {strRet='';}
		return (strRet);
	}
}
function CacheBuster() {

return Math.floor(Math.random()*1000001);

}
function createXMLHttpRequest() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
try { return new XMLHttpRequest(); } catch(e) {}
    return null;
}
