var Maiaworkspace = {
    tabid:0,
    tabSideId:0,
    tabDiary:0,
    isTabTaskConsulted:0,
    menuTransactionMap:{},
	fillMenuTransactionMap: function(){
		var jsonTransactions = $("#menuJsonForm\\:menuJsonFormValue").val();
		jsonTransactions = jsonTransactions.slice(0,-1);
		jsonTransactions = '{'+jsonTransactions+'}';
		this.menuTransactionMap = eval('('+jsonTransactions+')');
		$("#transactionMenuPanel").hide();
	},
	verifyChangePassword: function(){
		var isChange = $("#menuJsonForm\\:changePassword").val();
		if(isChange=='Y'){
			openChangePassword();
		}
	},
    loadPage: function(urlpage, pname, params) {
    	if(params!=undefined && params!=null){
    		urlpage = urlpage+"&bpmParams="+escape(params);
    	}
        $("#tab"+Maiaworkspace.tabid).attr("src", "/"+this.getContext()+"/"+urlpage);
        $("a[href='#tabs\\:option"+this.tabid+"']").first().text(pname);        
    },
    loadPageFromEvent: function(event){
    	var e = event || window.event;    	
    	var k = null;
        if(e.which) k = e.which;
        else if(e.keyCode) k = e.keyCode;
        
    	var jmodule = $("#menuJsonForm\\:tmodule");
    	var jtransaction = $("#menuJsonForm\\:ttransaction");
    	var key = null;
    	if(k===13 || k === 1){
    		key = jmodule.val()+"-"+jtransaction.val()+"-1";
    		if(jmodule.val() && jtransaction.val()){
                   
                        var transaction = this.menuTransactionMap[key];
    			if(transaction === null){
                            $("#tranMsgDialog").show();

			}else{
                            this.loadPage(this.menuTransactionMap[key]["url"], this.menuTransactionMap[key]["name"], null);
                        }

    			$("#transactionMenuPanel").hide();
    			jmodule.val("");
    			jtransaction.val("");
    		}
    	}
        
    	return false;
    },
    loadPageFromTransactionKey: function(key, params){
    	this.loadPage(this.menuTransactionMap[key]["url"], this.menuTransactionMap[key]["name"], params);
    },
    transactionTabEvent: function(event, other){
		var e = event || window.event;
    	var k = null;
        if(e.which) k = e.which;
        else if(e.keyCode) k = e.keyCode;
        if(k==9){
        	other.focus();
        }
        return false;
    },
    getContext: function(){
        var dieccion = window.location.pathname.split("/");
        return dieccion[1];
    },
    initializeTabsUrl: function(){
    	//var initTabUrl = location.pathname+"pages/initialtab.xhtml";
    	var initTabUrl = '/frontend/pages/initialtab.xhtml';
    	$("#tab0").attr("src", initTabUrl);
    	$("#tab1").attr("src", initTabUrl);
    	$("a[href='#tabs\\:option0']").first().text('Opci\u00f3n');
    	$("a[href='#tabs\\:option1']").first().text('Opci\u00f3n');
    	},
    initializePathTexto: function(url, texto){
        console.log('Contexto Please', this.getContext());
    	$("#tab0").attr("src", '/frontend'+url);
    	$("a[href='#tabs\\:option0']").first().text(texto);
    },
    handleTabChange: function(index) {
		Maiaworkspace.tabid = index;
	},
	handleTabSideChange: function(index) {
		this.tabSideId = index;
		if(this.tabSideId==1 && this.isTabTaskConsulted==0){
			this.isTabTaskConsulted = 1;
			this.handleTabDiaryChange(0);
		}
	},
	handleTabDiaryChange: function(index) {
		this.tabDiary = index;
		if(this.tabDiary==0){
			inboxTransactions([{name:'tabDiary',value:this.tabDiary}]);
		}else{
			inboxTransactionsByGroup([{name:'tabDiary',value:this.tabDiary}]);
		}
	},
	loadHelp: function(module, transaction, version, path){
		/*var ventana = */window.open('/'+this.getContext()+'/HelpServlet?cmodule='+module+'&ctransaction='+transaction+'&version='+version+'&path='+path, 'Ayuda',
				'height=400,width=600,top=200,left=300,scrollbars=0,toolbar=0,location=0,menubar=0,status=0,resizable=1');
	}
};