

function getTopWindow(){
  var w = window.self;
  while(w.parent!=null && w.parent!=w){
    if(w.IsTopFrame || w.frames.ADMIN_MENU)break;
    w = w.parent;
  }
  return w;
}

function formatNumber2(val, options) {
  if (isNaN(val)) {
    if(options && options.ifNull){
      return options.ifNull;
    } 
    return '';
  }
  var neg = false;
  if (val < 0) {
    neg = true;
    val = -val;
  }
  if(options){
    if(val==0 && options.ifZero){
      return options.ifZero;
    }
  }
  var s = "" + val;

  if (neg && options && options.negStyle){
    if(options.negStyle=='()'){
      s = '(' + s + ')';
      neg = false;
    }
  }
  if (neg) {
    s = "-" + s;
  }
  return s;
}


var HM_DOM  = true;
var HM_IE   = false;
var HM_OPER = false;
var HM_MOZ  = false;
var HM_CHRO = false;
var HM_IEVER=5;
if(HM_IE) {
  try {
    HM_IEVER=parseFloat(navigator.appVersion.split("MSIE")[1]);
  } catch(e) {}
}

function isIE(){
  return HM_IE;
}

function isOpera() {
  return HM_OPER;
}

function isMozilla() {
  return HM_MOZ;
}

function stopBubble(ev) {
 if (isNull(ev)) return;
 ev.cancelBubble=true;
 if (!isNull(ev.preventDefault)) {
   ev.preventDefault();
 }
 if (!isNull(ev.stopPropagation)) {
   ev.stopPropagation();
 }
}

function stopBubble_DontPreventDefault(ev) {
 ev.cancelBubble=true;
 if (!isNull(ev.stopPropagation)) {
   ev.stopPropagation();
 }
}

function getDocElm(elm) {
 
   var r = document.getElementById(elm);
   if (isNull(r) && !isNull(document.TheForm)) {
     r = TheForm[elm];
   }
   return r;
 
}

function getPageX() {
  
  return document.body.scrollLeft;
  
}

function getPageY() {
  
  return document.body.scrollTop;
  
}

function setStatus(s) {window.status = s;return true;}
setStatus('');


function isUndef(ver){return ( ver === undefined ||  ver == this._undef);}
function isNull(ver) {return ( ver === undefined ||  ver == null || ver == this._undef);}

function trim(s){
  if(isNull(s) || s=="") return "";
  var i=0;
  for(i=0; i<s.length; i++) {
    var c = s.charCodeAt(i);
    if ((c >= 33) && (c <=126 )){ break; }
  }
  var j;
  for(j=s.length-1; j>=i; j--) {
    var c = s.charCodeAt(j);
    if ((c >= 33) && (c <=126 )){ break; }
  }
  s = s.substring(i,j+1);
  return s;
}

function _onchange(_c){if(!isNull(_c)&&!isNull(_c.onchange)){_c.onchange();}}

function isBlank(s){return (trim(s).length==0);}

function escapeStr(str){
  var s = escape(str);
  s = s.replace( /\//g,"%2F" );
  s = s.replace( "#", "%23" );
  s = s.replace('+','%2B')
  return s;
}
function unescapeStr(str){
  var s = unescape(str);
  s = s.replace( /\+/g," " );
  return s;
}
function parseBoolean(val, defValue){
  val = ''+val;
  if(val=='' || val==null)return defValue;

  val = val.substring(0,1);

  if(val=='1')return true;
  if(val=='t' || val=='T')return true;
  if(val=='Y' || val=='y')return true;

  if(val=='0')return false;
  if(val=='f' || val=='F')return false;
  if(val=='N' || val=='n')return false;

  return defValue;
}

function parseNumber(val,_defVal) {
  if (isNull(val) || trim(val).length == 0)
    return isNull(_defVal)?0:_defVal;

  var haveDecimal=false;
  
  if (val.charAt(0) == '(' && val.charAt(val.length-1) == ')') {
    val = "-" + val.substring(1, val.length-1);
  }
  val = val.replace( "$", "" );
  val = val.replace( "%", "" );
  
  var charOne = val.charAt(0);
  var ret="";
  if (charOne == '+' || charOne == '-' || charOne == '.' || !isNaN(charOne)){
    var ret=""+charOne;
    haveDecimal = (charOne=='.');
  }

  for (var i = 1; i < val.length; i++) {
    var curChar = val.charAt(i);
    if (curChar == '.'){
      if(!haveDecimal){
        haveDecimal = true;
        ret = ret + curChar;
      }
      continue;
    }
    if(isNaN(curChar))
      continue;
    ret = ret + curChar;
  }
  if (isNaN(ret)){
    return isNull(_defVal)?0:_defVal;
  }
  return parseFloat(ret);
}

function parseNumber_Int(val,_defVal) {
  if (isNull(val) || trim(val).length == 0)
    return isNull(_defVal)?0:_defVal;
  
  if (val.charAt(0) == '(' && val.charAt(val.length-1) == ')') {
    val = "-" + val.substring(1, val.length-1);
  }
  val = val.replace( "$", "" );
  val = val.replace( "%", "" );
  
  var charOne = val.charAt(0);
  var ret="";
  if (charOne == '.') {
    return 0;
  }
  var i = 0;
  var sign='';
  if (charOne == '+' || charOne == '-'){
    sign=charOne;
    i=1;
  }

  for (; i < val.length; i++) {
    var curChar = val.charAt(i);
    if (curChar == '.'){
      break;
    }
    if(isNaN(curChar))
      continue;
    if (ret.length==0 && curChar=='0') {
      continue;
    } 
    ret = ret + curChar;
  }
  if (isNaN(ret)){
    return isNull(_defVal)?0:_defVal;
  }
  ret=sign+ret;
  if (ret > 2147483647) {
    return 2147483647;
  } else if (ret < -2147483648) {
    return -2147483648;
  }
  return parseInt(ret);
}

function getInnerText(el) {
  if ('string' == typeof el.textContent) return el.textContent;
  if ('string' == typeof el.innerText) return el.innerText;
  return el.innerHTML.replace(/<[^>]*>/g,'');
}

function parseNumberStrict(val,_defVal) {
  if (!isNull(val)) { val = val + ""; }
  if(isUndef(_defVal)){_defVal = 0;}

  if (isNull(val) || trim(val).length == 0)
    return _defVal;
    
  val = val.replace("$", "");

  val = trim(val);
  if (val.charAt(0) == '$')
    val = val.substring(1);
  if (val.charAt(val.length-1) == '%')
    val = val.substring(0, val.length-1);
  var sign="";
  if (val.charAt(0) == '-') {
    val = val.substring(1);
    sign="-";
  } else if (val.charAt(0) == "+") {
    val = val.substring(1);
  }

  var ret="";
  var bHavDecimal = false;

  for (var i = 0; i < val.length; i++) {
    var curChar = val.charAt(i);
    if (curChar == ',') {
      continue;
    }
    if (curChar == '.') {
      if (bHavDecimal){
        ret=null; break;
      } else {
        bHavDecimal = true;
      }
      ret = ret + curChar;
      continue;
    }
    if(isNaN(curChar)){
      ret=null;break;
    }
    ret = ret + curChar;
  }
  if (isNaN(ret)){
    return _defVal;
  }
  ret = parseFloat(sign+ret);
  if (isNaN(ret)){
    return _defVal;
  }
  return ret;
}

function verifyMoney(v1,v2){
  return verifyFloat(v1,v2);
}



function reInt(v1,v2,bZero){
  var i = parseNumber_Int(v1,v2);
  
  if (isNaN(i)) {
    return isNull(v2)?'':v2;
  }
  i = Math.floor(i);
  
  if (i == 0){
    return bZero ? '0' : '';
  } 
  return i;
}
function reLong(v1,v2,bZero,vMin,vMax){
  if(isBlank(v1)){
    return isNull(v2)?'':v2;
  }
//need to add support for large numbers
  return v1;
}
function reDouble(v1,v2,ndp,negOk,zeroOK){
  if(isBlank(v1)){
    return isNull(v2)?'':v2;
  }
  var i = parseNumber(v1,v2);
  if (isNaN(i) || isNull(i) || i==='') {
    return isNull(v2)?'':v2;
  }
  if (i < 0 && !negOk) {
    i = -i;
  }
  if (i == 0) {
    if(zeroOK)
      return '0';
    else
      return '';
  }
  if (ndp >= 0) {
    var s = i+"";
    var indx = s.indexOf(".");
    if (indx !=-1) {
      if (ndp == 0) {
        return s.substring(0,indx);
      }
      if (s.length - (indx+1) > ndp) {
        return s = s.substring(0, indx+ndp+1);
      }
    }
  }
  return i;
}

function reMonthDay(v1,v2){
  var vals = v1.split('/');
  if (vals.length == 0) {
    return '';
  }
  if (vals.length == 1) {
    vals[1] = '1';
  }
  for (i = 0; i < 2; i++) {
    v = reInt(vals[i], 1);
    if (i == 0 && (v <=0 || v > 12)) {
      v = 1;
    } else if (i == 1 && (v <=0 || v > 31)) {
      v = 1;
    }
    vals[i] = v + '';
    if (vals[i].length == 1) vals[i] = '0' + vals[i];
    if (vals[i].length > 2) vals[i] = vals[i].substring(0,2);
  }
  return vals[0] + '/' + vals[1];
}


function formatInt(val, showZero, addCommas) {
  if (val == 0 || isNaN(val)) {
    return showZero?'0':'';
  }
  val = Math.floor(val);
  if (!addCommas) {
    return val+'';
  }
  val2 = '' + val;
  ret = '';
  while (val2.length > 3) {
    ret = val2.substring(val2.length-3) + ret;
    val2 = val2.substring(0, val2.length-3);
    if (val2.length > 0) {
      ret = ',' + ret;
    }
  }
  ret = val2 + ret;
  return ret;
}

function formatMoney(val, roundValue, numDec, addSign, showZero, sep, allowNull) {
  var sign = "";
  if (addSign) {
    sign = "$";
  }
  if (isNull(numDec)) {
    numDec = 2;
  }
  if(allowNull) {
    if(val == "" || val == null || isNaN(val)) {
      if(!(val===0 && showZero==1)) {
        return "";
      }
    }
  }
  if (isNaN(val)) {
    val = 0;
  }
  if (val==0 && showZero==0) return "";

  var neg = false;
  if (val < 0) {
    neg = true;
    val = -val;
  }
  var prec = Math.pow(10,numDec);
  val = Math.round(val*prec)/prec;
  if (!isNull(roundValue) && roundValue == 1)
    val = Math.round(val/prec)*prec;

  var cents = val - Math.floor(val);
  cents = Math.round(cents*prec);
  var dollars = Math.floor(val);

  var centsStr = "";
  if (numDec>0) {
    centsStr = cents+"";
    centsStr = "000000".substring(0, numDec-centsStr.length) + cents;
    for(var i=centsStr.length-1;i>1; i--){
      if(centsStr.charAt(i)!='0')break
      centsStr = centsStr.substring(0,i);
    }
    centsStr = "." + centsStr;
  }
  
  var dollarsStr = dollars + "";

  var addMinus = "";
  if (neg) {
    addMinus = "-";
  }
  if (!isNull(sep) && dollarsStr.length > 3) {
    var ds = '';
    while (dollarsStr.length > 3) {
      if (ds.length > 0) ds = sep + ds;
      ds = dollarsStr.substring(dollarsStr.length-3) + ds;
      dollarsStr = dollarsStr.substring(0, dollarsStr.length-3);
    }
    if(dollarsStr.length>0){
      dollarsStr = dollarsStr + sep + ds;
    }
  }
  return sign + addMinus + dollarsStr + centsStr;
}

function formatNumber(val, roundValue, numDec) {
  return formatMoney(val, roundValue, numDec, false);
}

function formatSSN(val, event) {
  if (event.keyCode==8){
    return val;
  }
  var mask = "-";
  val = val.replace(/-/g,'');
  if (val.length >= 5){
    return val.slice(0,3) + mask + val.slice(3,5) + mask + val.slice(5,9);
  }if (val.length >= 3) {
    return val.slice(0,3) + mask + val.slice(3,5);
  } else {
    return val;
  }
}

function copyProperties(from, to) {
 for(i in from){
  to[i]=from[i];
 }
}

var _Arguments = null;
function getArguments(){
    if(!isNull(window.dialogArguments)){
      return window.dialogArguments;
    }
    if(isNull(this._Arguments)){
        var _search = document.location.search.substring(1).split('&');
        this._Arguments = new Object();
        for(var i in _search){
            var _nvp = _search[i].split('=');
            if( _nvp!=null && _nvp!=this._undef && _nvp.length==2
             && _nvp[0]!=null && _nvp[0]!=this._undef
             && _nvp[1]!=null && _nvp[1]!=this._undef
             ){
                this._Arguments[_nvp[0]] = unescapeStr(_nvp[1]);
            }
        }
    }
    return this._Arguments;
}

function setArgument(_name,_value){
  getArguments()[_name] = _value;
}
function getArgument(_name){
  return getArguments()[_name];
}

var Funcs_OnResize = new Array();
function resizeWindow() {
  for (var i = 0; i < Funcs_OnResize.length; i++) {
    Funcs_OnResize[i]();
  }
}
var PageLoaded = new Object();
function setPageLoaded() {
  PageLoaded.Loaded = '1';
}
function isPageLoaded() {
 if (isNull(PageLoaded.Loaded)) {
   return false;
 }
 return PageLoaded.Loaded == '1';
}

function isKeyboardNav(event) {
  if (event.keyCode==9 ||
      event.keyCode==13 || 
      event.keyCode==40 || 
      event.keyCode==38 || 
      event.keyCode==33 || 
      event.keyCode==34 || 
      event.keyCode==37 || 
      event.keyCode==39 || 
      event.keyCode==113 || 
      event.keyCode==27 
      ) {
    return true;   
  }
  return false;
}


function addOnClick(func){window.addEventListener ("click", func,true);}
function addOnScroll(func){document.addEventListener ("scroll", func,false); }
function addOnResize(func){Funcs_OnResize[Funcs_OnResize.length]=func; window.addEventListener ("resize", func,false);}
function addOnFocus(func){window.addEventListener ("focus", func,false);}
function addOnBlur(func){window.addEventListener ("blur", func,false);}
function addOnUnload(func){window.addEventListener ("unload", func,false);}
function addOnLoad(func){window.addEventListener ("load", func,true);}
function addOnMouseMove(func){document.body.addEventListener ("mousemove", func,true);}
function addOnMouseDown(func){document.body.addEventListener ("mousedown", func,true);}
function addOnKeyDown(func){window.addEventListener ("keydown", func,true);}
function addOnKeyUp(func){window.addEventListener ("keyup", func,true);}
function addOnKeyPress(func){document.body.addEventListener ("keypress", func,true);}
function addOnMouseUp(func){document.body.addEventListener ("mouseup", func,true);}

addOnLoad(setPageLoaded);

function getKeyName(keyCode) {
  switch(keyCode) {
    case 13:
      return "ENTER";
    case 27:
      return "ESC";
  }
  if (keyCode >= 32 && keyCode <= 126) {
    return String.fromCharCode(keyCode);
  }
  return keyCode;
}


var event=null;
function netscape_event_cap(e) {
  event = e;
  event.srcElement = event.target;
}
window.addEventListener ("click",netscape_event_cap,true);
window.addEventListener ("mouseup",netscape_event_cap,true);
window.addEventListener ("mousedown",netscape_event_cap,true);
window.addEventListener ("mouseout",netscape_event_cap,true);
window.addEventListener ("mousein",netscape_event_cap,true);


function getEventKeyCode(e) {
  if (typeof( e.keyCode ) == 'number') {
    return e.keyCode;
  } else if ( typeof( e.which ) == 'number' ) {
    return e.which;
  } else if( typeof( e.charCode ) == 'number'  ) {
    return e.charCode;
  }
}

function intersects(x1, y1, w1, h1, x2, y2, w2, h2) {
  return (x2 + w2) > x1 && (y2 + h2) > y1 && x2 < (x1 + w1) && y2 < (y1 + h1);
}

function isParent(parentElm, startElement) {
  var elm = startElement;
  while (!isNull(elm) && elm != parentElm)
    elm = elm.parentNode;
  if (!isNull(elm)) { return true; }
  return false;
} 

function isPopUp() {
  var arg = getArguments();
  if (arg['InPopUp'] == 1) {
    return true;
  } else {
   return false;
  }
}

function getObjPos(obj, relToElementId){ 
  var x = 0;
  var y = 0;
  var o = obj;
  while( !isNull(o) ){
    if(!isNull(o.id) && !isNull(relToElementId) && o.id != '' && o.id == relToElementId) {
      break;
    }
    var _x = 0;
    var _y = 0;
    var _x2 = 0; 
    var _y2 = 0;
    var br = false;
    if(!isNull(o.style)&&o.style.position=='fixed'){
      if(o.style.pixelTop){
        _x = o.style.pixelLeft;
        _y = o.style.pixelTop;
      }else if(o.style.top){
        _x = parseInt(o.style.left);
        _y = parseInt(o.style.top);
      }
      br = true;
    }else{
      _x = o.offsetLeft;
      _y = o.offsetTop;
      if(o.scrollLeft){_x2 = -o.scrollLeft;}
      if(o.scrollTop){_y2 = -o.scrollTop;}
    }

    if(_x)x+=_x;
    if(_x2)x+=_x2;
    if(_y)y+=_y;
    if(_y2)y+=_y2;

    if(br){
      break;
    }
    try {
      if(o==o.offsetParent){
        break;
      }
      o = o.offsetParent;
    } catch (e) { o = null; }
  }
  

  var pos = new Object();
  pos.x = x;
  pos.y = y;
  return pos;
}

function getObjScreenPos(obj){ // returns x,y of obj position on the screen
  var pos = getObjPos(obj);
  if(window.screenLeft)pos.x += window.screenLeft;
  if(window.screenTop )pos.y += window.screenTop;
  return pos;
}

// returnes x,y relative to obj position on the screen, but not off the screen
function getScreenPosRelToObj(_robj,_width,_height, _right, _bottom){
  var pos = getObjScreenPos(_robj);
  if(pos.x < window.screen.availLeft){ pos.x=window.screen.availLeft; }
  if(pos.y < window.screen.availTop ){ pos.y=window.screen.availTop; }

  if(_right==true){ pos.x = pos.x + _robj.offsetWidth; }
  if(_bottom==true){ pos.y = pos.y + _robj.offsetHeight; }

  var maxX = window.screen.availWidth-_width-10;
  if(pos.x>maxX)pos.x=maxX;
  var maxY = window.screen.availHeight-_height-30;
  if(pos.y>maxY)pos.y=maxY;

  return pos;
}

function verifyDate(_str, _alt){
  var str = trim(_str);
  if(str.length==0)return "";
  str = str.replace(/\D/g,"/");
  var dt = new Date(str);
  if(isNull(dt) || isNaN(dt.getTime()) || dt.getFullYear()>9999){
    return (isNull(_alt)?"":_alt);
  }
  var y = dt.getFullYear();
  if(y>=1900 && y<=1950){
    if(str.lastIndexOf(""+y)<0){
      dt.setFullYear(y+100);
    }
  }
  return dateToStr(dt);
}
function dateToStr(date){
    var str = "";
    if(isNull(date) || isNaN(date.getTime()) ){
      str = "N/A";
    }else{
      if((date.getMonth()+1)<10)str += "0";
      str += date.getMonth()+1;
      str += "/";
      if(date.getDate()<10)str += "0";
      str += date.getDate();
      str += "/";
      str += date.getFullYear();
    }
    return str;
}

function _dbg(o){
  window.DBGOBJ = o;
  window.open('/ta/js/_dbg.html?dbg=window.opener.DBGOBJ','_blank','',false);return;
}
function _dbgObj(_o){
  var sb = "";
  for(i in _o){sb = sb + i + " = " + _o[i] + "\n";}
  return sb;
}

// returnes true if there is a value enetered in form field

function getValue2(comp){
    if (comp==null || comp==this._undef) return null;
    if (comp.type == "checkbox") {
      if (comp.checked)
        return comp.value;
      return null;
    }
    return getValue(comp);
}

function getValue(comp){
    if (comp==null || comp==this._undef) return null;
    if (comp.getAttribute && comp.getAttribute('selectedValue')!=null) {
      return comp.getAttribute('selectedValue');
    }
    if ((comp.type == "text") ||
        (comp.type == "textarea") ||
        (comp.type == "file") ||
        (comp.type == "hidden") ) {
        return comp.value;
    } else if (comp.type == "select-multiple") {
        return comp.value;
    } else if (comp.type == "select-one") {
      var index = comp.selectedIndex;
      if( index >= 0){
        return isBlank(comp.options[index].value)?comp.options[index].text:comp.options[index].value;
      }
    } else if (comp.type == "checkbox") {
      if (comp.checked)
        return "1";
      return "0";
    } else if (comp.type == "radio" && comp.checked) {
      return comp.value;
    } else if (comp.length > 0) {
      for(var i=0; i< comp.length; i++){
        if (comp[i].type=="radio" && comp[i].checked) {
          return comp[i].value;
        }
      }
    }
    return "";
}


function getOptionText(list,key){
  for(j=0; j< list.length; j++){
    if(list[j].value == key){
      return list[j].text;
    }
  }
  return null;
}

function initComponent(component, value){
  if(isNull(component) || typeof(component)!="object"){return};
  if(component.type == "select-multiple"){
    return;
  }
  if(component.type == "select-one"){
    component.value=value;
    if(isBlank(component.value)){
      var index=-1;
      for(var i=0; i< component.options.length; i++){
        if(component.options[i].value == value){
          index=i;
          break;
        }
      }
      component.selectedIndex = index;
    }
  }else if(component.type == "checkbox"){
    component.checked = (value == component.value);
  }else {
    component.value = value;
  }
}


function clearComponent(comp){
  if( isNull(comp) || isBlank(comp.type) ){return;};
  if(comp.type=="button"){ return; }
  if(comp.type == "select-multiple"){
    for(var i = 0; i< comp.options.length; i++){
      comp.options[i].selected = false;
    }
  }else if(comp.type == "select-one"){
    comp.value='';
    if(!isBlank(comp.value)){ comp.selectedIndex = -1; }
  }else if(comp.type == "checkbox"){
    comp.checked = false;
  }else {
    comp.value = '';
  }
}

function checkSelectBoxes(prefix,_form,_startWith,_doCheck,_doOnClick) {
  var checkedVal = event.srcElement.checked;
  if(_doCheck==true || _doCheck==false)checkedVal=_doCheck;
  if(_form){
    if(_startWith){
      for (var i=0;i< _form.elements.length;i++) {
        var c = _form.elements[i];
        if (c.name.indexOf(prefix)==0) {
          c.checked = checkedVal;
          if (_doOnClick)c.onclick();
        }
      }
    }else{
      var elems = _form.elements[prefix];
      if(elems != null && elems.length){
        for (var i=0;i< elems.length;i++) {
          var c = elems[i];
          if (c.name==prefix){
            c.checked = checkedVal;
            if (_doOnClick)c.onclick();
          }
        }
      } else if (elems != null) {
        elems.checked = checkedVal;
        if (_doOnClick)elems.onclick();
      }
    }
  }else{
    var pref = new RegExp(prefix + ".+");
    for (var elem = 0; elem < TheForm.elements.length; elem++) {
      if (pref.test(TheForm.elements[elem].name)) {
        TheForm.elements[elem].checked = checkedVal;
        if (_doOnClick)TheForm.elements[elem].onclick();
      }
    }
  }
}

function collectSelectedBoxes(prefix, sep,_form) {
  var ret = new Array();

  if(_form){
    var elems = _form.elements[prefix];
    if(elems != null && elems.length){
      for (var i=0;i< elems.length;i++) {
        if(elems[i].checked){
          ret[ret.length] = elems[i].value;
        }
      }
    }else if(elems != null) {
      if(elems.checked){ret[ret.length] = elems.value};
    }
  }else{
    for (var i = 0; i< TheForm.elements.length; i++) {
      var nm = TheForm.elements[i].name;
      if (!isNull(nm) && nm.indexOf(prefix) == 0) {
        if (TheForm.elements[i].checked) {
          ret[ret.length] = TheForm.elements[i].name.substring(prefix.length);
        }
      }
    }
  }
  if (isNull(sep))
    sep = "|";

  return ret.join(sep);
}


function getFieldValues(fldName, sep) {
  var ret = new Array();
  var elems = TheForm.elements[fldName];
  if(elems != null && elems.length){
    for (var i=0;i< elems.length;i++) {
      var v = getValue2(elems[i]);
      if(!isBlank(v)){
        ret[ret.length] = v;
      }
    }
  }else if(elems != null) {
    var v = getValue2(elems);
    if(!isBlank(v)){
      ret[ret.length] = v;
    }
  }
  if (isNull(sep)){
    sep = "|";
  }
  return ret.join(sep);
}

function openWindow(url,target,w,h,bPop,bScroll,bResize) {
  var desc = new Object;
  desc.url = url;
  desc.width=800;
  if (!isNull(w))
    desc.width=w;
  desc.height=600;
  if (!isNull(h))
    desc.height=h;
  desc.scrollbars = bScroll;
  desc.resizable = bResize;
  if (!isNull(target)) {
    desc.target = target;
  } else {
    desc.target = "_blank";
  }
  if (isNull(bPop) || !bPop) {
    _showWindow(desc);
  } else {
    _showPopupWindow(desc);
  }
}

// allow only one
window._popupWindow = null;

function _closePopupWindow(){
  if(isNull(window._popupWindow))return;
  if(window._popupWindow.closed){
    window._popupWindow =null;
    return;
  }
  //only close if top window
  if(window._popupWindow){
    window._popupWindow.close();
  }
  window._popupWindow = null;
}


function _showPopupWindow(description){
  //_closePopupWindow();
  var _width= isNull(description.width)?100:description.width;
  var _height=isNull(description.height)?100:description.height;
  var _y = 0;
  var _x = 0;
  var winWidth = window.screen.width;
  var winHeight = window.screen.height;

  if(description.center==true){
    _x = (winWidth - _width)/2;
    _y = (winHeight - _height)/4;
  }else if(!isNull(description.relativeToObj)&& !isNull(description.relativeToObj.offsetParent)){
    var _rObj = description.relativeToObj;
    var pos = getScreenPosRelToObj(
      _rObj,_width,_height,
      description.relativeToObjRight==true?true:false,
      description.relativeToObjBottom==true?true:false);
    _x=pos.x;
    _y=pos.y;
  }else{
    _x = isNull(description.x) ? (winWidth - _width)/2 : description.x;
    _y = isNull(description.y) ? (winWidth - _height)/4 : description.y;
  }
  var _winProp = "";

  _winProp += "width=" + Math.floor(_width) + ",height=" + Math.floor(_height);
  _winProp += ",left=" + Math.floor(_x) + ",top=" + Math.floor(_y) ;

  if(description.scrollbars==true)_winProp += ",scrollbars";
  if(description.location  ==true)_winProp += ",location";
  if(description.status    ==true)_winProp += ",status";
  if(description.resizable ==true)_winProp += ",resizable";

  var _winUrl = description.url;
  var _param_count=0;
  var _param = "";
  for(i in description.param){
    _param_count++;
    _param += ( i + "=" + escapeStr(description.param[i]) + "&");
  }

  if(_param_count > 0){
    if (_winUrl.indexOf("?") == -1) {
      _winUrl += "?" + _param;
    } else {
      _winUrl += "&" + _param;
    }
  }

  var _target = description.target;
  return showPopUp({w:Math.floor(_width), h:Math.floor(_height), url:_winUrl, title:description.title, center:description.center});
}

function _showWindow(description){
  //_closePopupWindow();
  var _width= isNull(description.width)?100:description.width;
  var _height=isNull(description.height)?100:description.height;
  var _y = 0;
  var _x = 0;
  var winWidth = window.screen.width;
  var winHeight = window.screen.height;

  if(description.center==true){
    _x = (winWidth - _width)/2;
    _y = (winHeight - _height)/4;
  }else if(!isNull(description.relativeToObj)&& !isNull(description.relativeToObj.offsetParent)){
    var _rObj = description.relativeToObj;
    var pos = getScreenPosRelToObj(
      _rObj,_width,_height,
      description.relativeToObjRight==true?true:false,
      description.relativeToObjBottom==true?true:false);
    _x=pos.x;
    _y=pos.y;
  }else{
    _x = isNull(description.x) ? (winWidth - _width)/2 : description.x;
    _y = isNull(description.y) ? (winWidth - _height)/4 : description.y;
  }
  var _winProp = "";

  _winProp += "width=" + _width + ",height=" + _height;
  _winProp += ",left=" + _x + ",top=" + _y ;

  if(description.scrollbars==true)_winProp += ",scrollbars";
  if(description.location  ==true)_winProp += ",location";
  if(description.status    ==true)_winProp += ",status";
  if(description.resizable ==true)_winProp += ",resizable";

  var _winUrl = description.url;
  var _param_count=0;
  var _param = "";
  for(i in description.param){
    _param_count++;
    _param += ( i + "=" + escapeStr(description.param[i]) + "&");
  }
  if(_param_count>0){
    _winUrl += "?" + _param;
  }

  var _target = description.target;

  _target = _target;

  window._popupWindow1_1 = window.open(_winUrl, _target, _winProp);
  return window._popupWindow1_1;
}

function openEventNotificationWindow(eventDescription) {
  var screenX = (screen.width/2)-200;
  var screenY = (screen.height/2)-150;
  
  var notifWindow = window.open('','Event_Notification','status=0,scrolling=0,resizable=0,width=400,height=200, top='+screenY+', left='+screenX);
  
  notifWindow.document.write("<head><title>Calendar Event Notification</title></head>");
  notifWindow.document.write("<div align=center style='top:0px;overflow:auto;width:390px;height:160px;'>" + eventDescription);
  notifWindow.document.write("</div><input style='bottom:10px;left:45%;position:absolute;' type=button value=' OK ' name='notifOk' onClick='window.close()'>");
  notifWindow.focus();
}

/***********************************************************************>
 * Lookup Related Functions
 **********************************************************************/


function addSelectValue(_field,_value,_id){
  var _options = _field.options;
  var _l = _options.length;
  for(var i=0; i< _l; i++){
    if(_options[i].value==_id){
      _options[i].selected = true;
      return true;
    }
  }
  _options[_l] = new Option(_id,_value);
  _options[_l].selected = true;
}

function setFieldValue(_field, _value){
  if(isBlank(_value)) {
    _value = "";
  }
  if(isNull(_field))return;
  _field.value = _value;
}

function appendFieldValue(field, value){
  if(isBlank(value))return;
  if(isNull(field))return;
  if(!isBlank(field.value)){
    var values = field.value.split(/\s*,\s*/);
  for(var i=0; i< values.length; i++){
    if(values[i] == value)return;
  }
  values[values.length] = value;
  values.sort();
    field.value = values.join(", ");
  } else {
    field.value = value;
  }
}


function setNoteLinkId(_value) {
  var _oldVal = this.value;
  if (_value == -1) {
    setFieldValue(this,"");
  } else {
    setFieldValue(this,_value);
  }
  if(_oldVal!=_value){
    _onchange(this);
  }
  if (HM_IE) {
    this.form.all[this.lookupButton].src = (_value==-1?this.blankImg:this.existsImg);
  }else{
    var imgBtnName = ''+this.attributes['lookupButton'].value;
    var imgBtn = getDocElm(imgBtnName);
    if(imgBtn){
      var blankImgName = ''+this.attributes['blankImg'].value;
      var existsImgName = ''+this.attributes['existsImg'].value;
      imgBtn.src = (_value==-1?blankImgName:existsImgName);
    }
  }
}

function genRandom(len) {
 var ret = '';
 for (var i = 0; i < len; i++) {ret += parseInt(Math.random()*10);}
 return ret;
}

function addOnChangeToForm(_form) {
  for (var i = 0; i < _form.elements.length; i++) {
    elm = _form.elements[i];
    elm.setAttribute('changeMade','0');
    if (elm.onchange) {
      elm.oldOnChange = elm.onchange;
      elm.onchange = new Function("this.setAttribute('changeMade','1');return this.oldOnChange();");
    } else {
      elm.onchange = new Function("this.setAttribute('changeMade','1');");
    }
  }
}

function didFormValuesChange(_form) {
  for (var i = 0; i < _form.elements.length; i++) {
    elm = _form.elements[i];
    if (isBlank(elm.id) && isBlank(elm.name)){
      continue;
    }
    if (elm.getAttribute('changeMade')=='1') {
      if (isNull(elm.getAttribute('chkChng')) || elm.getAttribute('chkChng')!=0) {
        return true;
      }
    }
  }
  return false;
}

function isUserLoggedOut() {
  var actionWindow = window;
  while(true){
    if(actionWindow.opener!=this._undef && actionWindow.opener!=null && actionWindow.opener!=actionWindow){
     actionWindow = actionWindow.opener;
     continue;
    }
    if(actionWindow.parent!=this._undef && actionWindow.parent!=null && actionWindow.parent!=actionWindow){
     actionWindow = actionWindow.parent;
     continue;
    }
    break;
  }
  if (!isNull(actionWindow)) {
    if (actionWindow.UserLogout == 1) {
      return true;
    }
  }
  return false;
}

function _getAlertChangesText(){
  var ___div = "\n_______________________________________________________           ";
  var ___pre = "";
  var ___post = "";
  return  ___pre + ___div + "\n\n\n         C h a n g e s    h a v e    N O T    b e e n    s a v e d   \n" + ___div + ___post;
}

var alertText = _getAlertChangesText();



function getAlertChangesText(addWarn){
  if (addWarn) {
    return "Are you sure you want to navigate away from this page?\n\n" + 
           alertText + "\n\nPress OK to continue, or Cancel to stay on the current page.";
  }
  return alertText;
}

function fn_top_menu_getFirstMenuNum(){
  return 1;
}
function fn_top_menu_getLastMenuNum(){
  var _menuWindow = window.parent.frames.ADMIN_MENU;
  var i=-1;
  for(var iMenu=1; iMenu<50; iMenu++){
    var el = _menuWindow.getDocElm('TopMenu_HM_Menu' + iMenu);
    if(el==null)break;
    i = iMenu;
  }
  return i;
}
function fn_top_menu_popDownAll(m){
  var _menuWindow = window.parent.frames.ADMIN_MENU;
  for(var iMenu=1; iMenu<50; iMenu++){
    var el = _menuWindow.getDocElm('TopMenu_HM_Menu' + iMenu);
    if(el==null)break;
    if(el==m)continue;
    _menuWindow.popDown('HM_Menu'+iMenu,el);
  }
}
function fn_top_menu_Cancel(){
  var _menuWindow = window.parent.frames.ADMIN_MENU;
  fn_top_menu_popDownAll(null);
  _menuWindow.hideMenuFrame();
}
function fn_top_menu_item_onkeydown(m,ev){
   if(!m)m = this;
   if(!ev)ev = event;

  if(ev.keyCode==13 || ev.keyCode==40){
    fn_top_menu_popDownAll(null);
    var cMenu = parent.frames.ADMIN_MENU_BODY.HM_CurrentMenu;
    cMenu.focus();
    cMenu.firstChild.onmouseover();
  }else if(ev.keyCode>=65 && ev.keyCode<=90){
    fn_top_menu_popDownAll(null);
    var _c = String.fromCharCode(ev.keyCode);
    var cMenu = parent.frames.ADMIN_MENU_BODY.HM_CurrentMenu;
    cMenu.focus();
    fn_current_menu_mnemonic(cMenu,_c);
  }else if(ev.keyCode==37){
    var menuNum = parseInt(m.menuNum)-1;
    fn_selectNMenu(ev,menuNum);
  }else if(ev.keyCode==39){
    var menuNum = parseInt(m.menuNum)+1;
    fn_selectNMenu(ev,menuNum);
  }else if(ev.keyCode>=49 && ev.keyCode<=57){
    var _i = ev.keyCode-49;
    fn_selectNMenu(ev,_i+1);
  }else if(ev.keyCode==27){
    fn_top_menu_Cancel();
  }else{
  }
}
function fn_current_menu_mnemonic(m,_c){
  var _loop = true;
  var nextItem = m.currentItem && m.currentItem.nextSibling ? m.currentItem.nextSibling : m.firstChild;
  while(nextItem!=null){
    if(nextItem.mnemonic==_c){
      nextItem.onmouseover();
      return;
    }
    nextItem = nextItem.nextSibling;
    if(nextItem==null && _loop){
      _loop = false;
      nextItem = m.firstChild;
    }
  }
}
function fn_top_onkeydown(ev){

  if(!ev)ev = event;
  if(ev.altKey){
    if(ev.keyCode>=49 && ev.keyCode<=57){
      var _i = ev.keyCode-49;
      fn_selectNMenu(ev,_i+1);
    }else if(ev.keyCode>=65 && ev.keyCode<=90){
      var _c = String.fromCharCode(ev.keyCode);
      var _win_ADMIN_MENU = parent.frames.ADMIN_MENU;
      for(var iMenu=1; iMenu<50; iMenu++){
        var el = _win_ADMIN_MENU.getDocElm('TopMenu_HM_Menu' + iMenu);
        if(el==null)break;
        if(el.mnemonic==_c){
          fn_top_menu_popDownAll(el);
          _win_ADMIN_MENU.popUp('HM_Menu'+iMenu,ev, 1);
          el.focus();
          ev.cancelBubble=true;
          break;
        }
      }
    }
  }
}
function fn_selectNextMenu(e,_m){
  var menuNum = _m.id.substring(7).split('_')[0];
  menuNum = parseInt(menuNum)+1;
  fn_selectNMenu(e,menuNum);
}
function fn_selectPrevMenu(e,_m){
  var menuNum = _m.id.substring(7).split('_')[0];
  menuNum = parseInt(menuNum)-1;
  fn_selectNMenu(e,menuNum);
}
function fn_selectNMenu(ev,menuNum){
  var _win_ADMIN_MENU = parent.frames.ADMIN_MENU;
  var el=_win_ADMIN_MENU.getDocElm('TopMenu_HM_Menu' + menuNum);
  if(el==null){
    if(menuNum<_win_ADMIN_MENU.fn_top_menu_getFirstMenuNum())menuNum=_win_ADMIN_MENU.fn_top_menu_getLastMenuNum();
    if(menuNum>_win_ADMIN_MENU.fn_top_menu_getLastMenuNum())menuNum=_win_ADMIN_MENU.fn_top_menu_getFirstMenuNum();
    el=_win_ADMIN_MENU.getDocElm('TopMenu_HM_Menu'+menuNum);
  }
  if(el!=null){
    _win_ADMIN_MENU.fn_top_menu_popDownAll(null);
    _win_ADMIN_MENU.popUp('HM_Menu'+(menuNum),ev,1);
    el.focus();
  }
}
function setFocusToMainWindow(){
  var f = parent.frames.ADMIN_CENTER;
  if(f && f.document && f.document.body && f==window.self){
    if(f.document.focus)f.document.focus();
    else if(f.document.body.focus)f.document.body.focus();
  }
}
if(parent.frames.ADMIN_CENTER){
  document.onkeydown=fn_top_onkeydown;
  //addOnLoad(setFocusToMainWindow);
}

////AJAX

function getXmlHttp(){
 var xmlhttp=false;
 /*@cc_on @*/
 /*@if (@_jscript_version >= 5)
  try {xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
  } catch (e) {
   try {
    xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
   } catch (E) {
    xmlhttp = false;
   }
  }
 @end @*/
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 	try {
 		xmlhttp = new XMLHttpRequest();
 	} catch (e) {
 		xmlhttp=false;
 	}
 }
 if (!xmlhttp && window.createRequest) {
 	try {
 		xmlhttp = window.createRequest();
 	} catch (e) {
 		xmlhttp=false;
 	}
 }
 return xmlhttp;
}

function buildPOST(frm, excludeEmpty) {
  var f = frm?frm:document.forms['TheForm'];
  if(f==null)return '';
  var qs = '';
  for (i=0;i< f.elements.length;i++) {
	var elem = f.elements[i];
    if (elem.name!='') {
      if ((!elem.value || elem.value=='') && excludeEmpty) {
        continue;
      }
	  if (elem.type == "checkbox" && elem.checked==false) {
      continue;
	  }
	  if (elem.type == "radio" && elem.checked==false) {
      continue;
	  }
      var name = escapeStr(elem.name);
      qs+=(qs=='')?'':'&';
      qs+= name+'='+escapeStr(elem.value);
    }
   }
   return qs;
}


function doAjaxAction(p){
 var xmlHttp = getXmlHttp();
 var r=(new Date()).getTime()*Math.random();
 var frm = document.forms['TheForm'];
 var url = p.url ? p.url : frm.action;
 url += ((url.charAt(url.length-1)=='?'||url.charAt(url.length-1)=='&')?'':(url.indexOf('?')>-1)?'&':'?');
 url += '@AJAX='+p.action;
 xmlHttp.open('POST',url,true);
 if (!isNull(p.callback)) {
   xmlHttp.onreadystatechange=p.callback;
 }
 window.currentXmlHttp = xmlHttp;
 var postData = buildPOST(frm);
 xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
 xmlHttp.send(postData);
}

function disableEvent(e,_type){
  if (!e) var e = window.event;
  if(_type && e.type!=_type){
    return true;
  }
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	if (e.preventDefault) e.preventDefault();
  return false;
}

function setEnabledField(_field,_b){
  if(_field){
    _field.disabled=!_b;
  }
}
function setEnabledRadioField(_field,_value,_b){
  if(_field){
    for(var i=0; i< _field.length; i++){
      if(_field[i].value==_value){
        if(!_b)_field[i].checked=_b;
        _field[i].disabled=!_b;
      }
    }
  }
}

function getTopFrame(w){
  if(!w)w = self;
  while(true){
    if(w.parent==null)return w;
    if(w.parent==w)return w;
    w = w.parent;
  }
}
function getFrameByName(_name,_w){
  var w = (_w)?_w:self;
  while(true){
    var _result = _getFrameByName(_name,w);
    if(_result!=null){
       return _result;
     }
    if(w.parent==null || w.parent==w){
      return null;
    }
    w = w.parent;
  }
}
function _getFrameByName(_name,w){
  if(!w)w = self;
  if(w.name==_name){
    return w;
  }
  for(var i=0; i< w.frames.length; i++){
    var _w  = w.frames[i];
    if(_w.name==_name){
      return _w;
    }
  }
  for(var i=0; i< w.frames.length; i++){
    var _w  = w.frames[i];
    if(_w==w)continue;
    _w = _getFrameByName(_name,_w);
    if(_w){
      return _w;
    }
  }
  return null;
}


function setCookie( name, value, expires, path, domain, secure )  {
  var today = new Date();
  today.setTime( today.getTime() );
  if ( expires ) {
    expires = expires * 1000 * 60 * 60 * 24;
  }
  var expires_date = new Date( today.getTime() + (expires) );

  document.cookie = name + "=" +escapeStr( value ) +
  ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
  ( ( path ) ? ";path=" + path : "" ) +
  ( ( domain ) ? ";domain=" + domain : "" ) +
  ( ( secure ) ? ";secure" : "" );
}

function isInputEvent(e){
  if(e.keyCode<32) return false;
  if(e.keyCode>126) return false;
  if(e.keyCode>=33 && e.keyCode<=40) return false;
  if(e.altKey) return false;
  if(e.ctrlKey && e.keyCode!=86)return false;
  return true;
}

var numJsToLoad = 0;
function includeJavaScript(scriptFilename) {
  numJsToLoad++;
  var js = document.createElement('script');
  if (js.addEventListener) {
    js.addEventListener("load", function() { numJsToLoad--; }, false);
  } else {
    js.onreadystatechange = function() {
      if (this.readyState=="loaded"||this.readyState=="complete") {numJsToLoad--};
    }
  }
  js.setAttribute('language', 'javascript');
  js.setAttribute('type', 'text/javascript');
  js.setAttribute('src', scriptFilename);
  document.getElementsByTagName('body')[0].appendChild(js);
  
  return false;
}

function includeCSS(cssFilename) {
  var css = document.createElement('link');
  css.setAttribute('rel', 'stylesheet');
  css.setAttribute('type', 'text/css');
  css.setAttribute('href', cssFilename);
  document.body.appendChild(css);
  return false;
}

////////////////// TimeZone //////////////////////////////
function TimezoneDisplay(shortName, javaName, longName, timezoneOffset, dstOffset, displayName) {
  this.shortName = shortName;
  this.javaName = javaName;
  this.javaNameEnc = escapeStr(javaName);
  this.longName = longName;
  this.timezoneOffset = timezoneOffset;
  this.dstOffset = dstOffset;
  this.displayName = displayName;
}

var showedTimeZoneDisplayWarning = false;
var browserTimeZoneDisplay = null;
function getBrowserTimezoneDisplay() {
  if(browserTimeZoneDisplay != null) {
    return browserTimeZoneDisplay;
  }
  var rightNow = new Date();
  var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
  var jan1TimeZoneOffset = jan1.getTimezoneOffset()*60000;
  var jul1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
  var temp = jan1.toGMTString();
  var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
  var temp = jul1.toGMTString();
  var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
  var diffStdTime = (jan1 - date3);
  var diffDaylightTime = (jul1 - date4);
  
  var jul1DSTOffset = diffDaylightTime - diffStdTime;

  var tz =  timeZonesAvailable.getTZByOffsets(jan1TimeZoneOffset, jul1DSTOffset);
  if(tz != null) {
    if(tz.hasDSTMatch) {
      browserTimeZoneDisplay = tz;
      return tz;
    }
  } else {
    return timeZonesAvailable.getTZByShortName('EST');
  }
   
  var usingStr = '';
  usingStr = '\n\nDefaulting to '+ tz.displayName +'.';
  
  if(!showedTimeZoneDisplayWarning) {
    showedTimeZoneDisplayWarning = true;
    alert('The timezone of your computer is not supported.  Please verify your system time zone and daylight savings settings.'+usingStr);
  }
  
  browserTimeZoneDisplay = tz;
  return tz;
}

function TimeZonesAvailable() {
  
  this.timeZones = new Array();
  this.tzNames = new Array();
  this.tzOffsets = new Array();
  
  this.timeZones.push( new TimezoneDisplay('EST', 'US/Eastern', 'Eastern Time Zone', 18000000, 3600000, 'US/Eastern') );
  this.tzNames.push('EST');
  this.tzOffsets.push('18000000-3600000');
  
  this.timeZones.push( new TimezoneDisplay('America/Indianapolis', 'US/East-Indiana', 'East Indiana Time Zone', 18000000, 0, 'US/East-Indiana') );
  this.tzNames.push('America/Indianapolis');
  this.tzOffsets.push('18000000-0');

  this.timeZones.push( new TimezoneDisplay('CST', 'US/Central', 'Central Time Zone', 21600000, 3600000, 'US/Central') );
  this.tzNames.push('CST');
  this.tzOffsets.push('21600000-3600000');

  this.timeZones.push(  new TimezoneDisplay('America/Phoenix', 'US/Arizona', ' Arizona Time Zone', 25200000, 0, 'US/Arizona') );
  this.tzNames.push('America/Phoenix');
  this.tzOffsets.push('25200000-0');

  this.timeZones.push( new TimezoneDisplay('MST', 'US/Mountain', 'Mountain Time Zone', 25200000, 3600000, 'US/Mountain') );
  this.tzNames.push('MST');
  this.tzOffsets.push('25200000-3600000');

  this.timeZones.push( new TimezoneDisplay('PST', 'US/Pacific', 'Pacific Time Zone', 28800000, 3600000, 'US/Pacific') );
  this.tzNames.push('PST');
  this.tzOffsets.push('28800000-3600000');

  this.timeZones.push( new TimezoneDisplay('UTC', 'UTC', 'Universal Time Zone', 0, 0, 'UTC') );
  this.tzNames.push('UTC');
  this.tzOffsets.push('0-0');

  this.timeZones.push( new TimezoneDisplay('AST', 'US/Alaska', 'Alaska Time Zone', 32400000, 3600000, 'US/Alaska') );
  this.tzNames.push('AST');
  this.tzOffsets.push('32400000-3600000');

  this.timeZones.push( new TimezoneDisplay('HST', 'US/Hawaii', 'Hawaii Time Zone', 32400000, 0, 'US/Hawaii') );
  this.tzNames.push('HST');
  this.tzOffsets.push('32400000-0');

  // this has the same offsets as HST
  this.timeZones.push( new TimezoneDisplay('America/Adak', 'America/Adak', 'Alaska Aleutian Time Zone', 36000000, 0, 'America/Adak') );
  this.tzNames.push('America/Adak');
  this.tzOffsets.push('36000000-0');

  this.timeZones.push( new TimezoneDisplay('America/Puerto_Rico', 'America/Puerto_Rico', 'Puerto Rico & Virgin Islands Time Zone', 14400000, 0, 'America/Puerto Rico') );
  this.tzNames.push('America/Puerto_Rico');
  this.tzOffsets.push('14400000-0');
}

TimeZonesAvailable.prototype.getTZByShortName = function (shortName) {
  for(var i=0; i< this.tzNames.length; i++) {
    var el = this.tzNames[i];
    if(el == shortName) {
      var tz = this.timeZones[i];
      return tz;
    }
  }
  
  return null;

}

TimeZonesAvailable.prototype.getTZByOffsets = function (jan1TimeZoneOffset, jul1DSTOffset) {
  for(var i=0; i< this.tzOffsets.length; i++) {
    var el = this.tzOffsets[i];
    if(el == jan1TimeZoneOffset + '-' + jul1DSTOffset) {
      var tz = this.timeZones[i];
      tz.hasDSTMatch = true;
      return tz;
    }
  }
  
  for(var i=0; i< this.timeZones.length; i++) {
    var el = this.timeZones[i];
    if(el.timezoneOffset == jan1TimeZoneOffset) {
      el.hasDSTMatch = false;
      return el;
    }
  }
  
  return null;
}

TimeZonesAvailable.prototype.getDefault = function () {
  return this.timeZones[0];
}

var timeZonesAvailable = new TimeZonesAvailable();




function DEBUG(v){
  var DW = getDocElm('DEBUG');
  if(!DW){
    return;
  }
  DW.parentElement.style.display='block';
  var t = DW.innerText;
  while(t.length + v.length > 10000){
    var i = t.indexOf('\n');
    if(i==-1){
      t = '';
    }else{
      t = t.substring(i+1);
    }
  }
  t = t.length==0 ? ' - '+ v : t + '\n - '+ v;
  DW.innerText = t;
  DW.scrollTop = 999999;
}

function roundValue(v,numDec){
  if(v==0 || v==null){
    return v;
  }
  if(isNaN(v) || isNaN(numDec)){
    return v;
  }
  if(numDec>10 || numDec<-10){
    return v;
  }
  var prec = numDec==0 ? 1 : Math.pow(10,numDec);
  v = v*prec;
  v = Math.round(v);
  v = v/prec;
  return v;
}


function getValueAsInt(comp,defVal){
  var v = getValue(comp);
  if(isNull(v))return defVal;
  var i = parseInt(v);
  if(isNaN(i))return defVal;
  return i;
}


function onLinkClick(e,l){
  var s = '';
  for(i in e){
    if(i=='boundElements')continue;
    if(i=='srcElement')continue;
    if(e[i]){
      v = ''+e[i];
      s += '@e.' + i + '=' + v + '&';
    }
  }
  l.href = l.href + s;
  return false;
}

function flipVisibility(box, elName, val, negate) {
  var el = getDocElm(elName);
  if (el == null || box == null) return;
  var ok = false;
  if (val == null) {
    ok = box.checked;
  } else if (val instanceof Array) {
    for (var i = 0; i < val.length; i++) {
      if (box.value == val[i]) {
        ok = true;
        break;
      }
    }
  } else {
    ok = box.value == val;
  }
  if (negate) ok = !ok;
  var d = ok ? 'inline' : 'none';
  el.style.display = d;
}
