
// ------------------------------------------------------------
// Handles multiple functions on page load
// ------------------------------------------------------------

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}


// ------------------------------------------------------------
// Changes the height of the main divs of the page so
// they are the same height.
// ------------------------------------------------------------


function adaptMainDivs() {

    if (typeof (special) != "undefined") {
        adapt2ColumnDivs('mcscontentdiv', 'mcsrightmenudiv', 200);
        adapt2ColumnDivs('leftmenudiv', 'rightdiv', 400);

    }
    else {
        adaptColumnDivs('leftmenudiv', 'contentdiv', 'rightmenudiv', 400);

    }
};

function isDefined(variable) {
    return (!(!(variable || false)))
}



function adaptColumnDivs(leftDivID, mainDivID, rightDivID, height) {
    var leftDiv = document.getElementById(leftDivID);
    var mainDiv = document.getElementById(mainDivID);
    var rightDiv = document.getElementById(rightDivID);

    if (leftDiv != null && mainDiv != null && rightDiv != null) {
        // find the highest div
        if (leftDiv && leftDiv.clientHeight > height) height = leftDiv.clientHeight;
        if (mainDiv && mainDiv.clientHeight > height) height = mainDiv.clientHeight;
        if (rightDiv && rightDiv.clientHeight > height) height = rightDiv.clientHeight;

        // set new height
        if (leftDiv) leftDiv.style.height = height + 'px';
        if (mainDiv) mainDiv.style.height = height + 'px';
        if (rightDiv) rightDiv.style.height = height + 'px';
    }
};

function setExactHeightOfDivs(leftDivID, mainDivID, rightDivID, height) {
    document.getElementById(leftDivID).style.height = height + 'px';
    document.getElementById(mainDivID).style.height = height + 'px';
    document.getElementById(rightDivID).style.height = height + 'px';
}

function adaptColumnDivsMinHeight(leftDivID, mainDivID, rightDivID, height) {
    var leftDiv = document.getElementById(leftDivID);
    var mainDiv = document.getElementById(mainDivID);
    var rightDiv = document.getElementById(rightDivID);


    if (leftDiv != null && mainDiv != null && rightDiv != null) {

        // find the highest div
        if (leftDiv && leftDiv.clientHeight > height) height = leftDiv.clientHeight;
        if (mainDiv && mainDiv.clientHeight > height) height = mainDiv.clientHeight;
        if (rightDiv && rightDiv.clientHeight > height) height = rightDiv.clientHeight;

        // set new height
        if (leftDiv) leftDiv.style.height = height + 'px';
        if (mainDiv) mainDiv.style.height = height + 'px';
        if (rightDiv) rightDiv.style.height = height + 'px';
    }
};

function adapt2ColumnDivs(leftDivID, mainDivID, height) {
    var leftDiv = document.getElementById(leftDivID);
    var mainDiv = document.getElementById(mainDivID);

    if (leftDiv != null && mainDiv != null) {

        // find the highest div
        if (leftDiv && leftDiv.clientHeight > height) height = leftDiv.clientHeight;
        if (mainDiv && mainDiv.clientHeight > height) height = mainDiv.clientHeight;

        // set new height
        if (leftDiv) leftDiv.style.height = height + 'px';
        if (mainDiv) mainDiv.style.height = height + 'px';
    }
};

function changePageMenuImage(imagenr, imgsrc) {
    var imageid = "PageMenu" + imagenr;
    var image = document.getElementById(imageid);

    if (image != null) {
        image.src = imgsrc;
    }

};

function changeTopMenuImage(imagenr, imgsrc) {
    var imageid = "TopMenu" + imagenr;
    var image = document.getElementById(imageid);

    if (image != null) {
        image.src = imgsrc;
    }

};

function changeDivisionTopMenuImage(imagenr, imgsrc) {
    var imageid = "DivisionTopMenu" + imagenr;
    var image = document.getElementById(imageid);

    if (image != null) {
        image.src = imgsrc;
    }

};

// Toolbox


function TipPage(url) {
    w = window.open(url, 'PrintOfficeWindow', 'width=340,height=600,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=no,status=yes');
    w.focus();
};

// This function will fire a click event on the specified control when the 
// enter key is pressed in a text field. Attach this function to the 
// onkeypressed-event on the text field.
function fireClickOnEnter(evt, controlId) {
    var control = document.getElementById(controlId);
    var keyCode = (typeof window.event == 'object') ? window.event.keyCode : evt.keyCode;

    // If enter is pressed -> fire click-event on the control
    if (control && (keyCode == 13)) {
        control.focus();
        control.click();
        return false;
    }
    else {
        return true;
    }
}

function changeToColor(id, color) {
    document.getElementById(id).style.color = color;
}
function SetSiteCatalystData(sitecatalysthiddenid, value) {
    ClearSiteCataLystProperties();
    document.getElementById(sitecatalysthiddenid).value = value;
    SendCatalystData();
    var SCDebugger = document.getElementById('SiteCatalystDebugger');
    if (SCDebugger) {
        SCDebugger.innerHTML = GetSiteCatalystDebuggerHTML();
    }
}
function SetSiteCatalystDataWithoutClearingAndSending(sitecatalysthiddenid, value) {
    document.getElementById(sitecatalysthiddenid).value = value;
    var SCDebugger = document.getElementById('SiteCatalystDebugger');
    if (SCDebugger) {
        SCDebugger.innerHTML = GetSiteCatalystDebuggerHTML();
    }
}
function ClearSiteCataLystProperties() {
    document.getElementById('hiddenPageName').value = ''
    document.getElementById('hiddenChannel').value = '';
    document.getElementById('hiddenProp1').value = '';
    document.getElementById('hiddenProp2').value = '';
    document.getElementById('hiddenProp3').value = '';
    document.getElementById('hiddenProp4').value = '';
    document.getElementById('hiddenProp5').value = '';
    document.getElementById('hiddenProp6').value = '';
    document.getElementById('hiddenProp7').value = '';
    document.getElementById('hiddenProp8').value = '';
    document.getElementById('hiddenProp9').value = '';
    document.getElementById('hiddenProp10').value = '';
    document.getElementById('hiddenProp11').value = '';
    document.getElementById('hiddenProp12').value = '';
    document.getElementById('hiddenProp13').value = '';
    document.getElementById('hiddenProp14').value = '';
    document.getElementById('hiddenCampaign').value = '';
    document.getElementById('hiddenEvent').value = '';
    document.getElementById('hiddeneVar2').value = '';
    document.getElementById('hiddeneVar3').value = '';
    document.getElementById('hiddeneVar4').value = '';
}