addLoadEvent(initProfile);

function initProfile()
{
	$('compartilhe_form').onsubmit = function()
	{
		var url = 'backend/envia_convite_compartilhe.php';
		var pars = "to_email=" + $F('compartilhe_para') + "&user_id=" + $F('compartilhe_id_usuario') + "&comentarios=" + $F('compartilhe_comentarios');

		writeLoading('fb_compartilhe');

		var myAjax = new Ajax.Updater(
			{success: 'fb_compartilhe'}, url, {asynchronous: true, method: 'post', parameters: pars, onFailure: reportError, onComplete: showResponseShare }
		);
		
		return false;
	}
}

function showResponseShare(request)
{
	if(request.responseText == "Convite enviado") {
		$('fb_compartilhe').className = 'statusMessage';
		Form.reset('compartilhe_form');
		Form.focusFirstElement('compartilhe_form');
	}
	else {
		$('fb_compartilhe').className = 'errorMessage';
	}
}
