/**
 * Status
 *
 * @author Evgueni Palchukovsky <epalchukovsky@swsoft.com>
 * @version $Id: Status.js 18832 2006-08-31 03:44:31Z efedorova $
 * @since 2005/05/18
 * @package SB
 * @subpackage Wizard
 * @copyright (c) 2004-2006, SWsoft
 */

var HELP	= 0;
var INFO	= 1;
var WARNING	= 3;
var ERROR	= 2;

function SB_Status(stylePath) {
	this.stylePath = stylePath;
	this.iconControl = document.getElementById('StatusIcon');
	this.barControl = document.getElementById('StatusBar');
	this.messageControl = document.getElementById('StatusMessage');
	this.detailsControl = document.getElementById('StatusDetailed');
	this.detailedMessagesControl = document.getElementById('StatusDetailedMessages').tBodies[0];
	this.lastAddedMessegeStyle = 1;
	this.policies = new Array();
	this.policies[INFO] = new function() {
		this.statusIcon = 'icon_info.gif';
		this.messageIcon = 'information.gif';
	}
	this.policies[WARNING] = new function() {
		this.statusIcon = 'icon_stop.gif';
		this.messageIcon = 'warning.gif';
	}
	this.policies[ERROR] = new function() {
		this.statusIcon = 'icon_stop.gif';
		this.messageIcon = 'critical.gif';
	}
	this.policies[HELP] = new function() {
		this.statusIcon = 'icon_help.gif';
		this.messageIcon = 'information.gif';
	}
	this.messages = Array();
}

SB_Status.prototype.set = function(message, statusCode) {
	this.iconControl.src = this.stylePath+'/images/'+this.policies[statusCode].statusIcon;
	this.messageControl.innerHTML = message;
}

SB_Status.prototype.setByKey = function(messageKey, statusCode) {
	this.iconControl.src = this.stylePath+'/images/'+this.policies[statusCode].statusIcon;
	this.messageControl.innerHTML = SbGetLocaleByKey(messageKey);
}

SB_Status.prototype.filterDetails = function(statusCode) {
	this.clearDetailsList();
	for (var i = 0; i<this.messages.length; ++i) {
		var m = this.messages[i];
		if (statusCode == 0 || m.statusCode == statusCode) {
			this.addDetailedMessageInList(m.number, m.message, m.statusCode);
		}
	}
}

SB_Status.prototype.showDetails = function() {
	if (this.messages.length) {
		this.detailsControl.show();
	}
}

SB_Status.prototype.hideDetails = function() {
	this.detailsControl.hide();
}

SB_Status.prototype.clearDetails = function() {
	this.clearDetailsList();
	this.messages = Array();
	this.barControl.style.cursor = 'default';
	this.messageControl.style.cursor = 'default';
}

SB_Status.prototype.clearDetailsList = function() {
	var trs = this.detailedMessagesControl.getElementsByTagName('TR');
	for (var i = trs.length-1; i>2; --i) {
		this.detailedMessagesControl.removeChild(trs[i]);
	}
	this.lastAddedMessegeStyle = 1;
}

SB_Status.prototype.addDetailedMessage = function(message, statusCode) {
	var m = new SB_StatusDetailedMessage(this.messages.length+1, message, statusCode);
	this.messages.push(m);
	this.addDetailedMessageInList(m.number, m.message, m.statusCode);
	this.barControl.style.cursor = 'pointer';
}

SB_Status.prototype.addDetailedMessageInList = function(number, message, statusCode) {
	var trs = this.detailedMessagesControl.getElementsByTagName('TR');
	var tr = trs[this.lastAddedMessegeStyle].cloneNode(true);
	var tds = tr.getElementsByTagName('TD');
	tds[0].innerHTML = number;
	tds[1].innerHTML = '<img src="'+this.stylePath+'/icons/'+this.policies[statusCode].messageIcon+'" alt="">';
	tds[2].innerHTML = message;
	tr.removeAttribute("style");
	this.detailedMessagesControl.appendChild(tr);
	this.lastAddedMessegeStyle = this.lastAddedMessegeStyle==1 ? 2 : 1;
}

function SB_StatusDetailedMessage(number, message, statusCode) {
	this.message = message;
	this.statusCode = statusCode;
	this.number = number;
}