/*global DARTY */
DARTY = DARTY || {};
DARTY.util = DARTY.util || {};
// <dependencies checking>
(function(){// Depends on Init.js
    var from = "DARTY.util.Object";
    var libs = ["DARTY.util.Init"];    
	if (DARTY && DARTY.util && DARTY.util.required) {    
        DARTY.util.required(libs, from);
    }
    else {
       if(DARTY && DARTY.DEBUG) {	
        alert("Missing library : DARTY.util.Init in " + from);
       } 
    }
})();
// </dependencies checking>
DARTY.util.Object = function(){
    /////////////////////////////////////////////////////////////////
    //--------------- definition of private variables ---------------
    ////////////////////////////////////////////////////////////////
    
    // fixe typeof on Array instance 
    // even if the instance comes from another frameset or iframe
    function typeOf(value){
        var s = typeof value;
        if (s === 'object') {
            if (value) {
                if (typeof value.length === 'number' &&
                !(value.propertyIsEnumerable('length')) &&
                typeof value.splice === 'function') {
                    s = 'array';
                }
            }
            else {
                s = 'null';
            }
        }
        return s;
    }
    
    function isEmpty(o){
        var i, v;
        if (this.typeOf(o) === 'object') {
            for (i in o) { // explicit non filtering prototype chain properties
                v = o[i];
                if (v !== undefined && this.typeOf(v) !== 'function') {
                    return false;
                }
            }
        }
        return true;
    }
    
    ///////////////////////////////////////////////
    // ------------- public properties & methods     
    //////////////////////////////////////////////    
    return {
        typeOf: typeOf,
        isEmpty: isEmpty
    };
}();
