﻿
/* This is the CMS control scripting relating to the content on each page */
function GetObject(elementId, type, name)
{
    //var tags = element.all.tags(type);
    var tags = document.getElementsByTagName(type);

    for (i = 0; i < tags.length; i++)
    {
        var sdf = tags[i].id;

        if (tags[i].getAttribute("rel") != null)
            if (tags[i].getAttribute("rel") == name)
            return tags[i];
    }
}

function GetObjectAttribute(elementId, type, attribute)
{
    //var tags = element.all.tags(type);
    var tags = document.getElementsByTagName(type);

    for (i = 0; i < tags.length; i++)
    {
        var tagId = tags[i].id;

        if (tagId == elementId)
            if (tags[i].getAttribute(attribute) != null)
            return tags[i].getAttribute(attribute)
    }
}

function OpenEditPanel(editPanel,
                        cmsSectionTitleObjectId,
                        cmsSectionTextObjectId,
                        cmsSectionImageObjectId,
                        cmsSectionImageLinkId,
                        cmsSectionFileURLId,
                        cmsSectionId)
{
    objCMSPageFrame = document.getElementById('divCMSPageFrame');

    objCMSTitleControlsArray[1] = GetObject(editPanel, "input", "title");
    objCMSCopyControlsArray[1] = GetObject(editPanel, "textarea", "copy");
    objCMSImageControlsArray[1] = GetObject(editPanel, "img", "image");
    objCMSImageALTControlsArray[1] = GetObject(editPanel, "input", "imageALT");
    objCMSImageLinkControlsArray[1] = GetObject(editPanel, "input", "imageLink");
    objCMSSectionFileURLArray[1] = GetObject(editPanel, "input", "fileURL");
    objCMSSectionFileURLTitleArray[1] = GetObject(editPanel, "input", "fileURLTitle");

    // Content
    if (cmsSectionTitleObjectId != null)
        objCMSTitleControlsArray[0] = document.getElementById(cmsSectionTitleObjectId).innerHTML.toString();
    else
        objCMSTitleControlsArray[0] = null;

    if (cmsSectionTextObjectId != null)
        objCMSCopyControlsArray[0] = document.getElementById(cmsSectionTextObjectId).innerHTML.toString();
    else
        objCMSCopyControlsArray[0] = null;

    if (cmsSectionImageObjectId != null)
    {
        if (document.getElementById(cmsSectionImageObjectId).src != null)
            objCMSImageControlsArray[0] = document.getElementById(cmsSectionImageObjectId).src.toString();
        if (document.getElementById(cmsSectionImageObjectId).alt != null)
            objCMSImageALTControlsArray[0] = document.getElementById(cmsSectionImageObjectId).alt.toString();
    }
    else
    {
        objCMSImageControlsArray[0] = null;
        objCMSImageALTControlsArray[0] = null;
    }

    imageLinkedToFile = GetObjectAttribute(cmsSectionImageLinkId, "a", "FileLink");

    if (cmsSectionImageLinkId != null)
    {
        if (document.getElementById(cmsSectionImageLinkId).pathname == "")
            objCMSImageLinkControlsArray[0] = document.getElementById(cmsSectionImageLinkId).href.toString();
        else if (document.getElementById(cmsSectionImageLinkId).nameProp != null)
            objCMSImageLinkControlsArray[0] = document.getElementById(cmsSectionImageLinkId).nameProp.toString();
    }
    else
        objCMSImageLinkControlsArray[0] = null;

    if (cmsSectionFileURLId != null)
    {
        objCMSSectionFileURLArray[0] = document.getElementById(cmsSectionFileURLId).href.toString();
        objCMSSectionFileURLArray[2] = document.getElementById(cmsSectionFileURLId).innerHTML.toString();

    }
    else
    {
        objCMSSectionFileURLArray[0] = null;
    }

    txCMSSectionTitle = cmsSectionId;

    showCMSPanel();
}

function OpenMetaEditPanel(editPanel,
                        cmsPageTitle,
                        cmsPageKeywords,
                        cmsPageDescription)
{
    objCMSTitle = document.getElementById('divCMSTitle');

    objCMSPageFrame = document.getElementById('divCMSPageFrame');

    objCMSPageTitle = GetObject(editPanel, "input", "pageTitle");
    objCMSPageKeywords = GetObject(editPanel, "textarea", "keywords");
    objCMSPageDescription = GetObject(editPanel, "textarea", "description");

    // META
    if (cmsPageTitle != null)
        txCMSPageTitle = cmsPageTitle;
    else
        txCMSPageTitle = null;

    if (cmsPageKeywords != null)
        txCMSPageKeyWords = cmsPageKeywords;
    else
        txCMSPageKeyWords = null;

    if (cmsPageDescription != null)
        txCMSPageDesc = cmsPageDescription;
    else
        xCMSPageDesc = null;

    showMetaCMSPanel();
}