// JavaScript Document

function login() {
	new Effect.Appear('all');
	var left = $('all').getWidth()/2 - 250;
	var top = $('all').getHeight()/2 -200;
	$('all').update('<div id="loginwindow"></div>');
	new Effect.Morph('loginwindow',{
		style:'left:' + left + 'px;',	
		delay:0,
		duration:0
		});
	new Effect.Morph('loginwindow',{
		style:'top:' + top + 'px;',
			
		delay:0,
		duration:0
		});
	var url = 'ajax/gestione/loginform.php';
	new Ajax.Request(url,						// chiamata (usando prototype)
					{ 	
						method: 'get',				
						onSuccess:  showResponseLogin	// funzione chiamata in caso di risposta positiva
					}
				);
}


function closeAll() {
	$('all').replace('<div id="all" style="display: none;"></div>');
}

function showResponseLogin(transport) {
	$('loginwindow').update(transport.responseText);
}

function doLogin() {
	
		new Ajax.Request("ajax/gestione/login.php",{
				method: "post",
				parameters: { user: $F('login'), password: MD5($F('password'))},
				onSuccess:	loginResponse
						 });	
	
	}

function loginResponse(transport) {
        var group = Number(transport.responseText);
        if(group > -1 ) {
            if(group == 2)
                window.location = "gestione_rubriche/gestione.php?mode=moderazione";
            else 
                window.location = "gestione_index.php";
		} else {
       // $('loginwindow').update(group);
                $('loginwindow').update('<table width="100%" height="100%" border=0><tr><td colspan=2><p align=center>Login non riuscito</p></td></tr><tr><td width="50%"><div align=center><a href="#" onClick="login()">Riprova</a></div></td><td><div align=center><a href="#" onClick="closeAll()">Chiudi</a></div></td></tr></table>');	
		}
        
	
	}
	
function logout() {
	new Ajax.Request("ajax/gestione/logout.php",
	{ onSuccess:
	function(transport) { window.location.reload();}
	});
	
}
