/**
 * Selects an option with a given value in a "select" tag
 * @param comboBoxControlId
 * @param value
 * @return void
 */
function setSelectOption (comboBoxControlId, value)
{
	var obj = document.getElementById(comboBoxControlId);
	if (obj)
	{
		for (i=0; i<obj.options.length; i++)
		{
			if (obj.options[i].value == value)
			{
				obj.options[i].selected = "1";
				break;
			}
		}
	}
}

/**
 * Given a group of checkboxes with the same name, this function takes the ID's
 * of those checkboxes that are checked and creates a comma-separated list of IDs.
 * 
 * Then this list is assigned to a field whose ID is given as the second parameter. 
 * 
 * @return
 */
function setListFromSelectedCheckboxes(checkboxName, listFieldId)
{
	var checkboxes = document.getElementsByName(checkboxName);
	var ids = '';
	for (i = 0; i < checkboxes.length; i++)
	{
		if (checkboxes[i].checked == true)
		{
			ids += checkboxes[i].value + ",";
		}
	}
	
	ids = ids.substr(0,ids.length-1);
	
	var field = document.getElementById(listFieldId);
	if (field == null)
	{
		throw "Field with id "+listFieldId+" does not exist in call of setListFromCheckboxes";
		return;
	}
	field.value = ids;
}

/**
 * Given a group of checkboxes with the same name (checkboxName parameter),
 * the function checks if the number of selected checkboxes does not exceed the
 * maximum allowed (max parameter).
 * 
 * @param checkboxName
 * @param max
 * @param errorMsg
 * @return true if the number of selected checkboxes is OK, false if it's too big
 */
function controlNumberOfSelectedCheckboxes (checkboxName, max, errorMsg)
{
	var checkboxes = document.getElementsByName(checkboxName);
	var count = 0;
	for (i = 0; i < checkboxes.length; i++)
	{
		if (checkboxes[i].checked == true)
		{
			if (++count > max)
			{
				alert(errorMsg);
				return false;
			}
		}
	}
	return true;
}

var langMenuHover = false;

function hlmenu(tabId)
{
	var tab = document.getElementById(tabId); 
	tab.className += ' hltab';
}

function unhlmenu(tabId)
{
	var elem = document.getElementById(tabId);
	elem.className = elem.className.replace(' hltab', '');
}

function unhlLangMenu(tabId)
{
	setTimeout("unhlmenu('"+tabId+"')", 500);
}

function showLangMenu()
{
	langMenuHover = true;
	document.getElementById('langMenu').style.display = 'block';
}

function hideLangMenu()
{
	langMenuHover = false;
	setTimeout("if (!langMenuHover) { document.getElementById('langMenu').style.display = 'none' }",500);
}