
/**
 *  WebApplicationToolkit (WAT) control for the content management library
 *
 *  @author   Tobias Hettinger
 *  @version  $Id: wat.js,v 1.3 2008/10/24 13:19:09 tobias Exp $
 */
 

//  the script requires the variables 'cmsDesktop', 'cmsDesktopControl' and 'cmsTableControl'
//  to be set externally

//  initialize the external variables
var cmsDesktop = null;
var cmsDesktopControl = null;
var cmsTableControl = null;


/**
 *  default ajax response handler
 */
function cmsAjaxResponse(requestId)
{
  //  get the used xmlHttpRequest for the request
  var xmlHttpRequest = WATAjaxRequestData[requestId][0];
  
  //  check if the request was finished
  if (xmlHttpRequest.readyState == 4)
  {
    //  check if the request succeeded
    if (xmlHttpRequest.status == 200)
    {
      var ajaxResponse = xmlHttpRequest.responseXML.documentElement;
      if (ajaxResponse)
      {
        //  parse the ajax response that affects the desktop
        if (cmsDesktopControl) cmsDesktopControl.ParseXML(ajaxResponse, 'cmsAjaxResponse');
        //  parse the ajax response that affects a table
        if (cmsTableControl) cmsTableControl.ParseXML(ajaxResponse, true);
      }
      else
      {
        //  there is no valid XML
        alert(xmlHttpRequest.responseText);
      }
    }
    else
    {
      //  there was an error
      alert('the request failed with error \n\n' + xmlHttpRequest.statusText + ' (' + xmlHttpRequest.status + ')');
    }
    
    //  release the request object (this has to be done manually)
    WATAjaxRequestData[requestId][1] = false;
  }
}

/**
 *  default function to close the lightbox form with the passed name
 */
function cmsLightboxFormClose(name)
{
  if (name)
  {
    var lightbox = cmsDesktop.GetLightbox(name);
    if (lightbox)
    {
      //  the lightbox has been found, close the form
      lightbox.HideDiv(500);
      lightbox.HideBackground(500);
    }
  }
}

