String.prototype.replaceAll=function(s1, s2) {
	return this.split(s1).join(s2);
}

String.prototype.trim = function(){
	var s = this;
    while (s.substring(0,1) == ' '){
        s = s.substring(1, s.length);
    }
    while (s.substring(s.length-1, s.length) == ' '){
        s = s.substring(0,s.length-1);
    }
    return s;
}

String.prototype.toNameCase=function() {
	return this.substring(0,1).toUpperCase() + this.substring(1,this.length).toLowerCase();
}

function updateSession(){
	Ext.Ajax.request({
		url		: 'actions/CommonActions.php',
		method 	: 'POST',
		params	:{
			noCache	: new Date(),
			action	: "sessionRenew"
		}
	});
}

function getFormattedString(str) {
	return "<b style='color:#15428B'>" + str + "</b>";
}

function getRedString(str) {
	return "<b style='color:#C90000'>" + str + "</b>";
}

function getTitle(g_User){
	var oDate = new Date();
	if(oDate.getHours() >= 6 && oDate.getHours() < 12){
		return this.getFormattedString(oMessages.good_morn);
	}else if(oDate.getHours() >= 12 && oDate.getHours() < 18){
		return this.getFormattedString(oMessages.good_even);
	}else{
		return this.getFormattedString(oMessages.good_night);
	}
}

function getDate4NewRecord(){
	var oDate = new Date();
	return dateZeroFill(oDate.getDate()) + "/" + dateZeroFill(oDate.getMonth() + 1) + "/" + oDate.getUTCFullYear();
}

function formatDate(sDate){
	if(sDate !== ""){
		var oDate = new Date(sDate);
		//sDate = dateZeroFill(oDate.getDate()) + "/" + dateZeroFill(oDate.getMonth() + 1) + "/" + oDate.getUTCFullYear();
                /*
                 *maybe getUTCFullYear is bugged?
                 **/
		sDate = dateZeroFill(oDate.getDate()) + "/" + dateZeroFill(oDate.getMonth() + 1) + "/" + oDate.getFullYear();
                

	}
	return sDate;
}

function formatDate4Db(oDate){
	var	sDate = oDate.getUTCFullYear() + "/" + dateZeroFill(oDate.getMonth() + 1) + "/" + dateZeroFill(oDate.getDate());
	return sDate;
}

function dateZeroFill(nNumber){
	return (nNumber < 10) ? "0" + nNumber : nNumber;
}

function describe(oObj){
	var sTmp = '';
	for(var key in oObj){
		sTmp += key + ': ' + oObj[key] + '\n';
	}
	alert(sTmp);
}

function info(sMsg){
	Ext.Msg.show({
		msg: "<b style='color:#000'>" + sMsg + "</b>",
		resizable: false,
		title: "<b>" + oMessages.info + "</b>",
		buttons: Ext.Msg.OK,
		autoHeight: true,
		autoWidth: true,
		modal: true,
		icon: Ext.MessageBox.INFO
	});
}

function confirmBox(sTitle,sMsg,fn){
	Ext.Msg.show({
		msg: "<b style='color:#000'>" + sMsg + "</b>",
		resizable: true,
		title: sTitle,
		buttons: Ext.Msg.YESNO,
		autoHeight: true,
		autoWidth: true,
		fn: fn,
		modal: true,
		icon: Ext.MessageBox.QUESTION
	});
}

function confirmUnsavedData(fn){
	confirmBox(
		oMessages.unsaved_title,
		oMessages.unsaved_msg_1 + "<br />" + oMessages.unsaved_msg_2,
		fn
	);
}

/**
 * this.error(sMsg) - Create an error message window.
 * 
 * @param {String} sMsg This is the message who will be shown.
 */
function error(sMsg){
	Ext.Msg.show({
		msg: "<b style='color:#000'>" + sMsg + "</b>",
		resizable: false,
		title: "<b>" + oMessages.error + "</b>",
		buttons: Ext.Msg.OK,
		autoHeight: true,
		autoWidth: true,
		modal: true,
		icon: Ext.MessageBox.ERROR
	});
}

/**
 * this.warning(sMsg) - Create a warning message window.
 * 
 * @param {String} sMsg This is the message who will be shown.
 */
function warning(sMsg){
	Ext.Msg.show({
		msg: "<b style='color:#000'>" + sMsg + "</b>",
		resizable: false,
		title: "<b>" + oMessages.warning + "</b>",
		buttons: Ext.Msg.OK,
		autoHeight: true,
		autoWidth: true,
		modal: true,
		icon: Ext.MessageBox.WARNING
	});
}

/**
 * this.serverError(sResponse) - Create an error message window from a server response.
 * 
 * @param {String} sResponse This is the server response (html) message who will be shown.
 */
function serverError(sMsg){
	Ext.Msg.show({
		msg:"<b style='color:#000'>" + sMsg + "</b>",
		resizable: true,
		title: "<b>" + oMessages.error + "</b>",
		buttons: Ext.Msg.OK,
		autoHeight: true,
		autoWidth: true,
		modal: true,
		icon: Ext.MessageBox.ERROR
	});
}
	
