if (typeof(__clbk_Requests) == 'undefined')	{
	var __clbk_Requests = new Array();
}

function callBack_cleanupxmlhttp()
{
    var j=0;
	for (var i=0; i<__clbk_Requests.length;i++)
	{
		if (__clbk_Requests[i] != null)
		{
			if (__clbk_Requests[i].completed)
			{
				__clbk_Requests[i].dispose();
				__clbk_Requests[i]=null;
				
			} else {
			 j=j+1;
			}
		}
	}
	if (j==0) __clbk_Requests = new Array();
	//window.status = __clbk_Requests.length + ' ' + new Date();
}

function CallBackObject(url,ContentId,fun,key,RefRate)
{
  this.parserName = null;
  this.URL=url;
  this.Refresh=RefRate;
  this.recallFunction=fun;
  this.UseKey=key;
  this.ContentId=ContentId;
  this.completed = false;
  this.XmlHttp = this.GetHttpObject();
}

CallBackObject.prototype.GetHttpObject = function()
{ 
  var xmlhttp;
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      this.parserName = 'Native';
    } catch (e) {
      xmlhttp = false;
    }
  } else if (window.ActiveXObject) { // IE
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      this.parserName = 'ActiveX';
  }
  return xmlhttp;
}

CallBackObject.prototype.DoCallBack = function(){
  if( this.XmlHttp )
  {
    if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
    {
      var oThis = this;
      this.XmlHttp.open("GET", this.URL, true);
      this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
      this.XmlHttp.send(null);
    }
  }
}

CallBackObject.prototype.ReadyStateChange = function()
{
  if (this.XmlHttp.readyState == 4) { // Complete
    if (this.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK" ) { // OK response
		this.processResponse(this.XmlHttp.responseText);
    } else {
		//alert("Problem with server response:\n " + this.XmlHttp.statusText);
		this.Refresh=30000
    }
  }
  
  if (this.Refresh>3000) {
	rfun=this.recallFunction + "('" + this.URL + "','" + this.ContentId + "')";
	setTimeout(rfun,this.Refresh);
  } 
}

CallBackObject.prototype.dispose = function ()
{
	if (this.XmlHttp != null)
	{
		this.XmlHttp.onreadystatechange = new function() {};//stop IE memory leak.  Not sure why can't set to null;
		this.XmlHttp.abort();
		this.XmlHttp = null;
		this.URL=null;
		this.Refresh=null;
		this.recallFunction=null;
		this.UseKey=null;
		this.completed = null;
	}
}

CallBackObject.prototype.OnComplete = function()
{
  // Complete
  this.OnCompleting();
  this.completed = true;

  if (this.parserName =='ActiveX') setTimeout('callBack_cleanupxmlhttp()', 1);	//cleanup xmlhttp object
}

CallBackObject.prototype.OnCompleting = function()
{
  // Complete
}

CallBackObject.prototype.OnReplace = function(txt)
{
  return txt
}

CallBackObject.prototype.processResponse = function(txt)
{
  data=txt.split("*")
  strRefresh=data[2].replace("\n","")
  strRefresh=strRefresh.replace("#Refresh ","")
  this.Refresh=parseInt(strRefresh.replace("\n",""))*1000
  strTime=data[3].replace("\n","");
  strTitle=data[4].replace("\n","");
  strFields=data[5].replace("\n","");
  fields=strFields.split("#");
  
  for ( var j=6; j<data.length-1; ++j ){
	strRecord=data[j].replace("\n","");
    values=strRecord.split("#")
    for ( var i=1; i<values.length; ++i ){
      if (this.UseKey==true) {
        lbl="cVal" + this.ContentId + "_" + fields[i].replace(" ","") + "_" + values[1].replace(" ","");
      } else {
        lbl="cVal" + this.ContentId + "_" + fields[i].replace(" ","");
      }
	  if(document.getElementById(lbl))
	  {
	    var v=this.OnReplace(values[i]);
		document.getElementById(lbl).innerHTML = v;
	  } 
	 }
  }
  this.OnComplete();
}

function replaceTicker(txt){
  txt=txt.replace(/\=/g,"&nbsp;&nbsp;&nbsp;");
  txt=txt.replace(/\[\-/g,"(<font style='font-size: 12px;' face=wingdings color=red>ê</font><font class=tcNegative>");
  txt=txt.replace(/\[/g,"(<font style='font-size: 12px;' face=wingdings color=green>é</font><font class=tcPositive>");
  txt=txt.replace(/\]/g,"</font>)&nbsp;&nbsp;&nbsp;");
 return txt;
}
