﻿function ReloadPage() {
    location.reload(true);
}

function HideModal(ctrl) {
    $find(ctrl).hide();
}

function ShowModal(ctrl) {
    $find(ctrl).show();
}

function ShowAdmin(hoveritem, id, adminId) {
    //alert(id);
    var hp = document.getElementById(adminId + "_admin" + id.toString().substring(id.toString().lastIndexOf("_") + 1, id.toString().length));
    var regionPanel = document.getElementById(id);
    
    // Set position of hover-over popup
    //hp.style.left = findXLeft(hoveritem) + hoveritem.offsetWidth - (document.getElementById("admin" + id).offsetWidth + 10);

    regionPanel.style.background = "Gray";
    //regionPanel.style.filter = "alpha(opacity=70)";
    //regionPanel.style.opacity = "0.7";

    // Set popup to visible
    hp.style.visibility = "Visible";
    hp.style.zIndex = 9000;
    //hp.style.left = 1000;
}

function HideAdmin(id, adminId) {
    var hp = document.getElementById(adminId + "_admin" + id.toString().substring(id.toString().lastIndexOf("_") + 1, id.toString().length));
    var regionPanel = document.getElementById(id);

    regionPanel.style.background = "Transparent";
    //regionPanel.style.filter = "alpha(opacity=100)";
    //regionPanel.style.opacity = "1";

    hp.style.visibility = "Hidden";
}

//Get the left coordinate of the container
function findXLeft(obj) {
    var x = 0;
    while (obj) {
        x += obj.offsetLeft
        obj = obj.offsetParent;
    }

    return x;
}

//Get the top coordinate of the container
function findXTop(obj) {
    var x = 0;
    while (obj) {
        x += obj.offsetTop
        obj = obj.offsetParent;
    }

    return x;
}

//Resizes an iframe based on it's content (local urls only)
function resizeFrame(ctrl) {
    var s;
    s = 100;
    ctrl.style.height = s;
    s = ctrl.contentWindow.document.body.scrollHeight + 35 + "px";
    ctrl.style.height = s;

    //ctrl.style.height = ctrl.contentWindow.document.body.scrollHeight;
}

function DisableScrolling() {
    document.body.style.overflow = "hidden";
}

//Hides the modal div when editor is put into full screen mode so it appears on top of the page instead of behind the modal background
function EditorClientCommandExecuting(editor, args) {
    var commandName = args.get_commandName();
    if (commandName == "ToggleScreenMode") {
        if (!editor.isFullScreen()) {
            editor.get_element().style.position = "relative";
            editor.get_element().style.zindex = "999999999";
            for (var i = 0; i < getElementsByClassName("ModalBackground").length; i++) {
                getElementsByClassName("ModalBackground")[i].style.display = "none";
            }
            fullscreen = true;

            //alert(editor.get_element().style.zindex);
        }
        else {
            editor.get_element().style.position = "static";
            editor.get_element().style.zindex = "9999";
            for (var i = 0; i < getElementsByClassName("ModalBackground").length; i++) {
                getElementsByClassName("ModalBackground")[i].style.display = "";
            }
            //alert(editor.get_element().style.width);
        }
    }
}

//Helper for EditorClientCommandExecuting to find and hide divs with modal background class
function getElementsByClassName(classname, node) {
    if (!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\b' + classname + '\b');
    var els = node.getElementsByTagName("*");

    for (var i = 0, j = els.length; i < j; i++) {
        if (els[i].className.indexOf("ModalBackground") > -1) {
            a.push(els[i]);
        }
        
    }
    return a;
}

//Enables tab to enter the editor area immediately instead of tabbing through all the button options first
function EditorClientLoad(editor, args) {
    var buttonsHolder = $get(editor.get_id() + "Top");
    var buttons = buttonsHolder.getElementsByTagName("A");
    for (var i = 0; i < buttons.length; i++) {
        var a = buttons[i];
        a.tabIndex = -1;
        a.tabStop = false;
    }
}