//------------------------------------------------------------------
// Form functions

var categoryIndex = new Array();

function updateCategories(list, childListId, index)
{
	var id = list.value;
	var childList = document.getElementById(childListId);
	
	if (childList)
	{
		childList.options.length = 1;
		
		var category = index[id];
		
		if (category && category.children)
		{
			for (var i = 0; i < category.children.length; i++)
			{
				var item = category.children[i];
				addOption(childList, item.name, item.id);
			}
		}
	}
}

// Form functions
//------------------------------------------------------------------


//------------------------------------------------------------------
// Common functions

function createIndex(index, itemsToIndex, indexField)
{
	for (var i = 0; i < itemsToIndex.length; i++)
	{
		var item = itemsToIndex[i];
		if (item[indexField])
		{
			index[item[indexField]] = item;
		}
	}
}

function addOption(lst, text, value)
{
	var opt = new Option();
	opt.text = text;
	opt.value = value;
	lst.options.add(opt);
}

function paginateForm(formRef, startRowNo)
{
	/*Submit form with a particular start row*/	
	document.forms[formRef].startRow.value = startRowNo;
	document.forms[formRef].submit();
}

function clearTagId(formRef)
{
    document.getElementById("tagId").value = "";
    document.getElementById("startRow").value = "1";
    document.forms[formRef].submit();
}

// Common functions
//------------------------------------------------------------------