	/* <!--
	name:	popupLib.js
	dir:	htdocs\includes
	by: 	Iterate Pte Ltd
	func:	provides library of window popup functions
	rev: 	20061217, wmc, created this module
	--> */

var popupLib = this;

function viewOnDisc (location, discId, linkref, width, height, resizeOk, scrollOk) {
	if (!location) return (false);
	// alert("got: " + this.allowed_discId);
	if (top.document.location.protocol.substring(0, 4) == 'file' && discId != this.allowed_discId) 
		if (commonLib)
			commonLib.winAlert("The requested slide-video presentation is not on this CD-ROM disc, please insert '" + discId + "'.");
		else
			alert("The requested slide video presentation is not on this CD-ROM disc, please insert " + discId + ".");
	else
		viewDocPopup (location, linkref, width, height, resizeOk, scrollOk)
	return (false);
}

var docwin = null;
	// opens any document found in the 'htdocs' folder, or absolute URL, in a popup window
function viewDocPopup (location, linkref, width, height, resizeOk, scrollOk) {
	if (!location) return (false);
	if (!width) width = 780;
	if (!height) height = 490;
	var resize = (!resizeOk ? "yes" : "no");
	var scroll = (!scrollOk ? "yes" : "no");
	
	var mystyle = "toolbar=no,location=no,directories=no,menubar=no," +
		"titlebar=yes,scrollbars=" + scroll + ",resizable=" + resize + ",status=yes," +
		"width=" + width + ",height=" + height + ",left=10,top=10,screenX=10,screenY=10";

	// alert("viewDocPopup going to page: " + location);
	if (linkref && (document.all || document.getElementById)) 
		linkref.blur();		// if IE, blur the link selection
	if (docwin == null || docwin.closed) 
		docwin = window.open(location, "Popup", mystyle);
	else 
		docwin.location.href = location;
	docwin.focus();
	return(false);
}

	// declare variables global to progress bar
var POSITION_HORZ = 90;  						// initial position of Progress bar set to center of window
var POSITION_VERT = 125;  					// initial position of Progress bar set down from top of window
var BORDERSIZE = 2;									// pixel width of *inner* border in Progress bar
var BAR_HEIGHT = 20;								// vertical height of the Progress bar
var BAR_WIDTH = 384;								// chosen so that width - (2 * bordersize) is evenly divisible by 10
var BAR_SLIDER_COLOR = "99ccff";		// bar colors (text is black)
var BAR_BKGD_COLOR = "#eeeeee";
var UPDATE_INTERVAL = 1000					// interval between updates of progress bar (in milliseconds)
var HOLDUP_INTERVAL = 4000					// interval to hold before result page is shown (in milliseconds)
var progressBar;										// create a global variable to handle the progress bar object

	// slider layer goes in front, gets clipped so that text behind is overwritten in a different color
function progressBarCreate () {
	if (typeof(this.progressBar) == "object") return;
	if (!layerLib) {
		alert("Error - in 'progressBarCreate', 'layerLib' is not found.");
	} else if (containerObj = layerLib.createLayer('progressBarDiv')) {
			this.progressBar = containerObj;
			this.progressBar.textLayerId = "progressBarTextDiv";
			this.progressBar.sliderLayerId = "progressBarSliderDiv";

			layerLib.moveLayerTo(containerObj, POSITION_HORZ, POSITION_VERT);
			layerLib.setWidth(containerObj, BAR_WIDTH);
			layerLib.setHeight(containerObj, BAR_HEIGHT);
			layerLib.setBgColor(containerObj, BAR_BKGD_COLOR);

			var textLayerObj = layerLib.createLayerInLayer(this.progressBar.textLayerId, containerObj);
			layerLib.setLayerVisibility(textLayerObj, 'inherit');
			layerLib.moveLayerTo(textLayerObj, BORDERSIZE, BORDERSIZE);
			layerLib.setWidth(textLayerObj, BAR_WIDTH);
			layerLib.setHeight(textLayerObj, (BAR_HEIGHT - (2 * BORDERSIZE)));
			layerLib.setBgColor(textLayerObj, "");

			var sliderLayerObj = layerLib.createLayerInLayer(this.progressBar.sliderLayerId, containerObj);
			layerLib.setLayerVisibility(sliderLayerObj, 'inherit');
			layerLib.moveLayerTo(sliderLayerObj, BORDERSIZE, BORDERSIZE);
			layerLib.setWidth(sliderLayerObj, (BAR_WIDTH - (2 * BORDERSIZE)));
			layerLib.setHeight(sliderLayerObj, (BAR_HEIGHT - (2 * BORDERSIZE)));
			layerLib.setBgColor(sliderLayerObj, BAR_SLIDER_COLOR);
	}
}

function progressBarVisibility (status) {
	if (!status) status = 'visible';
	if (!layerLib)
		alert("Error - in 'progressBarHide', 'layerLib' is not found.");
	else if (this.progressBar) 
			layerLib.setLayerVisibility(this.progressBar, status);
}

function progressBarUpdate (percentComplete) {
	if (!layerLib) 
		alert("Error - in 'progressBarUpdate', 'layerLib' is not found.");
	else if (this.progressBar && (layerObj = layerLib.getLayerObj(this.progressBar.sliderLayerId)))
		layerLib.clipLayer(layerObj, 0, Math.floor(percentComplete * layerLib.getWidth(layerObj)), layerLib.getHeight(layerObj), 0);
}

function progressBarTextUpdate (str) {
	if (!layerLib) 
		alert("Error - in 'progressBarTextUpdate', 'layerLib' is not found.");
	else if (this.progressBar) {
		if (layerObj = layerLib.getLayerObj(this.progressBar.textLayerId))
			layerLib.writeLayerStr(layerObj, "<span class='progress_text'><center>" + str + "</center></span>");
		if (layerObj = layerLib.getLayerObj(this.progressBar.sliderLayerId)) 
			layerLib.writeLayerStr(layerObj, "<span class='progress_overlay_text'><center>" + str + "</center></span>");
	}
}


