/**
 * @author dan
 * This code requires use of the Prototype Javascript library
 */

/* Utility functions:
 * 
 * testAjax
 * isVisible
 * setVisibility
 * makeVisible
 * makeInvisible
 * clearSelectOptions
 * addSelectOption
 * onEnterKey
 */


// Test for AJAX support
function testAjax () {
	if (!Ajax.getTransport) {
		alert ("You cannot view this page: your browser does not support AJAX. Please upgrade your browser.");
		window.location = '/';
	}
}

function isVisible(el) {
	return $(el).getStyle('visibility') == 'visible'; // wrap with $() due to IE/Prototype
}

function setVisibility(divId, bool) {
	$(divId).style.visibility = bool ? 'visible' : 'hidden';
}

function makeVisible(divId) {
	setVisibility(divId, true);
}

function makeInvisible(divId) {
	setVisibility(divId, false);
}

function clearSelectOptions(input) {
	input.length = 0
}

function addSelectOption(select, value, text) {
	// Add option to the bottom of the list
	select[select.length] = new Option(text, value);
}

function onEnterKey(e){
	var key = window.event ? e.keyCode : e.which; //IE vs Firefox
	return key == 13
}
