function adjustHeight() {
    mainBox = document.getElementById('mainc');
    startBox = document.getElementById('startc');
    bottomBox = document.getElementById('backToTop');
 //   mainMargin = document.getElementById('main_margin');
    leftSide = document.getElementById('leftc');
    rightSide = document.getElementById('rightc');

    bottomBoxHeight = bottomBox.offsetTop-startBox.offsetTop;
    mainHeight = Math.max(mainBox.offsetHeight, bottomBoxHeight);
    maxHeight = mainHeight;

    if (leftSide) {
        leftHeight = Math.max(leftSide.offsetHeight, leftSide.scrollHeight);
        maxHeight = Math.max(mainHeight, leftHeight);
    }

    if (rightSide) {
        rightHeight = Math.max(rightSide.offsetHeight, rightSide.scrollHeight);
        maxHeight = Math.max(maxHeight, rightHeight);
    }

    maxHeight = maxHeight + 'px';

   // mainBox.style.height = maxHeight;
    if (leftSide)
        leftSide.style.height=maxHeight;

    if (rightSide)
        rightSide.style.height=maxHeight;

//    mainMargin.style.height=maxHeight;
}

function calculateYPos(item, startPos) {
    var pageHeight = document.body.clientHeight;
    var pixelsScrolled = document.body.scrollTop;

     var posY =  startPos + pixelsScrolled;
     return posY;
 }

function getPos(el) {
    // yay readability
    for (var lx=0, ly=0;
         el != null;
         lx += el.offsetLeft, ly += el.offsetTop, el = el.offsetParent);
    return {x: lx,y: ly};
}

function adjustMenu() {
        menu = document.getElementById('floatdiv');
        if (!menu)
            return;
        startAnchor = document.getElementById('startanchor');
        startPosition = getPos(startAnchor);
        startPosition = startPosition.y;
        anchor = document.getElementById('floatanchor');
        topPosition = calculateYPos('anchor', startPosition);
        var pixelsScrolled = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop 
        rightSide = document.getElementById('rightc');
        maxHeight = rightSide.offsetHeight + 250;
        if (pixelsScrolled<380) {
//          menu.style.position='absolute';
            menu.style.top='0px';
    //      menu.style.top='370px';
        }
        if (pixelsScrolled>380 && (maxHeight < 0 || topPosition<maxHeight)) {
            //alert(menu.style);
//          menu.style.position="absolute";
            newTop = pixelsScrolled-startPosition;
            menu.style.top=(newTop) + 'px';
        }
}
    
document.body.onscroll=function(){adjustMenu()}; 

window.onscroll=function(){adjustMenu()}; 

window.onload = setTimeout("adjustHeight()", 100);

