// v3 site behaviors, Mike Foster, Cross-Browser.com

// Frame breaker

if (top.location != document.location) top.location = document.location;

// Page Object

function xPage(bLeft, bRight, bVTb)
{
  this.left = bLeft;
  this.right = bRight;
  this.onLoad = function()
  {
    if (!this.downgrade) {
      if (bRight) this.xcr = new xCollapsible('none', 1);
      if (bVTb) vtbInit();
    }
  }
  this.onUnload = function()
  {
    if (this.xcr) this.xcr.onUnload();
  }
  // Constructor
  this.downgrade = true;
  if (document.getElementById || document.all) { // need to enhance downgrade detection
    this.downgrade = false;
  }
}

function eqCol() 
{
  var bo = xGetElementById('bodyblock');
  var boh = xHeight(bo);
  var ce = xGetElementById('center');
  var ceh = xHeight(ce);
  var co = xGetElementById('cont');
  var coh = xHeight(co);
  var lc = xGetElementById('l-col');
  var lch = xHeight(lc);
  var rc = xGetElementById('r-col');
  var rch = xHeight(rc);
  var ln = xGetElementById('l-nav');
  var lnh = xHeight(lc);
  //alert(coh);
  if (lnh > coh) { 
	xHeight(rc, lnh+10);
	xHeight(co, lnh+10);
	//xHeight(ln, lnh+10);	
  }
  else if (rch > coh) { 
	xHeight(lc, rch);
	xHeight(ln, rch);
	xHeight(co, rch);
  }
  else {        
	xHeight(rc, coh);
	//xHeight(co, coh);
	xHeight(ln, coh);
  }
}
function eqColLogin()
{
    var bo = xGetElementById('bodyblock');
    var boh = xHeight(bo);
    var ce = xGetElementById('center');
    var ceh = xHeight(ce);
    var co = xGetElementById('cont');
    var coh = xHeight(co);
    xHeight(co, boh + 10);
}
function fixContentHeight(h,isVisible)
{
    var newHeight;
    var n = h + "px";
    var co = xGetElementById('cont');
    var bo = xGetElementById('bodyblock');
    var fo = xGetElementById('ftr');
    
    //Get actual body height
    var y = fo.offsetTop - bo.offsetTop;
    if (co) if (co.style) newHeight = parseInt(co.style.height) + h;
    if (co) if (co.style) co.style.height = newHeight + "px";
}
function eqColIFrame(h)
{
    var ce = xGetElementById('center');
    var co = xGetElementById('cont');
    var lc = xGetElementById('l-col');
    var ln = xGetElementById('l-nav');
    var bo = xGetElementById('bodyblock');
    var fo = xGetElementById('ftr');

    if (ce) {
        // Do the new script which is based in the center-div
        //if (co) if (co.style) co.style.height = ce.offsetHeight + "px";
        //else ce.style.height = (lnh+55)+"px";
        if (co) if (co.style) {
			var coh = xHeight(co);
			if ((ce.offsetHeight) > coh)
				co.style.height = ce.offsetHeight + "px";
		}
        //if (bo) if (bo.style) bo.style.height = ce.offsetHeight + "px";
        if (bo) if (bo.style) {
			var boh = xHeight(bo);
			if ((ce.offsetHeight) > boh)
				bo.style.height = ce.offsetHeight + "px";
		}
        //if (lc) if (lc.style) lc.style.height = ce.offsetHeight + "px";
        if (lc) if (lc.style) {
			var lch = xHeight(lc);
			if ((ce.offsetHeight) > lnh)
				lc.style.height = ce.offsetHeight + "px";
		}
        //if (ln) if (ln.style) ln.style.height = (ce.offsetHeight - 55) + "px";
		if (ln) if (ln.style) {
			var lnh = xHeight(ln);
			if ((ce.offsetHeight - 55) > lnh)
				ln.style.height = (ce.offsetHeight - 55) + "px";
		}
    }
    else {
        // Do the script made earlier if center-div was not found

        var n = h + "px";
        if (co) if (co.style) co.style.height = n;
        //Get actual body height
        var y = fo.offsetTop - bo.offsetTop;
        if (bo) if (bo.style) bo.style.height = y + "px";
        if (ln) if (ln.style) ln.style.height = (y-55) + "px";
    };
}

function eqCol2()
{
  var co = xGetElementById('cont');
  var coh = xHeight(co);
  var rc = xGetElementById('r-col');
  var rch = xHeight(rc);
  if (coh > rch) {
	xHeight(rc, coh);
  }
  else {        
    xHeight(co, rch);
  }
}

function eqCol3()
{
  var co = xGetElementById('cont');
  var coh = xHeight(co);
  var lc = xGetElementById('l-nav');
  var rc = xGetElementById('r-col');
  var rch = xHeight(rc);
  if (coh > xHeight(rc)) {
    xHeight(lc, coh - 55);
	xHeight(rc, coh);
  }
  else {        
    xHeight(lc, rch - 55);
  }
}

function eqCol4()
{
  var bo = xGetElementById('bodyblock');
  var boh = xHeight(bo);
  var ce = xGetElementById('center');
  var ceh = xHeight(ce);
  var co = xGetElementById('cont');
  var coh = xHeight(co);
  var lc = xGetElementById('l-nav');
  var rc = xGetElementById('r-col');
  var rch = xHeight(rc);
  var lch = xHeight(lc);
  if (lch > xHeight(co)) {
    xHeight(co, lch + 55);
	xHeight(rc, lch + 55);
	xHeight(rc, boh);
  }
  else {        
    xHeight(lc, coh - 55);
	xHeight(rc, coh);
	xHeight(rc, boh);
  }
}

function eqCol5() 
{
  var mc = xGetElementById('MainContentThreeColumns');
  var mch = xHeight(mc);
  
  var ln = xGetElementById('l-nav');
  var lnh = xHeight(ln);
    
  var rc = xGetElementById('r-col');
  var rch = xHeight(rc);  
  
  if (rch < mch) {
      xHeight(rc, mch);
  }
  
  if (lnh < mch) {
    xHeight(ln, mch);
  }
    
}



// Vertical Toolbar

function xNewEle(p, n, cls, h, clk, movr, mout)
{
  var e = document.createElement('DIV');
  if (e && p) {
    e.id = cls + n;
    e.className = cls;
    if (h) e.innerHTML = h;
    p.appendChild(e);
    if (clk) e.onclick = clk;
    if (movr) e.onmouseover = movr;
    if (mout) e.onmouseout = mout;
  }
  return e;
}

function vtbInit(bLeft, bRight)
{
  var rc = xGetElementById('r-col');
  // vertical toolbar (button container)
  var tb = xNewEle(document.body, 1, 'xToolbar');
  tb.floatOffset = xPageY('cont'); //10;
  // sidebar button
  b = xNewEle(tb, 2, 'xButton', null, clpsBtnOnClick, btnOnMouseover, btnOnMouseout);
  b.clpsColor = '#ffc';
  b.clpsEle = rc;
  b.collapsed = true;
  b.onclick();
  // initial position and slide
  vtbWinOnResize(1);
  vtbWinOnScroll();
  // vtb event listeners
  xAddEventListener(window, 'resize', vtbWinOnResize, false);
  xAddEventListener(window, 'scroll', vtbWinOnScroll, false);
}

function clpsBtnOnClick()
{
  clpsBtnDoClick(this, this.collapsed);
}
function clpsBtnDoClick(thisEle, bShow)
{
  var d, t, w, h, b;
  var lc = xGetElementById('cont');
  var rc = xGetElementById('r-col');
  if (bShow) { // show
    d = 'block';
    t = 'Vis ikke';
    w = '72';
    h = '';
	b = 'url(PortalImages/3/tab.gif)';
  }
  else {                // hide
    d = 'none';
    t = 'Vis';
    w = '100';
    h = '';
	b = 'url(PortalImages/3/tab2.gif)';
  }
  t += ' højrespalte';
  rc.style.display = d;
  lc.style.width = w + '%';
  thisEle.innerHTML = h;
  thisEle.setAttribute('title', t);
  thisEle.style.background = b;
  thisEle.collapsed = !bShow;
}



function btnOnMouseover()
{
  this.className = 'xButtonHover';
}

function btnOnMouseout()
{
  this.className = 'xButton';
}

function vtbWinOnResize(init)
{
  var tb = xGetElementById('xToolbar1');  var lc = xGetElementById('cont');
  xMoveTo(tb, xClientWidth() - xPageX(lc), xPageY(lc));
  if (init==1) xShow(tb);
  else vtbWinOnScroll();
  eqCol();
}

function vtbWinOnScroll()
{
  var tb = xGetElementById('xToolbar1');
  xSlideTo(tb, xPageX(tb), xScrollTop() + tb.floatOffset, 800);
}




