function debug (obj) { return debug_var(obj); }
function debug_var(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}
var yuiHumanReadableFileSize = function (size){
    var result;
    if (size < 1024)
        result = size + ' Byte';
    else {
        result = Math.round((size / 1024) * 100) / 100;
        if (result < 1024){
            result += ' KB';
        } else {
            result = Math.round((result / 1024) * 100) / 100;
            if (result < 1024){
                result += ' MB';
            } else {
                result = Math.round((result / 1024) * 100) / 100 + ' GB';
            }
        }
    }
    return result;
};
function html_entity_decode(str)
{
    try
    {
        var  tarea=document.createElement('textarea');
        tarea.innerHTML = str; return tarea.value;
        tarea.parentNode.removeChild(tarea);
    }
    catch(e)
    {
        //for IE add <div id="htmlconverter" style="display:none;"></div> to the page
        document.getElementById("htmlconverter").innerHTML = '<textarea id="innerConverter">' + str + '</textarea>';
        var content = document.getElementById("innerConverter").value;
        document.getElementById("htmlconverter").innerHTML = "";
        return content;
    }
}
/**
 * make a object editable (textbox)
 *
 * @param object   srcObject        object to edit
 * @param function callbackFunction function to call on edit finish (objectId, newValue)
 * @returns
 */
var yuiInlineEdit = function (srcObject, callbackFunction, type, json){
    this.srcObject = srcObject;
    this.callbackFunction = callbackFunction;
    this.fieldId = srcObject.id + '_editableContentField';
    this.cancelId = srcObject.id + '_editableContentCancel';
    this.applyId = srcObject.id + '_editableContentApply';
    this.outTimer = null;
    this.outTimerTime = 5000;
    this.cancelClick = function (e, obj) {
        var q = document.getElementById(obj.newElementId);
        if (q)
            q.parentNode.removeChild(q);
    };
    this.applyClick = function (e, obj) {
        var value = YAHOO.util.Dom.get(obj.fieldId).value;
        obj.callbackFunction(obj.srcObject.id, value);
        obj.cancelClick(null, obj);
        return;
    };
    this.mouseOut = function (e, obj) {
        obj.outTimer = window.setTimeout(function () { obj.cancelClick(null, obj); }, obj.outTimerTime);
    };
    this.mouseOver = function (e, obj) {
        if (obj.outTimer){
            window.clearTimeout(obj.outTimer);
            obj.outTimer = null;
        }
    };
    this.keyPress= function (e, obj) {
        if (obj.outTimer){
            window.clearTimeout(obj.outTimer);
            obj.outTimer = null;
        }
        var charCode = (e.which) ? e.which : e.keyCode
        if (charCode == 13){
            obj.applyClick(null, obj);
        }
        if (charCode == 27){
            obj.applyCancel(null, obj);
        }
    };
    // create text field container
    var newEl = document.createElement("div");
    this.newElementId = newEl.id = srcObject.id + '_editableContent';
    YAHOO.util.Dom.addClass(newEl, 'editableContentContainer');
    newEl.style.position = 'absolute';
    newEl.style.border = '1px solid #cfcfcf';
    newEl.innerHTML = '<div id="' + this.cancelId + '" class="editableContentCancel"> </div>';
    switch (type){
        case 'select':
            var txt = '<select id="' + this.fieldId + '" class="editableContentField">';
            var items = YAHOO.lang.JSON.parse(json);
            if (items){
                for (var Key in items) {
                    if (Key == 'selected')
                        continue;
                    txt += '<option value="' + Key + '"' + (Key == items['selected'] ? ' selected="selected"' : '') + '>' + items[Key] + '</option>';
                }
            }
            txt += '</select>';

            newEl.innerHTML += txt;
            break;
        case 'text':
        default:
            newEl.innerHTML += '<input id="' + this.fieldId + '" class="editableContentField" type="text" value="' + srcObject.innerHTML + '" />';
            break;
    }
    newEl.innerHTML += '<div id="' + this.applyId + '" class="editableContentApply"> </div>';
    // insert
    YAHOO.util.Dom.insertBefore(newEl, srcObject);
    // set click handler
    new YAHOO.util.Element(this.cancelId).on('click', this.cancelClick, this);
    new YAHOO.util.Element(this.applyId).on('click', this.applyClick, this);
    new YAHOO.util.Element(this.newElementId).on('mouseout', this.mouseOut, this);
    new YAHOO.util.Element(this.newElementId).on('mouseover', this.mouseOver, this);
    new YAHOO.util.Element(this.fieldId).on('keypress', this.keyPress, this);
    // replace position
    var xyNewEl = YAHOO.util.Dom.getXY(srcObject);
    YAHOO.util.Dom.setX(newEl, xyNewEl[0] - 3);
    YAHOO.util.Dom.setY(newEl, xyNewEl[1] - 3);
    // focus textfield
    try {
        YAHOO.util.Dom.get(this.fieldId).select();
    } catch (e) { }
    YAHOO.util.Dom.get(this.fieldId).focus();
};
function sprintf()
{
    if( sprintf.arguments.length < 2 )
        return;
    var data = sprintf.arguments[ 0 ];
    for( var k=1; k<sprintf.arguments.length; ++k ) {
         switch( typeof( sprintf.arguments[ k ] ) ) {
              case 'string':
               data = data.replace( /%s/, sprintf.arguments[ k ] );
               break;
              case 'number':
               data = data.replace( /%d/, sprintf.arguments[ k ] );
               break;
              case 'boolean':
               data = data.replace( /%b/, sprintf.arguments[ k ] ? 'true' : 'false' );
               break;
              default:
               /// function | object | undefined
               break;
         }
    }
    return( data );
}

var YDom = YAHOO.util.Dom, YEvent = YAHOO.util.Event, status = null, phpmyXHRRequestStack = new Array();
