
	/* --------------------------
		Send By Email
	-------------------------- */

He.Bootstrap('He.Components.SendByEmail');

He.Components.SendByEmail.Form		= null;
He.Components.SendByEmail.Captcha	= null;

He.Components.SendByEmail.Trigger = function(hash)
{	
	$('#btn_send_by_email, a.btn_send_by_email').click(function()
	{
		He.Components.SendByEmail.ResetPopup();
		$('form')[0].reset();
		callAjaxGetCaptcha();
		
		$('#form_send_by_email').show();
		$('#response_send_by_email').hide();
		$('#send_by_email').jqmShow();
	});
};

He.Components.SendByEmail.DisplayCaptcha = function(json)
{
	if(json.status == 'ok')
	{
		$('#img_captcha').attr('src', json.content.img);
		$('#captcha_uidpk').val(json.content.UIDPK);
	}
}

He.Components.SendByEmail.Reponse = function(json)
{
	if( json.status == 'ok'){
		$('#form_send_by_email').hide();
		$('#response_send_by_email').show();
	}else if( json.status == 'captcha'){
		$("label.required[for='captcha']").addClass('alert');
		callAjaxGetCaptcha();
	}else if( json.status == 'email'){
		$("label.required[for='email']").addClass('alert');
		callAjaxGetCaptcha();
	}else if( json.status == 'nosku'){
		$('#form_send_by_email').hide();
		$('#response_send_by_email_fail_nosku').show();
	}else{
		$('#form_send_by_email').hide();
		$('#response_send_by_email_fail').show();
	}
}

He.Components.SendByEmail.ResetPopup = function()
{
	$('#form_send_by_email').show();
	$('#response_send_by_email').hide();
	$('#response_send_by_email_fail').hide();
	$('#response_send_by_email_fail_nosku').hide();
}

He.Components.SendByEmail.Init = function()
{
	/* Send By Email */
	$('#send_by_email').jqm();
	
	/* Form Obj */
	He.Components.SendByEmail.Form = $('#form_send_by_email');
	
	/* Popup Trigger */
	He.Components.SendByEmail.Trigger();
	
	/* Char Counter */
	$('#message').charCounter(350, 
	{
		container: '#characters_left'
	});	
	
	$('#form_send_by_email button.std_button').click(function(e)
	{
		e.preventDefault();
		if(He.Application.FormValide(He.Components.SendByEmail.Form))
		{
			var addressSERIAL = He.Components.SendByEmail.Form.serialize();
				
			callAjaxSendToFriend(addressSERIAL);
		}

	});
	
}
