var ContentLoader = function(url, id, options){
         this.url = url;
         this.id = id;
	 this.init = false;
	 this.xmlHttp = false;
	 this.xml = false;
	 this.text = '';
	 this.done = false;
	 this.browser = '';
	 this.responseType = 'text'; //'text' or 'xml'
	 this.callback1 = function(){};
	 this.callback2 = function(){};
	 this.callback3 = function(){};
	 this.callback4 = function(){
		document.getElementById(this.id).innerHTML = this.text;
	 };
	 if (typeof options != 'undefined' ){
		if (typeof options.responseType != 'undefined' ){
			this.responseType = options.responseType;
		}
		if (typeof options.callback1 != 'undefined' ){
			this.callback1 = options.callback1;
		}
		if (typeof options.callback2 != 'undefined' ){
			this.callback2 = options.callback2;
		}
                if (typeof options.callback3 != 'undefined' ){
			this.callback3 = options.callback3;
		}
                if (typeof options.callback4 != 'undefined' ){
			this.callback4 = options.callback4;
		}
	 }
	 this.setup();
   };
ContentLoader.prototype.isIe = function(){
	if( this.browser.indexOf("ie") >= 0 ){
		return true;
	}else{
		return false;
	}
};
ContentLoader.prototype.setup = function(){
	if (typeof XMLHttpRequest!='undefined')
	{
	     this.xmlHttp = new XMLHttpRequest();
	     if(document.all){
	       this.browser = 'ie'+parseFloat(navigator.appVersion.split('MSIE')[1]);
	     }else{
	       this.browser = 'mozilla';
	     }
	}
	if (!this.xmlHttp && window.ActiveXObject)
	{
	    this.browser = 'ie'+parseFloat(navigator.appVersion.split('MSIE')[1]);
	    try
	    {
		this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
		try
		{
			this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) { this.xmlHttp = false; }
	    }
	}
	var str = this.url;
	//alert(this.browser);
	if( this.isIe() ){
	  if( str.indexOf("?") >= 0 ){
	   this.url+="&millis"+new Date().getTime()+"="+new Date().getTime();
	  }else{
	   this.url+="?millis"+new Date().getTime()+"="+new Date().getTime();
	  }
	}
	//alert(this.url);
       if (this.xmlHttp) this.init = true;
};
ContentLoader.handler = function( o ){
		var obj = o;

		if (obj.xmlHttp.readyState == 1)
		{obj.callback1();
		}else if (obj.xmlHttp.readyState == 2)
		{obj.callback2();
		}else if (obj.xmlHttp.readyState == 3)
		{obj.callback3();
		}else if (obj.xmlHttp.readyState == 4)
		{	if (obj.xmlHttp.status == 200 || obj.xmlHttp.status == 0) {
				if( obj.responseType == 'text' ){
					obj.text = obj.xmlHttp.responseText;
				}else if( obj.responseType == 'xml' ){
					obj.xml = obj.xmlHttp.responseXML;
				}
				obj.done = true;
			}else{ 
				obj.text = obj.xmlHttp.status; 
			}
			obj.callback4();
		}
};
ContentLoader.prototype.start = function(){
		if (!this.init) return false;
		var me = this;
		try{
			this.xmlHttp.onreadystatechange = function() { ContentLoader.handler(me); }
			this.xmlHttp.open( 'GET', this.url, true );
			this.xmlHttp.send(null);
		}catch(e){
			this.init = false;
		}
};