Source code for /src/include_ajax.js.txt

// =====================================================================//
// Author: Mark Qian <markqian@hotmail.com>                             //
// WWW: http://www.coolshare.com/                                       //
// Copyright (c) 2006, Mark Qian                                        //
//                                                                      //
// You must contact Mark Qian to get a permission of use                //
// in case you want to make any use of the codes except viewing it     //
// on Mark's site.                                                      //
//======================================================================//

function Include() {
	  
	  this.load = function(url, id) {

	      if (!id)
	        id = "__include__";
	      this.id = id;
	      this.getUrl(url, this.cb, id);
	      
	  }
	  var self = this;
	  this.cb = function(status, headers, text) {
	  
	    var c = document.getElementById(this.id);
        if (!c) {
          //selTimeout(self.cb.apply(self, arguments), 500);
          //alert("failed to get "+this.id);
          return;
        }  
         
        var ttt; 
        var text2 = text.toLowerCase();
        var kk = 0;     
       
        while (true) {
          var i = text2.indexOf("<scr"+"ipt", kk); 
          if (i<0) 
            break; 
          var k = text2.indexOf(">", i+7);
          if (k<0)
            break;
	      var j = text2.indexOf("</scr"+"ipt>", i+8);
	      if (j<0) 
	        break;
        
	      ttt = this.clearCode(text.substring(k+1, j));
	      
 
	      var vv = "";
	      if (ttt.trim()!="") 
	        vv = eval(ttt);
	
	      text = text.substring(0, i)+vv+text.substring(j+9);
	      
	      kk = j+9;
        }
      
        c.insertAdjacentHTML("afterEnd", text);
        c.parentNode.removeChild(c);
	  }
	 
  
	  this.getXmlHttp = function(){
		  var xmlhttp;
		  try {
		    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		  } catch (e) {
		    try {
		      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		    } catch (E) {
		      xmlhttp = false;
		    }
		  }
		  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		    xmlhttp = new XMLHttpRequest();
		  }
		  return xmlhttp;
	}

    ////////////////// a closure is form to preserve self /////////////////
	this.getUrl = function(url, cb) {
	  this.xmlhttp = this.getXmlHttp();
	  this.xmlhttp.open("GET", url);
	  this.xmlhttp.onreadystatechange = function() {
	    if (self.xmlhttp.readyState == 4) {
	      self.cb(self.xmlhttp.status, 
	         self.xmlhttp.getAllResponseHeaders(), 
	         self.xmlhttp.responseText);
	      }
	  }
	  this.xmlhttp.send(null);
	}
	
	this.clearCode = function(s) {
	  var k = 0;
	  while (true) {
	    var i = s.indexOf("<!--", k);
	    if (i>-1) {
	      s = s.substring(0, i)+s.substring(i+5);
	      k = i+5;
	    }
	    i = s.indexOf("//-->");
	    if (i<0) 
	      break;
        s = s.substring(0, i)+s.substring(i+5);
	    k = i+5;	
	  }
	  return s;
	}
    
}

var include = new Include();

String.prototype.trim =      function() {
  return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}
function postamble() {
  return false;
}