function deleteItem(checkbox) {
	checkbox.checked = true;
	if (checkbox.form.onsubmit()) {
		checkbox.form.submit();
	} else {
		checkbox.checked = false;
	}
	// delay for changes to settle-in...
	//setTimeout("submitForm(" + checkbox.id + ");", 500); 	
}

/**
 * Checks (or un checks) all checkboxes amonf the
 * given list is checked.
 */
function checkAll (checkboxes, status) {
	var size = 1;
	if (checkboxes.length) {
		size = checkboxes.length;
	}
	if (size == 1) {
		checkboxes.checked = status;
	} else {
   		for (i = 0; i < size; i++) {
			checkboxes[i].checked = status;
		}
	}
}

/**
 * Checks to see if atleast one checkbox among the
 * given list is checked. If not, alerts the user with the
 * msg.
 */
function isChecked (checkboxes, msg) {
	var size = 1;
	if (checkboxes.length) {
		size = checkboxes.length;
	}
	if (size == 1) {
		if (checkboxes.checked) {
			return true;	
		}
	} else {
   		for (i = 0; i < size; i++) {
			if (checkboxes[i].checked) {
				return true;	
			}
		}
	}
	alert (msg);
	return false;
}

function openLink(url, windowName) {
	var win = window.open(url, windowName);
	win.focus();
	return false;
}

function calendarSetup(fieldname, withTime) {
	    Calendar.setup({
	        inputField     :    fieldname, 
	        ifFormat       :    "%Y-%m-%d",
	        showsTime      :    withTime,
	        button         :    fieldname + "_button",
	        step           :    1,
			weekNumbers	   :	false,
			electric	   : false,
			showOthers	   : true
	    });
}

function disableFilterNav(filterForm) {
	var pageNum = filterForm['filter.pageNumber'].selectedIndex;
	var noPages = false;
	if (filterForm['filter.pageNumber'].options.length == 0) {
		noPages = true;	
	}
	var numPages = filterForm['filter.pageNumber'].options.length;

	if (noPages || pageNum == numPages - 1) {
		document.getElementById("nextButton").disabled = true;
		document.getElementById("lastButton").disabled = true;
	}

	if (noPages || pageNum == 0) {
		document.getElementById("prevButton").disabled = true;
		document.getElementById("firstButton").disabled = true;
	}
}

function clearForm(aform) {
	var theElements = aform.elements;
	for (i = 0; i < theElements.length; i++) {
		if (theElements[i].type == "text") {
			theElements[i].value = '';	
		} else if (theElements[i].type == "select-one") {
			theElements[i].selectedIndex = 0;	
		}
	}
}

function toggleFilter(table, link) {
	var display = 'none';
	if (link.innerHTML == "+") {
		link.innerHTML = "&times;";	
		display = "block";
	} else {
		link.innerHTML = "+";	
	}
	table.style.display = display;	
	return false;
}


