function dddlb()
{
	if (arguments.length < 1) { alert("Not enough arguments for dddlb()"); }
	this.target = arguments[0];
	this.optionCount = 0;
	this.options = new Object();
	this.lbparent = new Array();
	this.notifications = new Array();
	
	this.addOption = dddlb_addOption;
	this.populate = dddlb_populate;
	this.setParent = dddlb_setParent;
	//this.getValue = dddlb_getValue;
	this.onChange = dddlb_onChange;
	//this.init = dddlb_init;
	this.addNotify = dddlb_addNotify;
}

function dddlb_addOption()
{
	var i=0;
	var dependentValue;

	if (this.lbparent.length > 0) 
		dependentValue = arguments[i++];
	else
		dependentValue = "__defaultdependentvalue";

	if (typeof this.options[dependentValue] != "object") { this.options[dependentValue] = new Array(); }

	for (; i<arguments.length; i+=2) 
	{
		this.optionCount++;
		this.options[dependentValue][this.options[dependentValue].length] = arguments[i];
		this.options[dependentValue][this.options[dependentValue].length] = arguments[i+1];
	}
}

function dddlb_populate()
{
	var dependentValue;

	if (this.lbparent.length > 0)
	{
		dependentValue = "";
		for(i=0; i<this.lbparent.length; i++)
		{
			if (i>0) {dependentValue += "|";}
			dependentValue += this.lbparent[i].target.value;
		}
	}
	else
		dependentValue = "__defaultdependentvalue";

	this.target.options.length = 0;
	if (typeof this.options[dependentValue] == "object") 
	{
		for (i=0; i<this.options[dependentValue].length; i+=2) 
		{
			var display = this.options[dependentValue][i];
			var value = this.options[dependentValue][i+1];
			
			this.target.options[this.target.options.length] = new Option(display, value, false, false);
		}
	}
}

function dddlb_setParent(dddlb_parent)
{
	this.lbparent[this.lbparent.length] = dddlb_parent;
	dddlb_parent.addNotify(this);
}

function dddlb_onChange()
{
if (typeof this.notifications != "object")
{
	alert("notifications is not valid");
}
else
{
	if (this.notifications.length > 0)
	{
		for(var i=0; i<this.notifications.length; i++)
		{
			this.notifications[i].populate();
		}
	}
}	
}

function dddlb_addNotify(callBack)
{
	this.notifications[this.notifications.length] = callBack;
}

