function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else if (document.getElementById) {
   document.onload = fn;
 } else { 
   return false; 
 } 
}

function showPopUpHelp(URL, width, height) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'location=no,statusbar=no,status=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,resizable=yes,width=" + width + ",height=" + height + "');");
}

function showDialog(URL, width, height) {
  day = new Date();
  id = day.getTime();

   /* status or statusbars?  either way, this window needs status bars */  
  
  eval("page" + id + " = window.open(URL, '" + id + "', 'location=no,statusbar=yes,status=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,resizable=yes,width=" + width + ",height=" + height + "');");
}

function showDialogWithLocation(URL, width, height, leftOffset, topOffset) {

  day = new Date();

  id = day.getTime();

   /* status or statusbars?  either way, this window needs status bars */  

  eval("page" + id + " = window.open(URL, '" + id + "', 'location=no,statusbar=yes,status=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,resizable=yes,width=" + width + ",height=" + height + ",left=" + leftOffset + ",top=" + topOffset + "');");

}

function setCBVal(form, name, val) {
        for(var i=0;i < form.length;i++)
          if(form.elements[i].name.indexOf(name)==0) {
            if(val=='Y')
              form.elements[i].checked=true;
            else 
              form.elements[i].checked=false;
          }                
        return false;
}

function getObjById(id) {
        if (document.getElementById) {
          return document.getElementById(id);
        }
        if(document.all){ 
          return document.all[id];
        }
        if (document.layers) {
          return document.layers[id];
        }
}
                              
function hideElement(id) { 
        var element = getObjById(id);
        if (element == null) {
          return;
        }
        element.style.display="none";
}
          
function showElement(id) { 
        var element = getObjById(id);
        if (element == null) {
          return;
        }
        element.style.display="";
}
      
function toggleView(id) { 
        var element = getObjById(id);
        if (element == null) {
          return;
        }
        if (element.style.display=="none") {
          element.style.display="";
        } else {
          element.style.display="none";
        }
}

function toggleTruncValue(truncValue, fullValue) {
        toggleView(truncValue);
        toggleView(fullValue);
}

function dualBoxMoveOver(choiceBox, available) {
  var boxLength = choiceBox.length;
  var selectedItem = available.selectedIndex;
  var selectedText = available.options[selectedItem].text;
  var selectedValue = available.options[selectedItem].value;
  var i;
  var isNew = true;
  if (boxLength != 0) {
    for (i = 0; i < boxLength; i++) {
      thisitem = choiceBox.options[i].text;
      if (thisitem == selectedText) {
        isNew = false;
        break;
      }
    }
  } 

  if (isNew) {
    newoption = new Option(selectedText, selectedValue, false, false);
    choiceBox.options[boxLength] = newoption;
  }
  available.selectedIndex=-1;
}

function dualBoxRemove(choiceBox) {
  var boxLength = choiceBox.length;
  arrSelected = new Array();
  var count = 0;
  for (i = 0; i < boxLength; i++) {
    if (choiceBox.options[i].selected) {
      arrSelected[count] = choiceBox.options[i].value;
    }
    count++;
  }

  var x;
  for (i = 0; i < boxLength; i++) {
    for (x = 0; x < arrSelected.length; x++) {
      if (choiceBox.options[i].value == arrSelected[x]) {
        choiceBox.options[i] = null;
      }
    }
    boxLength = choiceBox.length;
  }
}

function dualBoxSaveToString(choiceBox, saveTo) {
  var strValues = "";
  var boxLength = choiceBox.length;
  var count = 0;
  if (boxLength != 0) {
    for (i = 0; i < boxLength; i++) {
      if (count == 0) {
        strValues = choiceBox.options[i].value;
      } else {
        strValues = strValues + "," + choiceBox.options[i].value;
      }
      count++;
    }
  }

  saveTo.value = strValues;
}

function toggleCheckboxes(elm, chkboxName) {
  for (var i = 0; i < elm.form.elements.length; i++) {
    var e = elm.form.elements[i];
    if ( (e.name == chkboxName) && (e.type=='checkbox') && (!e.disabled) ) {
      e.checked = elm.checked;
    }
  }
}

function showDialogWindow(URL, width, height, leftOffset, topOffset) {
  day = new Date();
  id = day.getTime();
  
  eval("page" + id + " = window.open(URL, '" + id + "', 'location=yes,statusbar=yes,status=yes,scrollbars=yes,menubar=yes,toolbar=yes,directories=yes,resizable=yes,width=" + width + ",height=" + height + ",left=" + leftOffset + ",top=" + topOffset + "');");

}

