Event.observe(window, 'load', function() {
	
	$('lnk_rule').onclick = function(){inlinePage('include/text.regolamento.html');}

	$('loginform').onsubmit = function(){
	
		var valid = $(this.uname).present() && $(this.upass).present();
		
		if(valid){
			
			new Ajax.Request('scripts/php/login.php', {	
				method:'get',
				parameters:{ uname:$F('uname'), upass:$F('upass') },
				onComplete:function(transport){
					if(transport.responseText.match('new')){
						//window.location="myhome.php";
						window.location="scripts/php/getUserAnswer.php";
					} else if(transport.responseText.match('wrong')) {
						AccessNotAllowed('La combinazione email - password &egrave; errata.<br />Verifica i tuoi dati e prova ad accedere nuovamente.<br />Se non sei registrato puoi <a href="register.php"> farlo adesso.</a><br /> Se sei sicuro dei dati inseriti e il problema dovesse persistere contatta il supporto online.<br /><a href="mailto:help@predictionpeople.com">help@predictionpeople.com</a>');
					} else if(transport.responseText.match('old')) {
						//window.location="myhome.php";
						window.location="scripts/php/getUserAnswer.php";
					};
				}
			});
	
		} else {
			AccessNotAllowed('<b>Attenzione</b>.<br />Nessuno dei campi pu&ograve; essere vuoto.');
		}
		
		return false;
	}
		
});