String.prototype.stripslashes = function() { return this.replace(/\\/g, ''); };
String.prototype.trim = function() { return this.replace(/(^\s+)|(\s+$)/g, ''); };
String.prototype.nl2br = function() { return this.replace(/\n/g, '<br/>'); };
String.prototype.striptags = function() { return this.replace(/\<(.*?)\>/g, ''); };
String.prototype.quote_begin = function() { return this.replace(/\[quote\]/g, '<blockquote>'); };
String.prototype.quote_end = function() { return this.replace(/\[\/quote\]/g, '</blockquote>'); };
String.prototype.site_name = function() { var a = /^(?:[a-z]+:\/\/)?(?:(?:\w+):)?(?:(?:\w+)@)?((?:\w+\.)+[a-z]{2,4})(?:\/.*)?$/(this); return a[1]; };

String.prototype.break_text = function() {
	strz = this.split('<break>');
	return strz[0];
}

String.prototype.nl2dombr = function() {
	var parts = this.split(/(?:\r)?\n/);
	var domResult;
	var domNode;
	
	domResult = Builder.node('div');
	for (var i = 0, len = parts.length; i < len; i++) {
		domResult.appendChild(Builder._text(parts[i]));
		
		if (len > i + 1) {
			domResult.appendChild(Builder.node('br'));
		}
	}
	
	return domResult;
};

String.prototype.truncateit = function(to, etc, use_break) {
	if(!to)
		to = 80;
	if(!etc)
		etc = ' ...';
	if(!use_break)
		use_break = true;
	
	if(to == 0)
		return '';
		
	if(use_break) {
		old = this;
		rez = this.break_text();
		if(rez.length != old.length) {
			rez = rez + etc;
			return rez;
		}
	}
	strz = this.split(" ");
	rez = "";
	for(i=0;i<strz.length;i++) {
		rez = rez + strz[i] + " ";
		if(rez.length >= to)
			break;
	}
	rez = rez + etc;
	return rez;
}

String.prototype.truncate = function(to, etc, break_words, middle) {
	if(!to)
		to = 80;
	if(!etc)
		etc = '...';
	if(!break_words)
		break_words = false;
	if(!middle)
		middle = false;
	
	if(to == 0)
		return '';
	
	rez = '';
		
	if(this.length > to) {
		to = to - Math.min(to, this.length);
		if(!break_words && !middle) {
			rez = this.substr(0, to + 1).replace(/\s+?(\S+)?$/, '');
		}
		
		if(middle) {
			rez = this.substr(0, to) + etc;
		} else {
			rez = this.substr(0, Math.round(to/2)) + etc + this.substr(Math.round(-to/2));
		}
		
		return rez;
	} else {
		return this;
	}
};

Date.fromSQLTimestamp = function(sqlTimestamp) {
	var dateExtractor = new RegExp("([0-9]{4})\-([0-9]{1,2})\-([0-9]{1,2})\\s([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})");
	var matches;
	var date;
	
	matches = dateExtractor.exec(sqlTimestamp);
	if (matches) {
		for (var i = 1, len = matches.length; i < len; i++) {
			matches[i] = parseInt(matches[i]);
		}
		
		date = new Date(matches[1], matches[2] - 1, matches[3], matches[4], matches[5], matches[6]);
	}
	return date;
};

Date.fromUnixtime = function(unixtime) {
	var data = new Date(unixtime * 1000);
	return data;
};

Date.prototype.format = function() {
	return this.getDate() + '/' + (this.getMonth() + 1) + '/' + this.getFullYear() + ' ' + this.getHours() + ':' + (this.getMinutes()<10?'0':'') + this.getMinutes();
}

var shortMonthNames = new Array('Ian', 'Feb', 'Mar', 'Apr', 'Mai', 'Iun', 'Iul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var longMonthNames = new Array('Ianuarie', 'Februarie', 'Martie', 'Aprilie', 'Mai', 'Iunie', 'Iulie', 'August', 'Septembrie', 'Octombrie', 'Noiembrie', 'Decembrie');