jQuery( document ).ready( function() {
	
	jQuery( '#informativo-enviar' )
		.after('<div class="htac-loading" id="loading" style="display:none;"></div>');

	jQuery( '#form-newsletter' ).submit( function() {
		jQuery( '#informativo-enviar' ).attr( 'disabled', 'disabled' );
		var oldresponse = jQuery( '#subscribe-response' );
		oldresponse.attr( 'id', 'old-subscribe-response' );
		oldresponse.slideUp( 200, function() {
			oldresponse.remove();
		} );
		jQuery( '#form-newsletter > #loading' ).slideDown( 200 );
		jQuery.post( jQuery( this ).attr( 'action' ),
				{
					'informativo-nome' : jQuery( '#informativo-nome' ).val(),
					'informativo-email' : jQuery( '#informativo-email' ).val(),
					'informativo-enviar' : jQuery( '#informativo-enviar' ).val()
				},
				function( data ) {
					jQuery( '#humantech-newsletter-widget > div:first' ).append(
							'<p style="display: none;" id="subscribe-response">' +
							( ( data.sucesso ) ? data.sucesso : data.erro ) + '</p>'
						);
					if( data.erro )
						jQuery( '#subscribe-response' ).addClass( 'erro' );
					else {
						jQuery( '#subscribe-response' ).addClass( 'sucesso' );
						jQuery( '#informativo-nome' ).val( 'Nome' );
						jQuery( '#informativo-email' ).val( 'E-mail' );
					}
					jQuery( '#subscribe-response' ).slideDown( 200 );
					jQuery( '#informativo-enviar' ).attr( 'disabled', '' );
					jQuery( '#form-newsletter > #loading' ).slideUp( 200 );
				},
				"json"
			);
		return false;
		
	} );
	
	jQuery( '#informativo-nome' ).focus( function() {
		if( jQuery( this ).val() == 'Nome' )
			jQuery( this ).val( '' );
	} );
	
	jQuery( '#informativo-nome' ).blur( function() {
		if( jQuery( this ).val() == '' )
			jQuery( this ).val( 'Nome' );
	} );
	
	jQuery( '#informativo-email' ).focus( function() {
		if( jQuery( this ).val() == 'E-mail' )
			jQuery( this ).val( '' );
	} );
	
	jQuery( '#informativo-email' ).blur( function() {
		if( jQuery( this ).val() == '' )
			jQuery( this ).val( 'E-mail' );
	} );
	
} );