function CallBackObject()
{
  this.XmlHttp = this.GetHttpObject();
}
 
CallBackObject.prototype.GetHttpObject = function()
{ 
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
 
CallBackObject.prototype.DoCallBack = function(eventTarget, eventArgument)
{
  var thePage = window.location.pathname + window.location.search;
  var eName = '';
 
  theData  = '__EVENTTARGET='  + escape(eventTarget.split("$").join(":")) + '&';
  theData += '__EVENTARGUMENT=' + eventArgument + '&';
  theData += 'IsCustomCallBack=true&';

  if( this.XmlHttp )
  {
    if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
    {
      var oThis = this;
      this.XmlHttp.open('POST', thePage, true);
      this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
      this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      this.XmlHttp.send(theData);
    }
  }
}
 
CallBackObject.prototype.AbortCallBack = function()
{
  if( this.XmlHttp )
    this.XmlHttp.abort();
}
 
CallBackObject.prototype.OnLoading = function()
{
  // Loading
}
 
CallBackObject.prototype.OnLoaded = function()
{
  // Loaded
}
 
CallBackObject.prototype.OnInteractive = function()
{
  // Interactive
}
 
CallBackObject.prototype.OnComplete = function(responseText, responseXml)
{
  // Complete
}
 
CallBackObject.prototype.OnAbort = function()
{
  // Abort
}
 
CallBackObject.prototype.OnError = function(status, statusText)
{
  // Error
}
 
CallBackObject.prototype.ReadyStateChange = function()
{
  if( this.XmlHttp.readyState == 1 )
  {
    this.OnLoading();
  }
  else if( this.XmlHttp.readyState == 2 )
  {
    this.OnLoaded();
  }
  else if( this.XmlHttp.readyState == 3 )
  {
    this.OnInteractive();
  }
  else if( this.XmlHttp.readyState == 4 )
  {
    if( this.XmlHttp.status == 0 )
      this.OnAbort();
    else if( this.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK" )
      this.OnComplete(this.XmlHttp.responseText, this.XmlHttp.responseXML);
    else
      this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);   
  }
}

var Cbo = new CallBackObject();
Cbo.OnComplete = Cbo_Complete;
Cbo.OnError    = Cbo_Error;
var oContext = new Object();

/*function GetContent(content,target,pref)
{
	var sMessage = content+':'+pref;

	
	oContext.CommandName = 'GetSmaakContent';
	oContext.target = target;
	oContext.pref = pref;

  Cbo.DoCallBack(content,pref);

	try{
		document.getElementById(target+'_content').innerHTML="<p class=\"loading\">loading...</p>";
	}catch(e){}
  set_smaak(target,pref);
}*/

function GetContent(content,target,pref)
{
	var sMessage = content+':'+pref;

	oContext.CommandName = 'GetSmaakContent';
	oContext.target = target;
	oContext.pref = pref;
	oContext.content = content;

  //Cbo.DoCallBack(content,pref);

	try{
		document.getElementById(target+'_content').innerHTML="<p class=\"loading\">loading...</p>";
	}catch(e){}
  set_smaak(target,pref);

	setTimeout('DelayedGet()',500);
}

function DelayedGet()
{
  Cbo.DoCallBack(oContext.content,oContext.pref);
}

function Cbo_Complete(responseText, responseXML)
{
  if (oContext.CommandName == 'GetSmaakContent'){
    var oBlock = document.getElementById(oContext.target);
    var oContent = document.getElementById(oContext.target+'_content');
    oContent.innerHTML=responseText;
    //alert(result);
  }
  else alert('Unhandled callback:'+oContext.CommandName);
}

function Cbo_Error(status, statusText, responseText)
{
  alert(responseText);
}