function entries(collection) {
    var result = [];  // This is our real duck.

    for (var i = 0; i < collection.length; i++)
        result.push(collection[i]);

    return result;
}
Function.prototype.bind = function (object) {
    var method = this;
    var oldArguments = entries(arguments).slice(1);
    return function () {
        var newArguments = entries(arguments);
        return method.apply(object, oldArguments.concat(newArguments));
    };
}

Function.prototype.bindEventListener = function (object) {
	//alert("bind event listener");
    var method = this;
    var oldArguments = entries(arguments).slice(1);
    return function (event) {
        return method.apply(object, event || window.event, oldArguments);
    };
}

// use to create inheritance
Function.prototype.extend = function(baseClass) {
	
	for (i in baseClass)
   		if (i != "prototype")
			this[i] = baseClass[i];
			
	var inheritance = function() {};
	inheritance.prototype = baseClass.prototype;
	
	this.prototype = new inheritance();
	this.prototype.constructor = this;
	this.baseConstructor = baseClass;
	this.superClass = baseClass.prototype;
}

// Function to extend DOM Element
function applyInherit(original, iface)
{	
  for (method in iface)  	
    original[method] = iface[method];
  return original;
}

function applyInheritShort(original_name, iface)
{ 
	var original = document.createElement(original_name);	
	for (method in iface)  	
		original[method] = iface[method];
	return original;
}
/* Utility functions */
function isUrl(s) {
	if (s.indexOf(" ") == -1)
	{
		var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
		return regexp.test(s);
	}
	else return false;
}


