
var captionContext = {
	base: 'portal',
	name: 'portal', 
	captions: {},
	
	init: function () {
		$.getJSON("/common/service/requestparser", {name: 'codeset', codeset: captionContext.name}, captionContext.load);
	},
	
	load: function (data) {
		debug("data", data);
		
		if (data.success) {
			var objCaptions = {};
			
			for (var i=0; i<data.data.length; i++) {
				objCaptions[data.data[i].value] = data.data[i].name;
			}
			
			captionContext.captions[captionContext.name] = objCaptions;
		}
	},
	
	caption: function (strCaption, strName) {
		var strCaptionText = strCaption;
		
		if (typeof(strName) == "undefined") {
			strName = captionContext.base;
		}
		
		if (typeof(captionContext.captions[strName]) == "undefined") {
			alert("Caption scope not found: "+strName+" !");
		} else {
			var objScope = captionContext.captions[strName];
			
			if (typeof(objScope[strCaption]) == "undefined") {
				alert("Caption not found: "+strCaption+" in "+strName+" !");
			} else {
				strCaptionText = objScope[strCaption];
			}
		}
		
		return strCaptionText;
	}
};

$(document).ready(function(){
	captionContext.init();
});


