var LL_obj;
LL_obj = new function()
{
	this.id='';
	this.cfg = Array();

	//// initialize e new set of linked lists and checkboxes:
	this.new_set = function( id, la, lb, rel ) 
	{
		this.cfg[id] = Array();
		this.cfg[id]['la_obj'] = document.getElementById(la);
		this.cfg[id]['lb_obj'] = document.getElementById(lb);
		this.cfg[id]['lb'] = Array();
		var lb_num = this.cfg[id]['lb_obj'].options.length
		for (i=0; i<lb_num; i++) 
		{
			this.cfg[id]['lb'][i]  = Array(  this.cfg[id]['lb_obj'].options[i].value, this.cfg[id]['lb_obj'].options[i].text);
		}
		this.cfg[id]['rel'] = new Array();
		for (i = 0; i < rel.length; i++) 
		{
			// hotel | city 
			if (!this.cfg[id]['rel'][rel[i][1]])  
				this.cfg[id]['rel'][rel[i][1]] = new Array();
			if (!this.cfg[id]['rel'][rel[i][1]][rel[i][0]])  
				this.cfg[id]['rel'][rel[i][1]][rel[i][0]] = 1
		}
	}//new_set
	
	//// onCahnge handler called by listA.onchage and chechbox.onchange
	this.onChange = function( id ) 
	{
		// save selected value of listA
		if ( this.cfg[id]['la_obj'].selectedIndex >= 0 ) 
			Avalue = this.cfg[id]['la_obj'].options[ this.cfg[id]['la_obj'].selectedIndex ].value;
		else 
			Avalue = '';
		// save selected value of listB
		if ( this.cfg[id]['lb_obj'].selectedIndex >= 0 ) 
			Bvalue = this.cfg[id]['lb_obj'].options[ this.cfg[id]['lb_obj'].selectedIndex ].value;
		else 
			Bvalue = '';
		// truncate listB:
		this.cfg[id]['lb_obj'].options.length = 0;
		Bindex = 0;
		// add dummy item in listB / expect it to be the first one :-)
		h_first = 0;
		if ( this.cfg[id]['lb'][h_first][0] == '' )
		{
			this.cfg[id]['lb_obj'].options[0] = new Option( this.cfg[id]['lb'][h_first][1], '' );
			h_first = 1;
		}
		// loop list B options:
		var lb_num = this.cfg[id]['lb'].length;
		for (h = h_first; h < lb_num; h++) {
			add_hotel = false;
			if (this.cfg[id]['rel'][this.cfg[id]['lb'][h][0]])
			{
				if (this.cfg[id]['rel'][this.cfg[id]['lb'][h][0]][Avalue])
				{
					this.cfg[id]['lb_obj'].options[ this.cfg[id]['lb_obj'].options.length ] = new Option( this.cfg[id]['lb'][h][1], this.cfg[id]['lb'][h][0] );
					if ( Bvalue==this.cfg[id]['lb'][h][0]) this.cfg[id]['lb_obj'].options[ this.cfg[id]['lb_obj'].options.length-1 ].selected = true;
				}
			}
		}
	}//onChange
	
}//LL_obj

//// usage: ... onChange="oc('.*')"...
function oc(id)
{
	LL_obj.onChange(id);
};

//// simple hide and show div option
function toggle(id) 
{
	if (x=$(id))
		if (x.visible()) x.hide(); 
		else x.show(); 
	return false;
}

