/**
 * Returns the position of the element in the
 * browser window, as [x,y].
 */
function findElementPosition(obj) {
    var curtop;
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}

function scrollToElement(theElement){

    var selectedPosX = 0;
    var selectedPosY = 0;

    while(theElement != null){
        selectedPosX += theElement.offsetLeft;
        selectedPosY += theElement.offsetTop;
        theElement = theElement.offsetParent;
    }

    window.scrollTo(selectedPosX,selectedPosY);

}

/**
 * Bolds the selected radios label.  This method
 * is specific to ChoicesPanel.html.
 */
function hilightChoice(choice, selectedIndex) {

    var foils = choice.parentNode.parentNode.parentNode;
    var rows = foils.getElementsByTagName('tr');

    for(var i=0, il=rows.length; i<il; i++) {
        var labels = rows[i].getElementsByTagName('label');
        for(var j=0, jl=labels.length; j<jl; j++) {
            if(selectedIndex == i) {
                labels[j].style.fontWeight = 'bold';
                labels[j].style.fontSize = '115%';
            } else {
                labels[j].style.fontWeight = 'normal';
                labels[j].style.fontSize = '100%';
            }
        }
    }
}

/**
 * Return the x cordinate of the event.
 * @param element the element the event occurred on.
 * @param event the event.
 */
function getEventX(element, event) {
    if (event.offsetX != null) {
        return event.offsetX;
    }
    return event.pageX - element.offsetLeft;
}

/**
 * Return the y cordinate of the event.
 * @param element the element the event occurred on.
 * @param event the event.
 */
function getEventY(element, event) {
    if (event.offsetY != null) {
        return event.offsetY;
    }
    return event.pageY - element.offsetTop;
}