function windowHeight() {   // sigh ...
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    return window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    return document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    return document.body.clientHeight;
  }
}

function entityDecode(strHTML) {
    return strHTML.replace(/\xA0/, ' ').replace(/\&nbsp\;/ig, ' ').replace(/\&amp\;/ig, '&');
}

function show_bookmark_notes(id, url, cui, tui) {

	var comments = "User comments about this web page:";

	new Ajax.Request(rhr_root + "/page/page_notes?url=" + url + "&cui=" + cui + "&tui=" + tui, {
		method: 'get',
		onSuccess: function(transport) {
			if (transport.responseText.length > 0) {
				comments = comments + transport.responseText;
				Tip(comments, BALLOON, true, ABOVE, true, DELAY, 800);
			}
		}
	});
}

var pname;
var pwidth;
var pheight;
var const_tab_height;

var onPortalMaximized = new YAHOO.util.CustomEvent('portal maximized');
var onPortalMinimized = new YAHOO.util.CustomEvent('portal minimized');

function maximize_portal(name) {
    var ps = ($$('.portal')), p, title, text;

    for (var i = 0; i < ps.size(); ++i) {
        p = ps[i];
        title = entityDecode(p.select('.portaltitle').first().innerHTML);
        text = p.select('.portaltext').first();

        if (name != null) {
            if (title != name) {
                name = entityDecode(name); // to deal with 160s
                p.hide();
            } else {
                var newheight = 700;
                pname = name;
                pwidth = p.getStyle('width');
                pheight = text.getStyle('height');
                p.setStyle({width:'900px'});
                text.setStyle({height:newheight});
                p.select('.maximize').first().hide();
                p.select('.minimize').first().show();
                // All but one of the tab-const-heights will have 0 offset becuase the are hidden
                // .. find the one we need
                var ot = 0;
                for (var j = 0; j < p.select('.tab-const-height').size(); ++j) {
                    if (ot == 0) ot = p.select('.tab-const-height')[j].offsetTop;
                }
                for (var j = 0; j < p.select('.tab-const-height').size(); ++j) {
                    var d = p.select('.tab-const-height')[j];
                    const_tab_height = d.getStyle('height');
                    d.setStyle({height:(newheight - (2 * ot)), 'min-height':(newheight - (2 * ot))});
                }
                onPortalMaximized.fire(p);
            }
        } else {
            if (title == pname) {
                p.setStyle({width:pwidth});
                text.setStyle({height:pheight});
                p.select('.maximize').first().show();
                p.select('.minimize').first().hide();
                for (var j = 0; j < p.select('.tab-const-height').size(); ++j) {
                    var d = p.select('.tab-const-height')[j];
                    d.setStyle({height:const_tab_height});
                }
                onPortalMinimized.fire(p);                  
                pname = null;
            } else
                p.show();
        }
    }
}