// Requires jQuery and the jQuery Validate plugin.
// http://www.jquery.com
// http://bassistance.de/jquery-plugins/jquery-plugin-validation/

$(document).ready(function() {

  // Custom validator method - disallow certain strings
  jQuery.validator.addMethod("forbiddenValue", function(value, element, params) { 
	    return this.optional(element) || ($(element).val() != params); 
  }, jQuery.validator.format("This field is required"));
						   
  $('#signupform').validate({ 

    errorElement: 'div', // Use divs if we show errors
    errorPlacement: function() { }, // Not showing errors, so above is irrelevant

    submitHandler: function(form) { // If the form is valid... 
		
      // This has to come from somewhere. Might as well be a string here. 
      var reptext = '<div id="signup-thanks"><span class="signup-thanks">Thank you for registering. We\'re not into spam so we will not sell your data and only send you timely and relevant messages from Hair and its producers.</span></div>';
		
      if ($(form).valid()) { 
	  	var data = $(form).serialize();
        $('input', form).attr('disabled',true);

        var theurl = supref + 'signup/umspost.php';
        $.ajax({
	  processData: false,
          url: theurl,
          data: data,
          success: function(d, t) {
            $('#signup-container').slideUp(100); 
            $('#signup-container').parent().append(reptext); 
            $(':input',$('#signup-container')).not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
            $('.signup-back', $('#signupform').parent()).click(function() {  $('#signup-container').slideDown(100); $(this).parent().remove(); return false; });
            return false;
          },
          error: function(d, t) {  },
          type: 'POST'
        });
        $('input', form).attr('disabled',false);
      }
    },

    rules: {
      firstname: {
        required: true,
        forbiddenValue: 'Your Name'
      },
      email: {
        required: true,
        email: true
      }

    },
    messages: {
      name: "Please enter your first name",
      email: "Please enter a valid email address"
    }
  });
});
