/**
 * Class util's for OOP in javascript
 * 
 * 
 * <code>
 * 
 * function A() {                        // Define super class
 *     this.x = 1;
 * }
 * A.prototype.DoIt = function() {       // Define Method
 *     this.x += 1;
 * }
 * 
 * B.Extends(A);                         // Define sub-class
 * function B()  {
 *     this.A();                         // Call super-class constructor (if desired)
 *     this.y = 2;
 * }
 * B.Override(A, 'DoIt');
 * B.prototype.DoIt = function() {       // Define Method
 *     this.A_DoIt();                    // Call super-class method (if desired)
 *     this.y += 1;
 * }
 * 
 * b = new B;
 * 
 * document.write((b instanceof A) + ', ' + (b instanceof B) + '<BR/>');
 * b.DoIt();
 * document.write(b.x + ', ' + b.y);
 * 
 * </code>
 * 
 * 
 * @author Michael Mifsud
 * @notes Referenced from - http://mckoss.com/jscript/object.htm
 * @package javascript
 */


/**
 * The class to extend (Derive From)
 * 
 * 
 */
Function.prototype.Extends = function (fnSuper) {
    var prop;
    if (this == fnSuper) {
        alert("Error - cannot derive from self");
        return;
    }
    for (prop in fnSuper.prototype) {
        if (typeof (fnSuper.prototype[prop]) == "function" &&
            !this.prototype[prop]) {
            this.prototype[prop] = fnSuper.prototype[prop];
        }
    }
    this.prototype[fnSuper.StName()] = fnSuper;
}

/**
 * 
 * 
 * 
 */
Function.prototype.StName = function () {
    var st;
    st = this.toString();
    st = st.substring(st.indexOf(" ") + 1, st.indexOf("("));
    if (st.charAt(0) == "(") {
        st = "function ...";
    }
    return st;
}

/**
 * 
 * 
 * 
 */
Function.prototype.Override = function (fnSuper, stMethod) {
    this.prototype[fnSuper.StName() + "_" + stMethod] = fnSuper.prototype[stMethod];
}



