﻿function findPosX(obj) {
    var curleft = 0;

    if (obj.offsetParent) {
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curleft += obj.x;
    }

    obj.style.position = "static";

    return curleft;
}

function findPosY(obj) {
    var curtop = 0;

    if (obj.offsetParent) {
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    } else if (obj.y) {
        curtop += obj.y;
    }

    return curtop;
}



function closeDiv(elementID) {
    var elemObj = document.getElementById(elementID);
    if (elemObj != null) {
        elemObj.style.display = 'none';
        
        
        //targetObj.style.visibility = 'hidden';
    }
    else {
        alert('Object ' + elementID + ' not found.');
    }
}

function openDiv(elementID, targetObj) {
    
    var elemObj = document.getElementById(elementID);
    if (elemObj != null) {
       
        elemObj.style.display = 'block';
        var buttonPosX = findPosX(targetObj) +50;
        var buttonPosY = findPosY(targetObj);
        //elemObj.style.left = buttonPosX + 'px';
        //elemObj.style.top = buttonPosY + 'px';

        var divWidth = document.body.clientWidth - buttonPosX-40;
        //elemObj.style.width = divWidth + 'px';
        //alert('position x: ' + buttonPosX + 'position y: ' + buttonPosY + 'Width: ' + divWidth);
        //targetObj.style.visibility = 'visible';
    }
    else {
        alert('Object ' + elementID + ' not found.');
    }
}

$(document).ready(function() {
    $(".accordion").accordion({
        autoHeight: false,
        collapsible: true,
        active: false
    });
});
