/************************************************************
Solar Millenium
@author: 		Timo Trautmann
JavaScript Functions for module ConfirmationBox
This Functions shows a Confirmation Layer containing arrangements
which must be acknowledged before page information is readable
@created: 		2008-02-14
************************************************************/

var bMsie = (document.all) ? true : false;

/**
* Function is called, when user acknowledges the frame. It hides the frame,
* shows recent content and sets cookie for one hour. Layer must be 
* acknowledged only once time
*/
function do_confirmation(oConfCheckbox) {
    if (oConfCheckbox.checked == true) {
        var oDate = new Date();
        oDate = new Date(oDate.getTime() +1000*60*60);
        document.cookie = "confirmed=true; path=/; expires='+oDate.toGMTString()+"; 
        var confBox = document.getElementById('confirmation_layer');
        var confBoxContent = document.getElementById('confirmation_layer_content');
        confBox.style.display = 'none';
        confBoxContent.style.display = 'none';
        document.getElementById('mainContent').style.visibility = "visible";
    }
}

/**
* Function returns offset left, top, width and heigth of a given htnmlelement as array
*
* @param object oElement - Object which should be analyzed
* @return array - containing dimension information
*/
var getElementPostion = function (oElement) {
    var iHeigth = oElement.offsetHeight;
    var iWidth = oElement.offsetWidth;
    var iTop = 0, iLeft = 0;
    while (oElement) {
        iTop += oElement.offsetTop  || 0;
        iLeft += oElement.offsetLeft || 0;
        oElement = oElement.offsetParent;
    };
    return [iLeft, iTop, iHeigth, iWidth];
}


/**
* This function shows confirmation layer, if cookie is not set, which defines, if layer is also aknowledged
*/
function initConfirmation() {
    var cookie = String(document.cookie);
    var confBox = document.getElementById('confirmation_layer');
    var confBoxContent = document.getElementById('confirmation_layer_content');
    if (!cookie.match(/confirmed=true/g)) {
        document.getElementById('mainContent').style.visibility = "hidden";
        document.getElementById('confirmation_ok').checked = false;
        var footer = document.getElementById('footer');
        var header = document.getElementById('mainContent').getElementsByTagName('h1')[0];
        
        if (header && !bMsie) {
            header.style.visibility = "visible";
            var confHeaderOffset = header.offsetHeight;
            if (confHeaderOffset > 0) {
                 var confBoxHeader = document.getElementById('conf_header');
                 confBoxHeader.style.marginTop = confHeaderOffset + 'px';
            }
        }

        if (footer) {
            footer.style.visibility = "visible";
        }

        confBox.style.display = 'block';
        confBoxContent.style.display = 'block';

        var aPosContent = getElementPostion(document.getElementById('mainContent'));
        confBox.style.left = (aPosContent [0]-10)+'px';
        confBox.style.top = (aPosContent [1]+15)+'px';
        confBox.style.width = aPosContent [3]+'px';
        confBox.style.visibility = 'visible';
        confBoxContent.style.visibility = 'visible';

    }
    else
    {
       document.getElementById('mainContent').style.visibility = "visible";
       confBox.style.visibility = 'hidden';
       confBoxContent.style.visibility = 'hidden';
    }
}
