function refreshLoginInfo ()
{
    var info;
    if (isSU)
        info = execJSON("jsp/getLoginInfo.jsp");
    else
        info = { isLogged : false, userName : "" };
        
    loginInfo = info; // loginInfo variabile Globale
    return info;        
}


function on_login(el) 
{
    if (isSU)
    {
    	refreshLoginInfo()
    
    	if (!loginInfo.isLogged )
    	{
    		if (confirm("Si desidera accedere alle funzionalitą di Certificazione ? "))
    			window.location = "./jsp/login.jsp?ssoid=";	
    	} 
    	else if (!loginInfo.userName)
    	{
        	if (confirm("Si desidera annullare la sessione utente ?"))
        		window.location = "./jsp/logout.jsp";
    	}
    	else
        {	
        	if (confirm("Si desidera uscire dalla Certificazione ?"))
        		window.location = "./jsp/logout.jsp";
        }          	
    }
}    


function addLoginTools (mapID, toolbarItems)
{
    if (isSU)
    {
        if (loginInfo.isLogged)
        {
            if (loginInfo.userName)
            {
                toolbarItems.push (
                { 
                    xtype: 'tbtext', 
                    text: "Certificazione attiva per: <span id='userName' style='font-style:italic; background: white; padding: 2px 5px;'>" + loginInfo.userName + "</span>",
    			    style:  'margin-right: 2px;'
                });
                
            	toolbarItems.push 
            	({
    				icon: 		"img/logout.gif", 
    				tooltip: 	"Annullamento sessione di Certificazione", 
    				cls: 		'x-btn-icon toolbarButton selected', 		
    				handler: 	on_login, 
    				id:			mapID + "_logout",
    				style:      'margin-right: 10px;'
    			});
            }
            else
            {
                toolbarItems.push (
                { 
                    xtype: 'tbtext', 
                    disabled: true,
                    text: "Certificazione inattiva - utente non abilitato",
    			    style:  'margin-right: 2px;'
                });
    
            	toolbarItems.push 
            	({
    				icon: 		"img/logout.gif", 
    				tooltip: 	"Annullamento sessione utente", 
    				cls: 		'x-btn-icon toolbarButton selected', 		
    				handler: 	on_login, 
    				id:			mapID + "_logout",
    				style:      'margin-right: 10px;'
    			});
            }
        }                
        else
        {
            toolbarItems.push (
            { 
                xtype: 'tbtext', 
                text:   "Certificazione inattiva",
			    style:  'margin-right: 2px;'
            });
            
        	toolbarItems.push 
        	({
    			icon: 		"img/login.gif", 
    			tooltip: 	"Abilita il sito alla Certificazione", 
    			cls: 		'x-btn-icon toolbarButton', 		
    			handler: 	on_login, 
    			id:			mapID + "_login",
    			style:      'margin-right: 10px;'
    		});
        }                
    }    
    return toolbarItems;
}
