// work out which browser type is needed
var ns4 = false;
var ns5plus = false;
var ie = false;
if (document.layers)
	ns4 = true;
else if ((parseInt(navigator.appVersion) >= 5) && (navigator.appName=="Netscape"))
	ns5plus = true;
else if (document.all)
	ie = true;


// make the user confirm their action before proceeding (used when deleting things,  etc)
function confirm_action (message, urllocation) {
	if (!confirm (message)) {
		return (false);
	}
	else {
		document.location.href = urllocation;
	}
}

// record in a hidden field that a form on the page has been updated
function form_changed () {
	document.formChanges.changesMade.value = 'Y';
}

// record in a hidden field that a form on the page has been updated
function go_to (urllocation) {
	if (document.formChanges.changesMade.value == 'Y')
		confirm_action ("You have made changes to a form on this page.\nDo you wish to continue without saving?", urllocation);
//		alert ("You have made changes to the form on this page.\nPlease save this information before continuing.");
	else
		document.location.href = urllocation;
}

// toggle a checkbox's value
function toggle_checkbox (fieldName, arrayPosition) {
	temp = get_object (fieldName);

	// check to see if javascript thinks this is an object (array) or not
	if (typeof (temp[arrayPosition]) != 'undefined') {
		if (temp[arrayPosition].checked == false)
			temp[arrayPosition].checked = true;
		else
			temp[arrayPosition].checked = false;
	}
	else {
		if (temp.checked == false)
			temp.checked = true;
		else
			temp.checked = false;
	}
	return true;
}

// toggle a checkbox's value
function set_radio_button (fieldName, arrayPosition) {
	temp = get_object (fieldName);

	// check to see if javascript thinks this is an object (array) or not
	if (typeof (temp[arrayPosition]) != 'undefined')
		temp[arrayPosition].checked = true;
	else
		temp.checked = true;

	return true;
}

// display or hide a div
function flip_div (divName) {
	temp = get_object (divName);

	current=(temp.style.display == 'none') ? 'inline' : 'none';
	temp.style.display = current;
}

// display a div
function display_div (divName) {
	temp = get_object (divName);

	temp.style.display = 'inline';
}

// hide a div
function hide_div (divName) {
	temp = get_object (divName);

	temp.style.display = 'none';
}














// 
function get_object (fieldName) {
	if (ie)
		temp = document.all[fieldName];
	else if (ns5plus)
		temp = document.getElementById(fieldName);
	else if (ns4)
		temp = document.layers[fieldName];

	return temp;
}

// 
function select_all_checkboxes (fieldName) {
	temp = get_object (fieldName);

	if (temp.length) {
		for (count = 0; count < temp.length; count++)
			temp[count].checked = true;
	}
	else
		temp.checked = true;
}

// 
function unselect_all_checkboxes (fieldName) {
	temp = get_object (fieldName);

	if (temp.length) {
		for (count = 0; count < temp.length; count++)
			temp[count].checked = false;
	}
	else
		temp.checked = false;
}

function are_all_checkboxes_selected (fieldName) {
	temp = get_object (fieldName);

	allSelected = true;
	if (temp.length) {
		for (count = 0; count < temp.length; count++) {
			if (temp[count].checked == false)
				allSelected = false;
		}
	}
	else {
		if (temp.checked == false)
			allSelected = false;
	}
	return allSelected;
}

// 
function toggle_all_checkboxes (fieldName) {
	if (are_all_checkboxes_selected (fieldName))
		return unselect_all_checkboxes (fieldName);
	return select_all_checkboxes (fieldName);
}

// 
function update_button_text_based_on_all_checkboxes (fieldName, buttonName, allSelectedText, notAllSelectedText) {
	buttonObject = get_object (buttonName);

	if (are_all_checkboxes_selected (fieldName))
		buttonObject.value = allSelectedText;
	else
		buttonObject.value = notAllSelectedText;
}
