$(document).ready(function() {
    if($("#authMessage") != null)
    {
        $("#authMessage").highlightStyle();
    }

    if($(".errorMessage") != null)
    {
        $(".errorMessage").errorStyle();
    }

    if($(".noteMessage") != null)
    {
        $(".noteMessage").highlightStyle();
    }

    if($(":submit") != null)
    {
        $(":submit").button();
    }


        $("a.button, a[id^=button]").button();



        /*$("a.toggleButton").button({
            icons: {
                primary: "ui-icon-refresh"
            },
            text: false
        });*/

    if($(".radio") != null)
    {
        $(".radio").buttonset();
    }

    if($( "#tabs" ) != null)
    {
        $("#tabs").tabs();
    }

    if($(".datepicker") != null)
    {
        $(".datepicker").datepicker($.datepicker.regional["de"]);
        $(".datepicker").datepicker( "option", "dateFormat", "yy-mm-dd");
    }

    if($("#dialog") != null)
    {
        $("#dialog").dialog({
            autoOpen: false,
            modal: true
        });
    }

    if($("dialog-modal" != null))
    {
        $("#dialog-modal").dialog({
            modal: true,
            width: 600
        });
    }

    $(function(){
        $("[title]").mbTooltip({
            opacity : .65,
            wait:200,
            cssClass:"default",
            timePerWord:7000,
            hasArrow:false,
            hasShadow:true,
            imgPath:"images/",
            anchor:"mouse",
            shadowColor:"black",
            mb_fade:200
        });
    });
});


$.fn.errorStyle = function() {
    this.replaceWith(function(i,html){
        var StyledError = "<div class=\"ui-state-error ui-corner-all\" style=\"padding: 0 .7em;\">";
        StyledError += "<p><span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: .3em;\">";
        StyledError += "</span><strong>Fehler: </strong>";
        StyledError += html;
        StyledError += "</p></div>";
        return StyledError;
    });
}

$.fn.highlightStyle = function() {
    this.replaceWith(function(i,html){
        var StyledError = "<div class=\"ui-state-highlight ui-corner-all\" style=\"padding: 0 .7em;\">";
        StyledError += "<p><span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: .3em;\">";
        StyledError += "</span><strong>Hinweis: </strong>";
        StyledError += html;
        StyledError += "</p></div>";
        return StyledError;
    });
}

jQuery(function($){
    $.datepicker.regional['de'] = {
        closeText: 'schließen',
        prevText: '&#x3c;zurück',
        nextText: 'Vor&#x3e;',
        currentText: 'heute',
        monthNames: ['Januar','Februar','März','April','Mai','Juni',
        'Juli','August','September','Oktober','November','Dezember'],
        monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun',
        'Jul','Aug','Sep','Okt','Nov','Dez'],
        dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
        dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
        dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
        weekHeader: 'Wo',
        dateFormat: 'dd.mm.yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
    $.datepicker.setDefaults($.datepicker.regional['de']);
});
