function hideElement(elementId) {
	document.getElementById(elementId).style.display = 'none';
}

function showElement(elementId) {
	document.getElementById(elementId).style.display = '';	
}

/*
	A function to toggle the display style attribute between 'none' and ''.

	Usage: pass the ID of the element you want to toggle.
*/
function toggleHiddenElement(elementId) {
	if (document.getElementById(elementId).style.display == 'none') {
		showElement(elementId);
	} else {
		hideElement(elementId);
	}
}

/*
	A function to toggle the visibilty of every row in a table using the
	display style attribute. It doesn't toggle individual rows, but changes
	every row to correspond to the value of the button.

	Usage: pass the id of the form which the button is in which is used
	to toggle the rows visibilty. Also pass how many rows are to be toggled.

	Note: the button must be named rowTogg and it's value must swap between
	'+' and '-' using an external method. This function is associated with
	a button on each row (named showitems[]) which toggles the individual rows
	visibilty.
*/
function toggleHiddenRows(formId, totalrows) {
	for(var x=0; x < totalrows; x++)
		if (document.getElementById(formId)['rowTogg'].value == '+') {
			document.getElementById('row' + x + 'a').style.display = '';
			document.getElementById(formId)['showitems[]'][x].value = '-';
		} else {
			document.getElementById('row' + x + 'a').style.display = 'none';
			document.getElementById(formId)['showitems[]'][x].value = '+';
		}
}

/*
	A function which loops through every row (20) until it finds a row which
	is currently invisible, it then terminates and sets a 'totalrows' hidden
	input field to the amount of visible rows.
*/
function updateRowTotal() {
	for(var x = 0; x < 20; x++) {
		if(document.getElementById(x).style.display == 'none') {
			break;
		}
	}

	document.getElementById('totalrows').value = x;
}

/*
	A function to confirm that the user wants to delete one or more waiters
	based on the checked attribute of an array of checkboxes.
*/
function confirmDeletions() {
	var del = document.getElementById('editwaiters')['del[]'];
	var conf = false;

	for(var x=0; x < del.length; x++)
		if(del[x].checked == true)
			conf = true;

	if(conf == true)
		return confirm('Are you sure you want to delete the selected waiters?');

	return true;
}

/*
	A function to hide 2 buttons in an array with the from index and then show
	2 buttons in an array with the to index.
*/
function moveButtons(from, to) {
	//Hide the "from's"
	document.forms['addmenuitem']['addrow[]'][from].style.display = 'none';
	document.forms['addmenuitem']['remrow[]'][from].style.display = 'none';

	//Show the "to's"
	document.forms['addmenuitem']['addrow[]'][to].style.display = '';
	document.forms['addmenuitem']['remrow[]'][to].style.display = '';
}

/*
	A function to decrease the value in an element with ID totalrows
*/
function decreaseRowTotal()
{
	document.getElementById('totalrows').value--;
}

/*
	A function to increase the value in an element with ID totalrows
*/
function increaseRowTotal()
{
	document.getElementById('totalrows').value++;
}

/*
	A function to show a tooltip with a specific ID.
*/

function showToolTip(e, id, text)
{
	$('body')
		.append('<p class="tooltip" id="tooltip-' + id + '">' + text + '</p>');

	$('#tooltip-' + id)
		.css("top", (e.pageY + 10) + "px")
		.css("left", (e.pageX + 20) + "px")
		.fadeIn("fast");
}

/*
	A function to hide a tooltip with a specific ID.
*/
function hideToolTip(id)
{
	$('#tooltip-' + id)
		.fadeOut("fast");	
}
