/**
 * my_utils.js - Misc. JavaScript utility functions
 *
 * @version 3 Mar 2005
 * @author  Joseph Oster, wingo.com
 */

/* GENERIC FUNCTIONS */
String.prototype.trim = function () {
  return this.replace(/^\s+/g, '').replace(/\s+$/g, '');
  }

function my_ShowHide(divName, showIt) {
  document.getElementById(divName).style.visibility = (showIt) ? "visible" : "hidden";
  }

function my_ShowNone(divName, showIt, showStyle) {
  if (!showStyle) showStyle = "";
  var divObj = document.getElementById(divName);
  if (divObj) divObj.style.display = (showIt) ? showStyle : "none";
  }

function my_parseQuery(queryString) {
  // converts name/value pairs in 'queryString' to JS object
  var stQuery = (queryString) ? queryString : location.search; // use 'location.search' if 'queryString' is null
  if (stQuery.indexOf("?") == 0) stQuery = stQuery.substring(1);
  if (stQuery) {
    var nvPairs = stQuery.split("&");
    for (var i=0; i < nvPairs.length; i++) {
      var posEq = nvPairs[i].indexOf("=");
      eval( "this." + nvPairs[i].substring(0,posEq) + "='" + nvPairs[i].substring(posEq+1) + "'");
      }
    }
  }


/********** BEGIN: Event handling **********/
function my_AddListener(obj, evType, fn) {
  if (obj.addEventListener) {
    obj.addEventListener(evType, fn, false);
    return true;
    }
  else if (obj.attachEvent) return obj.attachEvent('on' + evType, fn);
  else return false;
  }

function my_fixE(ev) {
  var e = ev ? ev : window.event;
  return e;
  }
/********** END: Event handling **********/


/********** BEGIN: screen handling **********/
function my_Point(x, y) {
  // returns a "Point" object with '.x' and '.y' properties
  this.x = x;
  this.y = y;
  }

function my_getOffsetXY(obj) {
  // returns a "my_Point" object with both '.x' and '.y' coordinates of 'obj'; usage: "var point = my_getXY(obj); var left=point.x; var top=point.y;"
  var xPos = obj.offsetLeft;
  var yPos = obj.offsetTop;
  var parent = obj.offsetParent;
  while (parent != null) {
    xPos += parent.offsetLeft;
    yPos += parent.offsetTop;
    parent = parent.offsetParent;
    }
  return new my_Point(xPos, yPos);
  }

function my_moveTo(obj, x, y) {
  // moves 'obj' to x/y coordinates
  obj.style.left = x + "px";
  obj.style.top = y + "px";
  }

function my_getOffsetX(obj) {
  // returns 'x' coordinate of 'obj'
  var xPos = obj.offsetLeft;
  var parent = obj.offsetParent;
  while (parent != null) {
    xPos += parent.offsetLeft;
    parent = parent.offsetParent;
    }
  return xPos;
  }

function my_getOffsetY(obj) {
  // returns 'y' coordinate of 'obj'
  var yPos = obj.offsetTop;
  var parent = obj.offsetParent;
  while (parent != null) {
    yPos += parent.offsetTop;
    parent = parent.offsetParent;
    }
  return yPos;
  }
/********** END: screen handling **********/
// also see: http://www.mattkruse.com/javascript/anchorposition/source.html
