$(function()
{
	$('#email_suscribe').sahDefaultTextLabel('email@address.com');
	$('#btn_suscribe').click(function(e)
	{
		e.preventDefault();
		if($('#email_suscribe').val() == 'email@address.com')
			e.stopImmediatePropagation();
	}).sahFormValidator( {
		scope: '#frmSuscribe',
		success: suscribeMe,
		msg_div: '#suscribe_error',
		/* messages */
		prefix: 'Field',
		msg_required: 'is required.',
		msg_email: 'is not a valid e-mail address.'
	});
	$('#lightbox_suscribe').hide();
	$('#close_suscribe').click(hideSuscribe);
});

function hideSuscribe(e)
{
	$('#cortina').fadeOut('fast');
	$('#lightbox_suscribe').hide();
}

function suscribeMe()
{
	$.ajax( {
		url: $.sah.ajaxUrl('Index', 'ajax_suscribe'),
		data: {
			email: $('#email_suscribe').val()
		},
		beforeSend: function()
		{
			$('#btn_suscribe').sahDisable();
			$('#suscribing').show();
		},
		success: function(bOk, st)
		{
			if(bOk)
				alert('Thanks for suscribe.');
		},
		complete: function(Xhr, st)
		{
			$('#btn_suscribe').sahEnable();
			$('#suscribing').hide();
			hideSuscribe(null);
		}
	});
}

function showSuscribe()
{
	$('#email_suscribe').val('').trigger('blur');
	$('#suscribe_error,#suscribing').hide();
	$('#cortina').sahExpand();
	$('#lightbox_suscribe').show().sahCenter();
}