

window.addEvent('domready', function() {
	var account_check_user=false;
	var account_check_email=false;
	
	//richiesta ajax sull'username
	if($('f_user')) {
		$('f_user').addEvent('blur',function () {
			if(this.get('value')!="") {
				var req = new Request.HTML({url:'http://www.ciaogo.com/ajax/account_check.html', 
					onSuccess: function(tree,elements,html) {
						if(html=="1") {account_check_user=true; $('f_user_span').set('class','testo_verde'); $('f_user_span').set("html","&nbsp;&nbsp;<img src='http://www.ciaogo.com/sito/img/account_check_si.png' title='' alt='' style='vertical-align:middle' />&nbsp;nome utente utilizzabile");}
						if(html=="2") {account_check_user=false; $('f_user_span').set('class','testo_rosso'); $('f_user_span').set("html","&nbsp;&nbsp;<img src='http://www.ciaogo.com/sito/img/account_check_no.png' title='' alt='' style='vertical-align:middle' />&nbsp;nome utente già utilizzato!");}
						
					},
					onFailure: function(error) {}
				}).get({'user':this.get('value')});	
				
			}
		});
	}
	//richiesta ajax sulla email
	if($('f_email')) {
		$('f_email').addEvent('blur',function () {
			if(this.get('value')!="") {
				var req = new Request.HTML({url:'http://www.ciaogo.com/ajax/account_check.html', 
					onSuccess: function(tree,elements,html) {
						if(html=="1") {account_check_email=true; $('f_email_span').set('class','testo_verde'); $('f_email_span').set("html","&nbsp;&nbsp;<img src='http://www.ciaogo.com/sito/img/account_check_si.png' title='' alt='' style='vertical-align:middle' />&nbsp;email valida ed utilizzabile");}
						if(html=="2") {account_check_email=false; $('f_email_span').set('class','testo_rosso'); $('f_email_span').set("html","&nbsp;&nbsp;<img src='http://www.ciaogo.com/sito/img/account_check_no.png' title='' alt='' style='vertical-align:middle' />&nbsp;email già associata ad un account!");}
						
					},
					onFailure: function(error) {}
				}).get({'email':this.get('value')});	
				
			}
		});
	}
	
	//fa sparire i box di suggerimento quando si invia il modulo
	$('accountGestisci').addEvent('submit',function (e) {
		if(!account_check_user) {alert("Attenzione, hai inserito un username già utilizzato da un altro account. Ti preghiamo di sceglierne un altro.");e.stop();}
		if(!account_check_email) {alert("Attenzione, hai inserito una email già utilizzata da un altro account. Ti preghiamo di sceglierne un'altra.");e.stop();}
		$$('.suggerimento').setStyle('display','none');
	});
	
});
