﻿/// <reference path="/germany/dynamics/_global/components/infocenter/js/jquery-1.3.2-vsdoc2.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/extend/urlEncodeDecode.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/extend/getUrlParameters.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/extend/uniqueArray.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/extend/sortArray.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/extend/getUrlParametersFromUrlString.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/addCategoryId.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/deleteCategoryId.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/setWidthEqual.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/resetSelect.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/addCategoryToBasket.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/removeCategory.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/disableOption.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/hideElementsWhenCategoriesChanged.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/jquery.jtruncate.pack.js" />
/// <reference path="/germany/dynamics/_global/components/infocenter/js/plugins/jquery.string.1.0.js" />


jQuery.noConflict();
function clueTipActivate(obj, title) {
    var openFXEffect = 'fadeIn';
    obj.attr('title', title);
    obj.cluetip({ splitTitle: '_', fx: { open: openFXEffect }, sticky: true });
}
//CategorySearch variables end

var tabsPositionArray = new Array();
var tabId = 0;
var userInteraction = false;
var userInteractionFirst = false;
var activeTabPositionId = 0;

var resultTableContentDiv = '#icResultsWin #resultTableBox .win .cont';

jQuery(document).ready(function($) {


    //wenn free text search active than hide category search
    if (jQuery.gup(resultModeVars['key']) == 2) {
        if (catVars['categorySelectObj'].html() != null) {
            catVars['categorySearchMaskSelectDiv'].slideUp();
        }
    }
    if (jQuery.gup(sisVars.key) != null) {
        if (catVars['categorySelectObj'].html() != null) {
            catVars['categorySearchMaskSelectDiv'].slideUp();
        }
    }
    $('#smask').hover(
        function() {
            if (catVars['categorySelectObj'].html() != null) {
                catVars['categorySearchMaskSelectDiv'].slideDown();
            }
        }
    );
    $('#tagSubmit').hover(
        function() {
            if (catVars['categorySelectObj'].html() != null) {
                catVars['categorySearchMaskSelectDiv'].slideDown();
            }
        }
    );

    //Submit Form Actions
    catVars['form'].submit(function() {
        if (ftsVars['obj'].val() == ftsVars['blindCopy']) {
            ftsVars['obj'].val('');

        }
        //Check if free text search input is not empty than set resultMode to FreeTextSearch
        if (ftsVars['obj'].val() != '') {
            resultModeVars['obj'].val(2);
            catVars['categoriesObj'].val('');
        } else {
            resultModeVars['obj'].val(1);
        }

        return true;
    });

    //FreeText Search Start
    //initial set field to standard value

    if (jQuery.gup(ftsVars['ftsKey']) != null && jQuery.gup(ftsVars['ftsKey']) != "") {
        ftsVars['obj'].css({ 'color': '#000' });
    } else {
        ftsVars['obj'].val(ftsVars['blindCopy']);
        ftsVars['obj'].css({ 'color': '#ccc' });
    }
    ftsVars['obj'].click(function() {
        if (ftsVars['blindCopy'] == $(this).val()) {
            $(this).val('');
            ftsVars['obj'].css({ 'color': '#000' });
        }
        catVars['categorySearchMaskSelectDiv'].slideUp();
    });
    ftsVars['submitObj'].click(function() {
        resultModeVars['obj'].val(2);
        ftsVars['formObj'].submit();
    });
    //FreeText Search End

    //Category Search Start
    //*** fill all baskets with a &nbsp;
    catVars['categorySelectObj'].each(function() {
        //clear basket before refill
        $(this).next().children('.win').children('.cont').children('div').html('&nbsp;');
    });

    //set initial categories inputfield
    if (jQuery.gup(catVars['categoryUrlKey']) != null && jQuery.gup(catVars['categoryUrlKey']) != "") {
        var urlCategoriesString = jQuery.trim(jQuery.gup(catVars['categoryUrlKey']).split('+').join(' '));
        catVars['categoryArray'] = urlCategoriesString.split(' ');
        catVars['categoriesObj'].val(urlCategoriesString);
        //add categories to basket
        //catVars['categorySelectObj'].addCategoryToBasket(null, catVars['categoriesObj']);
        catVars['pageLoadCategoryValues'] = urlCategoriesString;
        catVars['categoriesObj'].addCategoryToBasket();

    }
    else {
        catVars['categoriesObj'].val('');
    }
    //*** setCategorySelectObj width equal ***
    catVars['categorySelectObj'].setWidthEqual();


    //*** delete all categories ***
    catVars['deleteAllCategoriesObj'].click(function() {
        //delete all categories in basket
        catVars['categorySelectObj'].each(function() {
            $(this).next().children('.win').children('.cont').children('div').html('&nbsp;');
        });
        //delete categories from input field
        catVars['categoriesObj'].val('');
        //        if (jQuery.browser.mozilla) {
        //            console.log("#cat: '" + catVars['categoriesObj'].val() + "'");
        //        }
        //hide elements when category changed
        $.fn.hideElementsWhenCategoriesChanged();

        catVars['categoriesObj'].disableOptions();

    });

    //*** Category Selects ***
    catVars['categorySelectObj'].change(function() {
        //add category to basket
        catVars['categoriesObj'].addCategoryToBasket($(this).val());
        //reset Selects
        $(this).resetSelect();
        if (catVars['autoSubmitFormOnChange']) {
            //try submit onchange categories
            catVars['form'].submit();
        }
    });
    //*** searchMask ***
    catVars['searchMaskObj'].change(function() {
        //remove all categories
        catVars['categoriesObj'].val('');
        $('#orderby').remove();
        //set tabsetid & default tabid
        $(this).find('option').each(function() {
            if (catVars['searchMaskObj'].val() == $(this).val()) {
                //set tabsetid
                catVars['tabSetIdObj'].val($(this).attr(catVars['searchMaskTabSetIdKey']));
                //set default tabid
                catVars['tabIdObj'].val($(this).attr(catVars['searchMaskTabIdKey']));
            }
        });
        ftsVars['obj'].val('');
        //SetResultMode to CategorySearch
        resultModeVars['obj'].val(1);
        //submit form
        catVars['form'].submit();
    });
    //*** searchMethod ***
    catVars['searchMethodObj'].change(function() {
        //SetResultMode to CategorySearch
        //submit form
        catVars['form'].submit();
    });
    //*** itemsPerPage ***
    catVars['itemsPerPageObj'].change(function() {
        //SetResultMode to CategorySearch
        //submit form
        catVars['form'].submit();
    });
    //Category Search End

    //TabNavi start
    if (tabVars['tabsNaviContObj'].position() != undefined) {
        tabVars['tabsNaviContObj'].css({ 'position': 'absolute', 'left': tabVars['tabsNaviContObj'].position().left + "px", 'top': tabVars['tabsNaviContObj'].position().top + "px" });
        tabVars['forwardBtnObj'].click(function() {
            flag = true;
            tabVars['tabsNaviContObj'].children().each(function() {
                if (flag) {
                    //obj1Position = $(this).next().next().position().left - $(this).position().left;
                    $(this).clone().appendTo(tabVars['tabsNaviContObj']);
                    $(this).next().clone().appendTo(tabVars['tabsNaviContObj']);
                    $(this).next().remove();
                    $(this).remove();
                    flag = false;
                } else {
                    return false;
                }

            });
        });
        tabVars['backBtnObj'].click(function() {
            flag = true;
            tabVars['tabsNaviContObj'].find(':last').each(function() {
                if (flag) {
                    $(this).clone().prependTo(tabVars['tabsNaviContObj']);
                    $(this).prev().clone().prependTo(tabVars['tabsNaviContObj']);
                    $(this).prev().remove();
                    $(this).remove();
                    flag = false;
                } else {
                    return false;
                }
            });
        });
        //set on load active tab to first one
        tabVars['tabsNaviContObj'].scrollToActiveTab();
    }
    //TabNavi end



    //ToolTips
    helpVars.showObj.qtip({
        content: { title: helpVars.showToolTipTitle, text: helpVars.showToolTipTxt },
        position: { corner: { target: 'bottomLeft', tooltip: 'topRight'} },
        style: helpVars.style,
        show: helpVars.show,
        hide: helpVars.hide
    });

    helpVars.hideObj.qtip({
        content: { title: helpVars.hideToolTipTitle, text: helpVars.hideToolTipTxt },
        position: { corner: { target: 'bottomLeft', tooltip: 'topRight'} },
        style: helpVars.style,
        show: helpVars.show,
        hide: helpVars.hide
    });
    ctaVars['keywordsObj'].qtip({
        content: { text: $(this).parent().find('.ico_keywords').attr('title'), title: ctaVars['keywordsToolTipTitle'] },
        position: { corner: { target: 'bottomMiddle', tooltip: 'topMiddle'} },
        style: helpVars.style,
        show: 'mouseover',
        hide: 'mouseout'
    });
    $('.ico_info').qtip({
        content: { text: $(this).parent().find('.ico_keywords').attr('title'), title: "Infos" },
        position: { corner: { target: 'bottomLeft', tooltip: 'topRight'} },
        //style: helpVars.style,
        style: { width: 650, title: { 'background-color': '#164a79', 'color': '#fff' }, border: { color: '#164a79'} },
        show: 'mouseover',
        hide: 'mouseout'
    });

    catVars['tagSubmitBtnObj'].click(function() {
        ftsVars['obj'].val('');
        resultModeVars['obj'].val(1);
    });

    //toggle Hilfe Tooltips
    //show
    $('.showHelpToolTipsShow:first').click(function() {
        if ($(this).text() != helpVars.helpLinkHideTxt) {
            $(this).attr('showTxt', $(this).text());
            $(this).text(helpVars.helpLinkHideTxt);
            //Show Tooltips
            catVars['deleteAllCategoriesObj'].qtip({
                content: { text: catVars['deleteAllCategoriesToolTipTxt'], title: catVars['deleteAllCategoriesToolTipTitle'] },
                position: { corner: { target: 'bottomMiddle', tooltip: 'topMiddle'} },
                style: helpVars.style,
                show: helpVars.show,
                hide: helpVars.hide
            });
            ctaVars['emailItemObj'].qtip({
                content: { text: ctaVars['emailItemToolTipTxt'], title: ctaVars['emailItemToolTipTitle'] },
                position: { corner: { target: 'bottomLeft', tooltip: 'topRight'} },
                style: helpVars.style,
                show: helpVars.show,
                hide: helpVars.hide
            });

            catVars['searchMaskObj'].qtip({
                content: { title: catVars['searchMaskChoiceToolTipTitle'], text: catVars['searchMaskChoiceToolTipTxt'] },
                position: { corner: { target: 'bottomMiddle', tooltip: 'topMiddle'} },
                style: helpVars.style,
                show: helpVars.show,
                hide: helpVars.hide
            });
            catVars['searchMethodObj'].qtip({
                content: { title: catVars['searchMethodToolTipTitle'], text: catVars['searchMethodToolTipTxt'] },
                position: { corner: { target: 'bottomRight', tooltip: 'topLeft'} },
                style: helpVars.style,
                show: helpVars.show,
                hide: helpVars.hide
            });
            catVars['categoryBaskets'].qtip({
                content: { title: catVars['categorySelectToolTipTitle'], text: catVars['categorySelectToolTipTxt'] },
                position: { corner: { target: 'bottomMiddle', tooltip: 'topMiddle'} },
                style: helpVars.style,
                show: helpVars.show,
                hide: helpVars.hide
            });
            ftsVars['obj'].qtip({
                content: { title: ftsVars['toolTipTitle'], text: ftsVars['toolTipTxt'] },
                position: { corner: { target: 'bottomMiddle', tooltip: 'topMiddle'} },
                style: helpVars.style,
                show: helpVars.show,
                hide: helpVars.hide
            });
            catVars['deleteAllCategoriesObj'].qtip("enable");
            ctaVars['emailItemObj'].qtip("enable");
            catVars['searchMaskObj'].qtip("enable");
            catVars['searchMethodObj'].qtip("enable");
            catVars['categoryBaskets'].qtip("enable");
            ftsVars['obj'].qtip("enable");

        } else {
            $(this).text($(this).attr('showTxt'));
            $(this).removeAttr('showTxt')
            //Disable Tooltips
            $(this).css({ 'display': 'none' });
            $('.showHelpToolTipsShow').css({ 'display': '' });
            //catVars['deleteAllCategoriesObj'].qtip("disable");
            $('#deleteActiveCategories').qtip("disable");
            //ctaVars['emailItemObj'].qtip("disable");
            $('.icItemMenuUl li a.ico_email').qtip("disable");
            //ctaVars['keywordsObj'].qtip("destroy");
            //catVars['searchMaskObj'].qtip("disable");
            $('#smask').qtip("disable");
            //catVars['searchMethodObj'].qtip("disable");
            $('#smethod').qtip("disable");
            //catVars['categoryBaskets'].qtip("disable");
            $('#icTagSearchValues .icTagSelect .icTagSelectBasket').qtip("disable");
            //ftsVars['obj'].qtip("disable");
            $('#ftsInput').qtip("disable");
        }
    });

    //createOverlay
    $('.icItemCtaUl .overlay').each(function() {
        $(this).click(function() {
            switch ($(this).attr('contentType')) {
                case 'casestudy':
                    $(this).createOverlay({ 'ctaType': $(this).attr('contentType'), 'cta': $(this), 'windowWidth': $(this).attr('winWidth'), 'windowHeight': $(this).attr('winHeight') });
                    break;
                case 'image':
                    $(this).createOverlay({ 'ctaType': $(this).attr('contentType'), 'cta': $(this), 'imageWidth': $(this).attr('imgWidth'), 'imageHeight': $(this).attr('imgHeight'), 'windowWidth': $(this).attr('winWidth'), 'windowHeight': $(this).attr('winHeight') });
                    break;
                case 'video':
                    $(this).createOverlay({ 'ctaType': $(this).attr('contentType'), 'cta': $(this), 'windowWidth': $(this).attr('winWidth'), 'windowHeight': $(this).attr('winHeight') });
                    break;
            }
        });
    });

    //guidCopy
    $('.guidCopyA').each(function() {
        $(this).click(function() {
            document.getElementById('guidCopy').innerText = $(this).text();
            Copied = document.getElementById('guidCopy').createTextRange();
            Copied.execCommand("Copy");
        });
        if (!jQuery.browser.msie) {
            $(this).css({ display: 'none' });
        }
    });

    //Get Related Content
    $('#icResultsTbl .icTr .icRC .plus').each(function() {
        $(this).click(function() {
            //if related Content is already loaded
            var rcAvailable = false;
            if ($(this).hasClass('minus')) {
                $(this).parent().parent('.icTr').nextAll().each(function() {
                    if ($(this).hasClass('icTrRc')) {
                        $(this).css({ 'display': 'none' });
                    } else {
                        return false;
                    }
                });
            } else {
                $(this).parent().parent('.icTr').nextAll().each(function() {
                    if ($(this).hasClass('icTrRc')) {
                        $(this).css({ 'display': '' });
                        rcAvailable = true;
                    } else {
                        return false;
                    }
                });
            }
            //toggle between minus and plus
            $(this).toggleClass("minus");

        });
    });

});

function changeToUmlaute(input) {
    input = input.replace(/%C3%A4/g, "ä");
    input = input.replace(/%C3%B6/g, "ö");
    input = input.replace(/%C3%BC/g, "ü");
    input = input.replace(/%C3%84/g, "Ä");
    input = input.replace(/%C3%96/g, "Ö");
    input = input.replace(/%C3%9C/g, "Ü");
    input = input.replace(/%C3%9F/g, "ß");
    return input;
}
function qTipInsertLineBreaks(obj) {
    //alert(obj);
    return obj.parent('li').find('.ico_keywords').attr('title').replace(/nl/g, "<br />");
}

