var fw = 
{
	GetResponse: function(strJSon) {
		var jSon = {};
		try {
			jSon = eval('('+strJSon+')');
		} catch(err) {
			jSon.blnSuccess = false;
			jSon.strMessage = strJSon;
		}
		// do what it's supposed to:
		if (jSon.blnSuccess !== true) {
			if (!jSon.strMsgType) jSon.strMsgType = 'X';
			var strMsg = jSon.action+" has returned an error:\n"+jSon.strMessage+"\npassed params (if available):\n"+fw.dump(jSon.arrParams);
			this.ShowMessage('divTestDialog', jSon.action, strMsg, jSon.strMsgType);
			jSon.blnSuccess = false;
		} else {
			if (jSon.strMessage != '') {
				this.ShowMessage('divTestDialog', jSon.action, jSon.strMessage, jSon.strMsgType);
			}
		}
		return jSon;
	},
	ShowMessage: function(strDialogID, strTitle, strMessage, chrType) {
		// function to easily build-up ui modal dialog.
		// chrType allowed values: 'I'=info, 'Q'=question, 'W'=warning, 'E'=error, 'X'=fatal error.
		if (!$('#'+strDialogID).length) {
			alert(strTitle+":\n\n"+strMessage);
		} else {
			var jqDialog = $('#'+strDialogID);
			jqDialog.find('#divDialogText').html(fw.conv.Nl2br(strMessage));
			jqDialog.find('#divDialogIcon').css('background', 'url("/common/images/' + chrType + '-ico.png") no-repeat scroll left top transparent');
			jqDialog.dialog('option', 'title', strTitle);
			jqDialog.dialog('open');
		}
	},
	dump: function (arr,level) {
		var dumped_text = "";
		if(!level) level = 0;

		//The padding given at the beginning of the line.
		var level_padding = "";
		for(var j=0;j<level+1;j++) level_padding += "    ";
		if(typeof(arr) == 'object') { //Array/Hashes/Objects
			for(var item in arr) {
				var value = arr[item];
				if(typeof(value) == 'object') { //If it is an array,
					dumped_text += level_padding + "'" + item + "' ...\n";
					dumped_text += this.dump(value,level+1);
				} else {
					dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
				}
			}
		} else { //Stings/Chars/Numbers etc.
			dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
		}
		return dumped_text;
	}
};

$(function() {
	var shift = -330;
	function shiftBubbles() {
		$("#bubbles").css({backgroundPosition: ' 0' + shift + 'px'});
		shift -= 1;
	}
	var timer = setInterval(shiftBubbles, 100); 
});
