/* --------------------------------------------------- */
/* name:     j5utilities.js                            */
/* author:   J5 Development                            */
/* purpose:  javascript utility functions              */
/* --------------------------------------------------- */

/* --------------------------------------------------- */
/* image rollover functions                            */
/* --------------------------------------------------- */
function imgOn(imgName) {
  if (document.images) {
    document[imgName].src = eval(imgName + "on.src");
  }
}
function imgOff(imgName) {
  if (document.images) {
    document[imgName].src = eval(imgName + "off.src");
  }
}

/* --------------------------------------------------- */
/* display tool tip                                    */
/* --------------------------------------------------- */
function tooltip(fieldName, fieldFormat) {
	alert("Enter " + fieldName + " as " + fieldFormat);
}

/* --------------------------------------------------- */
/* position cursor at form field                       */
/* --------------------------------------------------- */
function throwFocus(focusForm, focusField) {
  theField = eval("document." + focusForm + "." + focusField);
  if (!theField.options && theField.value != '') { 
    theField.select(); 
  }
  theField.focus();
}

/* --------------------------------------------------- */
/* tab to next field when full                         */
/* --------------------------------------------------- */
function tabNext(tabField, tabLength, tabNext) {
  var fieldContents = tabField.value;
  if (fieldContents.length == tabLength) {
    theForm = tabField.form;
    nextField = eval("document." + theForm.name + "." + tabNext);
    nextField.focus();
  }
}

/* --------------------------------------------------- */
/* get the value of the selected radio button          */
/* --------------------------------------------------- */
function getRadioButton(radioGroup) {
  for (var i=0; i < radioGroup.length; i++) {
	  if (radioGroup[i].checked) { return i; }
	}
	return 0;
}

/* --------------------------------------------------- */
/* page through multi-page list display                */
/* --------------------------------------------------- */
function getPage(formName,number) { 
  thisForm = eval("document." + formName);
  thisForm.pageNum.value = number;
  thisForm.submit(); 
}

/* --------------------------------------------------- */
/* go to the specified page                            */
/* --------------------------------------------------- */
function gotoPage(formName,selectBox) { 
  thisForm = eval("document." + formName);
	thisSelect = eval("document." + formName + "." + selectBox);
	actionPage = thisSelect.options[thisSelect.selectedIndex].value;
	if (actionPage != "")
	{
	  thisForm.action = actionPage;
  	thisForm.submit(); 
	}
	else
	{
		alert("Please select a page");
	}
}

/* --------------------------------------------------- */
/* toggle archives display                             */
/* --------------------------------------------------- */
function toggleArchives(formName) { 
  thisForm = eval("document." + formName);
	if (thisForm.Archives.value == "1") {
	  thisForm.Archives.value = "0";
	} else {
	  thisForm.Archives.value = "1";
	}
  thisForm.submit(); 
}

/* --------------------------------------------------- */
/* change sort column/direction on list                */
/* --------------------------------------------------- */
function changeSort(formName,strField) { 
  thisForm = eval("document." + formName);
  if (thisForm.sortField.value == strField) {
	/* same column: toggle the direction */
	if (thisForm.sortDirection.value == "Asc") {
	  thisForm.sortDirection.value = "Desc";
	} else {
	  thisForm.sortDirection.value = "Asc";
	}
  } else {
	/* new sort column: assume ascending */
	thisForm.sortField.value = strField;
	thisForm.sortDirection.value = "Asc";
  }
  thisForm.submit(); 
}

/* --------------------------------------------------- */
/* open new browser window with no controls            */
/* --------------------------------------------------- */
function popWindow(url, width, height, windowName) {
  /* defaults if not passed to function */
  if (!width) { width = 600; }
  if (!height) { height = 450; }
  if (!windowName) { windowName = "J5pop"; }
  wref = window.open (url, windowName,
        "toolbar=no,location=no,width=" + width + ",height=" + height +
        ",directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no");
  if (navigator.appName == "Netscape" || navigator.appVersion.substring(0,1) == '5') {
    wref.focus();
  }
}

/* --------------------------------------------------- */
/* open new browser window with full controls          */
/* --------------------------------------------------- */
function newWindow(url, width, height, windowName) {
  /* defaults if not passed to function */
  if (!width) { width = 800; }
  if (!height) { height = 600; }
  if (!windowName) { windowName = "J5new"; }
  wref = window.open (url, windowName,
        "toolbar=yes,location=yes,width=" + width + ",height=" + height +
        ",directories=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes");
  if (navigator.appName == "Netscape" || navigator.appVersion.substring(0,1) == '5') {
    wref.focus();
  }
}
