//-----------------------------------------------------------
// AJAX Message 
//-----------------------------------------------------------\
function lookForMessage(filename,targetElement,onCompletion)
{
  try{
    if (!document.getElementById) return;
    if (typeof(filename)=="undefined" || !filename) return;
    if (typeof(onCompletion)=="undefined" || ! onCompletion) onCompletion=printMessage;
    var parentdir=location.href.replace(/^(https?\:\/\/[^\/]+).+$/,"$1");
    var url=parentdir+((!/^\//.test(filename))?"/":"")+filename;//?shouldn't I be using relative paths if so desired?
    var ajax = new sack(url);
    if(ajax.failed){ return; }
    ajax.onCompletion = function(){onCompletion(this.response,targetElement);}; 
    ajax.runAJAX();
  }catch(e){}//discard
}

function printMessage(data,targetElement)
{
  try{
    if (!targetElement) return;
    data=data.replace(/(^\s+|\s+$)/,"");
    if (!data  || /Page Not Found|was not found on this server/i.test(data)) return;
    var hold=document.getElementById(targetElement);
    if (!hold) return;
    hold.innerHTML=data;
  }catch(e){}//discard
}


/* Simple AJAX Code-Kit (SACK) ©2005 Gregory Wild-Smith www.twilightuniverse.com */
/* Software licenced under a modified X11 licence, see documentation or authors website for more details */
/* simplified for use by StockCharts.com */
function sack(file){
  this.requestFile = file;
  this.onCompletion = function() { };
  this.failed=false;
  this.response="";
  this.createAJAX = function() {
    try {
      this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (err) {
        this.xmlhttp = null;
      }
    }
    if(!this.xmlhttp && typeof XMLHttpRequest != "undefined"){
      this.xmlhttp = new XMLHttpRequest();
    }
    if (!this.xmlhttp){
      this.failed = true; 
    }
  };
  this.runAJAX = function(){
    if (this.failed && this.AjaxFailedAlert) return;
    if (this.xmlhttp)
    {
       var self = this;
       this.xmlhttp.open("GET", this.requestFile, true);
       this.xmlhttp.onreadystatechange = function() {
          if (self.xmlhttp.readyState == 4)
          {
              self.response = self.xmlhttp.responseText;
              self.onCompletion();
          }
       };
       this.xmlhttp.send("");
    }
    this.response="";
  };
this.createAJAX();
}

