﻿

$(document).ready(function () {

    // Event & Publication Search -----------------------------------------------------------------------
    // ------------------------------------------------------------------------------------
    $('#searchAreaLanguages').hide();
    $('#hideSearchAreaLanguages').hide();
    $('#searchAreaCategories').hide();
    $('#hideSearchAreaCategories').hide();
    $('#searchAreaTypes').hide();
    $('#hideSearchAreaTypes').hide();

    $("#showSearchAreaLanguages").click(function () {
        $('#searchAreaLanguages').show("fast");
        $('#hideSearchAreaLanguages').show();
        $('#showSearchAreaLanguages').hide();
    });

    $("#hideSearchAreaLanguages").click(function () {
        $('#searchAreaLanguages').hide("fast");
        $('#hideSearchAreaLanguages').hide();
        $('#showSearchAreaLanguages').show();
    });

    $("#showSearchAreaCategories").click(function () {
        $('#searchAreaCategories').show("fast");
        $('#hideSearchAreaCategories').show();
        $('#showSearchAreaCategories').hide();
    });

    $('#hideSearchAreaCategories').click(function () {
        $('#searchAreaCategories').hide("fast");
        $('#hideSearchAreaCategories').hide();
        $('#showSearchAreaCategories').show();
    });

    $("#showSearchAreaTypes").click(function () {
        $('#searchAreaTypes').show("fast");
        $('#hideSearchAreaTypes').show();
        $('#showSearchAreaTypes').hide();
    });

    $('#hideSearchAreaTypes').click(function () {
        $('#searchAreaTypes').hide("fast");
        $('#hideSearchAreaTypes').hide();
        $('#showSearchAreaTypes').show();
    });

    // Calendar

    $(function () {
        $('#DateFromTextbox').datepicker({ buttonImage: '/img/calendar.gif', buttonImageOnly: true, firstDay: 1, dateFormat: 'dd.mm.yy', showOn: 'both' });
        $('#DateToTextbox').datepicker({ buttonImage: '/img/calendar.gif', buttonImageOnly: true, firstDay: 1, dateFormat: 'dd.mm.yy', showOn: 'both' });
    });

    // Subvention Search -----------------------------------------------------------------
    // ------------------------------------------------------------------------------------

    $("div[name^='subventionCategoryContent-']").hide();
    $("a[name^='hideSubventionCategory-']").hide();

    $("a[name^='showSubventionCategory-']").click(function () {
        var id = this.name.replace('showSubventionCategory-', '')
        var divcontrol = $("div[name^='subventionCategoryContent-" + id + "']");
        divcontrol.show("fast");
        $("a[name^='hideSubventionCategory-" + id + "']").show();
        $("a[name^='showSubventionCategory-" + id + "']").hide();

    });

    $("a[name^='hideSubventionCategory-']").click(function () {
        var id = this.name.replace('hideSubventionCategory-', '')
        var divcontrol = $("div[name^='subventionCategoryContent-" + id + "']");
        divcontrol.hide("fast");
        $("a[name^='showSubventionCategory-" + id + "']").show();
        $("a[name^='hideSubventionCategory-" + id + "']").hide();

    });

    $("a[name^='SubventionCategory-']").click(function () {
        var id = this.name.replace('SubventionCategory-', '')
        var divcontrol = $("div[name^='subventionCategoryContent-" + id + "']");

        if(divcontrol.is(':visible')){
            divcontrol.hide("fast");
            $("a[name^='showSubventionCategory-" + id + "']").show();
            $("a[name^='hideSubventionCategory-" + id + "']").hide();
        }
        else{
            divcontrol.show("fast");
            $("a[name^='showSubventionCategory-" + id + "']").hide();
            $("a[name^='hideSubventionCategory-" + id + "']").show();
        }
    });


    // Placeholder hack -------------------------------------------------------------------
    // Not every browser understand HTML5 now. In HTML5 is the placeholder attribute normal
    // ------------------------------------------------------------------------------------
    $('[placeholder]').focus(function () {
        var input = $(this);
        if (input.val() == input.attr('placeholder')) {
            input.val('');
            input.removeClass('placeholder');
        }
    }).blur(function () {
        var input = $(this);
        if (input.val() == '' || input.val() == input.attr('placeholder')) {
            input.addClass('placeholder');
            input.val(input.attr('placeholder'));
        }
    }).blur().parents('form').submit(function () {
        $(this).find('[placeholder]').each(function () {
            var input = $(this);
            if (input.val() == input.attr('placeholder')) {
                input.val('');
            }
        })
    });

});



