$(document).ready(function(){

   // Open links in new windows

   $('a.new-window').click(function(){
      window.open(this.href);
      return false;
   });

   // Add / remove default text on form input fields
   
   var defaultValues =  new Array();

   $(".default-text").focus(function() {

      if (!defaultValues[$(this).attr('id')]) {

         defaultValues[$(this).attr('id')] = $(this).val();
         $(this).val('');

      } else if (defaultValues[$(this).attr('id')] == $(this).val()) {

         $(this).val('');

      }

   });

   $(".default-text").blur(function() {

      if ($(this).val().length <= 0) {
        $(this).val(defaultValues[$(this).attr('id')]);
      }

   });

   // Booking form validation

   $("#booking-submit").click(function() {

      if (!$("#choose-event").val()) {

         alert('Please select an event.');
         $("#choose-event").focus();

         return false;

      }

      if (!$("#booking-name").val() || !defaultValues[$("#booking-name").attr('id')] || $("#booking-name").val() == defaultValues[$("#booking-name").attr('id')]) {

         alert('Please enter your name.');
         $("#booking-name").focus();

         return false;

      }

      if (!$("#booking-surname").val() || !defaultValues[$("#booking-surname").attr('id')] || $("#booking-surname").val() == defaultValues[$("#booking-surname").attr('id')]) {

         alert('Please enter your surname.');
         $("#booking-surname").focus();

         return false;

      }

      if (!$("#booking-company").val() || !defaultValues[$("#booking-company").attr('id')] || $("#booking-company").val() == defaultValues[$("#booking-company").attr('id')]) {

         alert('Please enter your company name.');
         $("#booking-company").focus();

         return false;

      }

      if (!$("#booking-address").val() || !defaultValues[$("#booking-address").attr('id')] || $("#booking-address").val() == defaultValues[$("#booking-address").attr('id')]) {

         alert('Please enter your address.');
         $("#booking-address").focus();

         return false;

      }

      if (!$("#booking-postcode").val() || !defaultValues[$("#booking-postcode").attr('id')] || $("#booking-postcode").val() == defaultValues[$("#booking-postcode").attr('id')]) {

         alert('Please enter your postcode.');
         $("#booking-postcode").focus();

         return false;

      }

      if (!$("#booking-email").val() || !defaultValues[$("#booking-email").attr('id')] || $("#booking-email").val() == defaultValues[$("#booking-email").attr('id')]) {

         alert('Please enter your email address.');
         $("#booking-email").focus();

         return false;

      }

      if (!$("#booking-telephone").val() || !defaultValues[$("#booking-telephone").attr('id')] || $("#booking-telephone").val() == defaultValues[$("#booking-telephone").attr('id')]) {

         alert('Please enter your telephone number.');
         $("#booking-telephone").focus();

         return false;

      }

      if (!$("#booking-places").val()) {

         alert('Please select the number of places required.');
         $("#booking-places").focus();

         return false;

      }

   })

});

