/**
 * Stores the reference to the XMLHttpRequest object
 */
var xmlhttp; 

/**
 * Loads a document asynchronously using the XMLHttpRequest object.
 */ 
function loadXMLDoc(url)
{
  // code for Opera, Mozilla, Safari etc.
  if (window.XMLHttpRequest)
  {
    xmlhttp = new XMLHttpRequest()
    xmlhttp.onreadystatechange = OnStateChange; 
    xmlhttp.open("GET", url, true)
    xmlhttp.send(null)
  }
  // code for IE
  else if (window.ActiveXObject)
  {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
      xmlhttp.onreadystatechange = OnStateChange;
      xmlhttp.open("GET", url, true);
      xmlhttp.send();
    }
  }
}

/**
 * This function is called automatically when the server responds after
 * a request with the XMLHttpRequest object. 
 */ 
function OnStateChange()
{
    // if xmlhttp shows "loaded"
  if (xmlhttp.readyState == 4)
  {
    // if "OK"
    if (xmlhttp.status == 200)
    {
      SetContent(xmlhttp.responseText);
    }
    else
    {
      alert("Problem retrieving data:" + xmlhttp.statusText)
    }
  }
}

/**
 * Post data using the XMLHttpRequest object.
 */ 
function AJAX_PostData(_sUrl, _sData)
{
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
  if (xmlhttp)
  {
    xmlhttp.onreadystatechange = OnStateChange;
    xmlhttp.open("POST", _sUrl, true);
    xmlhttp.setRequestHeader("Content-Type", 
      "application/x-www-form-urlencoded");
    xmlhttp.send(_sData);
  }
}

/**
 * Returns the form data as a string.
 */ 
function GetFormData(_oForm) 
{
  aParams = new Array();
  
  for (i = 0 ; i < _oForm.elements.length; i++) 
  {
    sParam = encodeURIComponent(_oForm.elements[i].name);
    sParam += "=";
    sParam += encodeURIComponent(_oForm.elements[i].value);
    aParams.push(sParam);
  }
  return aParams.join("&");
}

/**
 * Sets the HTML of the Contents Div.
 */ 
function SetContent(_sHTML)
{
  document.getElementById('idLeftpane').innerHTML = _sHTML;
}

/**
 * Sets the HTML of the Contents Div by loading a URL.
 */ 
function LoadContent(_sURL, _sMsgHTML)
{
  //SetContent(_sMsgHTML);  
  SetContent('Loading...<img src="images/gears8.gif"> </img>');
  loadXMLDoc(_sURL);
}


//--- Useful functions

/**
 * Shows a popup error box.
 */ 
function ShowError(_sMsg)
{
  /*SetDialog( 
    '<div class="clsDialog">\n'
    +'    <h1>Error</h2>\n'
    +'    <p>'+sMsg+'</p>\n'
    +'    <button onclick="HideDialog();">&nbsp;OK&nbsp;</button>'
    +'</div>');*/
  alert(_sMsg);
}

/**
 * Ensures a field on a form is not empty.
 *  
 * @param _oField The field to check.
 * @param _sMsg The message to display if the field is empty.
 */ 
function Frm_Val_ReqFld(_oField, _sMsg)
{
  with (_oField)
  {
    if (value == null || value == "")
    {
      ShowError(_sMsg);
      _oField.focus();
      return false;
    }
    else return true;
  }
}







