function getInnerHeight() {
  var w=600;
  if (navigator.userAgent.toLowerCase().indexOf('msie')>0) {
    w=document.body.clientHeight;
  } else {
    w=window.innerHeight;
  }
  return w;
}

//get visible size of browser
function getInnerWidth() {
  var w=600;
  if (navigator.userAgent.toLowerCase().indexOf('msie')>0) {
    w=document.body.clientWidth;
  } else {
    // why minus 10 ?
    //w=window.innerWidth - 10;
    w=window.innerWidth - 0;
  }
  return w;
}

function getRelativeLeft(objectId, pnodeId) {
  return getAbsoluteLeft(objectId) - getAbsoluteLeft(pnodeId);
}

function getRelativeTop(objectId, pnodeId) {
  return getAbsoluteTop(objectId) - getAbsoluteTop(pnodeId);
}

function getAbsoluteLeft(objectId) {
  // Get an object left position from the upper left viewport corner
  // Tested with relative and nested objects
  var o = document.getElementById(objectId)
  var oLeft = o.offsetLeft            // Get left position from the parent object
  while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
    var oParent = o.offsetParent    // Get parent object reference
//alert(o.id+':'+oParent.id+':'+oParent.offsetLeft);
    oLeft += oParent.offsetLeft // Add parent left position
    o = oParent
  }
  // Return left postion
  return oLeft
}

function getAbsoluteTop(objectId) {
  // Get an object top position from the upper left viewport corner
  // Tested with relative and nested objects
  var o = document.getElementById(objectId)
  var oTop = o.offsetTop            // Get top position from the parent object
  while(o.offsetParent!=null) { // Parse the parent hierarchy up to the document element
    var oParent = o.offsetParent  // Get parent object reference
//alert(o.id+':'+oParent.id+':'+oParent.offsetTop);
    oTop += oParent.offsetTop // Add parent top position
    o = oParent
  }
  // Return top position
  return oTop
}

function getTagID(input, tag, delim) {
  var idx = input.indexOf(delim);
  if (idx < 0) return input;
  var name = input.substring(idx+1);
  return tag + delim + name;
}

function getTableID(input) {
  return getTagID(input, 'tbl', '_');
}

function getBlockID(input) {
  return getTagID(input, 'blk', '_');
}

function closeAllErrmsg() {
  var divs = document.body.getElementsByTagName('div');
  for (var i=divs.length-1;i>=0;i--) {
    if (divs[i].id.indexOf('msg_') == 0) {
      var msg = divs[i];
      document.body.removeChild(msg);
    }
  }
}

function getMouseY(event) {
  if (event.pageY) return event.pageY;
  return event.clientY + document.body.scrollTop - document.body.clientTop;
}

function getMouseX(event) {
  if (event.pageX) return event.pageX;
  return event.clientX + document.body.scrollLeft - document.body.clientLeft;
}

function setCursor(style) {
  document.body.style.cursor=style;
}

function getPageHeight() {
  var agent = navigator.userAgent.toLowerCase();
  var is_ie = (agent.indexOf('msie') != -1);
  var pageHeight = is_ie ? window.document.body.clientHeight : window.innerHeight;
  return pageHeight;
}

function getPageWidth() {
  var agent = navigator.userAgent.toLowerCase();
  var is_ie = (agent.indexOf('msie') != -1);
  var pageWidth = is_ie ? window.document.body.clientWidth : window.innerWidth;
  return pageWidth;
}

function resizeDiv() {
  // client detection and page height/width
  var agent = navigator.userAgent.toLowerCase();
  var is_ie = (agent.indexOf('msie') != -1);
  var is_mac = (agent.indexOf('macintosh') != -1);
  var pageWidth = is_ie ? window.document.body.clientWidth : window.innerWidth;
  var pageHeight = is_ie ? window.document.body.clientHeight : window.innerHeight;

  // fix 1-way scrollbars in Firefox
  if (!is_ie) {
    var scrollbarSize = is_mac ? 15 : 19;
    if (pageWidth < minWidth) pageHeight -= scrollbarSize;
    if (pageHeight < minHeight) pageWidth -= scrollbarSize;
  }
  var minWidth = 500;
  var minHeight = 300;
  if (pageWidth >= minWidth && pageHeight >= minHeight) {
    document.body.style.overflow = 'hidden';
  } else {
    document.body.style.overflow = 'auto';
  }

  // resize the DIV
  var TX_div = document.getElementById("divBody");
  if (TX_div != null) {
    TX_div.style.width = pageWidth;
    TX_div.style.height = pageHeight;
  }
}

function setHeight(ele, height) {
  if (isFireFox()) {
    var padding = getStyle(ele, "padding");
    var padding_top = getStyle(ele, "padding-top");
    var padding_bottom = getStyle(ele, "padding-bottom");
    if (isNaN(parseInt(padding))) {
      padding = 0;
    }
    if (isNaN(parseInt(padding_top))) {
      padding_top = 0;
    }
    if (isNaN(parseInt(padding_bottom))) {
      padding_bottom = 0;
    }
    var total = parseInt(padding) + parseInt(padding_top) + parseInt(padding_bottom);
    ele.style['height'] = parseInt(height) - total;
  } else {
    ele.style['height'] = height;
  }
}

function setWidth(ele, width) {
  if (isFireFox()) {
    var padding = getStyle(ele, "padding");
    var padding_left = getStyle(ele, "padding-left");
    var padding_right = getStyle(ele, "padding-right");
    if (isNaN(parseInt(padding))) {
      padding = 0;
    }
    if (isNaN(parseInt(padding_left))) {
      padding_left = 0;
    }
    if (isNaN(parseInt(padding_right))) {
      padding_right = 0;
    }
    var total = parseInt(padding) + parseInt(padding_left) + parseInt(padding_right);
    ele.style['width'] = parseInt(width) - total;
  } else {
    ele.style['width'] = width;
  }
}

