/**
 * common.js
 * Funciones comunes para uso global de javascript
 */
 
 
/**
 * Si el navegador es firefox
 */
function isFirefox()
{
	return navigator.userAgent.toLowerCase().match("firefox")!=null;
}

/**
 * Si el navegador es internet explorer
 */
function isExplorer()
{
   return navigator.userAgent.toLowerCase().match("msie")!=null;
}

/**
 * Si el navegador es opera
 */
function isOpera()
{
   return navigator.userAgent.toLowerCase().match("opera")!=null;
}

/**
 * Si el navegador es safari
 */
function isSafari()
{
   return navigator.userAgent.toLowerCase().match("safari")!=null;
}

function positionInfo(object) {

  var p_elm = object;

  this.getElementLeft = getElementLeft;
  function getElementLeft() {
    var x = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      x+= elm.offsetLeft;
      elm = elm.offsetParent;
    }
    return parseInt(x);
  }

  this.getElementWidth = getElementWidth;
  function getElementWidth(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetWidth);
  }

  this.getElementRight = getElementRight;
  function getElementRight(){
    return getElementLeft(p_elm) + getElementWidth(p_elm);
  }

  this.getElementTop = getElementTop;
  function getElementTop() {
    var y = 0;
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    while (elm != null) {
      y+= elm.offsetTop;
      elm = elm.offsetParent;
    }
    return parseInt(y);
  }

  this.getElementHeight = getElementHeight;
  function getElementHeight(){
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } else {
      elm = document.getElementById(p_elm);
    }
    return parseInt(elm.offsetHeight);
  }

  this.getElementBottom = getElementBottom;
  function getElementBottom(){
    return getElementTop(p_elm) + getElementHeight(p_elm);
  }
  
  this.toString=toString;
  function toString()
  {
    return "Left: "+getElementLeft()+" Top: "+getElementTop();
  }
}

function trim(stringToTrim) 
{
	var result="";
	if(stringToTrim)
		result= stringToTrim.replace(/^\s+|\s+$/g,"");
	return result;
}

