var util = {

  shouldDebug: false,

  getXCoord: function(el)
  {
    x = 0;
    while(el){
      x += el.offsetLeft;
      el = el.offsetParent;
    }
    return x;
  },

  getYCoord: function(el)
  {
    y = 0;
    while(el){
      y += el.offsetTop;
      el = el.offsetParent;
    }
    return y;
  },

  //Given an element, calculate the maximum X coordinate of any element contained within the specified element...
  getMaxCoordX: function(el, max)
  {
  },

  //Given an element, calculate the maximum Y coordinate of any element contained within the specified element...
  getMaxCoordY: function(el, max)
  {
    var i = 0;
    for(i = 0; i < el.childNodes.length; i++)
    {
      max = this.getMaxCoordY(el.childNodes[i], max);
    }

    var elemBottom = this.getXCoord(el);
    if(isNaN(elemBottom)) elemBottom = 0;
    //if(!isNaN(el.offsetHeight))
    //  elemBottom += el.offsetHeight;

    return Math.max(elemBottom, max);
  },

  // Note: Will fail in pathological cases (where the members contain
  // strings similar to describe() result).
  membersEqual: function(array1, array2) {
    return util.describe(array1)==util.describe(array2);
  },

  describe: function(obj) {
    if (obj==null) { return null; }
    switch(typeof(obj)) {
      case 'object': {
        var message = "";
        for (key in obj) {
          message += ", [" + key + "]: [" + obj[key] + "]";
        }
        if (message.length > 0) {
          message = message.substring(2); // chomp initial ', '
        }
        return message;
      }
      default: return "" + obj;
    }
  },

  debug: function(message) {
      if (this.shouldDebug) {
        alert("AjaxJS Message:\n\n" + message);
      }
  },

  error: function(message) {
      if (this.shouldDebug) {
        alert("AjaxJS ERROR:\n\n" + message);
      }
  },

  trim: function(str) {
    return str.replace(/(^\s+|\s+$)/g,'');
  },

  strip: function(str) {
    return str.replace(/\s+/, "");
  }

}

function getElementsByClassName(classname) {
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = document.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function extractIFrameBody(iFrameEl) {

  var doc = null;
  if (iFrameEl.contentDocument) { // For NS6
    doc = iFrameEl.contentDocument;
  } else if (iFrameEl.contentWindow) { // For IE5.5 and IE6
    doc = iFrameEl.contentWindow.document;
  } else if (iFrameEl.document) { // For IE5
    doc = iFrameEl.document;
  } else {
    alert("Error: could not find sumiFrame document");
    return null;
  }
  return doc.body;

}
