/* special funtions for the dynamic menu at Valg */

function move_box2(an, box, width)
{
    var cleft = 0;
    var ctop = 0;
	var offsetLeft = 0;
    var obj = an;

    while (obj.offsetParent)
    {
//	alert('offsetLeft='+obj.offsetLeft+' offsetWidth='+obj.offsetWidth+' offsetTop='+obj.offsetTop+' offsetHeight='+obj.offsetHeight);
        offsetLeft += obj.offsetLeft; // of last one
        cleft += obj.offsetWidth;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }

  var elem1=parent.document.getElementById('across5');

  if(elem1!=null){
    var x1=GetPageOffsetLeft(elem1);
//    var x2=x1+elem1.offsetWidth;  // also right edge of page

	if(width > elem1.offsetWidth) {cleft=x1+elem1.offsetWidth-width}
    else{cleft=x1};
	
    box.style.left = cleft + 'px';
//	alert('offsetLeft='+offsetLeft+' box.style.left='+box.style.left+' parent.screen.left='+parent.screen.left);

    ctop += an.offsetHeight + 8;
 /*   cleft += obj.offsetWidth; */

    // Handle Internet Explorer body margins,
    // which affect normal document, but not
    // absolute-positioned stuff.
    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    box.style.top = ctop + 'px';
	}
}  //  move_box2

function getAbsoluteDivs2()
{
    var arr = new Array();
    var all_divs = parent.document.body.getElementsByTagName("DIV");
    var j = 0;

    for (i = 0; i < all_divs.length; i++)
        if (all_divs.item(i).style.position=='absolute')
        {
            arr[j] = all_divs.item(i);
            j++;
        }

    return arr;
}

function bringToFront2(obj)
{
    if (!document.getElementsByTagName)
        return;

    var divs = getAbsoluteDivs2();
    var max_index = 0;
    var cur_index;
/*	alert('divs.length=' + divs.length); */

    // Compute the maximal z-index of
    // other absolute-positioned divs
    for (i = 0; i < divs.length; i++)
    {
        var item = divs[i];
        if (item == obj ||
            item.style.zIndex == '')
            continue;

        cur_index = parseInt(item.style.zIndex);
        if (max_index < cur_index)
        {
            max_index = cur_index;
        }
    }

    obj.style.zIndex = max_index + 1;
}

function show_hide_box2(an, anparent, width, height, borderStyle)
{
    var href = an.href;

//    var boxdiv = document.getElementById(href);
    var boxdiv = parent.document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            // Show existing box, move it
            // if document changed layout
            move_box2(an, boxdiv, width);
            boxdiv.style.display='block';

            bringToFront2(boxdiv);

            // Workaround for Konqueror/Safari
            if (!boxdiv.contents.contentWindow)
                boxdiv.contents.src = href;
        }
        else
            // Hide currently shown box.
            boxdiv.style.display='none';
        return false;
    };

    // Create box object through DOM
    boxdiv = parent.document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);

    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
	
    boxdiv.style.border = borderStyle;
    boxdiv.style.textAlign = 'right';
    boxdiv.style.padding = '4px';
    boxdiv.style.background = '#FFFFFF';
    parent.document.body.appendChild(boxdiv);

    var offset = 0;

    // Remove the following code if 'Close' hyperlink
    // is not needed.
    var close_href = parent.document.createElement('a');
    close_href.href = 'javascript:void(0);';
    close_href.onclick = function()
        { show_hide_box2(an, width, height, borderStyle); }
		

var fontx = parent.document.createElement("font");
fontx.style.color = "black";
fontx.style.fontWeight = "bold";
fontx.style.fontFamily = "Verdana, Geneva, Arial, helvetica, sans-serif";
fontx.style.fontSize = "12px";
fontx.style.textDecoration = "none";

fontx.appendChild(parent.document.createTextNode("Steng"));
close_href.appendChild(fontx);
/*
close_href.appendChild(parent.document.createTextNode("Steng"));
close_href.className = 'myC';
*/

 /*   close_href.appendChild(parent.document.createTextNode('Steng')); */
    boxdiv.appendChild(close_href);
    offset = close_href.offsetHeight;
    // End of 'Close' hyperlink code.

    var contents = parent.document.createElement('iframe');
    //contents.scrolling = 'no';
    contents.name = 'iframe3';
    contents.id = 'iframe3';
    contents.overflowX = 'hidden';
    contents.overflowY = 'scroll';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    boxdiv.contents = contents;
    boxdiv.appendChild(contents);

    move_box2(an, boxdiv, width);
	
    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(
            href);
    else
        contents.src = href;

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return false;
}

