﻿
function trimString(inputString) {
  return inputString.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function isVariableDefined(variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function isIEBrowser() {
  var browser = navigator.appName;
  if (browser.indexOf("Internet Explorer") > 0) {
    return true;
  }
  return false;
}

/**
 * gets the top (client) position of an element
 * - need to do this recursively because the
 * offsetTop is relative to the parent
 * adding all these up will get us our screen top
 *
 * @param whichElement the HTML DOM element
 * @return the top position of the element
 */
function getElementTopPosition(whichElement) {
  var workingElement=whichElement;
  var iPos=0;
  while (workingElement!=null) {
    iPos += workingElement.offsetTop;
    workingElement=workingElement.offsetParent;
  }
  return iPos;
}

/**
 * In the same vein as getElementTopPosition,
 * gets the left (client) position of an element
 *
 * @param whichElement the HTML DOM element
 * @return the left position of the element
 */
function getElementLeftPosition(whichElement) {
  var workingElement=whichElement;
  var iPos=0;
  while (workingElement!=null) {
    iPos += workingElement.offsetLeft;
    workingElement=workingElement.offsetParent;
  }
  return iPos;
}

/**
 * Sets an HTML DOM element to the same height as
 * another one
 *
 * @param sourceElement the HTML DOM element to get the height from
 * @param targetElement the HTML DOM element to set the height for
 */
function setElementToHeight(sourceElement, targetElement) {
  targetElement.style.height=sourceElement.clientHeight + "px";
}

/**
 * Sets an HTML DOM element to the same width as
 * another one
 *
 * @param sourceElement the HTML DOM element to get the width from
 * @param targetElement the HTML DOM element to set the width for
 */
function setElementToWidth(sourceElement, targetElement) {
  targetElement.style.width=sourceElement.clientWidth + "px";
}

/**
 * Cross browser method to get a HTML DOM element by
 * it's name
 */
function getElementByName(elementName) {
  var retElement=null;
  if (document.getElementById) {
    retElement=document.getElementById(elementName);
  } else {
    if (document.layers) {
      retElement=eval("document." + elementname);
    } else {
      retElement=eval("document.all." + elementname);
    }
  }
  return retElement;
}

function getBrowserHeight() {
 if (typeof window.innerWidth != 'undefined')
 {
   return window.innerHeight;
 } else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
    return document.documentElement.clientHeight;
 } else {
    return document.getElementsByTagName('body')[0].clientHeight;
 }
}

function getBrowserWidth() {
 if (typeof window.innerWidth != 'undefined')
 {
   return window.innerWidth;
 } else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
    return document.documentElement.clientWidth;
 } else {
    return document.getElementsByTagName('body')[0].clientWidth;
 }
}

