//////////////////////////////////////////////////////////////////////////////
//
// Project: www.eskonline.nl
// File: ajax.js
// Author: Frank van Wensveen (frank@silverwolfmedia.com)
// Purpose: simple ajax(ish) support functions
//
// --------------------------------------------------------------------------
//
// Revision history
// ----------------
// 2008-08-20:  Initial version
// 2009-04-15:  Rewrite for ESK
//
// --------------------------------------------------------------------------
//
// LEGAL NOTICE
// ------------
// THE CONTENTS OF THIS FILE ARE PROPRIETARY, AND THE EXCLUSIVE PROPERTY OF
// SILVER WOLF MEDIA. UNAUTHORIZED COPYING, DISTRIBUTION, DISLOSURE TO THIRD
// PARTIES, MODIFICATION OR OTHER USE WITHOUT PRIOR WRITTEN CONSENT ARE
// EXPRESSLY PROHIBITED.
// (c) 2008 Silver Wolf Media - www.silverwolfmedia.com - All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////


// ---------------------------------------------------------------------------
// ajaxRead - fetch an AJAX object. Accepts: file/url, target object
function ajaxRead (file, ajaxTarget) {
  var xmlObj = null;

  // The ubiquitous code branching:
  if (window.XMLHttpRequest) {
    xmlObj = new XMLHttpRequest ();
  } else {
    if (window.ActiveXObject) {
      xmlObj = new ActiveXObject ("Microsoft.XMLHTTP");
    } else {
      alert ('Fatal: Your web browser does not support AJAX features.');
      return;
    }
  }

  // At this point, xmlObj is our object handler for the Ajax object.
  // If the target document has an 'ajaxRotator' object, activate it:
  if (document.getElementById('ajaxRotator'))
    document.getElementById('ajaxRotator').innerHTML='<img src="images/ajaxLoading.gif" width="16" height="16" border="0" alt="Loading...">'; 

  // Set up a state change event handler that updates the target object:
  xmlObj.onreadystatechange = function () {
    if (xmlObj.readyState == 4) {
      ajaxUpdateObj (ajaxTarget, xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data);
    }
  }

  // Fetch the XML data:
  xmlObj.open ('GET', file, true);
  xmlObj.send (null);
}

// Update target with data:
function ajaxUpdateObj (obj, data) {
   document.getElementById(obj).innerHTML = data; // Beware IE quirks!

  // If the target document has an 'ajaxRotator' object, deactivate it:
  if (document.getElementById('ajaxRotator'))
    document.getElementById('ajaxRotator').innerHTML='&nbsp;';

}

// EOF

