

function log(){
    try
    {
        var args = [];
        for(var i = 0; i < arguments.length; i++) {
            args.push(arguments[i]);
        }
        window.console.log.apply(window.console, args);
    } catch (e){ }
}




//jQuery extentions

$.fn.enabled = function(isEnabled){
    if (isEnabled){
        $(this).removeAttr("disabled");
    } else {
        $(this).attr("disabled", "disabled");
    }
    return $(this);
}

//validator messages
if ($.validator){
    $.extend($.validator.messages, {
      required: 'Neįvesta reikalinga reikšmė'
    });
}

//cms utilities

var cms = {

    //submiting form with id=formName
    submitForm : function(formName, action){
        $("input[name='entity_action']").val(action);
        $("#"+formName).submit();
    },

    confirmDelete: function(){
        return confirm("Ar tikrai norite ištrinti pasirinktą įrašą?");
    },
    
    closeDialog: function(){
        if (window.parent){
            window.parent.$("#modalDiv").dialog('close');
        }
    },
    
    ajax: function(settings){
        $.ajax(settings);
    }
}



$(function() {
    
    if (jQuery().dialog){
        $("#modalDiv").dialog({
                    modal: true,
                    autoOpen: false,
                    height: 400,
                    width: 800,
                    draggable: true,
                    resizeable: true
                });
    }
        
        $('a.modal_link').click(function(e) {
            e.preventDefault();
            var $this = $(this);
            var href = this.href;
            if (this.href.indexOf("?") > 0){
                href = this.href + "&layout=modal";
            } else {
                href = this.href + "?layout=modal";
            }
            var w = parseInt($this.attr('width'));
            if (w > 100){
                $("#modalDiv").dialog("option", "width", w);
            }
            var h = parseInt($this.attr('height'));
            if (h > 100){
                $("#modalDiv").dialog("option", "height", h);
            }
            $("#modalDiv").dialog("option", "title", ($this.attr('title')) ? $this.attr('title') : '');
            $("#modalDiv").dialog("open");
            $("#modalIFrame").attr('src', href);
            return false;
        });
  
    
});

