$(document).ready(function() { 
    $('#newsletterSubscribe').ajaxForm({ 
        dataType:  'json', 
        success:   processJson 
    }); 
});

function processJson(data) {
    var total = 0;
    
    if(data.errors) {
        for(key in data.errors) {
            if(data.errors[key] != null) {
                total++;
                
                $("#"+key).css({'border':'1px solid #930E2F'});
                $("#"+key+"Error").html(data.errors[key])
                                  .fadeIn(1500);
            } else {
                $("#"+key).removeAttr('style');
                $("#"+key+"Error").fadeOut(0)
                                  .html('');
            }
        }
    }
    
    if(total == 0) {
        $("#newsletterSubscribeResult").html('Bedankt voor uw inschrijving. U bent succesvol ingeschreven.');
        
        $("#newsletterSubscribe").slideUp(1000,function(){
            $("#newsletterSubscribeResult").slideDown(500);
        });
    }
}

