/*

Ajaxian 

This script holds the main AJAX functions.

It needs to be included on any pages that require the ajax behaviours.

*/

var httpRequest;

function processRequest(sHandlerName)
{
  if (httpRequest.readyState == 4)
  {
    if(httpRequest.status == 200)
    {
      // Pass the XML back to the right handler
      eval(sHandlerName + '(httpRequest.responseXML);');
    }
    else
    {
      alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }
} 

function getValueFromXML(sTagName, xXML) {



    if (xXML.getElementsByTagName(sTagName)[0].childNodes.length > 0) {
  
      return (xXML.getElementsByTagName(sTagName)[0].childNodes[0].nodeValue);
 
    }


}

function updateHTML(sElement, sNewValue)
{
  
  try {
  
    //Create the Text Node with the data received
    var oTextNode = document.createTextNode(sNewValue);

    //Get the reference of the DIV in the HTML DOM by passing the ID
    var oHMTL = document.getElementById(sElement);

    if (sNewValue == undefined) { 

      if (oHMTL.childNodes[0] != undefined) { oHMTL.removeChild(oHMTL.childNodes[0]); }     
      return;

    }

    //Check if the TextNode already exist
    if(oHMTL.childNodes[0])
    {
      //If yes then replace the existing node with the new one
      oHMTL.replaceChild(oTextNode, oHMTL.childNodes[0]);
    }
    else
    {
      //If not then append the new Text node
      oHMTL.appendChild(oTextNode);
    }       
  
  }
  
  catch(e) {
  
  }
  
} 

