$(document).ready(function() {

    // Javascript email form
    $('#id_email').focus(function() { 
        if ( $(this).val() == 'steve@apple.com' ) {
            $(this).val('');  
            $(this).css('color', '#151515'); 
        }
    }); 
    $('#id_email').blur(function() {
        if ( $(this).val() == '' ) {
            $(this).val('steve@apple.com');
            $(this).css('color', '#cacaca');
        }
    });

    $('#emailform').submit(function(e) {
       e.preventDefault(); 
       
       $('#response').hide();
       $('#error').hide();
       
       
       
       // Make ajax call to the server
       var post_string = $(this).serialize();
       
       $.ajax({
          type: 'post',
          url: $(this).attr('action'),
          data: post_string,
          dataType: 'json', 
          
          success: function(data) { 
               if ( data.error ) {
                   $('#error').html(data.error);
                   $('#error').fadeIn(1000);
                   
               } else {
                   $('#response').html(data.success);  
                   $('#response').fadeIn(1000);
                   
               } 
               
          },
          
          error: function(request, textStatus, error) {
            $('#error').html('Unknown error');
            $('#error').fadeIn(1000);
          }
          
       });          
       return false;
    });
});   
           

