﻿var ID_PREFIX = "ctl00_ContentPlaceHolder_content_";
var JQ_ID_PREFIX = "#" + ID_PREFIX;

//checks if the array contains the element
Array.prototype.contains = function(element) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            return true;
        }
    }
    return false;
}

//checks if any of the expression in the array match the given text
Array.prototype.matches = function(text) {
    for (var i = 0; i < this.length; i++) {
        if (text.search(this[i]) != -1) {
            return true;
        }
    }
    return false;
}

$(document).ready(function() {
    if (GLOBAL_LANGUAGE = 'de') {
        $.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'],
            dateFormat: 'dd.mm.yy', firstDay: 1,
            isRTL: false
        };

        //datepicker localization
        $.datepicker.setDefaults($.datepicker.regional[GLOBAL_LANGUAGE]);
    }    

    //IE checkbox change() fix
    $("input:checkbox, input:radio").click(function() {
        if ($.browser.msie) {
            this.blur();
            this.focus();
        }
    });

    //disable postback on enter key
    //    $(document).keypress(function(e) {
    //        return (e.which != 13);
    //    });    

    //add maxlength-functionality to textarea. use class="maxlength_100" on a textarea and add a label with the for-attribute assigned to the textarea's id
    var fn = function(sender) {
        var obj = $(sender);
        var max = parseInt(obj.attr('class').match(/(maxlength_)([0-9]*)/)[2]);

        //remove characters if to many
        if (obj.val().length > max)
            obj.val(obj.val().substr(0, max));

        //display the remaining characters
        $('label[for=' + sender.id + ']').html(max - obj.val().length);
    };

    $('textarea[class*=maxlength_]').bind('keyup paste input', function() { fn(this); }).trigger('keyup'); //trigger the event once to refresh label

    //each ajax request will change the cursor to wait
    //$("html").bind("ajaxStart", function() { $(this).addClass('busy'); }).bind("ajaxStop", function() { $(this).removeClass('busy'); });

    //social bookmarks
    bookmarkPages = ["/", "/forum/", "/news.aspx", "/community.aspx", "/timetable.aspx"];
    bookmarkPageExpressions = [/^\/event\/[0-9]+_.+\.html/, /^\/garage\.aspx/, /^\/(profile|circledb|forum)\/[0-9]+_.+\.html/, /^\/(thumbs|gallery)\/.+\.html/, /^\/direct_[0-9].+\.html/, /^\/pics\.aspx/];

    if (bookmarkPages.contains(window.location.pathname) || bookmarkPageExpressions.matches(window.location.pathname))
        $("#social_bookmarks").show();
    else
        $("#social_bookmarks").remove();

    //    $("#social_bookmarks_content").bookmark({ compact: false }).hide();
    //    $("#social_bookmarks_button").click(function() {
    //        $(this).hide();
    //        $("#social_bookmarks_content").show();
    //        return false;
    //    });
});

function conForward(text,link)
{
    var doForward = confirm(text);
    if(doForward) {window.location.href = link;}
}

function toDuo(s)
{
    if (parseInt(s) < 10)
        return '0'+s;
    
    return s;
}
