var outputscript="global.php"

function displaybox(itemId, divId){
	this.loadingHTML='<img src="images/loading.gif">';
	this.itemId=itemId;
	this.boxid=divId;
	//this.cachetime=30;
}

// -------------------------------------------------------------------
// PUBLIC: set_cache_time(minutes)- Set cache time in minutes. INT.
// -------------------------------------------------------------------
displaybox.prototype.set_cache_time=function(minutes){
	this.cachetime=parseInt(minutes);
}

// -------------------------------------------------------------------
// PUBLIC: start()- User initiated start() function, to tell the script to initialize itself.
// -------------------------------------------------------------------
displaybox.prototype.start=function(){
	this.ajaxobj=createAjaxObj();
	this.getAjaxcontent();
}

// -------------------------------------------------------------------
// PRIVATE: getAjaxcontent()- Makes asynchronous GET request to "content.php" with the supplied parameters
// -------------------------------------------------------------------
displaybox.prototype.getAjaxcontent=function(){
	if (this.ajaxobj){
		var instanceOfBox=this;
		//var parameters="id="+this.itemId+"&cachetime="+this.cachetime+"&bustcache="+new Date().getTime();
		var parameters="mode="+this.itemId+"&bustcache="+new Date().getTime();
		temp = getElement(this.boxid);
		temp.innerHTML=this.loadingHTML;
		this.loadingHTML=null;
		this.ajaxobj.onreadystatechange=function(){
			instanceOfBox.initialize();
		}
		this.ajaxobj.open('GET', outputscript +"?"+ parameters, true);
		this.ajaxobj.send(null);
	}
}

// -------------------------------------------------------------------
// PRIVATE: initialize()- Initialize Display Box method.
// -------------------------------------------------------------------
displaybox.prototype.initialize=function(){ 
	if (this.ajaxobj.readyState == 4){
		if (this.ajaxobj.status==200){
			var itemContent=this.ajaxobj.responseText;
			temp = getElement(this.boxid);
			temp.innerHTML = itemContent;
		}
		else {
			temp = getElement(this.boxid);
			temp.innerHTML = this.ajaxobj.responseText;
		}
	}
}

////////// END RSSDISPLAYBOX() FUNCTION ////////////////////
//Create Ajax instance function
function createAjaxObj(){
	var httprequest=false
	if (window.XMLHttpRequest){ // if Mozilla, IE7, Safari etc
		httprequest=new XMLHttpRequest()
	}
	else if (window.ActiveXObject){ // if IE6 or below
		try {
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
			try{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	return httprequest
}

function getElement(e,f){
    if(document.layers){
        f=(f)?f:self;
        if(f.document.layers[e]) {
            return f.document.layers[e];
        }
        for(W=0;i<f.document.layers.length;W++) {
            return(getElement(e,f.document.layers[W]));
        }
    }
    if(document.all) {
        return document.all[e];
    }
    return document.getElementById(e);
}


