﻿function ReturnWindowHeight() {
  var theHeight = 768;
  if (typeof (window.innerHeight) == 'number') {
    theHeight = window.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight) {
    theHeight = document.documentElement.clientHeight;
  }
  else if (document.body && document.body.clientHeight) {
    theHeight = document.body.clientHeight;
  }
  else {
    theHeight = 768;
  }
  return theHeight;
}

function ReturnWindowWidth() {
  var theWidth = 1024;
  if (typeof (window.innerWidth) == 'number') {
    theWidth = window.innerWidth;
  }
  else if (document.documentElement && document.documentElement.clientWidth) {
    theWidth = document.documentElement.clientWidth;
  }
  else if (document.body && document.body.clientWidth) {
    theWidth = document.body.clientWidth;
  }
  else {
    theWidth = 1024;
  }
  return theWidth;
}

function GetScrollX() {
  var scrollX = 0;
  if (document.all) {
    if (!document.documentElement.scrollLeft)
      scrollX = document.body.scrollLeft;
    else
      scrollX = document.documentElement.scrollLeft;
  }
  else {
    scrollX = window.pageXOffset;
  }
  return scrollX;
}

function GetScrollY() {
  var scrollY = 0;
  if (document.all) {
    if (!document.documentElement.scrollTop)
      scrollY = document.body.scrollTop;
    else
      scrollY = document.documentElement.scrollTop;
  }
  else {
    scrollY = window.pageYOffset;
  }
  return scrollY;
}

function ReturnRightPosition(itemWidth) {
  var maxRight = ReturnWindowWidth();
  var rightSide = maxRight;
  var theRight = posx;
  if ((theRight + (itemWidth + 5)) > rightSide) {
    theRight = rightSide - (itemWidth + 5);
  }
  else {
    theRight = theRight + 5;
  }
  return theRight;
}

function ReturnTopPosition(itemHeight) {
  var theTop = posy;
  var scrollY = GetScrollY();
  var windowHeight = ReturnWindowHeight();
  var bottom = windowHeight;
  if (scrollY > 0)
    bottom = windowHeight + scrollY;

  theTop += scrollY;
  if ((theTop + (itemHeight + 5)) > bottom) {
    theTop = theTop - (itemHeight + 10);
  }
  else {
    theTop = theTop + 5;
  }
  if (theTop < 0) {
    theTop = 5;
  }
  return theTop;
}

function ImposeMaxLength(maxLength, control) {
  var value = control.value;
  if (value.length > maxLength) {
    obj.value = value.substring(0, maxLength);
  }
}

function doBeforePaste() {
  event.returnValue = false;
}

function doPaste(maxLength, control) {
  value = control.value;
  if (maxLength) {
    event.returnValue = false;
    var oTR = control.document.selection.createRange();
    var iInsertLength = maxLength - value.length + oTR.text.length;
    var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
    oTR.text = sData;
  }
}
