String.prototype.trim = function() { 
	return this.replace(/^\s+|\s+$/, ''); 
};

function openWindow( content, popup, link, offsetY, offsetX ) {
	var w = $( link ).get(0);
	var offsetY = ( offsetY == undefined ? 0 : offsetY );
	var offsetX = ( offsetX == undefined ? 0 : offsetX );
	var position = $( link ).offset();
	$( content ).block();
	$( popup ).css({position: 'absolute', cursor: 'default', left:(position.left - offsetX), top:(position.top - offsetY), 'z-index':2000 } ).show();
};

function closeWindow( content, popup ) {
	$( content ).unblock( { fadeOut:false } );
	$( popup ).hide();	
};
//***************************************************************************
// Browser Window Size and Position
// copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
// you may copy these functions but please keep the copyright notice as well
// http://javascript.about.com/od/guidesscriptindex/a/screen.htm
function pageWidth() {	
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?  document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} ;
function pageHeight() { 
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
};
function posLeft() {
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
};
function posTop() {
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
};
function posRight() {
	return posLeft()+pageWidth();
};
function posBottom() {
	return posTop() + pageHeight();
};
//////////////////////
// firebugx.js      //
//////////////////////
if (!window.console || !console.firebug){
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml","group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
	window.console = {};
	for (var i = 0; i < names.length; ++i)
		window.console[names[i]] = function() {};
}
function createPackage(name){
	var t		= window;
	var pkgs	= name.split(".");
	for(p in pkgs){
		if(!t[pkgs[p]]){
			t[pkgs[p]] = {};
		}else{
			if(typeof t[pkgs[p]] == 'function'){
				alert(name+': '+pkgs[p]+' is a Class and cannot be package name!');
			}
		};
		t = t[pkgs[p]];
	};
	return t;
};
jQuery.fn.extend({
	disable	: function(){
		return $(this).attr('disabled', 'disabled');
	},
	enable	: function(){
		return $(this).attr('disabled', '');
	}	
});

/*
 * jQuery JSON Plugin
 * version: 1.0 (2008-04-17)
 */
(function($) {   
    function toIntegersAtLease(n){    
        return n < 10 ? '0' + n : n;
    }
    Date.prototype.toJSON = function(date){
        return this.getUTCFullYear()   + '-' +
             toIntegersAtLease(this.getUTCMonth()) + '-' +
             toIntegersAtLease(this.getUTCDate());
    };
    var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
    var meta = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };
    $.quoteString = function(string){
        if (escapeable.test(string)){
            return '"' + string.replace(escapeable, function (a) {
                var c = meta[a];
                if (typeof c === 'string') {
                    return c;
                }
                c = a.charCodeAt();
                return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
            }) + '"';
        }
        return '"' + string + '"';
    };
    $.toJSON = function(o, compact){
        var type = typeof(o);
        if (type == "undefined")
            return "undefined";
        else if (type == "number" || type == "boolean")
            return o + "";
        else if (o === null)
            return "null";
        if (type == "string") 
        {
            return $.quoteString(o);
        }
        if (type == "object" && typeof o.toJSON == "function") 
            return o.toJSON(compact);
        if (type != "function" && typeof(o.length) == "number"){
            var ret = [];
            for (var i = 0; i < o.length; i++) {
                ret.push( $.toJSON(o[i], compact) );
            }
            if (compact)
                return "[" + ret.join(",") + "]";
            else
                return "[" + ret.join(", ") + "]";
        }
        if (type == "function") {
            throw new TypeError("Unable to convert object of type 'function' to json.");
        }
        var ret = [];
        for (var k in o) {
            var name;
            type = typeof(k);
            if (type == "number")
                name = '"' + k + '"';
            else if (type == "string")
                name = $.quoteString(k);
            else
                continue;
            var val = $.toJSON(o[k], compact);
            if (typeof(val) != "string") {
                continue;
            }
            if (compact)
                ret.push(name + ":" + val);
            else
                ret.push(name + ": " + val);
        }
        return "{" + ret.join(", ") + "}";
    };
    $.compactJSON = function(o){
        return $.toJSON(o, true);
    };
    $.evalJSON = function(src){
        return eval("(" + src + ")");
    };
    $.secureEvalJSON = function(src){
        var filtered = src;
        filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@');
        filtered = filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
        filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
        
        if (/^[\],:{}\s]*$/.test(filtered))
            return eval("(" + src + ")");
        else
            throw new SyntaxError("Error parsing JSON, source is not valid.");
    };
})(jQuery);

function createClass(pkgName, constr, impl, extend){
	constr	= constr || function(){};
	impl	= impl||{};
	var pkgNameAr = pkgName.split('.');
	var className = pkgNameAr.pop();
	var extended = extend?(extend.prototype?extend.prototype:{}):{};
	
	var pkg = createPackage(pkgNameAr.join('.'));
	pkg[className] = constr;
	pkg[className].prototype = $.extend({}, pkg[className].prototype, extended, impl, true);
	return pkg[className];
};

DEBUG = {
		console		: null,
		options 	: null,	
		LVL_ALL		: 0,	
		LVL_INFO	: 10,
		LVL_LOG		: 20,
		LVL_WARN	: 30,
		LVL_ERROR	: 40,
		LVL_NONE	: 999,

		__call		: function(func, arguments, level){
			if(level >= this.options.logLevel){
				func.apply(this.console, arguments);
			}
		},

		info		: function(){return this.__call(this.console.info,	arguments, DEBUG.LVL_INFO);},
		log			: function(){
			return this.__call(this.console.log,	arguments, DEBUG.LVL_LOG);
		},
		debug		: function(){return this.__call(this.console.debug,	arguments, DEBUG.LVL_LOG);},
		warn		: function(){return this.__call(this.console.warn,	arguments, DEBUG.LVL_WARN);},
		error		: function(){return this.__call(this.console.error,	arguments, DEBUG.LVL_ERROR);},
		
		time		: function(){return this.__call(this.console.time,		arguments, DEBUG.LVL_LOG);},
		timeEnd		: function(){return this.__call(this.console.timeEnd,	arguments, DEBUG.LVL_LOG);}	
};

createClass(
	'marketplace.Debugger',
	function(options){
		this.options = options;
		this.console = console;
	},
	DEBUG
);

Debug = new marketplace.Debugger({
	logLevel:DEBUG.LVL_WARN
});
