﻿function includeJavaScript(jsFile) {
    document.write('<script type="text/javascript" src="' + jsFile + '"></scr' + 'ipt>');
}

//includeJavaScript("/Root/System/Skins/TigazSkin/js/JQuery/ui.spinner.js");
includeJavaScript("/Root/System/Skins/TigazSkin/js/JQuery/jquery.ui.core.js");
includeJavaScript("/Root/System/Skins/TigazSkin/js/JQuery/jquery.ui.widget.js");
includeJavaScript("/Root/System/Skins/TigazSkin/js/JQuery/jquery.ui.button.js");
includeJavaScript("/Root/System/Skins/TigazSkin/js/JQuery/jquery.ui.position.js");
includeJavaScript("/Root/System/Skins/TigazSkin/js/JQuery/jquery.ui.autocomplete.js");
//includeJavaScript("/Root/System/Skins/TigazSkin/js/JQuery/ui.selectmenu.js");

includeJavaScript("/Root/System/Skins/TigazSkin/js/ComboBox.js");


$(document).ready(function() {
    $('#Tigaz_Index #mainTab1').addClass('act');
    $('#Tigaz_Index #tMainMenu .tab').mouseover(function() {
        var parentId = $(this).attr('id');
        $('#tMainMenu .tab').removeClass('act');
        $(this).addClass('act');
        $('#tIndexTabs .tab').hide();
        $('#' + parentId + 'Content').show();
    });


    $('#snQuickSearch').focus(function() {
        $(this).val('');
    });

    $('#tTopTools .fontSwitch').click(function(ev) {
        ev.preventDefault();
        var switchSize = $(this).attr('name');
        $('body').removeClass('smallFont normalFont largeFont').addClass(switchSize + 'Font');
        $.cookie("bodyFontSize", switchSize, { expires: 365 });
    });


    // login helper

    var loginInputs = $('.loginSkin .inputLine input');
    $(loginInputs).val('');
    $(loginInputs).focus(function() {
        $(this).siblings('label').hide();
    }).blur(function() {
        if ($(this).val() == "") {
            $(this).siblings('label').show();
        }
    }).keyup(function() {
        if ($(this).val().length) {
            $(':password').siblings('label').hide();
        }
    });


    //fade images on index

    if ($('#Tigaz_Index').length) {
        var baseItem = $('#tSlide');
        var tLength = baseItem.children('li').length;
        var paramClass = baseItem.attr('class').split('_');
        var itemNo = 1;

        var paramFadeIn = parseInt(paramClass[1]);
        var paramFadeOut = parseInt(paramClass[2]);
        var paramTimeOut = parseInt(paramClass[3]);


        function fadeImage() {
            $('#tSlide li#item' + itemNo).fadeOut(paramFadeOut);
            if (itemNo < tLength) { itemNo++; }
            else { itemNo = 1; }
            $('#tSlide li#item' + itemNo).fadeIn(paramFadeIn);
            timeOut();
        }
        function timeOut() {
            setTimeout(function() {
                fadeImage()
            },
            paramTimeOut);
        }
        timeOut();
    };

    //Show-hide offices on indexen

    $('#offices .parent').click(function(ev) {
        ev.preventDefault();
        if ($(this).hasClass('opened')) {
            $(this).siblings('.child').slideDown(300);
            $(this).removeClass('opened');
        } else {
            $(this).siblings('.child').slideUp(300);
            $(this).addClass('opened');
        }
    });

    $('#tFooterTigaz select').change(function(ev) {
        ev.preventDefault();
        if ($(this).find('option[value*="http"]:selected').val()) {
            var url = $(this).attr('value');
            window.open(url, '_blank');
        }
    });

    // Favorites

    var docTitle = document.title;
    var docUrl = document.location;

    $("#favLink").attr({
        'rel': function() { return (window.opera && this.rel.length > 0) ? this.rel : 'sidebar'; }, // set rel for Opera 7+
        'title': docTitle	// set title
    }).click(function(ev) {
        ev.preventDefault();
        if (window.opera) return true;
        if (window.sidebar) { // Mozilla Firefox Bookmark
            window.sidebar.addPanel(docTitle, docUrl, '');
        } else if (window.external) { // IE Favorite
            window.external.AddFavorite(docUrl, docTitle);
        }
    });

    $('#printLink').click(function(ev) {
        ev.preventDefault();
        window.print();
    });

    // LightBox
    if ($('.lightbox-enabled').length) {
        $('.lightbox-enabled').colorbox();
    }

    // Content Toolbox

    var catLink = $('.tTools .catLink');

    $(catLink).click(function(ev) {
        ev.preventDefault();
        if ($(this).hasClass('open')) {
            $(this).removeClass('open').siblings('div').slideUp(200);
        }
        else {
            $(catLink).siblings('div').slideUp(200);
            $(catLink).removeClass('open');
            $(this).addClass('open').siblings('div').slideDown(200);
        }
    });

    // Content with tabs

    if ($('#Tigaz_Content #tabs').length) {
        var baseItem = $('#Tigaz_Content #tabs');
        tabSwitch();
    }

    function tabSwitch() {
        baseItem.find('ul.tabWrapper li a').click(function(ev) {
            ev.preventDefault();
            var href = $(this).attr('href').slice(1);

            if ($(this).parent().not('active')) {
                baseItem.find('li.active').removeClass('active');
                $(this).parent().addClass('active');
                $('.tabContent').removeClass('active');
                $('#' + href).addClass('active');
            }
        });
    }


    //dictation
    var fixData = $('.fixData a');
    fixData.hide();
    $(".currentData input").keyup(function() {
        var begin = $('.diff input').val().substring(0, 1);
        if ($(this).val() != "") {
            fixData.css('display', 'block');
            if (begin == 'N' || begin == "-") {
                $('.calcData').hide();
            }
            else { $('.calcData').show(); }
        }
        else {
            fixData.hide();
        }
    });



    // Map for offices

    $('#mapWrapper a.right').hover(
    function(ev) {
        if ($.browser.msie) {
            $('#mapWrapper a').removeClass('hover');
            $(this).addClass('hover');
        }
        var origLeft = $(this).position().left;
        var origWidth = $(this).width();
        var newLeft = origLeft - origWidth;
        if ($(this).hasClass('head-office')) {
            newLeft -= 13;
        } else {
            newLeft -= 6;
        }
        $(this).css('left', newLeft + 'px');
        $(this).mouseout(function(ev) {
            $(this).css('left', origLeft + 'px');
        });
    },
    function(ev) {
        if ($.browser.msie) {
            $(this).removeClass('hover');
        }
    });

    //tooltip
    snTooltip(".tooltipimg", "jsTooltip");

    // suggestContent

    $('#mailLink').click(function(ev) {
        ev.preventDefault();
        $('.sendemailPopUp').show();
        $("#pageURLdiv input").val(document.location.href);
        $("#pageTitlediv input").val($(".tContent h3").text());

        $('.PopUpButtonRow input').click(function(fv) {

            $('.PopUpFormRow .tText').each(function() {
                if ($(this).attr('value') == "") {
                    $(this).addClass('empty');
                    $(this).css('border', '1px solid red');
                }
                else {
                    $(this).removeClass('empty');
                    $(this).css('border', '1px solid #DEDEDE');
                }
            });
            if ($('.PopUpFormRow .empty').length) {
                return false;
            }
            else {
                return true;
            }
        });
    });
    $('.PopUpClose div').click(function() {
        $('.sendemailPopUp').hide();
    });

    //make all checkbox to unchecked by default
    $("span.szezonCheckBox input:checked").parent(".szezonCheckBox").next("#szezonDiv").css('display', 'inline');

    //szezonalis fogyaszto checkbox
    $("span.szezonCheckBox input").click(function() {
        if (this.checked) {
            $(this).parent(".szezonCheckBox").next("#szezonDiv").css('display', 'inline');
        }
        else {
            $(this).parent(".szezonCheckBox").next("#szezonDiv").hide();
            $(this).parent(".szezonCheckBox").next(".inputBoxes input").val('');
        }
    });

    //onRegistrationSubmit check
    $("#regForm input[type='submit']").click(function() {
        var adatV = $("#regForm #adatVedelmi input");
        //var onlineF = $("#regForm #szerzodesiFeltetel input");

        if (adatV[0].checked) {
            /*if (onlineF[0].checked) {
                //regButton.submit
                $(this).parent("form").submit();
            } else {
                alert("Az Online szerződés feltételeit el kell fogadni a regisztrációhoz!");
                return false;
            }*/

            //regButton.submit
            $(this).parent("form").submit();
        } else {
            alert("Az adatvédelmi nyilatkozatot el kell fogadni a regisztrációhoz!");
            return false;
        }
    });

    //numeric up-down
    $(".inputSpinner").each(function() {
        $(this).spinner({ max: 100, min: 0 });
    });

    //autocomplete combobox
    //$("#combobox").each(function() {
    //    $(this).combobox();
    //});

    $(".combobox option").click(function() {
        if ($(this).is("[value='other']")) {
            $(this).parents('.wrapper').siblings("div#other").show();
        } else {
            $(this).parents('.wrapper').siblings("#other").hide();
        }

    });


});

function snTooltip(targetItem, className) {

    $(targetItem).each(function(i) {
        $("body").append("<div class='" + className + "' id='" + className + i + "'><div><p><span></span>" + $(this).attr('title') + "</p></div></div>");

        var tooltipId = $("#" + className + i);
        var thisLeft = parseInt($(this).position().left) + 50;
        var thisTop = parseInt($(this).position().top) - 10;

        if ($(this).attr("title") != "") {

            $(this).removeAttr("title").hover(
            function(ev) {
                ev.stopPropagation();
                tooltipId.css({ left: thisLeft, top: thisTop }).show(100);
            },
            function() {
                tooltipId.hide(100);
            });
        }
    });
}
