/**
 * Created by Benny on 12.10.2014.
 */
"use strict";

var TB = TB || {};

TB.log = function( data ) {
    console.log( data );
};

TB._ = function( str, params ) {
    if ( TB.Lang.hasOwnProperty( str ) ) {
        if ( params ) {
            var str = TB.Lang[str];
            return str.replace(/{(\d+)}/g, function(match, number) {
                return typeof params[number] != 'undefined'
                    ? params[number]
                    : match;
            });
        } else {
            return TB.Lang[ str ];
        }
    } else {
        return str;
    }
};

// Extend jQuery
$.fn.serializeObject = function()
{
    var o = {};
    var disabled = this.find(':input:disabled').removeAttr('disabled');
    var a = this.serializeArray();
    disabled.attr('disabled','disabled');
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

$.fn.exists = function () {
    return this.length !== 0;
}