<!--

// change 'innerText' attribute of DOM element
function changeInnerText (id,newtext) {
  // simpler IE method
  if (document.all) {
    document.getElementById(id).innerText = newtext;
    return;
  }
  
  // Mozilla, Netscape method
  var oElem = document.getElementById(id).firstChild;
  var txt = document.createTextNode(newtext);
  document.getElementById(id).replaceChild(txt, oElem);
}

// read 'innerText' attribute of DOM element
function getInnerText (id) {
  // simpler IE method
  if (document.all) return document.getElementById(id).innerText;
  
  // Mozilla, Netscape method
  var oElem = document.getElementById(id).firstChild;
  return oElem.nodeValue;
}

// add options to Select Element using DOM style
// optlist is comma-sep string of options
function addSelectOptions (id,optlist) {
  var elSel = document.getElementById (id);
  var optArray = optlist.split (",");
  for (var i=0; i < optArray.length; i++) {
    var elOpt = document.createElement ("option");
    elOpt.text = optArray[i];
    elOpt.value = optArray[i];
    if (document.all) elSel.add (elOpt);
      else elSel.appendChild (elOpt);
  }
}

// remove all options from Select element
function purgeSelectOptions (id) {
  var elSel = document.getElementById(id);
  var cnt = elSel.length;
  for (var i=0; i < cnt; i++) elSel.remove(0);
}

// get list of all select options
function getSelectOptionsAll (id) {
  var elSel = document.getElementById(id);
  var txt = "";
  for (var i=0; i < elSel.length; i++) {
    txt += "," + elSel.options[i].text;
  }
  return txt.substr(1);
}

// pick a select option programmatically
function setSelectOptions (id,item) {
  var elSel = document.getElementById(id);
  for (var i=0; i < elSel.length; i++) {
    if (elSel.options[i].text == item) {
      elSel.selectedIndex = i;
      return;
    }
  }
}

// populate a select box
function populateSelect (id,itemlist) {
  purgeSelectOptions (id);
  addSelectOptions (id,itemlist);
}

// remove an option from select box
function removeSelectOption (id,item) {
  var elSel = document.getElementById(id);
  for (var i=0; i < elSel.length; i++) {
    if (elSel.options[i].text == item) {
      elSel.remove(i);
      return;
    }
  }
}

// attach event handler to a html element
// func is specified without brackets and no quotes!
function attachEventHandler (id,event,func) {
  var el = document.getElementById(id);
  if (el.addEventListener) {
    el.addEventListener (event,func,false);
  }
  if (el.attachEvent) {
    el.attachEvent ("on"+event,func);
  }
}

function getEventSource (e) {
  var el = null;
  if (!e) e = window.event
  if (e.srcElement) el = e.srcElement; // IE
  if (e.target) el = e.target; // Mozilla
  return el;
}

// placed here for reference only. never called!
// supports both IE and Mozilla
function modelEventHandler (e) {
  var el = null;
  if (!e) e = window.event;  // IE
  if (e.srcElement) el = e.srcElement; // IE
  if (e.target) el = e.target; // Mozilla
  alert ("ID is " + el.getAttribute ("id")); // common
}


// add a new html element to a div block
// tag has no angle brackets eg "select"
function addHtmlElement (id,tag,id2) {
  //alert ("addHtmlElement()!");
  var elTag = document.createElement(tag);
  var tgtDiv = document.getElementById (id);
  if (id2 != "") elTag.setAttribute ("id",id2);
  tgtDiv.appendChild (elTag);
}

// add text (string label) to a div block
function addHtmlText (id,txt) {
  if (document.createTextNode){
    var elText = document.createTextNode (txt);
    document.getElementById(id).appendChild (elText)
  }
}

// add text with entities to a div block
function addHtmlEntities (id,txt) {
  var span = document.createElement('span');
  span.innerHTML = txt;
  var tgtDiv = document.getElementById (id);
  tgtDiv.appendChild (span);
}

// get url parameter
function gup (name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

// check for Enter keypress and trigger user function
// eg onkeypress = "checkEnter ('userLogin()',event)"
function checkEnter (userfunc,e) {
  var ascii;
  // Mozilla case
  if(e && e.which){
     ascii = e.which;
  }
  // IE case
  else{
     e = event;
     ascii = e.keyCode;
  }
  // if Enter key, then trigger grpLogin()
  if (ascii == 13) eval (userfunc);
}

function closeWindow () {
  if (document.all) {
    window.close ();
    return;
  }
  alert ("Please close manually if using Mozilla, Firefox or Netscape");
}

// important to use this when using ajax.js to
// read in a file with single or double quotes!
function addSlashes2Quotes(str) {
  str=str.replace(/\'/g,'\\\'');
  str=str.replace(/\"/g,'\\"');
  return str;
}

//-->
