function login(){	id = $('input[name="id"]').val();		page = $('input[name="page"]').val();	
	username = $('#login_username').val();
	password = $('#login_password').val();
	if($('#login_tipoUtente').val()){		tipoUtente = $('#login_tipoUtente').val();	}else{		tipoUtente = "standard";	}
	$("#form-login").hide();
	$("#ajax-loader-login").show(); //DA METTERE CENTRATO IN VERTICALE E ORIZZONTALE
	$.ajax({
		   type: "POST",
		   url: URL_ROOT+"ajax_engine.php?page=ajaxCheckLogin.php",
		   data: "u=" + username + "&p=" + password +"&t=" + tipoUtente,
		   success: function(msg){
		
				if(msg == "errorUsername" || msg == "errorPassword" || msg == "error"){
					if(msg == "errorUsername"){
						newMsg = "Si &egrave; verificato un errore. Le credenziali inserite non sono corrette";
					}else if(msg == "errorPassword"){
						newMsg = "Si &egrave; verificato un errore nella password";
					}else{
						newMsg = "Si &egrave; verificato un errore nel login. Le credenziali inserite non sono corrette.";
					}
					$('#msg-login').html(newMsg);
					$('#msg-login').show();
				}else{					msg += "<input type=\"hidden\" name=\"page\" value=\""+page+"\" /><input type=\"hidden\" name=\"id\" value=\""+id+"\" />";										if(page=="iscr_lista"){						location.reload();						return true;					}else{
						$('#lucchetto-login').removeClass("lucchetto_close").addClass("lucchetto_open");	
						$("#form-login").html(msg);					}
				}
				$("#ajax-loader-login").hide();
				$("#form-login").show();
				
				/*if(msg != "errorUsername" || msg != "errorPassword" && msg != "error"){
					//SE SONO SULLA PAGINA DI ISCRIZIONE IN LISTA MI RICARICARE LA PAGINA -- ATTUALMENTE NON USATO
					url = location.href;
					if( url.indexOf("index.php?page=iscr_lista.php", 0) != -1){
						
						//RECUPERO L'ID DELLA LISTA PER PASSARLO VIA GET(SIMULANDO UN LINK) ALLA PAGINA BL-ISCRITTI-IN-LISTA
						indiceId = url.indexOf("&id=", 0);
						delimitatoreFinale = url.indexOf("#", indiceId+4);
						if(delimitatoreFinale==-1){
							delimitatoreFinale = url.indexOf("&", indiceId+4);
							if(delimitatoreFinale==-1){
								delimitatoreFinale = url.length;
							}
						}
						idLista = url.substring(indiceId+4, delimitatoreFinale); 
						
						window.location.href="index.php?page=iscr_lista.php&id="+idLista;
					}
				}*/
		   }
	 });
	
	return false;
}

function logout(){
	$("#ajax-loader-login").show();	page = $('input[name="page"]').val();	id = $('input[name="id"]').val();		data = "page="+page+"&id="+id;	
	$.ajax({
		   type: "POST",
		   url: URL_ROOT+"ajax_engine.php?page=ajaxLogout.php",		   data: data,			   
		   success: function(msg){				if(page=="iscr_lista"){					location.reload();					return true;				}else{
					$('#lucchetto-login').removeClass("lucchetto_open").addClass("lucchetto_close");	
					$("#form-login").html(msg);	
					$("#ajax-loader-login").hide();	
					$("#form-login").show();
				
				//SE SONO SULLA PAGINA DI ISCRIZIONE IN LISTA MI RICARICARE LA PAGINA
				/*url = location.href;
				if( url.indexOf("index.php?page=iscr_lista.php", 0) != -1){
					
					//RECUPERO L'ID DELLA LISTA PER PASSARLO VIA GET(SIMULANDO UN LINK) ALLA PAGINA BL-ISCRITTI-IN-LISTA
					indiceId = url.indexOf("&id=", 0);
					delimitatoreFinale = url.indexOf("#", indiceId+4);
					if(delimitatoreFinale==-1){
						delimitatoreFinale = url.indexOf("&", indiceId+4);
						if(delimitatoreFinale==-1){
							delimitatoreFinale = url.length;
						}
					}
					idLista = url.substring(indiceId+4, delimitatoreFinale); 
					
					window.location.href="index.php?page=iscr_lista.php&id="+idLista;
				}*/				}
		   }
	 });
	return false;
}
