/*global DARTY */

// extending build-in javascript objects

// =======================================================================
//  Extending Objects and pseudo-classes
// =======================================================================

// construire un objet a partir d'un autre
// le nouvel objet possede toutes les proprietes
// de l'objet modele
if (typeof Object.beget !== 'function') {
    Object.beget = function(o){
        var F = function(){
        };
        F.prototype = o;
        return new F();
    };
}

// Alias 
if (typeof Object.clone !== 'function') {
    Object.clone = Object.beget;
}

// ajout d'une methode 
// sur une pseudo-classe javascript (définie par constructeur)
if (!Function.prototype.method) {
    Function.prototype.method = function(name, func){
        if (!this.prototype[name]) {
            this.prototype[name] = func;
        }
        return this;
    };
}

// ajouter plusieurs methodes
// en une fois :
Function.method('methods', function(specifier){
    for (var methodname in specifier) {
        if (specifier.hasOwnProperty(methodname)) {
            this.method(methodname, specifier[methodname]);
        }
    }
    return this;
});

// Heritage d'une classe définie par constructeur
// Pseudoclassical inheritance
Function.method('inherits', function(Parent){
    this.prototype = new Parent();
    return this;
});

// =======================================================================
//  Darty javascript namespace
// =======================================================================
DARTY = {};
DARTY.DEBUG = DARTY.DEBUG || false;
DARTY.VARS = {};
DARTY.VARS.SAME_APPLICATION = DARTY.VARS.SAME_APPLICATION || true;
DARTY.VARS.SAME_DOMAIN_REFERRER = (function() {
    var domain = document.domain,
            referrer = document.referrer,
            referrerDomain = null,
            URL_PARTS_REGEXP = /\b(https?|ftp):\/\/([\-A-Z0-9.]+)(\/[\-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[A-Z0-9+&@#\/%=~_|!:,.;]*)?/i;

    referrerDomain = ((referrer || "").match(URL_PARTS_REGEXP)||{})['2'];
    return (domain === referrerDomain);
})();
DARTY.VARS.URL = {};
DARTY.util = DARTY.util || {};
DARTY.util.Init = {};
DARTY.util.required = function(arrNames,from) {
    var msg;
	if (arrNames && arrNames instanceof Array) {
		for( var i = 0; i< arrNames.length ; i +=1 ) {
		  try {
			if (!eval(arrNames[i])) {
			   msg = "missing library : " + arrNames[i] + " in " + from;
			   if(DARTY && DARTY.DEBUG) {			     
				 alert(msg);
			   }			   
			}
		  }
		  catch(e){
		   msg = e.message + " in " + from ;
		   if(DARTY && DARTY.DEBUG) {		     
		     alert(msg);
		    } 
		  }	
		}
	}
};
// common methods definitions




