function doLogin(loginURL, loginSessionURL){
	try{
		var screen = document.getElementsByName("screen")[0].value;
		var loginChoice = document.getElementsByName("loginChoice")[0].value;
		var username = document.getElementById("username").value;
		var password = document.getElementById("password").value;
		
		//alert(screen + " " + loginChoice + " " + username + " " + password);
		
		var params="username=" + username + "&password=" + password;
        
		//showPleaseWait(true);
        process_ajax_call( params,_USER_LOGIN_CONTROLLER,
            function(error){
                if(!error)
                {
                	//Controllo se vi sono errori
                	if(typeof this.responseXML.getElementsByTagName("error") == "undefined")
                	{
	                	var error_message = this.responseXML.getElementsByTagName("error")[0].firstChild.nodeValue;
	               		//Alert del messaggio d'errore
	                	alert(error_message);
	                	return true;
                	}
                	
                	var corsi_nome = this.responseXML.getElementsByTagName("nome")[0].firstChild.nodeValue;
                	var corsi_cognome =  this.responseXML.getElementsByTagName("cognome")[0].firstChild.nodeValue;
                	var corsi_username = this.responseXML.getElementsByTagName("username")[1].firstChild.nodeValue;
                	var corsi_user_id = this.responseXML.getElementsByTagName("id")[0].firstChild.nodeValue;
                	
                	//Creazione dell'Array per il passaggio dei dati alla Session di Jahia
                	var corsi_params_session = "username=" + corsi_username + "&nome=" + corsi_nome + "&cognome=" + corsi_cognome + "&id=" + corsi_user_id;
                	
                	//Recupero username e password per Jahia dal profilo
                    var jahia_username = this.responseXML.getElementsByTagName("username")[0].firstChild.nodeValue;
                    var jahia_password = this.responseXML.getElementsByTagName("password")[0].firstChild.nodeValue;
                    
                    //Creazione dell'Array da passare alla funzione form_post_to_url
                    var jahia_params = new Array();
                    
                    //Inserimento dei parametri in array
                    jahia_params['loginChoice'] = loginChoice;
                    jahia_params['screen'] = screen;
                    jahia_params['username'] = jahia_username;
                    jahia_params['password'] = jahia_password;
                    
                    //Chiamata del form nascosto
                    form_post_to_url(loginURL, jahia_params);
                    
                    //Invio dei dati alla pagine di store nella Session Jahia (JQuery)
                    setTimeout($.ajax({
                    	  url: loginSessionURL,
                    	  data: corsi_params_session,
                    	  async: false,
                    	  success: function(msg){
                    			//alert((new XMLSerializer()).serializeToString(msg));
                       			var session_id = msg.responseXML.getElementsByTagName("id")[0].firstChild.nodeValue;
                    		}
                    	 })
                    ,50);
                    
                    //Invio dei dati alla pagine di store nella Session Jahia
                	/*process_ajax_sync_call( corsi_params_session, loginSessionURL, function(error){
	                    if(!error)
	                    {	
	                       	alert((new XMLSerializer()).serializeToString(this.responseXML));
	                       	var session_id = this.responseXML.getElementsByTagName("id")[0].firstChild.nodeValue;

	                    } else {
	                       	return false;
	                    }
	                });*/
                    
                	
                    //showPleaseWait(false);
                    return true;
                }
                else
                {
                	//showPleaseWait(false);
                    return false;
                }
            } );

    } catch(e) {
    	alert("error: "+e);
    	//showPleaseWait(false);
    	return false;
    }
}

function doLogout(logoutURL, jahiaLogout){
	try{
		//showPleaseWait(true);
		process_ajax_sync_call(null,logoutURL,function(error){
            if(!error)
            {
            	//alert(this.responseXML.getElementsByTagName("message")[0].firstChild.nodeValue);
            	return true;
            } else {
            	return false;
            }
            });

    } catch(e) {
    	alert("error: "+e);
    	//showPleaseWait(false);
    	return false;
    }
    location.href = jahiaLogout;
}
