/*
* X-Developed-By:	DarCas(.net) The Architect; www.DarCas.net - darcas@darcas.net
* X-Supported-By:	EstroWeb Srl; www.estroweb.it - estroweb@estroweb.it
*/
String.prototype.trim = function () { return this.replace(/\s+$|^\s+/g, ""); }
String.prototype.rtrim = function () { return this.replace(/\s+$/, ""); }
String.prototype.ltrim = function () { return this.replace(/^\s+/, ""); }
String.prototype.number_format = function ( float_number, int_decimals, string_dec_point, string_thousands_sep ) {

	string_dec_point = string_dec_point || '.';
	string_thousands_sep = string_thousands_sep || ',';
	float_number = Math.round(float_number * Math.pow(10, int_decimals)) / Math.pow(10, int_decimals);
	e = float_number + ''; f = e.split('.'); if (!f[0]) f[0] = '0'; if (!f[1]) f[1] = '';
	if (f[1].length < int_decimals) { g = f[1]; for (i=f[1].length + 1; i <= int_decimals; i++) g += '0'; f[1] = g; }
	if(string_thousands_sep != '' && f[0].length > 3) {
		h = f[0]; f[0] = '';
		for(j = 3; j < h.length; j+=3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = string_thousands_sep + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	string_dec_point = (int_decimals <= 0) ? '' : string_dec_point;
	return f[0] + string_dec_point + f[1];

}
String.prototype.datestamp_format = function ( format, intext  ) {

	try {

		this.replace(/\s+$|^\s+/g, '');

		year = this.substr(0, 4);
		month = this.substr(4, 2);
		day = this.substr(6, 2);

		if (intext) {

			switch (parseInt(month)) {

				case  1: month = 'Gennaio'; break;
				case  2: month = 'Febbraio'; break;
				case  3: month = 'Marzo'; break;
				case  4: month = 'Aprile'; break;
				case  5: month = 'Maggio'; break;
				case  6: month = 'Giugno'; break;
				case  7: month = 'Luglio'; break;
				case  8: month = 'Agosto'; break;
				case  9: month = 'Settembre'; break;
				case 10: month = 'Ottobre'; break;
				case 11: month = 'Novembre'; break;
				case 12: month = 'Dicembre'; break;

			}

		}

		result = format.replace('%Y', year);
		result = result.replace('%M', month);
		result = result.replace('%D', day);

		return result;

	} catch (e) { return false; }

};

function empty_dom_box ( obj ) { obj.innerHTML = ''; return; }