Event.add(window, 'load', function()
{
	if (I('user_contact_form')) 
	{
		var fnc = function(e)
		{
			var usr = V('user_contact_user'), obj = V('user_contact_object'), msg = V('user_contact_message'), eml = V('user_contact_email'), nam = V('user_contact_name');
			
			Ajax.get({
				url: BASE_URL + '/index.php?mdu=ajax/contact',
				post: {
					user: usr,
					name: nam,
					email: eml,
					object: obj,
					message: msg
				},
				onRequest: function()
				{
					ViewPort.open();
				},
				onSuccess: function(t)
				{
					var m = 'Un disguido ha impedito l\invio...', c = 'error', r;
					
					if ((t = JSON.decode(t))) 
					{
						r = t.result;
						if (r == 'success') 
						{
							m = 'eMail inviata con successo.';
							c = 'confirm';
							
							setTimeout(function()
							{
								document.location = BASE_URL + '/user/' + t.adressee + '/';
							}, 2000);
							
						}
						else if (r == 'empty') 
						{
							m = 'Solo il campo Oggetto è facoltativo!';
						}
						else if (r == 'bad-email') 
						{
							m = 'L\'email ha un formato non valido!';
						}
						else if (r == 'cannot-send') 
						{
							m = 'Non è stato possibile inviare l\'email!';
						}
					}
					
					Aols.messageLayer(m, c);
				}
			});
			
			return e.stop();
		};
		$('#user_contact_form form')[0].addEvent('submit', fnc);
		I('user_contact_send').addEvent('click', fnc);
	}
	
	
	if (I('user_description')) 
	{
		I('user_description').styles({
			borderRadius: '10px'
		});
	}
	
	if (I('microblog')) 
	{
		I('microblog').styles({
			borderRadius: '10px'
		});
	}
	
	if (I('microblog_form')) 
	{
		I('microblog_send').addEvent('click', function(e)
		{
			var cnt = V('microblog_input');
			
			Ajax.get({
				url: BASE_URL + '/index.php?mdu=ajax/panel/microblogs&action=edit',
				post: {
					content: cnt
				},
				onSuccess: function(t)
				{
					var m = 'Un disguido ha impedito il salvataggio...', c = 'error', r;
					if ((t = JSON.decode(t))) 
					{
						r = t.result;
						if (r == 'success') 
						{
							I('microblog_rows').prepend(['p', {
								id: 'microlog_' + t.id
							}, ['span', t.username + ' ' + t.content], ' ', ['em', t.add_date]]);
							
							return;
						}
						else if (r == 'empty') 
						{
							m = 'Il messaggio non può essere lascaito vuoto';
						}
						else if (r == 'wait') 
						{
							m = 'Sei stato troppo veloce! Aspetta ancora un pò per aggiornare il tuo stato!';
						}
					}
					
					Aols.messageLayer(m, c);
				}
			});
			
			return e.stop();
		});
	}
});