/*
	Autore: Danilo Cicognani
	Script: optionlist.js
	Applicazione: www.athena.it
	Versione: 1.00
	Data: 04/06/2008
	Scopo: Linked Option List
	Copyright (c) 2008 Danilo Cicognani
*/
function OptionList_Change(selected) {
	this.selectedIndex = selected;
	if (this.items[selected].child) {
		this.items[selected].child.Populate();
	}
}
function OptionList_AddItem(text, value, child) {
	var newItem = new Option;
	newItem.text = text;
	newItem.value = value;
	newItem.child = child;
	this.items[this.items.length] = newItem;
}
function OptionList_Populate() {
	this.src.OptionList = this;
	for (var i = 0; i < this.items.length; i++) {
		this.src.options[i] = this.items[i];
	}
	this.Clear(this.src, this.items.length);
	this.src.selectedIndex = this.selectedIndex;
	if (this.items.length && this.items[this.selectedIndex].child)
		this.items[this.selectedIndex].child.Populate();
}
function OptionList(src) {
	this.src = src;
	this.items = new Array;
	this.selectedIndex = 0;
	this.Change = OptionList_Change;
	this.AddItem = OptionList_AddItem;
	this.Populate = OptionList_Populate;
	this.Clear = OptionList_Clear;
}
function OptionList_Clear(select, from) {
	var len = select.options.length;
	for (var i = len - 1; i >= from; i--) select.options[i] = null;
}
function OptionListChange(select) {
	select.OptionList.Change(select.selectedIndex);
}
