function showJgrowlMessage(message)
{
    $.jGrowl(message, {life:10000});
}


/**
 * Shows confirmation dialog and calls corresponding callback depending from
 * user choice
 * @param message message to show in dialog
 * @param successCallback called if user clicked ok
 * @param cancelCallback called if user clicked cancel
 */
function showConfirmationDialog(message, successCallback, cancelCallback, title)
{
    if ($('#confirmationDialog').length)
    {
        // dialog exists, change handlers
        $('#confirmationDialog').dialog('option', {buttons: {
                                                "Confirm": function() {
                                                    $('#confirmationDialog').attr('success', 1);
                                                    $( this ).dialog( "close" );
                                                    if (successCallback)
                                                    {
                                                        successCallback();
                                                    }
                        
                                                  },
                        
                                                  Cancel: function() {
                                                    $( this ).dialog( "close" );
                                                    /*if(cancelCallback)
                                                    {
                                                        cancelCallback();
                                                    }*/
                                                  },
                                               },
                                                
                                               close: function(event, ui){
                                                if ($('#confirmationDialog').attr('success'))
                                                {
                                                    $('#confirmationDialog').attr('success', 0);
                                                }
                                                else
                                                {
                                                   if(cancelCallback)
                                                   {
                                                      cancelCallback();
                                                   }
                                                }
                                               }
                                              });
        
        $('#confirmationDialog').dialog('open');
    }
    else
    {
        $('<div id="confirmationDialog"></div>').dialog({
              resizable: false,
                    title: title == null ? 'Confirmation' : title,
                    height: 'auto',
                    //width: 'auto',
                    modal: true,
                    buttons: {
                                                "Confirm": function() {
                                                    $('#confirmationDialog').attr('success', 1);
                                                    $( this ).dialog( "close" );
                                                    if (successCallback)
                                                    {
                                                        successCallback();
                                                    }
                        
                                                  },
                        
                                                  Cancel: function() {
                                                    $( this ).dialog( "close" );
                                                    /*if(cancelCallback)
                                                    {
                                                        cancelCallback();
                                                    }*/
                                                  },
                                               },
                                                
                    close: function(event, ui){
                    if ($('#confirmationDialog').attr('success'))
                    {
                        $('#confirmationDialog').attr('success', 0);
                    }
                    else
                    {
                        if(cancelCallback)
                        {
                            cancelCallback();
                        }
                    }
                }
                
            });
    }
    $('#confirmationDialog').html(message);
}


/**
 * Creates dialog
 * @param element either id or element it self on/from that we create dialog
 */
function createDialog(element, options)
{
    var defaultOptions = {
        resizable: false,
        height: 'auto',
        width: 'auto',
        modal: true,
        closeOnEscape: true,
    };

    return $(element).dialog($.extend(defaultOptions, options));
}

