window.log = function(){
  log.history = log.history || [];  
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


var pr = {};

/**
 * Converts seconds to an object with days,hours,minutes,seconds based on the
 * seconds given.  For example, if you pass 60 you will get an object with the 'minutes'
 * fields set to 1 and everything else 0.
 * @param secs The number of seconds to convert
 * @return {Object} The time diff object with the fields days,hours,minutes,seconds
 */
pr.secondsToTimeDiff = function(secs){
    return {
        'days':Math.floor(secs / 86400),
        'hours':Math.floor((secs % 86400) / 3600),
        'minutes':Math.floor(((secs % 86400) % 3600) / 60),
        'seconds':((secs % 86400) % 3600) % 60
    }
};

/**
 * Displays a modal confirmation dialog (which returns immediately).
 * @param settings An object containing the following settings:
 *          msg: The message to display to the user
 *          title: The title of the dialog
 *          width: The width in pixels (optional)
 *          height: The height in pixels (optional)
 *          yesText: The text for the ok button (defaults to "Yes")
 *          noText: The text for the no button (defaults to "No")
 *          onYes: Either a string which is a link to redirect the user to or a function to call
 *          onNo:  Either a string which is a link to redirect the user to or a function to call or null
 */
pr.confirm = function(settings){

    var buttons = {};
    var yes = "Yes";
    var no = "No";
    if (settings.yesText){
        yes = settings.yesText;
    }
    if (settings.noText) {
        no = settings.noText;
    }
    buttons[no] = function(){
        if (settings.onNo){
            if ($.isFunction(settings.onNo)){
                settings.onNo();
            }
            else if (typeof settings.onNo == 'string'){
                document.location.href=settings.onNo;
            }
        }
        $(this).dialog("destroy");
    };
    buttons[yes] = function(){
        if (settings.onYes){
            if ($.isFunction(settings.onYes)){
                settings.onYes();
            }
            else if (typeof settings.onYes == 'string'){
                document.location.href=settings.onYes;
            }
        }

        $(this).dialog('destroy');
    };
    cfg = {
        resizable: false,
        modal: true,
        buttons: buttons,
        title:settings.title || "Confirmation"
    };

    if (settings.height){
        cfg['height'] = settings.height;
    }
    if (settings.width){
        cfg['width'] = settings.width;
    }

    $( "<div class='ask'>"+settings.msg+"</div>" ).dialog(cfg);
};

