$(document).ready(function() {

  //***************************
  // superfluous hover effects
  //***************************
    $('table#shopping-cart tr tr.item-row').hover(function() {
      $(this).addClass('hover');
    }, function() {
      $(this).removeClass('hover');
    });
    
    $('div#steps ol li').hover(function() {
      $(this).addClass('hover');
    }, function() {
      $(this).removeClass('hover');
    });

  //***************************
  // contact validation rules
  //***************************
  $('form#contact-form').validate({
    
    // tell the validation plugin to check the following inputs
		// documentation: http://docs.jquery.com/Plugins/Validation
    rules: {
      Name: "required",
	  Location: "required",
	  Method_Contact: "required",
	  Time_Contact: "required",
      Phone: {required: true, digits: true},
		  Email_From: {required: true, email: true},
		  Comments_Enquiry: "required"
    },
    messages: {
      Phone: {digits: "Please enter numbers only"}
    },
    success: function(label) { 
      // inform user their input is valid
      label.html(" ").addClass("correct"); 
    }
    
  });
    
  
  //***************************
  // checkout validation rules
  //***************************
  $('form#checkout-form').validate({
    
    // tell the validation plugin to check the following inputs
		// documentation: http://docs.jquery.com/Plugins/Validation
    rules: {
      // BILLING
      Billing_FirstName: "required",
      Billing_Surname: "required",
      Billing_Phone: {required: true, digits: true},
		  Billing_Email: {required: true, email: true},
      Billing_Address1: "required",
      Billing_Suburb: "required",
      Billing_Postcode: {required: true, digits: true},
      Billing_State: "required",
      Billing_Country: "required",
      
      // DELIVERY
      Delivery_FirstName: "required",
      Delivery_Surname: "required",
      Delivery_Phone: {required: true, digits: true},
		  Delivery_Email: {required: true, email: true},
      Delivery_Address1: "required",
      Delivery_Suburb: "required",
      Delivery_Postcode: {required: true, digits: true},
      Delivery_State: "required",
      Delivery_Country: "required"
    },
    messages: {
      
      // BILLING
      Billing_Phone: {digits: "Please enter numbers only"},
      Billing_Postcode: {digits: "Please enter numbers only"},
      
      // DELIVERY
      Delivery_Phone: {digits: "Please enter numbers only"},
      Delivery_Postcode: {digits: "Please enter numbers only"}
    },
    success: function(label) { 
      // inform user their input is valid
      label.html(" ").addClass("correct"); 
    }
    
  });
  
  
  //***************************
  // disables delivery info
  // inputs if user checks
  // "same as billing"
  //***************************
  $('a#delivery-same').toggle(function() {
      $('ol#delivery input:text').val("");
      $('ol#delivery input:text').attr("disabled", true);
      $('ol#delivery select').attr("disabled", true);
      $('ol#delivery input:text').addClass('disabled');      
    }, function() {
      $('ol#delivery input:text').removeAttr("disabled");
      $('ol#delivery select').removeAttr("disabled");
      $('ol#delivery input:text').removeClass('disabled');
  });

  $('form #form-reset').click(function() {
    $('form.baseform').clearForm();
    $('ol#delivery input:text').removeAttr("disabled");
    $('ol#delivery select').removeAttr("disabled");
    $('ol#delivery input:text').removeClass('disabled');
  });
  
  
  
  //***************************
  // Clear form with reset
  // Do not delete!
  //***************************    
  $.fn.clearForm = function() {
    return this.each(function() {
  	var type = this.type, tag = this.tagName.toLowerCase();
  	if (tag == 'form')
  	  return $(':input',this).clearForm();
  	if (type == 'text' || type == 'password' || tag == 'textarea')
  	  this.value = '';
  	else if (type == 'checkbox' || type == 'radio')
  	  this.checked = false;
  	else if (tag == 'select')
  	  this.selectedIndex = 0;
    });
  };
    
});
