﻿
function ShowNewsletterSamples(guid) {
    //alert('nl_' + guid);
    $.prettyPhoto.open('http://localhost:50333/Pages/de/preview_newsletter.aspx?guid=' + guid + '&iframe=true&width=975', 'Newsletter Beispiele', '');
    //alert(document.getElementById('nl_' + guid));
    //document.getElementById('nl_' + guid).onclick();
}

function Blind(expandElementId, minValue, maxValue, flowVertical, shrinkElementId) {
    var targetValue;

    if (typeof (flowVertical) == 'undefined')
        flowVertical = true;

    var expandElement = document.getElementById(expandElementId);

    if (flowVertical) {
        if (expandElement.offsetHeight < maxValue)
            targetValue = maxValue;
        else
            targetValue = minValue;
    }
    else {
        if (expandElement.offsetWidth < maxValue)
            targetValue = maxValue;
        else
            targetValue = minValue;
    }

    AdjustSize(expandElementId, targetValue, flowVertical, shrinkElementId)
}

var showHideElement = new Array();

function showElement(id) {
    var child = document.getElementById(id).getElementsByTagName('ul')[0];
    if (child) {
        showHideElement[child.id] = 'show';
        window.setTimeout('doDisplay(\'' + child.id + '\',true)', 0);
    }
}
function hideElement(id) {
    var child = document.getElementById(id).getElementsByTagName('ul')[0];
    if (child) {
        showHideElement[child.id] = 'hide';
        window.setTimeout('doDisplay(\'' + child.id + '\',false)', 1);
    }
}
function doDisplay(id, bDisplay) {
    if (bDisplay) {
        if (showHideElement[id] == 'show') {
            document.getElementById(id).style.display = 'block';
        }
    } else {
        if (showHideElement[id] == 'hide') {
            document.getElementById(id).style.display = 'none';
        }
    }
}


function AdjustSize(expandElementId, targetValue, flowVertical, shrinkElementId) {
    if (typeof (flowVertical) == undefined)
        flowVertical = true;

    var expandElement = document.getElementById(expandElementId);
    var shrinkElement;
    if (typeof (shrinkElementId) != undefined)
        shrinkElement = document.getElementById(shrinkElementId);

    var doExpand = false;
    if (flowVertical)
        doExpand = expandElement.offsetHeight < targetValue;
    else
        doExpand = expandElement.offsetWidth < targetValue;

    var step = -2;
    if (doExpand)
        step = 2;

    if (flowVertical) {
        expandElement.style.height = (expandElement.offsetHeight + step) + 'px';
        expandElement.style.display = '';

        if (shrinkElement) {
            shrinkElement.style.height = (shrinkElement.offsetHeight + (step * -1)) + 'px';
            if (shrinkElement.style.height == '0px')
                shrinkElement.style.display = 'none';
        }

        if ((doExpand && expandElement.offsetHeight < targetValue) || (!doExpand && expandElement.offsetHeight > targetValue))
            window.setTimeout("AdjustSize('" + expandElementId + "', " + targetValue + ", " + flowVertical + ", '" + shrinkElementId + "')", 1);
    }
    else {
        expandElement.style.width = (expandElement.offsetWidth + step) + 'px';
        expandElement.style.display = '';

        if (shrinkElement) {
            shrinkElement.style.width = (shrinkElement.offsetWidth + (step * -1)) + 'px';
            if (shrinkElement.style.width == '0px')
                shrinkElement.style.display = 'none';
        }

        if ((doExpand && expandElement.offsetHeight < targetValue) || (!doExpand && expandElement.offsetHeight > targetValue))
            window.setTimeout("AdjustSize('" + expandElementId + "', " + targetValue + ", " + flowVertical + ", '" + shrinkElementId + "')", 1);
    }
}
var newsletterDefaultValue = '';
function initiateNewsletterForm(id) {
    newsletterDefaultValue = document.getElementById(id).value;
    document.getElementById(id).className = 'inactiv';
}
function handleNewsletterForm(id, b) {
    if (id != null && document.getElementById(id) != null) {
        if (b) {
            if (document.getElementById(id).value == newsletterDefaultValue) {
                document.getElementById(id).value = '';
                document.getElementById(id).className = '';
            }
        } else {
            if (document.getElementById(id).value == '') {
                document.getElementById(id).value = newsletterDefaultValue;
                document.getElementById(id).className = 'inactiv';
            }
        }
    }
}

function RenderIndex(id) {
    var edlText = "";
    var edlh2 = document.getElementsByTagName("h2");
    for (var i = 0; i < edlh2.length; i++) {
        var spacer = "";
        if (i % 2 == 0) {
            spacer = " style=\"clear:left;\"";
        }
        edlText += "<li" + spacer + "><a href=\"#edl" + i + "\">" + edlh2[i].innerHTML + "</a></li>";
        var anchor = document.createElement("a");
        anchor.setAttribute("name", "edl" + i);
        anchor.setAttribute("id", "edl" + i);
        edlh2[i].parentNode.insertBefore(anchor, edlh2[i]);
    }
    document.getElementById(id).innerHTML = "<ul class=\"indexList\">" + edlText + "</ul><div class=\"clear\" style=\"height:20px\"></div>";
};


//Producttour
var tour = {
    root_id: 'ProductTour',
    root_animation_class: 'tourActive',
    headline_id: 'TourHeadline',
    button_id: 'TourButton',
    indicator_id: 'TourIndicator',
    canvas_id: 'TourCanvas',
    canvas_inner_id: 'TourInner',
    item_width: 514, //in pixels
    time_animation: 600, //in ms

    //don't change
    items: null,
    index: 0,
    offset: 0,
    button_prev: null,
    button_next: null,
    indicator_items: null
};
tour.initiate = function() {
    //getId(tour.root_id).style.backgroundColor = '#eee';
    getId(tour.root_id).className = tour.root_animation_class;
    tour.items = getId(tour.root_id).getElementsByTagName('li');

    if (tour.items.length > 1) {
        //Vorbereitung für Animation
        getId(tour.canvas_id).style.width = tour.item_width + 'px';
        getId(tour.canvas_inner_id).style.width = (tour.item_width * tour.items.length) + 'px';
        var indicator_text = '';
        for (var i = 0; i < tour.items.length; i++) {
            tour.items[i].style.width = tour.item_width + 'px';
            indicator_text += '<a onmousedown="tour.go_to(' + i + ');"><span>' + tour.items[i].getElementsByTagName('h2')[0].innerHTML + '</span></a>';
            //tour.indicator_items[i] = document.createElement('a');
            //tour.indicator_items[i].innerHTML = tour.items[i].getElementsByTagName('h2')[0].innerHTML;
            tour.items[i].getElementsByTagName('h2')[0].style.display = 'none';
        }
        getId(tour.indicator_id).innerHTML = indicator_text;
        tour.indicator_items = getId(tour.indicator_id).getElementsByTagName('a');
        getId(tour.indicator_id).style.marginLeft = parseInt((tour.items.length * 20 * (-1)) / 2) + 'px';


        getId(tour.headline_id).innerHTML = '<h2 class="flag">' + tour.items[tour.index].getElementsByTagName('h2')[0].innerHTML + '</h2>';
        //Link generierung
        getId(tour.button_id).innerHTML = '';


        //Button Previous
        tour.button_prev = document.createElement('a');
        tour.button_prev.className = 'buttonPrev';
        tour.button_prev.innerHTML = '<span>vorheriger</span>';
        tour.button_prev.onmousedown = function() { tour.click_prev(); };

        //Button Next
        tour.button_next = document.createElement('a');
        tour.button_next.className = 'buttonNext';
        tour.button_next.innerHTML = '<span>nächster</span>';
        tour.button_next.onmousedown = function() { tour.click_next(); };

        getId(tour.button_id).appendChild(tour.button_prev);
        getId(tour.button_id).appendChild(tour.button_next);

        tour.indicator_items[tour.index].className = 'current';
    }
};
tour.click_prev = function() {
    var i = tour.index - 1;
    tour.go_to(i);
};
tour.click_next = function() {
    var i = tour.index + 1;
    tour.go_to(i);
};
tour.go_to = function(i) {
    if (!isNaN(parseInt(i))) {

        if (i < 0) {
            i = tour.items.length - 1;
        } else if (i >= tour.items.length) {
            i = 0;
        }

        if (i == 0) {
            tour.offset = 0;
        } else {
            tour.offset = tour.item_width * i * (-1);
        }
        tour.move_canvas_inner();
        getId(tour.headline_id).innerHTML = '<h2 class="flag">' + tour.items[i].getElementsByTagName('h2')[0].innerHTML + '</h2>';
        tour.indicator_items[tour.index].className = '';
        tour.index = i;
        tour.indicator_items[i].className = 'current';
    }
}


tour.move_canvas_inner = function() {
    $(getId(tour.canvas_inner_id)).animate({
        marginLeft: tour.offset
    }, tour.time_animation, function() { });
};
function getId(id) {
    return document.getElementById(id);
}

//round Border
function initiateRoundBorder(id) {
    if (navigator.userAgent.indexOf('MSIE 6.') > -1) {
        // code for ie 6
    } else {
        var parent = document.getElementById(id);
        if (parent) {
            var img = parent.getElementsByTagName('img');
            for (var i = 0; i < img.length; i++) {
                if (img[i].getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder' &&
            img[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('rel') != 'noBorder') {
                    var div0, div1, div2, div3;
                    div0 = document.createElement('div');
                    div1 = document.createElement('div');
                    div2 = document.createElement('div');
                    div3 = document.createElement('div');



                    var newData = img[i];

                    if (newData.getAttribute('align') == 'right') {
                        div0.className = 'roundBorderRight';
                    } else {
                        div0.className = 'roundBorderLeft';
                    }
                    newData.removeAttribute('align');

                    img[i].parentNode.replaceChild(div0, img[i]);

                    div3.appendChild(newData);
                    div2.appendChild(div3);
                    div1.appendChild(div2);
                    div0.appendChild(div1);
                }
            }
        }
    }
};
//isInclude=true
function checkForNewsletterExamples(param) {
    var links = document.getElementsByTagName('a');
    var modifyPoint = new Array();
    for (var i = 0; i < links.length; i++) {
        if (links[i].getAttribute('href') != null) {
            if (links[i].getAttribute('href').indexOf(param) > -1) {
                modifyPoint.push(links[i]);
                //alert('found');
            }
        }
        //alert(links[i].getAttribute('href'));
    }
    if (modifyPoint.length > 0) {
        for (var j = 0; j < modifyPoint.length; j++) {
            //alert(modifyPoint[j].parentNode);
            $(modifyPoint[j].parentNode).load('/Includes/NewsletterExampleBanner.aspx #Coverflow', function() { iniateCoverflow();$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'mailworx'}); })
            //modifyPoint[j].parentNode.innerHTML = '<iframe src="/Includes/NewsletterExampleBanner.aspx" style="width:250px;height:190px;"scrolling="no" frameborder="0" />';
        }
    }
}
//fanBox=true
function checkForFaceBookFanBox(param) {
    var links = document.getElementsByTagName('a');
    var modifyPoint = new Array();
    for (var i = 0; i < links.length; i++) {
        if (links[i].getAttribute('href') != null) {
            if (links[i].getAttribute('href').indexOf(param) > -1) {
                modifyPoint.push(links[i]);
                //alert('found');
            }
        }
        //alert(links[i].getAttribute('href'));
    }
    if (modifyPoint.length > 0) {
        for (var j = 0; j < modifyPoint.length; j++) {
            //alert(modifyPoint[j].parentNode);
            modifyPoint[j].parentNode.innerHTML = '<iframe src="http://www.facebook.com/plugins/likebox.php?id=344012702239&amp;width=218&amp;connections=0&amp;stream=false&amp;header=false&amp;height=62&amp;css=http://www.mailworx.info/App_Themes/facebook_fan_box.css" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:218px; height:62px;" allowTransparency="true"></iframe>';
        }
            //'<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/de_DE"></script><script type="text/javascript">FB.init("5eb581f5291989b693550cb7fc85ad7c");</script><fb:fan profile_id="344012702239" css="http://www.mailworx.info/App_Themes/facebook_fan_box.css?1" stream="" connections="" width="218"></fb:fan>';}
    }
}
//add top anchor links to h2
function addTopAnchor(tag) {
    var parent = document.getElementById('ctl00_pnlContent');
    if (parent) {
        var items = parent.getElementsByTagName(tag);
        if (items.length > 0) {
            for (var i = 0; i < items.length; i++) {
                if (i != 0 && items[i].className == 'flag') {
                    var link = document.createElement('a');
                    items[i].appendChild(link);

                    link.innerHTML = '<span>top</span>';
                    link.setAttribute('class', 'topAnchor');
                    link.setAttribute('onclick', 'scrollToTop();');
                }
            }
        }
    }
}
function scrollToTop() {
    $('html, body').animate({ scrollTop: 0 }, 'slow');
}

function generateLinkButton() {
    var className = 'linkbutton';
    var items = document.getElementsByTagName('a');
    var buttons = null;

    if (items.length > 0) {
        for (var i = 0; i < items.length; i++) {
            if (items[i].className == className) {
                var inner = items[i].innerHTML;
                items[i].innerHTML = '<span class="before">&nbsp;</span><span class="data"><span class="inner">'+inner+'</span></span><span class="after">&nbsp;</span>';
            }
        }
    }
}