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, opts, 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();
		for (i=0; i<this.cfg[id]['lb_obj'].options.length; 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();
		this.cfg[id]['opts'] = opts;
		this.cfg[id]['opt_obj'] = new Array();
		for (i = 0; i < rel.length; i++) 
		{
			// hotel | city | option
			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]] = new Array();
			if (!this.cfg[id]['rel'][rel[i][1]][rel[i][0]][rel[i][2]])  
				this.cfg[id]['rel'][rel[i][1]][rel[i][0]][rel[i][2]] = 1;
		}
		for (j=0; j<opts.length; j++) 
		{
			this.cfg[id]['opt_obj'][j] = new Array();
			for (k=0; k<opts[j].length; k++) 
			{
				if(box=document.getElementById(opts[j][k]))
				{
					this.cfg[id]['opt_obj'][j][k] = box;
				}
			}
		}
	}//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:
		for (h = h_first; h < this.cfg[id]['lb'].length; 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])
				{
					choice_found = false;
					for (j=0; j<this.cfg[id]['opt_obj'].length; j++) {
						choice_found = false;
						for (k=0; k<this.cfg[id]['opt_obj'][j].length; k++) {
							if ( this.cfg[id]['opt_obj'][j][k].checked && this.cfg[id]['rel'][this.cfg[id]['lb'][h][0]][Avalue][this.cfg[id]['opt_obj'][j][k].value])
							{
								choice_found = true;
								break;
							}
						}
						if (!choice_found) break;
					}
					add_hotel = choice_found;
				}
			}
			else
			{
				//if true then hotels not found in relations' array are shown.
				//add_hotel = true;
			}
			if (add_hotel)
			{
				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;
}
