﻿
function ColorByName(ColorText) {
    ColorText = ColorText.toLowerCase();

    var result = 1; // black
    if (ColorText == 'fg_schauspiel')
        result = 2;

    return result;
}


function FontSizeByName(Size) {
    Size = Size.toLowerCase();

    var result = 0; // h1
    if (Size == 'h2')
        result = 1;
    if (Size == 'uet')
        result = 2;

    return result;
}

function ContainerWidthByName(Size) {
    Size = Size.toLowerCase();

    var result = "0";
    if (Size == 'colteaser')
        result = "1";

    return result;
}



function ReplaceFormatedHeadline(ItemID, Width, Height, ImageUrl, AltText, FontSize, Color) {
    var vgColor = ColorByName(Color);  // Aus dem Master übernommen
    var hgColor = "0";
    var textSize = FontSizeByName(FontSize);

    var item = document.getElementById(ItemID);
    if ((item != null) && (typeof (item) != 'undefined')) {
        var node = item.parentNode;
        var sizeName = "";
        while ((node != null) && (typeof (node) != 'undefined')) {
            var className = node.className;
            if ((className != null) && (typeof (className) != 'undefined')) {
                var idx = className.toLowerCase().indexOf("col");
                if (idx >= 0) {
                    sizeName = className.toLowerCase();
                    break;
                }

            }
            node = node.parentNode;
        }

        var containerWidth = ContainerWidthByName(sizeName);
        //alert(vgColor + "#" + textSize + "#" + containerWidth);

        var format = textSize.toString() + vgColor.toString() + hgColor.toString() + containerWidth.toString() + "_";
        ImageUrl = ImageUrl.replace("FORMAT_", format);
        //alert(ImageUrl);
        ReplaceHeadlineWithinLink(ItemID, Width, Height, ImageUrl, AltText);
    }
}

function ReplaceHeadline(ItemID, Width, Height, ImageUrl, AltText) {
    var item = document.getElementById(ItemID);
    internalReplaceHeadline(item, Width, Height, ImageUrl, AltText);
}

function ReplaceHeadlineWithinLink(ItemID, Width, Height, ImageUrl, AltText) {
    var item = document.getElementById(ItemID);
    if ((item != null) && (typeof (item) != 'undefined')) {
        var itemFound = false;
        for (child in item.childNodes) {
            var tagName = item.childNodes[child].tagName;
            if ((tagName != null) && (typeof (tagName) != 'undefined') && tagName.toUpperCase() == 'A') {
                internalReplaceHeadline(item.childNodes[child], Width, Height, ImageUrl, AltText);
                itemFound = true;
                break;
            }
        }
        if (!itemFound) {
            internalReplaceHeadline(item, Width, Height, ImageUrl, AltText);
        }
    }
}

function internalReplaceHeadline(Item, Width, Height, ImageUrl, AltText) {
    if ((Item != null) && (typeof (Item) != 'undefined')) {
        var width = '';
        var height = '';
        if (Width > 0)
            width = ' width="' + Width.toString() + '"';
        if (Height > 0)
            height = ' height="' + Height.toString() + '"';
        Item.innerHTML = '<img' + width + height + ' border="0" alt="' + AltText + '" src="' + ImageUrl + '">';
    }
}
