﻿// this script contains functions to enable page preview-based
// editing and selection of content blocks and rows

function blockEdit(varBlockID)
{
    // this function sets the URL of the frame containing edit controls
    // when the handler_content page is being viewed within the admin
    // area
    window.parent.document.getElementById("iframeEdit").src = "/admin/cms_page_edit_block.aspx?blockid=" + varBlockID;
}

function blockDelete(varBlockID)
{
    // this function asks for confirmation before deleting a content block
    // via an ASP.NET script
    var varConfirmed = confirm("Do you really want to delete this block?");

    if (varConfirmed == true)
    {
        window.location="/admin/scripts/cms_blockdelete.aspx?blockid=" + varBlockID;
    }
}

function headerEdit(varPageID)
{
    // this function sets the URL of the frame containing edit controls
    // for page headers when the edit button is clicked from cms_page_header_preview.aspx
    window.parent.document.getElementById("iframeEdit").src = "/admin/cms_page_headers.aspx?pageid=" + varPageID;
}

function updatePreviewPanel(varPageKeyword,varOnlyRefresh,varDomain)
{
    // this function sets the url of the frame containing page previews
    // when the CMS page editing script loads and refreshes
    
    // first, if the OnlyRefresh parameter is set, just update the preview panel
    if (varOnlyRefresh != "1")
    {
        var varPreviewURL;
        
        // build the URL for the preview page
        if (varPageKeyword == "index")
        {
            varPreviewURL = "/index.html?designtime=1&domain=" + varDomain;
        }
        else
        {
            varPreviewURL = "/" + varPageKeyword + ".html?designtime=1&domain=" + varDomain;
        }
        
        window.parent.document.getElementById("iframePreview").src = varPreviewURL;
    } else
    {
        var varCurrentURL = window.parent.document.getElementById("iframePreview").src;
        window.parent.document.getElementById("iframePreview").src = varCurrentURL;
    }
}

function updateHeaderPreviewPanel()
{
    // this function refreshes the frame containing header previews
    // when the CMS header editing script loads and refreshes
    var varCurrentURL = window.parent.document.getElementById("iframeHeaderPreview").src;
    window.parent.document.getElementById("iframeHeaderPreview").src = varCurrentURL;
}
