﻿var AjaxComboBox = new Class(
{
	initialize : function(uiManager)
	{
		this._uiManager = uiManager;

		this._uiManager.registerViewStateHandler("ComboBox", this.collectViewState);
	},

	initControl : function(controlID)
	{
		var control = $(controlID);

		if (control == null)
		{
			return;
		}

//		var newControl = new Element("select");
//		newControl.id = control.id;

//		for (var i = 0; i < control.options.length; i++)
//		{
//			var newControlItem = new Element("option");
//			newControlItem.value = control.options[i].value;
//			newControlItem.innerHTML = newControlItem.value;

//			newControl.adopt(newControlItem);
//		}

//		newControl.replaces(control);
	},

	collectViewState : function(control)
	{
		return { "__type" : "vs", "SelectedIndex" : control.selectedIndex };
	},

	toggle : function(dialogID, controlID)
	{
		var cb = this._uiManager.getNestedControl($(dialogID), controlID);
		var cbItems = this._uiManager.getNestedControl($(dialogID), controlID + "Items");

		if (cb == null || cbItems == null)
		{
			return;
		}

		currentStyle = cbItems.getStyle("display");
		newStyle = "";

		if (currentStyle == "none")
		{
			newStyle = "block";
		}
		else if (currentStyle == "block")
		{
			newStyle = "none";
		}

		cbPos = cb.getPosition(cb.getParent());
		cbSize = cb.getSize();

		//cbItems.setStyles( { position : "absolute", display : newStyle, left : cbPos.x, top : cbPos.y + cbSize.y, width : cbSize.x } );
		cbItems.setStyles( { position : "absolute", "z-index" : 1000, "background-color" : "#FFFFFF", display : newStyle, width : cbSize.x } );
	}
});

var comboBox = new AjaxComboBox(uiManager);