﻿// this script contains functions to enable page preview-based
// editing and selection of content blocks and rows

function blockEdit(varBlockID,varBlockStyleID)
{
    // 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;
    //$('div[id$=_blockedit]').show();
    var editwindow = window.open("/admin/cms_page_edit_block.aspx?blockid=" + varBlockID + "&styleid=" + varBlockStyleID, null, 'resizable=1,width=750,height=620');
    editwindow.moveTo(350,200);
}

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(varSectionKeyword,varPageKeyword,varOnlyRefresh)
{
    //alert('updatePreviewPanel:sectionkeyword:' + varSectionKeyword + ' pagekeyword:' + varPageKeyword + ' refresh:' + varOnlyRefresh);
    // 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 ((varSectionKeyword == "index") && (varPageKeyword == "index"))
        {
            varPreviewURL = "/index.html?designtime=1";
        }
        else
        {
            varPreviewURL = "/" + varSectionKeyword + "/" + varPageKeyword + ".html?designtime=1";
        }
        //alert('1:' + varPreviewURL);
        window.parent.document.getElementById("iframePreview").src = varPreviewURL;
    } 
    //we do a reload instead of page redirect -- so this is not needed
    //    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;
}