
function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

function test(e) {
    window.alert(getX(e) + ',' + getY(e));
}
function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}
function jahiaGetObject(idf) {
    if (document.getElementById) {
        return document.getElementById(idf);
    } else if (document.all) {
        return document.all[idf];
    } else {
        return null;
    }
}

function getX(id) {
    //var e = document.getElementById ? document.getElementById(id) : document.all ? document.all[id] : document.layers[id];
    var e = jahiaGetObject(id);
    x = getPageOffsetLeft(e);
    // adjust position for IE
    if (browser.isIE) {
        x += e.offsetParent.clientLeft;
    }
    x -= 1;
    return x;
}
function getY(id) {
    //var e = document.getElementById ? document.getElementById(id) : document.all ? document.all[id] : document.layers[id];
    var e = jahiaGetObject(id);
    y = getPageOffsetTop(e) + e.offsetHeight;
    // adjust position for IE
    if (browser.isIE) {
        y += e.offsetParent.clientTop;
    }
    y += 1;
    return y;
}
function topmenuOn(id) {
	var topmenutd = jahiaGetObject(id);
	topmenutd.style.backgroundColor ="#FFFFFF";
	topmenutd.style.color="#5d5d5d";
	topmenutd.style.borderBottom="2px solid #35b4e8";
}
function topmenuOff(id) {	
	var topmenutd = jahiaGetObject(id);
	topmenutd.style.backgroundColor ="#FFFFFF";
	topmenutd.style.color="#5d5d5d";
	topmenutd.style.borderBottom="2px solid #ffffff";
}
        function OpenPopup(puFilename, puName, puWidth, puHeight) {
        window.open (puFilename,
            puName,
            'toolbar=no,' +
            'location=no,' +
            'directories=no,' +
            'status=no,' +
            'menubar=no,' +
            'scrollbars=yes,' +
            'resizable=no,' +
            'width='+  puWidth + ',' +
            'height=' + puHeight);
        }
        function NewWindow(url, name) {
            var newWindow = window.open(url, name, 'toolsbar=no,scrollbars=yes,width=775,height=600');
        }
function swithToEditMode(){
     var theUrl = window.location.href;

     var pos = theUrl.indexOf("/op/edit");
     if (pos == -1) {
        pos = theUrl.indexOf("/op/");
        if ( pos == -1 ){
            pos = theUrl.indexOf("/pid/");
            if ( pos != -1 ){
                theUrl = theUrl.substring( 0, pos ) + "/op/edit" + theUrl.substring( pos );
            }
         } else {
            theUrl = theUrl.substring( 0, pos ) + "/op/edit/oldop/" + theUrl.substring( pos + 4 );
         }
         //alert(theUrl);
         window.location.href = theUrl;
    }
}
