function Instancier(){
    this.map = new Array();
}

Instancier.prototype.createInstance = function(name, object){
    this.map[name] = object;
}

Instancier.prototype.getInstance = function(name){
    return this.map[name];
}

var instancier = new Instancier();

//TOOLS
String.prototype.startsWith = function(str){
    return (this.match("^" + str) == str)
}

Array.prototype.contains = function(needle){
    for (i in this) {
        if (this[i] == needle)
            return true;
    }
    return false;
}


function print_r(obj){
    win_print_r = window.open('about:blank', 'win_print_r');
    win_print_r.document.write('<html><body>');
    r_print_r(obj, win_print_r);
    win_print_r.document.write('</body></html>');
}

function r_print_r(theObj, win_print_r){
    if (theObj.constructor == Array ||
    theObj.constructor == Object) {
        if (win_print_r == null)
            win_print_r = window.open('about:blank', 'win_print_r');
    }
    for (var p in theObj) {
        if (theObj[p].constructor == Array ||
        theObj[p].constructor == Object) {
            win_print_r.document.write("<li>[" + p + "] =>" + typeof(theObj) + "</li>");
            win_print_r.document.write("<ul>")
            r_print_r(theObj[p], win_print_r);
            win_print_r.document.write("</ul>")
        }
        else {
            win_print_r.document.write("<li>[" + p + "] =>" + theObj[p] + "</li>");
        }
    }
    win_print_r.document.write("</ul>")
}

function createCookie(name, value, days){
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else
        var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name){
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ')
            c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0)
            return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name){
    createCookie(name, "", -1);
}

/**
 *	Delete the content of an input
 */
jQuery.fn.openNewTab = function(exception)
{
	return this.each
	(
		function()
		{
			var sHref = jQuery(this).attr('href');
			var reg = new RegExp('/' + exception + '/','g');
			if(!sHref.match(reg))
			{
				jQuery(this).click(function(){window.open(sHref); return false;});
			}
		}
	);
}

/**
 * Cannot type other touches except numeric touches
 */
jQuery.fn.numeric = function()
{
	this.each
	(
		function()
		{
			jQuery(this).keypress
			(
				function(e)
				{
					if(e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
					{
						return false;
					}
				}
			);
		}
	);
}


xajax_call2 = function()
{
	xajax.config.requestURI = "/lib/Pelican/Index/xajax_server_ctrl.php";
	var res =  xajax.request( { xjxfun: 'call' }, { parameters: arguments } );
	xajax.config.requestURI = "/lib/Pelican/Index/xajax.server.php";
	return res;
}
	