var last_id = -1;

function ShowSubcategory(obj)
{
	sub_cat_id = obj.value;
	
	if (sub_cat_id != -1)
	{
		if (last_id != -1)
		{
			document.getElementById("sub_cat_" + last_id).style.display = "none";
		}
		var select = document.getElementById("sub_cat_" + sub_cat_id);
		select.style.display = "block";
		select.value = -1;
		last_id = sub_cat_id;
	}
}
function LoadSubCat(obj)
{
	sub_category = obj.value;
	if (sub_category != -1)
	{
		document.getElementById("selected_cat_id").value = sub_category;
	}
}

function DirectorySearch(form)
{
	var main = form.elements.main_category;
	var sub  = document.getElementById('sub_cat_' + main.value);
	var category = -1;
	
	if (sub != null)
	{
		if (sub.value != -1)
		{
			category = sub.value;
		}
	}
	
	if (category == -1)
	{
		category = main.value;
	}
	
	if (category == -1)
	{
		alert('Please make a selection before continuing');
	}
	else
	{
		var url = window.location + '/show_subcategory/' + category;
		window.location = url;
	}
}