//
//	Copyright (c) 2003 General Electric Medical Systems IT
//
//	Version control:
//		$Archive: /releases/FreeViewer_2.0/src/WebViewer/FreeViewer/HTML/wlpreset.js $
//		$Revision: 3 $
//		$Date: 3/06/03 2:59p $
//		$Author: Marceld $
//

// -------------------- WindowLevelPreset ------------------------------
//
// WindowLevelPreset C'tor
//
function WindowLevelPreset(strPresetName, strPresetValue)
{
	this._strPresetName = strPresetName;
	this._strPresetValue = strPresetValue;
}

//
// GetName
//
function WindowLevelPreset.prototype.GetName()
{ with(this) {
	return _strPresetName;
}}

//
// GetValue
//
function WindowLevelPreset.prototype.GetValue()
{ with(this) {
	return _strPresetValue;
}}

// -------------------- ModalityPresetList ------------------------------
//
// ModalityPresetList
//
function ModalityPresetList(strMod)
{
	this._strMod = strMod;
	this._rgPresets = new Array;
}

//
// Initialize
//
function ModalityPresetList.prototype.Initialize(rgnode)
{ with(this) {
	for (var i = 0; i < rgnode.length; i++)
	{
		_rgPresets[_rgPresets.length] = new WindowLevelPreset(rgnode[i].getAttribute('name'), rgnode[i].getAttribute('value'));
	}
}}

// -------------------- WLPresetListControl ------------------------------
//
// WLPresetListControl C'tor
//
function WLPresetListControl(elemSelect)
{
	elemSelect.onchange = CreateStaticFunction(this, 'OnWindowLevelPresetChange');
	this._elemSelect = elemSelect;
	this._mpModPresets = new Object;
	this._strMod = '';
}


//
// Initialize
//
function WLPresetListControl.prototype.Initialize(nodeXML)
{ with(this) {
	if (nodeXML == null)
		return;

	var rgnode = nodeXML.selectNodes('modality');
	for (var i = 0; i < rgnode.length; i++)
	{
		var strMod = rgnode[i].getAttribute('value');
		var modpresetlist = new ModalityPresetList(strMod);
		modpresetlist.Initialize(rgnode[i].selectNodes('wlpreset'));
		_mpModPresets[strMod] = modpresetlist;
	}
}}

//
// OnWindowLevelPresetChange
//
function WLPresetListControl.prototype.OnWindowLevelPresetChange()
{ with(this) {
	parent.ChangeWindowLevelPreset(_elemSelect.value);
}}


//
// OnModalityChange
//
function WLPresetListControl.prototype.OnModalityChange(strMod)
{ with(this) {
	if (_strMod == strMod)
		return;

	ClearPresets();
	AddPresets(_mpModPresets[strMod]);
	_strMod = strMod;
}}

//
// ClearPresets
//
function WLPresetListControl.prototype.ClearPresets()
{ with(this) {
	var len = _elemSelect.options.length;
	for (var i = 0; i < len; i++)
	{
		_elemSelect.options.remove(0);
	}
}}

//
// AddOption
//
function WLPresetListControl.prototype.AddOption(strValue, strText, nPosition)
{ with(this) {
	for (var i = 0; i < _elemSelect.options.length; i++)
	{
		if (_elemSelect.options[i].text == strText)	// preset already exists
		{
			if (_elemSelect.options[i].value == strValue)	// value already exists
				return;
			else
			{
				_elemSelect.options.remove(i);
				break;
			}
		}
	}

	var oOption = document.createElement("OPTION");
	oOption.text = strText;
	oOption.value = strValue;
	_elemSelect.options.add(oOption, nPosition);
}}

//
// AddPresets
//
function WLPresetListControl.prototype.AddPresets(rgpresets)
{ with(this) {
	if (rgpresets == null)
		return;
	var rgPresets = rgpresets._rgPresets;
	for (var i = 0; i < rgPresets.length; i++)
	{
		AddOption(rgPresets[i].GetValue(), rgPresets[i].GetName());
	}
}}
