
function showLayer( whichLayer) {
  var elem = getLayer(whichLayer);
  elem.style.display = 'block';
}

function hideLayer(whichLayer) {
  var elem = getLayer(whichLayer);
  elem.style.display = 'none';
}

function toggleLayer( whichLayer) {
  var elem, vis;
  elem = getLayer(whichLayer);
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  return vis.display == 'block';
}

function toggleRowGroupByPrefix(prefix) {
  divs = document.getElementsByTagName('tbody');
  for (i=0; i<divs.length; i++) {
    //alert(divs[i]);
    children = divs[i].getElementsByTagName('*');
    //alert(children);
    //alert(children.length);
    //alert(children[0].id);
    //id = divs[i].innerHTML;
    //alert(id);
    //toggleRowGroup(id);

      for (j=0; j<children.length; j++) {
        toggleRowGroup(children[j].id);
      }
    }
}

function toggleRowGroup(id) {
  style = (BrowserDetect.browser == "Explorer") ? "block" : "table-row-group";
  var elem, vis;
  elem = getLayer(id);
  if (!elem) { return };
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?style:'none';
  vis.display = (vis.display==''||vis.display==style)?'none':style;
  return vis.display == style;
}

function getLayer(whichLayer) {
  var elem;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  return elem;
}

// Pop up a modal dialog
function openWindow(url, name, height, width, customParams) {
    width = 980;
    var params = 'height='+height+',width='+width+',resizable=no,status=no,help=no,' + customParams;
    if (url.indexOf("?") <= 0) {
        url += "?ts=" + new Date().getTime();
    } else {
        url += "&ts=" + new Date().getTime();
    }

    if(screen.width){
        var winl = (screen.width-width)/2;
        var wint = (screen.height-height)/2;
    } else {
        winl = 0;
        wint = 0;
    }
    if (winl < 0) winl = 0;
    if (wint < 0) wint = 0;
    params += ',top=' + wint + ',';
    params += 'left=' + winl + ',';

    return window.open(url, name, params);
}


function moveOptions(theSelFrom, theSelTo) {
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  for(i=selLength-1; i>=0; i--) {
    if(theSelFrom.options[i].selected) {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
}

function addOption(theSel, theText, theValue) {
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex) { 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

