$(document).ready(function(){

    //Open any links marked rel="external" in a new window.
    $('a').click(function(){
        if ($(this).attr('rel')=='external') {
            window.open($(this).attr("href"));
            return false;
        }
    });

    //Adds the friendlyForm class to any Zend forms that appear
    if ($('#customForm').length) {
        $('#customForm').addClass('friendlyForm');
    }

    //Make all navigation items with Stud 100 bold
    $('#mainMenu li').highlight('STUD 100');
    
    /* Stripe the stockists table */
    $("#stockistTable tbody tr:odd").addClass("odd");


    //Set up form validation....
    if ($('#customForm').length != 0) {

        jQuery.validator.messages.required = "";  //Defines that the error labels are populated.
        
        $('#customForm').validate({
        invalidHandler: function(e, validator) {
            var errors = validator.numberOfInvalids();
            if (errors) {
                var message = errors == 1
                    ? 'It appears you have not completed a field.  This has been highlighted below.'
                    : errors + ' fields have not been completed. They have been highlighted below.';
                $("div.error h3").html(message);
                $("div.error").show();
                $("label.error").css('color: #fff000;');
            } else {
                $("div.error").hide();
            }
        }
     });
    };

      if ($('#gateway_form').length != 0) {
        $('#gateway_form').submit();
      }
      
      $('#deliveryCharge').change(function (){
          $('#basketForm').submit();
      });
      
      $('#priority').change(function (){
          $('#basketForm').submit();
      });
      
      $('.buyNow').click(function() {
         $('.productForm').submit(); 
      });
      
      $('.quantity').change(function () {
         $('#basketForm').submit(); 
      });

});


