// If type is "width" returns browser width else returns browser height
function getSize(type) {
  var browserWidth = 0;
  var browserHeight = 0;
  if(typeof(window.innerWidth) == "number" ) {
    // All browsers except MSIE
    browserWidth  = window.innerWidth;
    browserHeight = window.innerHeight;
  } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    // MSIE 6+ in 'standards compliant mode'
    browserWidth  = document.documentElement.clientWidth;
    browserHeight = document.documentElement.clientHeight;
  } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    // MSIE 4 compatible - old browsers
    browserWidth  = document.body.clientWidth;
    browserHeight = document.body.clientHeight;
  }
  // Return value according type
  if(type == "width") return browserWidth;
  else return browserHeight;
}

// Returns browser width via getSize()
function getBrowserWidth() {
  return getSize("width");
}

// Returns browser width via getSize()
function getBrowserHeight() {
  return getSize("height");
}

// Count and return top right corner of element - left
function getElementPositionLeft(id) {
  var e = document.getElementById(id);
  var eWidth = removePx(document.getElementById(id).style.width);
  return (Math.round((getBrowserWidth() - eWidth) / 2));
}

// Count and return top right corner of element - top
function getElementPositionTop(id) {
  var e = document.getElementById(id);
  var eHeight = removePx(document.getElementById(id).style.height);
  return Math.round((getBrowserHeight() - eHeight) / 2);
}

// Set element position - left
function setElementPositionLeft(id) {
  checkAbsolutePosition(id);
  document.getElementById(id).style.left = getElementPositionLeft(id) + "px";
  return;
}

// Set element position - top
function setElementPositionTop(id) {
  checkAbsolutePosition(id);
  document.getElementById(id).style.top = getElementPositionTop(id) + "px";
  return;
}

// Set element position
function setElementPosition(id) {
  setElementPositionLeft(id);
  setElementPositionTop(id);
  setZIndex(id);
  setVisibility(id);
  return;
}

/* ************************************************************************** */
/*                            Support functions                               */
/* ************************************************************************** */

// Check absolute position setting
function checkAbsolutePosition(id) {
  if(document.getElementById(id).style.position != "absolute")
    document.getElementById(id).style.position = "absolute";
  return;
}

// Remove string 'px' from CSS style
function removePx(text) {
  return text.replace(/px/, "");
}

// Set z-index - great number for its layer
function setZIndex(id) {
  document.getElementById(id).style.zIndex = 1000;
  return;
}

// Set visibility
function setVisibility(id) {
  document.getElementById(id).style.display = "inline";
  return;
}

// Hide element
function hideElement(id) {
  document.getElementById(id).style.display = "none";
  return;
}
