﻿$(document).ready(function() {

    var actualLang = $("html").attr("lang");
    if (actualLang == "en") {
        $("body").addClass("langEn");
    }

    if (actualLang == "cz") {
        $("body").addClass("langCz");
    }

    $("div.fontResize a").each(function(i) {
        if (i == 0) {
            $(this).click(function() {
                setActiveStyleSheet('small');
                return false;
            });

        } else if (i == 2) {
            $(this).click(function() {
                setActiveStyleSheet('large');
                return false;
            });
        } else {
            $(this).click(function() {
                setActiveStyleSheet('default');
                return false;
            });
        }
    });


    var emails = $(".encodedAddress");
    for (var i = 0, j = emails.length; i < j; i++) {
        var anchor = document.createElement("a");
        var textField = emails[i].innerHTML.replace("[at]", "@");
        var text = emails[i].title;
        if (text == null || text.length == 0) {
            text = textField;
        }

        anchor.appendChild(document.createTextNode(text));
        anchor.setAttribute("href", "mailto:" + textField);
        emails[i].parentNode.replaceChild(anchor, emails[i]);
    }

    $(".printIcon").click(function() {
        window.print();
        return false;
    });

    $(".backIcon").click(function() {
        history.go(-1);
        return false;
    });

    $("#pmenu2 li.submenu li:first-child").css("border-top", "0");
    $("div.hchoices:last").after('<div style="clear: both"></div>');
    $("#pmenu2 li.active").next("li").css("background", "none");

    $("#pmenu2 > li").hover(function() {
        $(this).next("li").addClass("SepRemoved");
    },
    function() {
        $(this).next("li").removeClass("SepRemoved");
    });


    // stare schovavace praveho menu
    /*$('h3.icofunds a').click(function() {
    $(".aktualneKurzy").stop(true, true).toggle();
    return false;
    });*/
    $('.logIn').click(function() {
        $("#header #roll").stop(true, true).toggle("fast");
        return false;
    });

    // Nove schovavace
    $(".rcontent h3").append('<a href="" class="colapsator"><img alt="" src="/Img/fundshow.gif"></a>');
    //$(".rcontent .schovaj").toggle(); 

    $(".rcontent div h3").click(function() {
        $(this).parent().find(".schovaj").stop(true, true).toggle();
        return false;
    });


    //osetrenie zobrazenia login boxu pre validaciu
    var loginInputVal = $("#header #roll input.tEmail").val();
    var valLogin = $("#header #roll .valLogin").css("display");
    if (loginInputVal != "" && valLogin != "none") {
        $("#header #roll").toggle("fast");
    }
    else {
        $("#header #roll").hide();
    }

    var countTabs = $('.tabsDiv').length;
    if (countTabs > 0) {
        if ($('.tabs li:has(a[href="#tab0"])').length > 0) {
            $('.tabs li:has(a[href="#tab0"])').addClass('active');
            $('.tabsDiv').hide();
            $('#tab0').show();
        }
        else {
            $('.tabs li:has(a[href="#tab1"])').addClass('active');
            $('.tabsDiv').hide();
            $('#tab1').show();
        }
    }

    $(".datepicker").datepicker({
        showOn: 'both',
        buttonImage: '/Img/calendar.gif',
        buttonImageOnly: true
    });

    $(".datepickNoCal").datepicker();

    /* dictionary tooltip */
    $(".dictionary").hover(function(e) {
        var idElm = $(this).attr("id");
        createTooltip(idElm, this);
    }, function() {
        $(".tooltip").remove();
    });

    function updatePosition(obj, wrp) {
        var objPosition = $(obj).offset();
        var span = wrp.find("span");
        var leftArr = $(obj).width() / 2;

        var posX = objPosition.left;
        var posY = objPosition.top + 25;
        wrp.css({ left: posX - 7, top: posY });
        span.css({ left: leftArr, top: -7 });
    }

    function createTooltip(idStr, thisObj) {
        var webMethod = '/dictionaryservice.asmx/GetDictionaryText';
        var arrID = idStr.split("_");
        var parameters = '{"idStr":"' + arrID[1] + ";" + arrID[2] + '"}';
        var output;
        $.ajax({
            type: "POST",
            url: webMethod,
            data: parameters,
            contentType: 'application/json; charset=utf-8',
            dataType: "json",
            success: function(response) {
                output = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                var wrp = $("<div/>");
                var arr = $("<span/>");
                var title = $("<h3/>");
                var txt = $("<div/>");
                wrp.attr("class", "tooltip");
                arr.attr("class", "arrow");
                txt.attr("class", "text");
                title.text(output.title);
                txt.html(output.txt);
                wrp.append(title);
                wrp.append(txt);
                wrp.append(arr);
                $(document.body).append(wrp);
                updatePosition(thisObj, wrp);
            },
            error: function(e) {
                alert("err");
            }
        });
    }
    /**/

});

$.datepicker.regional['sk'] = { clearStatus: '',
    prevText: '< Predošlý',
    nextText: 'Naledujúci >',
    monthNames: ['Január', 'Február', 'Marec', 'April', 'Máj', 'Jún', 'Júl', 'August', 'September', 'Október', 'November', 'December'],
    weekStatus: '',
    dayNamesMin: ['Ne', 'Po', 'Ut', 'St', 'Št', 'Pi', 'So'],
    dateFormat: 'dd.mm.yy', firstDay: 1
};
$.datepicker.regional['en'] = { clearStatus: '',
    prevText: '< Previous',
    nextText: 'Next >',
    monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    weekStatus: '',
    dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    dateFormat: 'dd.mm.yy', firstDay: 1
};
$.datepicker.regional['cz'] = { clearStatus: '',
    prevText: '< Předchozí',
    nextText: 'Další >',
    monthNames: ['Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'],
    weekStatus: '',
    dayNamesMin: ['Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So'],
    dateFormat: 'dd.mm.yy', firstDay: 1
};

$.datepicker.setDefaults($.datepicker.regional[$("html").attr("lang")]);

$('.tabs li a').live('click', function(e) {
    e.preventDefault();

    $('.tabs li').removeClass('active');
    $(this).parent().addClass('active');
    var divId = $(this).attr('href');

    $('.tabsDiv').each(function() {
        $(this).hide();
    });

    $(divId).show();

});

