﻿function TheaterCategory(value, text)
{
	this.value = value;
	this.text = text;
	this.length = 0;
}

function TheaterCategoryAdd(category, value, text)
{
	category[category.length] = new TheaterCategory(value, text);
	category.length++;
}

function ClearOptions(ControlID)
{
    var control = document.getElementById(ControlID);

	for (var i = control.childNodes.length - 1; i >= 0; i--)
	{
		control.removeChild(control.childNodes[i]);
	}
}

function AddOption(ControlID, Value, Text)
{
    var control = document.getElementById(ControlID);

	var obj_node = document.createElement("option");
	var text = document.createTextNode(Text);
	obj_node.setAttribute("value", Value);
	obj_node.appendChild(text);

	control.appendChild(obj_node);
}

function TheaterCategorySelectChange(category, depth1controlID, depth2controlID, depth2valuecontrolID)
{
    var depth1control = document.getElementById(depth1controlID);
    var depth2control = document.getElementById(depth2controlID);
    var depth2valuecontrol = document.getElementById(depth2valuecontrolID);

	var idx = 0;
	var i = depth1control.selectedIndex;

	ClearOptions(depth2controlID);

	for (var j = 0; j < category[i].length; j++)
	{
		AddOption(depth2controlID, category[i][j].value, category[i][j].text);

		if (depth2valuecontrol.value == category[i][j].value)
		{
			idx = j;
		}
	}
	depth2control.selectedIndex = idx;
}

function TheaterSelectControlInit(category, depth1controlID, depth1valuecontrolID, depth2controlID, depth2valuecontrolID)
{
	var idx = 0;

	var depth1control = document.getElementById(depth1controlID);
	var depth1valuecontrol = document.getElementById(depth1valuecontrolID);

	ClearOptions(depth1controlID);

	for (var i = 0; i < category.length; i++)
	{
		AddOption(depth1controlID, category[i].value, category[i].text);

		if (depth1valuecontrol.value == category[i].value)
		{
			idx = i;
		}
	}

	depth1control.selectedIndex = idx;
	TheaterCategorySelectChange(category, depth1controlID, depth2controlID, depth2valuecontrolID);
}