$(document).ready(function() {

  // Click on "Kostenlose Tipps"
    $('#tipps').click(function(e) {
      e.preventDefault();
      $.scrollTo('#form_1', 1000);
      $('#email_1').pulse( {
        backgroundColors : [ '#FFDD00', 'white' ],
        runLength : 3,
        speed: 800
      });
      $('#email_1').focus();
    });

    // Blocks RETURN/ENTER key (otherwise IE will submit complete form)
    $('input').keypress(function(event) {
      return event.keyCode == 13 ? false : true;
    });

    // Click on SUBMIT in step a, form 1.
    $('#submit_a_1').click(function(e) {
      e.preventDefault();

      $('#step_a_1').fadeOut(100);
      $('#step_b_1').fadeIn(100);
      $('#response_1').focus();
    });

    // Click on SUBMIT in step b, form 1.
    $('#submit_b_1').click(function(e) {
      e.preventDefault();

      $('#step_b_1').fadeOut(100);
      $('#progress_1').text("Bitte warten...");
      $("#progress_1").fadeIn(100);

      $.get("send_email.php", $("#form_1").serialize(), function(result) {
        if (result == 'SENT') {
          $('#progress_1').text("Die E-Mail wurde an Sie verschickt.");
        } else {
          $('#progress_1').text("Sorry, bitte später nochmals versuchen.");
        }
      });
    });

    // Click on SUBMIT in step a, form 2.
    $('#submit_a_2').click(function(e) {
      e.preventDefault();

      $('#step_a_2').fadeOut(100);
      $('#step_b_2').fadeIn(100);
      $('#response_2').focus();
    });

    // Click on SUBMIT in step b, form 2.
    $('#submit_b_2').click(function(e) {
      e.preventDefault();

      $('#step_b_2').fadeOut(100);
      $('#progress_2').text("Bitte warten...");
      $("#progress_2").fadeIn(100);

      $.get("send_email.php", $("#form_2").serialize(), function(result) {
        if (result == 'SENT') {
          $('#progress_2').text("Die E-Mail wurde an Sie verschickt.");
        } else {
          $('#progress_2').text("Sorry, bitte später nochmals versuchen.");
        }
      });
    });

  });
