if (!window.i18n){window.i18n = {};}

// BEGIN Array
if(typeof Array.prototype.push == 'undefined') { // Prototyp na Array.push() 
	Array.prototype.push = function() {
		for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
			this[b+i] = a[i];
		}
		return this.length;
	}
}

if(typeof Array.prototype.splice == 'undefined') {
	Array.prototype.splice = function(a, c) {
		var i = 0;
		var e = arguments;
		var d = this.copy();
		var f = a;
		var l = this.length;
		
		if(!c) {c = l - a;}
		for(i; i < e.length - 2; i++) {
			this[a + i] = e[i + 2];
		}
		
		for(a; a < l - c; a++) {
			this[a + e.length - 2] = d[a - c];
		}
		
		this.length -= c - e.length + 2;
		return d.slice( f, f + c );
	}
}

if(typeof Array.prototype.pop == 'undefined') {
	Array.prototype.pop = function() {
		var b = this[this.length - 1];
		this.length--;
		return b;
	}
}

if(typeof Array.prototype.inArray == 'undefined') {
	Array.prototype.inArray = function(needle, argStrict) {
		var key = '', strict = !!argStrict;
		
		for(key in this) {
			if(strict) {
				if (this[key] === needle) {
					return true;
				}
			} else {
				if (this[key] == needle) {
					return true;
				}
			}
		}
		
		return false;
	}
}
// END Array

// BEGIN String
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

if(typeof String.prototype.urlencode == 'undefined') {
	String.prototype.urlencode = function() {
	    str = (this+'').toString();
	    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
	}
}

if(typeof String.prototype.localize == 'undefined') {
	String.prototype.localize = function() {
		var cReturnValue = (window.i18n) ? window.i18n[this] : this;
		if(!cReturnValue){
			cReturnValue = this;
		}
		return cReturnValue;
	};
}
// END String

if(typeof myRound == 'undefined') {
	myRound = function(x, y)	{
		x = parseFloat(x);
		var z = Math.pow(10, parseInt(y, 10));
		return Math.round(x * z) / z;
	}
}

// This code is in the public domain. Feel free to link back to http://jan.moesen.nu/
if(typeof sprintf == 'undefined') {
	function sprintf()
		{
			if (!arguments || arguments.length < 1 || !RegExp)
			{
				return;
			}
			var str = arguments[0];
			var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
			var a = b = [], numSubstitutions = 0, numMatches = 0;
			while (a = re.exec(str))
			{
				var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
				var pPrecision = a[5], pType = a[6], rightPart = a[7];
				
				//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

				numMatches++;
				if (pType == '%')
				{
					subst = '%';
				}
				else
				{
					numSubstitutions++;
					if (numSubstitutions >= arguments.length)
					{
						alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
					}
					var param = arguments[numSubstitutions];
					var pad = '';
					       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
					  else if (pPad) pad = pPad;
					var justifyRight = true;
					       if (pJustify && pJustify === "-") justifyRight = false;
					var minLength = -1;
					       if (pMinLength) minLength = parseInt(pMinLength);
					var precision = -1;
					       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
					var subst = param;
					       if (pType == 'b') subst = parseInt(param).toString(2);
					  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
					  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
					  else if (pType == 'u') subst = Math.abs(param);
					  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
					  else if (pType == 'o') subst = parseInt(param).toString(8);
					  else if (pType == 's') subst = param;
					  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
					  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
				}
				str = leftpart + subst + rightPart;
			}
			return str;
		}
}
