// Requires jQuery and the jQuery Validate plugin.
// http://www.jquery.com
// http://bassistance.de/jquery-plugins/jquery-plugin-validation/

$(document).ready(function() {
						   
  $("#signuplink").click(function() {
    $("#form").slideToggle(100);
	return false;
  });
$('#winclose').click(function() { $('#formthanks').slideUp(100); return false;});
						   
  $('#signupform').validate({ 
    // errorPlacement: function(error, element) {
      // error.appendTo( element.prev() );
    // },

    errorElement: 'div',

    submitHandler: function(form) {
		
		var reptext = '<table style="margin-top: 15px; margin-left: 40px;" width="300" cellpadding="0" border="0" cellspacing="5"><tr><td valign="top"><img src="images/tick.gif" /></td><td><p>Thank you for registering.</p><p>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.</p><p><a href="#" id="winclose"><img border="0" src="images/close.gif" /></a></p></td></tr></table>';
		
      if ($(form).valid()) {
        $('input[type=image]', form).attr('disabled',true);
        $.post('umspost.php', $(form).serialize(), function(data) { $(form).replaceWith(reptext); $('#winclose').click(function() { $('#form').slideUp(100); return false;}); }); 
        $('input[type=image]', form).attr('disabled',false);
      }
    },

    rules: {
      name: 'required',
      email: {
        required: true,
        email: true
      }

    },
    messages: {
      name: "Please enter your first name",
      email: "Please enter a valid email address"
    }
  });
});
