shown = 0;

function show_help() {
    var sbox  = document.getElementById("search_box");
    var slink = document.getElementById("search_link");
    var stab  = document.getElementById("search_tab");
    var keybox = document.getElementById("keywords");
    if (shown == 0) {
        var x     = findPosX(slink);
        var elt_width = slink.offsetWidth;
        var win_width = windowWidth();
        if (!isNaN(x) && !isNaN(elt_width) && !isNaN(win_width)) {
            var newx = win_width - ( x + elt_width) - 1;
            if (newx > 0) {
                sbox.style.marginRight = String(newx) + "px" ;
            }
        }
        sbox.style.display = 'block';
        slink.className    = "sel";
        stab.className     = "sel";
        shown = 1;
        keybox.focus();
    }
    else {
        sbox.style.display = 'none'; 
        slink.className    = "";
        stab.className     = "";
        shown = 0;
    }
    return(false);
}

function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x) {
        curleft += obj.x;
    }
    return curleft;
}

function windowWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}
