/* **************************	*/
/* STANDARD LOADING PAGE 	*/
/* VERSION 3, MJR, FEB 2008	*/
/* **************************	*/


// THE VERSION 6. SEPARATE THE CONTENT FROM THE NAVBAR: THAT'S BETTER
if(!this.miltiPager_Index) {
function multiPager_Index  (pName) {
	// FUNCTION HOLDER 
	if(!window.FUNCHLD) window.FUNCHLD = new Array();
	var thisInd = FUNCHLD.length;
	FUNCHLD[thisInd] = this;
	
	// IMPORTANT
	this.name = pName;
	
	// SET THE DEFAULT VALUES FOR
	// REFERENCES TO VARIOUS DOMS REQUIRED
	this.objRef = {
		text			: "pnl" + this.name + "__content",
		loader		: "pnl" + this.name + "__loader",
		loadingStatus	: "pnl" + this.name + "__status"
	}
	
	// PATH OF LOADER
	this.loaderPath		= "";				// PATH OF LOADER
	this.otherQuery		= "";				// OTHER QUERY THAT WILL BE PASSED TO THE LOADER
	
	// LOADING TEXT
	this.loadingText		= "Please wait...";
	
	// 
	
	// HTML CONTENT
	this.prevHTMLContent 	= "";
	
	
	// FOR WAITING OF LOADED DATA\
	this.maxTimeoutSeconds = 30;
	this.___inc_checkLoad = 0;
	this.___secsWaitingForData = 0;
	
	
	
	
	// ---------.---------.---------.
	// THIS WILL HANDLE CHANGING OF PAGE
	this.changePage = function(pPage, obj, isCustom, addOpts) {
		// OBJECT REFERENCES
		var objContent 	= document.getElementById(this.objRef.text);
		var objLoader 	= eval(this.objRef.loader);
		
		// SAVE PREVIOUS HTM
		this.prevHTMLContent = objContent.innerHTML;
		objLoader.isLoaded = false;
		
		
		// COMPILE THE LOADER PATH + PARAMETERS
		// CUSTOM PAGE:
		if(isCustom) {
			var t_path = 
				this.loaderPath + "&" + 
					((this.otherQuery) ? this.otherQuery + "&" : "") +
					pPage;
			// LOAD NOW THE LOADER
			objLoader.document.location.href = t_path;	
		}
		// pPage MUST NOT BE NULL
		else if(pPage!=false) {
			var t_path = 
				this.loaderPath + "&" + 
					((this.otherQuery) ? this.otherQuery + "&" : "") +
					"pg=" + pPage;
					
			// LOAD NOW THE LOADER
			objLoader.document.location.href = t_path;	
		}

		
		// SHOW STATUS
		if(!addOpts) addOpts={};
		if(!addOpts.noStatus) {
			this.showStatus();
		}
		
		
		// SET THE WAITER
		clearInterval(this.___inc_checkLoad);
		this.___secsWaitingForData = 0;
		this.___inc_checkLoad = setInterval("FUNCHLD["+thisInd+"].___checkTimeout()", 1000);
	}
	
	
	
	
	// ---------.---------.---------.
	// SHOW LOADING MESSAGE
	this.showStatus = function () {
		var objLoadingMsg	= document.getElementById(this.objRef.loadingStatus);
		if(objLoadingMsg.style.display=="none")
			objLoadingMsg.style.display = "";
		objLoadingMsg.innerHTML = this.loadingText;
	}
	
	// ---------.---------.---------.
	// HIDE LOADING MESSAGE
	this.hideStatus = function () {
		var objLoadingMsg	= document.getElementById(this.objRef.loadingStatus);
		if(objLoadingMsg.style.display!="none")
			objLoadingMsg.style.display = "none";
	}
	
	
	
	// ---------.---------.---------.
	/* CHECK IF THE FILE IS LOADED */
	this.___checkTimeout = function() {
		var objContent 	= document.getElementById(this.objRef.text);
		var objLoader 	= eval(this.objRef.loader);
		
		/* WARN ON THE TIMEOUT ERROR. */
		if(!objLoader.isLoaded) {
			this.___secsWaitingForData++;
			if(this.___secsWaitingForData > this.maxTimeoutSeconds) {
				objContent.innerHTML = this.prevHTMLContent;
				alert("Sorry, but request timed out while processing your request. Please try again later.");
				var isFinish = true;
				
				if(this.ontimeout) 
					this.ontimeout();
			}
		}
		/* LOADED */
		else {
			var isFinish = true;
		
			// onload : EVENT TO RUN AFTER THE DATA HAS BEEN LOADED
			if(this.onload)
				setTimeout("FUNCHLD["+thisInd+"].onload();", 250);
		}
		
		
		// RUN IF FINISHED
		if(isFinish) {
			this.___secsWaitingForData = 0;
			clearInterval(this.___inc_checkLoad);

			this.hideStatus();
		}
	}


	
	// ---------.---------.---------.
	/* SPECIAL: ON SEARCH */
	this.special_onsearch = function () {
		var objMainPage 	= document.getElementById(this.objRef.text);
		// CLEAR objMainPage
		this.changePage(false);
		this.showLoader();
	}
}
}
