/**
 *	Copyright 2002-2006 by Earth Resource Mapping Ltd.  All rights reserved.
 *	Image Integration Framework generated pages may only be served by organizations that have
 *	a license for the Image Integration Framework product. Image Integration Framework may only be used by
 *	Application Service Providers (ASPs) with a license for the Image Integration Framework ASP Edition product.
 *
 *  @fileoverview
 *	Include this script if you need a simple, customizable JavaScript progressbar. 
 *	To use the progressbar, create an instance as follows:
 * 
 *	ECWProgressBar = new NCSProgressbar3(uid, objectID, nWidth, nHeight, nIncrements, bUseLabels, sLeftLabel, nLeftLabelWidth, nPercentCompleteLabelWidth)
 *
 *	Use the method ECWProgressBar.SetProgress(value) to set the value of the control to an integer between 1 and 100. 
 */

/**
 * @class Creates a simple, customizable JavaScript progressbar.
 * @constructor
 * @param {String} uid				Unique ID for this HTML element
 * @param {String} objectID			ID of the object that the HTML will be written to, 
 * or null if the HTML is to be written to the page directly
 * @param {Integer} nWidth			Width of the progress bar
 * @param {Integer} nHeight			Height of the progress bar
 * @param {Integer} nIncrements		Number of increments shown on the progress bar
 * @param {Boolean} bUseLabels		Specifies whether or not to display labels
 * @param {String} sLeftLabel		Left label text
 * @param {Integer} nLeftLabelWidth Left label width 
 * @param {Integer} nPercentCompleteLabelWidth Percent complete label width
 */
function NCSProgressbar3(uid, objectID, nWidth, nHeight, nIncrements, bUseLabels, sLeftLabel, nLeftLabelWidth, nPercentCompleteLabelWidth)
{
    if (arguments.length > 0)
    {
    	this.init(uid, objectID);
    }
    
	this.outerDivID = uid + "_outerDivID";
	this.innerDivID = uid + "_innerDivID";
	this.percentCompleteLabelID = uid + "_percentCompleteLabelID";    
    
	this.progress = 0;
	this.nWidth = nWidth;
	this.nHeight = nHeight;
	this.nLeftLabelWidth = (nLeftLabelWidth ? nLeftLabelWidth : Math.floor(0.4 * this.nWidth));	
	this.nPercentCompleteLabelWidth = (nPercentCompleteLabelWidth ? nPercentCompleteLabelWidth : Math.floor(0.2 * this.nWidth));
	this.progressCompleteColor = "#FF0000";
	this.progressIncompleteColor = "#00FF00";
	this.backgroundColor = "transparent";
	this.nCustomBorderWidth = 0;
	
	if (sLeftLabel != null)
		this.sLeftLabel = sLeftLabel;

	if(bUseLabels != null)
		this.percentCompleteLabel = bUseLabels;
	
	this.nProgressWidth = this.nWidth - (this.percentCompleteLabel ? this.nPercentCompleteLabelWidth : 0) -
						(this.sLeftLabel ? this.nLeftLabelWidth : 0);

	this.nIncrements = (nIncrements ? nIncrements : 1);
	this.nIncrementSpacing = ((nIncrements == 1) ? 0 : 2);
	this.nIncrementWidth = Math.floor(this.nProgressWidth / this.nIncrements - this.nIncrementSpacing);
	if (this.nIncrementWidth < 2) this.nIncrementWidth = 2;

	if (objectID != null)
    {
    	this.build();
    }
}
function NCSProgressbar3_Build()
{	
	var nAdjust = 2;
	var barheight = this.nHeight;
	var text = "";
	
	text += '<div style="padding:0px;margin:0px;border:0px;overflow:hidden;width:' + this.nWidth + 'px;">';
	if ( this.sLeftLabel != null || this.percentCompleteLabel == true)
	{
		if (this.sLeftLabel != null)
			text += '<div style="width:' + this.nLeftLabelWidth + 'px;margin:0px;padding-top:0px;padding-bottom:0px;padding-right:5px;padding-left:0px;position:relative;float:left;text-align:right;font-size:11px">' + this.sLeftLabel + '</div>';
	}
	
	text+='<div id="'+this.outerDivID+'" style="width:' + ((this.nIncrements > 1) ? this.nIncrements * (this.nIncrementWidth + this.nIncrementSpacing) : 0) + 'px;position:relative;float:left;visibility:visible;background-color:'+this.backgroundColor+'; height:'+barheight+'px; border: ' + this.nCustomBorderWidth + 'px solid">';
	for (var i=0; i<this.nIncrements; i++)
	{
		text+='<div id="'+this.innerDivID+i+'" style="position:absolute; top:0px; left:' + ((i > 0) ? i * (this.nIncrementWidth + this.nIncrementSpacing) : 0) + 'px; width:' + this.nIncrementWidth + 'px; height:'+(barheight-nAdjust)+'px; background-color:'+this.progressIncompleteColor+'; font-size:0px; "></div>';
	}
	text+='</div>';
	
	if ( this.sLeftLabel != null || this.percentCompleteLabel == true)
	{
		if (this.percentCompleteLabel == true)
		   text += '<div id='+ this.percentCompleteLabelID + ' style="width:' + this.nPercentCompleteLabelWidth + 'px;margin:0px;padding-top:0px;padding-bottom:0px;padding-right:0px;padding-left:5px;position:relative;float:left;text-align:left;font-size:11px">&nbsp;</div>';
	}

	text += '</div>';
    if (this.element)
    {
    	this.element.innerHTML = text;
    }
    else
    {
    	return text;
    }
}
function NCSProgressbar3_SetProgressCompleteColor(color)
{
	this.progressCompleteColor = color;
}
function NCSProgressbar3_SetProgressIncompleteColor(color)
{
	this.progressIncompleteColor = color;
}
function NCSProgressbar3_SetBackgroundColor(color)
{
	this.backgroundColor = color;
}
function NCSProgressbar3_SetProgress(value)
{
	if (value < 0) value = 0;
	if (value > 100) value = 100;
	
	if (this.nIncrements == 1)
	{
		var elem = document.getElementById(this.innerDivID + 0);
		if (elem) 
			elem.style.width = value + '%';
	}
	else 
	{
		var nHighestIncrement = (value * this.nIncrements / 100) - 1; 
		for (var i=0; i<this.nIncrements; i++)
		{
			var elem = document.getElementById(this.innerDivID + i);
			if (elem)
				elem.style.backgroundColor = ((nHighestIncrement >= i) ? this.progressCompleteColor : this.progressIncompleteColor);
		}
	}
	if (this.percentCompleteLabel == true)
	{
		var elem = document.getElementById(this.percentCompleteLabelID)
		if (elem)
			elem.innerHTML = value + '%';
	}
}
NCSProgressbar3.prototype								= new NCSControl();
NCSProgressbar3.prototype.constructor					= NCSProgressbar3;
NCSProgressbar3.superclass								= NCSControl.prototype;
NCSProgressbar3.prototype.build							= NCSProgressbar3_Build;
NCSProgressbar3.prototype.setProgress					= NCSProgressbar3_SetProgress;
NCSProgressbar3.prototype.setProgressCompleteColor		= NCSProgressbar3_SetProgressCompleteColor;
NCSProgressbar3.prototype.setProgressIncompleteColor	= NCSProgressbar3_SetProgressIncompleteColor;
NCSProgressbar3.prototype.setBackgroundColor			= NCSProgressbar3_SetBackgroundColor;




