/*
	Roku.ResultsAB
*/

if(typeof(Roku) == "undefined")
    Roku = { classes : [] };

Roku.ResultsAB =
{
	category_combo_id			: "category_combo",
	sub_category_combo_id		: "sub_category_combo",
	default_entry_attrib_name	: "default_entry"
};

Roku.classes.push(Roku.ResultsAB);

Roku.ResultsAB.select_drop_entry = function(combo, id)
{
	var drop_down = Roku.Util.childClassElement(combo, Roku.Combo.dropDownClassName);
	var entries = Roku.Util.childrenClassElements(drop_down, Roku.Combo.contentClassName);
	var entries_count = entries.length;
	for(var index = 0; index < entries_count; index++)
	{
		var entry = entries[index];
		entry.style.backgroundColor = (entry.id == id) ? "#9E96CA" : "";
	}
}

Roku.ResultsAB.default_drop_entry = function(combo)
{
	var drop_down = Roku.Util.childClassElement(combo, Roku.Combo.dropDownClassName);
	var entries = Roku.Util.childrenClassElements(drop_down, Roku.Combo.contentClassName);
	var entries_count = entries.length;
	for(var index = 0; index < entries_count; index++)
	{
		var entry = entries[index];
		if(entry.getAttribute(this.default_entry_attrib_name))
			return entry.id; 
	}
	return "";
}

Roku.ResultsAB.initialize = function()
{
	var category_combo = document.getElementById(this.category_combo_id);
	if(category_combo)
	{
		category_combo[Roku.Combo.displayHilightHandler] = function(display, hilight)
		{
			if(display)
				display.style.color = hilight ? "#0000E0" : "";			
		};

		category_combo[Roku.Combo.selChangedEventName] = function(combo, entry)
		{
			document.form.filtertype.value = entry ? entry.id : "";
			document.form.filtervalue.value = 0;
			document.form.page.value = 1;
			document.form.submit();
		}
	}
	
	var sub_category_combo = document.getElementById(this.sub_category_combo_id);
	if(sub_category_combo)
	{
		sub_category_combo[Roku.Combo.displayHilightHandler] = function(display, hilight)
		{
			// do not hilight sub-category display
		}

		sub_category_combo[Roku.Combo.dropHilightHandler] = function(drop, hilight)
		{
			if(drop)
			{
				drop.style.textDecoration = hilight ? "underline" : "";
				drop.style.color = hilight ? "#FFFF80" : "";
			}
		}
		
		sub_category_combo[Roku.Combo.selChangedEventName] = function(combo, entry)
		{
			var category_combo = document.getElementById(Roku.ResultsAB.category_combo_id);
			document.form.filtertype.value = Roku.Combo.selected(category_combo);
			document.form.filtervalue.value = entry ? entry.id : 0;
			document.form.page.value = 1;
			document.form.submit();
		}
		
		
		var sel_id = this.default_drop_entry(sub_category_combo);
		Roku.Combo.select(sub_category_combo, sel_id);
		this.select_drop_entry(sub_category_combo, sel_id);
	}
}


