// 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 = 'block';
}

// hide a div
function hide_div (divName) {
	temp = get_object (divName);

	temp.style.display = 'none';
}

// display a parent div
function display_parent_div (divName) {
	temp = get_parent_object (divName);

	temp.style.display = 'block';
}

// hide a parent div
function hide_parent_div (divName) {
	temp = get_parent_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 get_parent_object (fieldName) {
	if (ie)
		temp = parent.document.all[fieldName];
	else if (ns5plus)
		temp = parent.document.getElementById(fieldName);
	else if (ns4)
		temp = parent.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;
}










// cookie functions
function get_cookie_val (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape (document.cookie.substring (offset, endstr));
}

function get_cookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring (i, j) == arg)
			return get_cookie_val (j);
		i = document.cookie.indexOf (" ", i) + 1;
		if (i == 0)
			break; 
	}
	return null;
}

function set_cookie (name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape (value)
	+ ((expires) ? "; expires=" + expires.toGMTString () : "")
	+ ((path) ? "; path=" + path : "")
	+ ((domain) ? "; domain=" + domain : "")
	+ ((secure) ? "; secure" : "");
}

function delete_cookie (name, path, domain) {
	if (get_cookie (name)) {
		document.cookie = name + "="
		+ ((path) ? "; path=" + path : "")
		+ ((domain) ? "; domain=" + domain : "")
		+ "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


// limit chars entered into a textarea
function text_limiter_with_counter(field,maxlimit,cntfield, cntfieldtext) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	
	// otherwise, update 'characters left' counter
	else 
		cntfield.value = maxlimit - field.value.length + cntfieldtext;
}

function text_limiter_without_counter(field,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
}


// force IE to blink
function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("blink")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",500)
}
window.onload = startBlink;
