﻿/********************/
function _(text, id) {
    return text;
}

/*** alert.js ***/
function sessionping(callback, cont) {
    if (dexconfig['ping.interval'] != null && dexconfig['ping.interval'] > 0) {
        window.setInterval(function() {
            $.ajax({
                method: 'POST',
                url: dexconfig['page.ping.name'],
                data: "control=" + cont + "&ez=10",
                dataType: 'text',
                complete: function(transport) {
                    var ct = transport.getResponseHeader('Content-Type');
                    var res = transport.responseText;
                    if (ct.match(/application\/x-redirect/)) {
                        location.href = res;
                    }
                    else if (ct.match(/text\/html/)) {
                        if (res.indexOf('Dexter.fw.login') > -1)
                            location.href = dexconfig['page.login.name'];
                    }
                    else {
                        callback(res);
                    }
                },
                error: function(request, textStatus, errorThrown) {

                }
            });
        }, dexconfig['ping.interval'] * 1000, callback);
    }
}

var isDexalertOpened = false;
function dexalert(message, title, callback, cparams, width, height) {
    var ret = true;

    if (typeof (height) == 'undefined' || height == null || height == -1)
        height = 'auto';
    if (typeof (width) == 'undefined' || width == null || width == -1)
        width = '300';
    if (width == -2)
        width = 'auto';

    if (!isDexalertOpened) {
        isDexalertOpened = true;
        if (title == null)
            title = 'Hiba';

        var el = $(document.body).createAppend(
        'div', { title: title }, message).hide();

        $(el).dialog({
            bgiframe: true,
            resizable: false,
            width: width,
            height: height,
            //show: 'slideDown',
            modal: true,
            overlay: {
                backgroundColor: '#000',
                opacity: 0.5
            },
            close: function(event, ui) {
                isDexalertOpened = false;
            },
            buttons: {
                'Ok': function() {
                    $(this).dialog('destroy');
                    el.remove();
                    isDexalertOpened = false;
                    if (typeof (callback) != 'undefined' && callback != null)
                        callback(cparams);
                }
            }
        });
        $(".ui-dialog-buttonpane button").wrapInner("<span/>");
    }
    else {
        ret = false;
    }

    return ret;
}

/*** ajaxaction.js ***/
function $1(id) {
    return document.getElementById(id);
}

function dexsubmit2(action, form, xtraparams, handler, options) {
    dexsubmit(action, form, xtraparams, handler, options['update_target_id'], options['method'], options['async'], options['insertion_mode'], options['show_loading']);
    return;
}

function dexsubmit(action, form, xtraparams, handler, contentid, method, async, insertionMode, showLoading) {
    //alert(action);

    //alert(insertionMode);
    var ajaxWorking = true;
    
    if (typeof (showLoading) == 'undefined' || showLoading == null)
        showLoading = true;

    if (showLoading) {
        var opleasewait = $1('ajaxbusy');

        var loadEl = $('<div style="z-index: 2000; background: black;" class="ui-widget-overlay"></div>');

        window.setTimeout(function() {
            if (ajaxWorking) {
                $(opleasewait).show();
                $(document.body).append(loadEl);
            }
        }, 500);
    }


    //    
    //    var loadEl = $(document.body).createAppend('div', { title: 'toltes' }, '');
    //    loadEl.attr('style', 'z-index: 2000; background: black;');
    //    loadEl.attr('class', 'ui-widget-overlay'); /* */
    //    loadEl.attr('onclick', '');
    //    loadEl.height($(document).height());
    //    loadEl.width($(document).width());
    //    

    //alert(FCKeditorAPI);
    // fckeditor
    if (typeof (FCKeditorAPI) != 'undefined') {
        for (var name in FCKeditorAPI.Instances) {
            var oEditor = FCKeditorAPI.Instances[name];
            oEditor.UpdateLinkedField();
        }
    }

    

    if (typeof (method) == 'undefined' || method == null)
        method = 'POST';

    if (typeof (async) == 'undefined' || async == null)
        async = true;

    var params = [];
    if (form) {
        if (typeof (form) == 'string') {
            params = $('#' + form).serializeArray();
        }
        else if (jQuery.isArray(form)) {
            jQuery.each(form, function () {
                if (form != '')
                    params = jQuery.merge(params, $('#' + this).serializeArray());
            });
        }
        else {
            params = $(form).serializeArray();
        }
    }

    

    //alert(params);

    if (xtraparams) {
        for (var k in xtraparams)
            params.push({ name: k, value: xtraparams[k] });
    }
    //params.push(xtraparams);
    //alert(typeof(xtraparams));
    //params=jQuery.merge(params, xtraparams);

    //alert(params);

    params.push({ name: 'X-Requested-With', value: 'XMLHttpRequest' });

    //alert(params);
    //    for (var k in params) {
    //        alert(k + ":" + params[k]);
    //    }

    url = action;

    var erroroccured = false;

    //alert(url);
    //alert(params);

    $.ajax({
        async: async,
        type: method,
        url: url,
        data: params,
        cache: false,
        processData: true,
        dataType: 'text',
        complete: function (transport) {
            if (erroroccured)
                return;

            var ct = transport.getResponseHeader('Content-Type');
            var res = transport.responseText;

            /*if (ct.match(/text\/errormsg-data/)) {
            eval('res = ' + res + ';');
            if (handler)
            handler(res);
            else
            dexalert('unhandled_error: ' + res);
            }*/
            /*else if (ct.match(/text\/errormsg/)) {
            dexalert(res);
            }*/
            if (ct.match(/text\/html/)) {
                if (res.indexOf('Dexter.fw.login') > -1)
                    location.href = dexconfig['page.login.name'];
                else {
                    // ie9 bug
                    if ($.browser.msie) {
                        res = res.replace(/td>\s+<td/g, 'td><td');
                    }
                    if (contentid && typeof (contentid) == 'string') {
                        if (typeof (insertionMode) != 'undefined' && insertionMode == 'ReplaceOuter')
                            $(contentid ? '#' + contentid : '#the_content').hide().after(res).remove();
                        else
                            $(contentid ? '#' + contentid : '#the_content').html(res);
                    }
                    else if (contentid) {
                        if (typeof (insertionMode) != 'undefined' && insertionMode == 'ReplaceOuter')
                            $(contentid).after(res).remove();
                        else
                            $(contentid).html(res);
                    }
                    else if (handler) {
                        handler(res);
                    }
                }
                if (SubmitReadyFunction != "") {
                    if (SubmitReadyFunctionParam != "") {
                        eval(SubmitReadyFunction)(SubmitReadyFunctionParam);
                    }
                    else {
                        eval(SubmitReadyFunction)
                    }
                }

                //alert($('#altkeresoform div:first')).size();
            }
            else if (ct.match(/application\/json/)) {
                eval('res = ' + res + ';');
                if (handler)
                    handler(res, 'json');
                /*else
                handlejson(res);*/
            }
            /*else if (ct.match(/text\/dexalert/)) {
            eval('res = ' + res + ';');
            dexalert(res.Message, res.Title);
            }*/
            //else if (ct.match(/text\/refresh/)) {
            //    location.reload(true);
            //}
            else if (ct.match(/text\/run/)) {
                var funcStr = "function() { " + res + "}";
                var func = eval('[' + funcStr + ']')[0];
                func();
                //jQuery.globalEval(res);
                //eval(res);
            }

            else if (ct.match(/application\/x-htmlpart/)) {
                try {
                    //alert(ct);
                    //var re = /<htmlpart[^>]*id="([^">]+)"[^>]*>((?:(?!<\/htmlpart)[\s\S])*)<\/htmlpart>/mig;
                    var re = /<htmlpart[^>]*id="([^">]+)"[^\/>]*(?:\/>|>((?:(?!<\/htmlpart)[\s\S])*)<\/htmlpart>)/mig;
                    var ms;
                    while ((ms = re.exec(transport.responseText))) {
                        //alert(ms[0]);
                        //var o = $('#' + ms[1]);
                        var o = $1(ms[1]);
                        var h = ms[2];
                        if (typeof (h) == 'undefined')
                            h = '';

                        if (o) {
                            $(o).html(h);

                        } else
                            alert('htmlpart missing: ' + ms[1]);
                        /*
                        if (o) {
                        o.innerHTML = '<div style="display:none;">ie-script-workaround</div>' + h;
                        var scripts = o.getElementsByTagName("script");
                        for (var lv = 0; lv < scripts.length; lv++) {
                        eval(scripts[lv].text);
                        }
                        */
                    }
                } catch (e) { alert('ERR:' + e.message); }
            } else if (ct.match(/application\/x-redirect/)) {
                location.href = res;
            }
            //ajaxfuncs();
            ajaxWorking = false;


            if (opleasewait) {
                loadEl.remove();
                $(opleasewait).hide();
                //opleasewait.remove();
            }
        },
        error: function (request, textStatus, errorThrown) {
            erroroccured = true;
            alert('AJAX error\n' + request.responseText);
            ajaxWorking = false;

            if (opleasewait) {
                loadEl.remove();
                $(opleasewait).hide();
                //opleasewait.remove();
            }
        }
    });
    return;
}

/*function handlemsg(res) {
var title = _('Válasz üzenet');
if (res.MessageType == 'Message') {
title = _('Hiba');
}

dexalert(res);
}

function handlejson(res) {
dexalert(res);
}*/

jQuery.download = function(url, form, method) {
    var params = [];
    if (form) {
        if (typeof (form) == 'string') {
            params = $('#' + form).serializeArray();
        }
        else if (jQuery.isArray(form)) {
            jQuery.each(form, function() {
                params = jQuery.merge(params, $('#' + this).serializeArray());
            });
        }
        else {
            params = form.serializeArray();
        }
    }

    data = params;

    //url and data options required
    if (url && data) {
        //data can be string of parameters or array/object
        data = typeof data == 'string' ? data : jQuery.param(data);
        //split params into form inputs
        var inputs = '';
        jQuery.each(data.split('&'), function() {
            var pair = this.split('=');
            inputs += '<input type="hidden" name="' + pair[0] + '" value="' + pair[1] + '" />';
        });
        //send request
        jQuery('<form action="' + url + '" method="' + (method || 'post') + '">' + inputs + '</form>')
        .appendTo('body').submit().remove();
    };
};


function naviPrint(id) {

    var a = $('#' + id + ' .table-sorted-desc');
    var desc = true;
    if (typeof (a.attr("id")) == 'undefined') {
        a = $(' #' + id + ' .table-sorted-asc');
        desc = false;
    }
    var rend = a.attr("id");
    var urlpost = "?_act=" + id + "/print&rendezes=" + rend + "&desc=" + desc;
    //var urlpost = "?_act=" + id + "/print";

    var url = location.href.replace(/#.*$/, '');
    url = url + urlpost;
    //alert(url);

    window.open(url, "Nyomtatás", "width=640,height=480,direktories=no,menubar=no,toolbar=no,scrollbars=yes");
    //location.href = url;

}
var popupdb = 0;
function dexpopupaction(url, title, width, height, ajax, onclose, extraparams, id, forms) {
    //alert('alam:'+ url);
    var href = url;
    //alert('1.');
    var hasId = false;

    // ha nincs id akkor generálni kell
    if (typeof (id) == 'undefined' || id == null || id == '') {
        popupdb++;
    }
    else {
        hasId = true;
    }

    if (typeof (ajax) == 'undefined')
        ajax = true;

    if (typeof (height) == 'undefined' || height == -1)
        height = 500;
    else if (height == -2)
        height = 'auto';
    if (typeof (width) == 'undefined' || width == -1)
        width = 780;

    if (typeof (title) == 'undefined' || title == null)
        title = '';

    if (typeof (onclose) == 'undefined' || onclose == null)
        onclose = null;

    //var buttons = {'bezárás': function(){$(this)}};

    if (ajax) {
        var el = $(document.body).createAppend('div', { title: title }, '').hide();

        el.attr('id', hasId ? id : 'popupp_' + popupdb);
        //alert($(".ui-dialog-titlebar-close"));

        $(el).dialog({
            bgiframe: true,
            modal: true,
            //show: 'fade',
            resizable: true,
            height: height,
            width: width,
            dialogClass: 'dialog_' + (hasId ? id : popupdb),
            overlay: {
                backgroundColor: '#000',
                opacity: 0.5
            },
            close: function (event, ui) {
                // disable tinymce instances
                if (typeof (tinyMCE) != 'undefined') {
                    var l = tinymce.editors.length;
                    for (var i = 0; i < l; i++) {
                        //tinyMCE.remove(tinymce.editors[i].id);
                        tinyMCE.execCommand('mceRemoveControl', false, tinymce.editors[i].id);
                    };
                }

                var tabid = el.find('.d_tabpanel').attr('id');

                if (tabid != 'undefined')
                    tabs[tabid] = null;

                $(this).dialog('destroy');
                el.remove();

                if (!hasId)
                    popupdb--;

                if (onclose)
                    onclose();
            },
            buttons: {
                'Bezár': function () {
                    // disable tinymce instances
                    if (typeof (tinyMCE) != 'undefined') {
                        for (var i = 0; i < tinymce.editors.length; i++) {
                            tinyMCE.execCommand('mceRemoveControl', false, tinymce.editors[i].id);
                        };
                    }

                    var tabid = el.find('.d_tabpanel').attr('id');

                    if (tabid != 'undefined')
                        tabs[tabid] = null;

                    $(this).dialog('destroy');
                    el.remove();

                    if (!hasId)
                        popupdb--;

                    if (onclose)
                        onclose();
                }
            }
        });

        //$(".ui-dialog-buttonpane button").wrapInner("<span/>");
        //$(".ui-dialog-titlebar-close").before('<a href="adfdas">hello</a>');

        dexsubmit(href, forms, extraparams, function(a) { $(el).html(a); }, null, 'POST', true);
    }
    else {

        if (onclose) {
            window.onchildclose = onclose;
        }

        var centerWidth = (window.screen.width - width) / 2;
        var centerHeight = (window.screen.height - height) / 2;

        var opened = window.open(href, '', 'width=' + width + ',height=' + height + ',left=' + centerWidth + ',top=' + centerHeight + ',menubar=no,toolbar=no,scrollbars=yes,resizable=1');
        
        //alert(opened.document.title);
        //opened.document.title = 'asfdfdaf'; 
        
    }

}

//function onchildclose() {
//    alert('hehe');
//}

function confirmAblak(title, message, callback, callback2) {
    var el = $(document.body).createAppend(
        'div', { title: title }, message).hide();

    $(el).dialog({
        bgiframe: true,
        resizeable: false,
        //show: 'fade',
        resizable: false,
        height: 'auto',
        // width: 'auto',
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
        buttons: {
            'Mégsem': function() {
                $(this).dialog('close');
            },
            'Elutasít': function() {
                $(this).dialog('close');
                callback2();
            },
            'Jóváhagy': function() {
                $(this).dialog('close');
                callback();
            }
        }
    });
}


function dexconfirm(title, message, callback) {
    var el = $(document.body).createAppend(
        'div', { title: title }, message).hide();

    $(el).dialog({
        bgiframe: true,
        resizeable: false,
        //show: 'fade',
        resizable: false,
        height: 'auto',
        // width: 'auto',
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
        buttons: {
            'Mégsem': function() {
                $(this).dialog('close');
            },
            'Igen': function() {
                $(this).dialog('close');
                callback();
            }
        }
    });
}
if ($.mask) {
    $.mask.definitions['2'] = '[0-2]';
    $.mask.definitions['5'] = '[0-5]';
}

$.fn.equals = function(compareTo) {
    if (!compareTo || !compareTo.length || this.length != compareTo.length) {
        return false;
    }
    for (var i = 0; i < this.length; i++) {
        if (this[i] !== compareTo[i]) {
            return false;
        }
    }
    return true;
}

var tabs = new Array();
function kuldCuccos(update_id, sel, url) {

    var param = "?$afe="; //"?%24afe=";
    $("#" + sel + " option:selected").each(function() {
        param += $(this).attr('saf');
    });
    dexsubmit2(url + param, [], null, null, { method: 'POST', insertion_mode: 'ReplaceOuter', loading_element_id: 'ajaxbusy', update_target_id: update_id, async: true })
}




/********** Form figyelés *************/
var FormOk = true; //Ezel lehet egy tabpanelen lévő form megváltozását jelezni ( true => okés nem változott semmi | false = változott valami a formon )
var FormKerdes = 'A oldalon vannak nem mentett adatok!\n Biztos el kívánja hagyni az oldalt?';

$.fn.FormObserve = function() {
    SubmitReadyFunctionParam = $(this).attr("id");
    SubmitReadyFunction = "FormObs";

    //    FormOk = true;
    //    $(this).find(':input').change(function() {
    //        FormOk = false;
    //    });
};
function FormObs(form_id) {
    //alert('He');
    SubmitReadyFunction = "";
    SubmitReadyFunctionParam = "";
    FormOk = true;
    $('#' + form_id).find(':input').change(function() {
        FormOk = false;
    });
}

// Ezt a fn-t a dexsubmit lefutatja ha végzet. ( persze csak ha van valami értéke!!! )
var SubmitReadyFunction = "";
var SubmitReadyFunctionParam = "";

function fancyEditor(selector, script_url, theme) {
    if (theme == 'simple') {
        $(selector).tinymce({
            // Location of TinyMCE script
            script_url: script_url, //'../tiny_mce/tiny_mce.js',

            // General options
            theme: 'advanced',

            // Theme options
            theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,|,undo,redo,|,cleanup,|,bullist,numlist",
            theme_advanced_buttons2: "",
            theme_advanced_buttons3: "",
            theme_advanced_buttons4: "",
            theme_advanced_toolbar_location: "top",
            /*theme_advanced_toolbar_align: "left",*/
            theme_advanced_statusbar_location: "bottom",
            theme_advanced_resizing: false

            // Example content CSS (should be your site CSS)
            //            content_css: "css/content.css",

            // Drop lists for link/image/media/template dialogs
            //            template_external_list_url: "lists/template_list.js",
            //            external_link_list_url: "lists/link_list.js",
            //            external_image_list_url: "lists/image_list.js",
            //            media_external_list_url: "lists/media_list.js",

            // Replace values for the template plugin
            //            template_replace_values: {
            //            username: "Some User",
            //            staffid: "991234"
            //            }
        });

    }
}

function noAjaxTabClick(a) {
    var tabno = $(a).attr('class');
    $(a).parents('.tabs_ul').children('li').each(function() {
        if ($(this).hasClass(tabno))
            $(this).addClass('active');
        else
            $(this).removeClass('active');
    });

    $(a).parents('.d_tabpanel').children('div').each(function() {
        if ($(this).hasClass(tabno))
            $(this).removeClass('hidden');
        else
            $(this).addClass('hidden');
    });

}

function clearValaszto(megnevezesId, valueId) {
    $('#' + megnevezesId).val('-');
    $('#' + valueId).val('1000');
}

function clearValaszto2(megnevezesId, valueId, value) {
    $('#' + megnevezesId).val('-');
    $('#' + valueId).val(value);
}

function valasztoClick(megnevezesId, megnevezesValue, valueId, valueValue) {
    $("#" + megnevezesId).attr('value', megnevezesValue);
    $("#" + valueId).val(valueValue);

    var el = $("#valaszto_popup");
    $(el).dialog('close');
}


// tabpanel
function setActive(tpId, tabId) {
    if (tabId == undefined) {
        //alert('itt');
        var elsoTab = $('#' + tpId + '_tabs a')[0];
        var href = $(elsoTab).attr('href');

        if (href != null) {
            //$($(elsoTab).parent().get(0)).addClass('active');
            $(elsoTab).click();
        }
    }
    else {
        $('#' + tpId + '_tabs a').each(function() {
            if ($(this).attr('href').indexOf(tabId) > -1) {
                $(this).click();
                //break;
            }
        });
    }
}

function setActiveClass(tpId, hash) {
    $('#' + tpId + '_tabs a').each(function(k, v) {
        var h = v.href.split('#');

        if (h.length > 1 && h[1] == hash) {
            $($(v).parent().get(0)).addClass('active');
        }
        else {
            $($(v).parent().get(0)).removeClass('active');
        }
    });
}

function initTabPanel(id, urlPrefix, js) {

    tabs[id] = js;

    $('#' + id + '_tabs a').click(function() {

        if (FormOk || (FormOk == false && confirm(FormKerdes))) {
            FormOk = true;
            if (this.href) {
                var hash = this.href;
                hash = hash.replace(/^.*#/, '');
                $.historyLoad(hash);
            }
        }

        return false;
    });

    $.historyInit(function (hash) {
        if (tabs[id] == null)
            return;

        if (hash) {
            //alert(hash);
            var hashSplit = hash.split('=');
            if (hashSplit.length == 1)
                return;

            // tabpanel
            var tpId = hashSplit[0];
            // tab
            var tabId = hashSplit[1];

            var tabUrl = '';

            $(tabs[tpId]).each(function () {
                if (this.Id == tabId) {
                    tabUrl = this.Url;
                }
            });
            if (tabUrl == '') {
                setActive(id);
                return;
            }
            //alert(url1);

            //dexsubmit('{1}/' + valami[1], null, null, null, '{0}_content')

            dexsubmit(tabUrl, null, null, null, tpId + '_content')

            setActiveClass(tpId, hash);

        } else { // default vagy elsonek a tartalmat kell betolteni

            var defIndex = 0; // azétrt mert a tabokat 0-tól idexeljük...

            for (defIndex = 0; defIndex < tabs[id].length; defIndex++) {
                if (tabs[id][defIndex].Default)
                    break;
            }

            if (defIndex == tabs[id].length)
                defIndex = 0;

            if (tabs[id][defIndex].Url != '')
                dexsubmit(tabs[id][defIndex].Url, null, null, null, id + '_content')

            if (false) {
                //alert(def);

                if (def != '')
                    setActive(id, def);
                else
                    setActive(id);
            }
        }
    });
}


(function($, undefined) {
    '$:nomunge'; // Used by YUI compressor.

    $.fn.serializeObject = function() {
        var obj = {};

        $.each(this.serializeArray(), function(i, o) {
            var n = o.name,
        v = o.value;

            obj[n] = obj[n] === undefined ? v
          : $.isArray(obj[n]) ? obj[n].concat(v)
          : [obj[n], v];
        });

        return obj;
    };

    $.fn.arrayToKeyValue = function() {
        var obj = {};

        $.each(this, function(i, o) {
            var n = o.name,
            v = o.value;

            obj[n] = obj[n] === undefined ? v
          : $.isArray(obj[n]) ? obj[n].concat(v)
          : [obj[n], v];
        });

        return obj;
    };

})(jQuery);

//Dex context Menu
(function($) {
    $.fn.dexContextMenu = function(id) {
        $(this).bind('click', function(e) {
            e.stopPropagation();
        });
        content = $('#' + id);
        content.addClass('dex_context_menu');

        $(this).bind('click', function(e) {
            if ($(this).hasClass('active_context'))
                $(this).removeClass('active_context');
            else
                $(this).addClass('active_context');

            var ez = $(this);
            $('.active_context').each(function(i) {
                if ($(this).attr('id') != $(ez).attr('id')) {
                    $(this).removeClass('active_context');
                }
            });
            $('.dex_context_menu').each(function(i) {
                if ($(this).css('display') == "block" && $(this).attr('id') != id) {
                    $(this).hide();
                }
            });
            $('#' + id).toggle();


            $(document).one('click', function() {
                $('#' + id).hide();
                $(ez).removeClass('active_context');
            });
            return false;
        });
    };
})(jQuery);

(function($) {
    $.fn.multiDayDatePicker = function(minDt, maxDt) {
        Date.format = 'dd.mm.yyyy';
        var a = $(this).datePicker(
                {
                    createButton: false,
                    displayClose: true,
                    closeOnSelect: false,
                    selectMultiple: true,
                    startDate: minDt,
                    endDate: maxDt
                }
                )
                .bind(
                    'click',
                    function() {
                        $(this).dpDisplay();
                        this.blur();
                        return false;
                    }
                );

        return a;
    };
})(jQuery);

(function($) {
    $.fn.dexDatePicker = function(onselect, minDt, maxDt) {
        var a = $(this).datepicker({
            dateFormat: 'yy.mm.dd',
            dayNames: [_('Vasárnap'), _('Hétfő'), _('Kedd'), _('Szerda'), _('Csütörtök'), _('Péntek'), _('Szombat')],
            dayNamesMin: [_('Va'), _('Hé'), _('Ke'), _('Sz'), _('Cs'), _('Pé'), _('Sz')],
            dayNamesShort: [_('Vas'), _('Hét'), _('Ked'), _('Sze'), _('Csü'), _('Pén'), _('Szo')],
            monthNames: [_('Január'), _('Február'), _('Március'), _('Április'), _('Május'), _('Június'),
                         _('Július'), _('Augusztus'), _('Szeptember'), _('Október'), _('November'), _('December')],
            monthNamesShort: [_('Jan'), _('Feb'), _('Már'), _('Ápr'), _('Máj'), _('Jún'), _('Júl'), _('Aug'), _('Sep'), _('Okt'), _('Nov'), _('Dec')],
            currentText: _('Ma'),
            nextText: _('Következő'),
            prevText: _('Előző'),
            firstDay: 1,
            onSelect: onselect,
            minDate: minDt,
            maxDate: maxDt
        });

        return a;
    };
})(jQuery);

(function($) {
    $.fn.dexDateTimePicker = function(onselect, onclose) {
        var a = $(this).datetimepicker({
            dateFormat: 'yy.mm.dd',
            timeFormat: 'hh:mm',
            dayNames: [_('Vasárnap'), _('Hétfő'), _('Kedd'), _('Szerda'), _('Csütörtök'), _('Péntek'), _('Szombat')],
            dayNamesMin: [_('Va'), _('Hé'), _('Ke'), _('Sz'), _('Cs'), _('Pé'), _('Sz')],
            dayNamesShort: [_('Vas'), _('Hét'), _('Ked'), _('Sze'), _('Csü'), _('Pén'), _('Szo')],
            monthNames: [_('Január'), _('Február'), _('Március'), _('Április'), _('Május'), _('Június'),
                             _('Július'), _('Augusztus'), _('Szeptember'), _('Október'), _('November'), _('December')],
            monthNamesShort: [_('Jan'), _('Feb'), _('Már'), _('Ápr'), _('Máj'), _('Jún'), _('Júl'), _('Aug'), _('Sep'), _('Okt'), _('Nov'), _('Dec')],
            currentText: _('Ma'),
            nextText: _('Következő'),
            prevText: _('Előző'),
            currentText: _('Most'),
            closeText: _('Kész'),
            ampm: false,
            timeOnlyTitle: _('Válasszon időt'),
            timeText: _('Idő'),
            hourText: _('Óra'),
            minuteText: _('Perc'),
            secondText: _('Másodperc'),
            firstDay: 1,
            onSelect: onselect,
            onClose: onclose
        });
        return a;
    };
})(jQuery);

function initEditorForElement(id) {
    if (g_editors.findEditor(id)) {
        return;
    }
    g_editors.addEditor(id);
    tinyMCE.execCommand('mceAddControl', true, id);
}

function removeEditorForElement(id) {
    if (g_editors.findEditor(id)) {
        g_editors.removeEditor(id);

        if (tinyMCE.getInstanceById(id) != null) {
            tinyMCE.execCommand('mceRemoveControl', true, id);
        }
    }
}

function editorClearList() {
    var ed_list = g_editors.getEditorList();
    for (var i = 0; i < ed_list.length; i++) {
        removeEditorForElement(ed_list[i]);
    }
    g_editors.clearEditorList();
}

//
//user input szabályozás, az érték mezőre
//
// Numeric only control handler
jQuery.fn.ForceNumericOnly =
    function () {
        return this.each(function () {
            $(this).keydown(function (e) {
                var key = e.charCode || e.keyCode || 0;
                // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
                return (
                key == 8 ||
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
            })
        })
    };

//A maximálisan beírható karakterkek számának beállítása
//
//Használat: <textarea onkeyup="return ismaxlength(this);" maxlength="10"></textarea>
//
function isMaxLength(obj) {
    var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : "";
    if (obj.getAttribute && obj.value.length > mlength)
        obj.value = obj.value.substring(0, mlength);
}

//A help ikonok ki- és bekapcsolása
function toggleHelp() {
    $('.help_icon').toggle();
}
