﻿
function ResizeAllFrames(editableDocument) {
    try {
        if (editableDocument == null || editableDocument == undefined) {
            editableDocument = document.getElementById('EditablePage').contentDocument;
        }

        if (editableDocument != null) {
            // get a list of all iframes on the page
            var frameList = editableDocument.getElementsByTagName("iframe");
            var currentDoc = null;
            var newHeight = 0;
            // for each iframe 
            for (var i = 0; i < frameList.length; i++) {

                if (frameList[i].id != "Dialog") {
                    // get the document object
                    if (frameList[i].contentDocument) { // Firefox, Opera
                        currentDoc = frameList[i].contentDocument;
                        newHeight = currentDoc.body.scrollHeight;
                    }
                    else if (frameList[i].contentWindow) { // Internet Explorer
                        currentDoc = frameList[i].contentWindow.document;
                        newHeight = currentDoc.body.scrollHeight + currentDoc.body.offsetHeight;
                    }

                    /*
                    // make sure designmode is on 
                    if (currentDoc.designMode != "On")
                        currentDoc.designMode = "On";
                      */
                    if (newHeight != frameList[i].height) {
                        frameList[i].height = newHeight + 30;
                    }
                }
            }
        }
    }
    catch (err) {
        alert(err);
    }

    setTimeout('ResizeAllFrames(' + editableDocument + ')', 500);
}

function ToolButtonDown(button) { button.style.border = 'inset 2px white'; }
function ToolButtonUp(button) { button.style.border = 'outset 2px white'; }

function Navigate(url) {
    var editablePageFrame = document.getElementById('EditablePage');
    editablePageFrame.attributes['src'] = url;
}

function OpenDialog(url, height, width) {
    try {
        try {
            // get the window dimensions for positioning the lightbox 
            var winWidth = document.all ? document.body.clientWidth : window.innerWidth;
            var winHeight = document.all ? document.body.clientHeight : window.innerHeight;
            // calculate the actual position of the lightbox
            var xpos = (winWidth - width) * 0.5;
            var ypos = (winHeight - height) * 0.5;

            // prepare the dialog container
            var dialog = document.getElementById('Dialog');
            if (dialog != null) {
                //set the position of the dialog
                dialog.style.left = xpos;
                //dialog.style.top = ypos;

                // populate the dialog with the content specified by the url ...
                dialog.src = url;
                //ajaxCall(dialog, url);

                // show the dialog elements
                document.getElementById('DialogBackground').style.visibility = 'visible';
                dialog.style.visibility = 'visible';
                dialog.style.width = width + "px";
                dialog.style.height = height + "px";
            }
        }
        catch (err) {
            alert('Couldnt open dialog:\n' + err);
        }
    }
    catch(err)
    {
        alert(err);
    }
}

