// some generic utilities to assist page functionality

/**
 * Useful where there are elements with ids that have a common base + a number (e.g. tabContent1, tabcontent2, ...)
 * This function shows the element with id ending in 'num' and hides all others
 */
function showNumberedPane(num, contentNameBase, tabNameBase) {
  if (typeof(contentNameBase)=='undefined' || contentNameBase===null) {
    contentNameBase = 'tabContent';
  }
  if (typeof(tabNameBase)=='undefined') {
    tabNameBase = false;
  }
  var i = 1;
  var tabContent = null;
  while (tabContent = document.getElementById(contentNameBase+i)) {
    tabContent.style.display = (num == i) ? 'block' : 'none';
    if (tabNameBase) {
      var tab = document.getElementById(tabNameBase+i);
      if (tab) {
        tab.src = "/images/tab"+i+"_"+((num == i) ? 'on' : 'off')+".gif";
      }
    }
    i++;
  }
}

/**
 * Where there is a list of elements that have a common base + a number, 
 * num is the offset that is highlighted
 * itemNameBase is the base id of the elements to highlight/unhighlight
 * highlight - a function that takes an element as a parameter, and performs the highlight operations
 * unhighlight - a function that takes an element as a parameter, and performs the unhighlight operations
 */
function highlightSelectedItem(num, itemNameBase, highlight, unhighlight) {
  if(typeof(itemNameBase) == 'undefined' || itemNameBase === null) {
    itemNameBase = 'listItem';
  }
  var i=1;
  var listContent = null;
  while (listContent = document.getElementById(itemNameBase + i)) {
    if (num == i) {
      highlight(listContent);
    }
    else {
      unhighlight(listContent);
    }
    i++;
  }
}
/**
 * submit a form when enter is pressed
 */
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

// a given list element 'ele' is highlighted in this way:
  function highlight( ele ) {
  ele.style.color = 'rgb(118,6,3)';
  ele.style.listStyleImage = 'url(/images/list_arrow_red.png)';
  //ele.class="jslink red";
  }

// a given list element 'ele' is unhighlighted in this way:
  function unhighlight( ele ) {
    ele.style.color = 'rgb(39,26,84)';
    ele.style.listStyleImage = "url('/images/list_arrow_blue.png')";
    //ele.class="jslink blue";
  }


