// JavaScript Document

/*
Validate a form then disable the button so that it can not be double clicked.
Uses jQuery and jQuery validation plug-in
Form ID = #signup
button class = .dbutton

Andrea Wetzel - May 2009

*/



$(function() {
		   
	$.validator.addMethod("AlNumRegEx", function(value, element) { 
  return this.optional(element) || /^[A-Za-z0-9_]{4,10}$/.test(value); 
}, "4-10 letters or numbers only");


	
	 //Add validation to all forms with ID of Signup
	$('#signup').validate({					  

		 rules: {
			 
			 pledgegoal: {
				required: false,
				digits: true
			 },
			 
			 username: {
				  required: true,
				  AlNumRegEx: true
  			  },			
			 password: {
				  required: true,
				  AlNumRegEx: true
  			  },
			  password2: {
     			 equalTo: "#password"
  			  },
			 pagetext: {
				 required: false,
				 maxlength: 1000
			 },
			 
			 max1000: {
				 required: false,
				 maxlength: 1000
			 },
			 
			 max500: {
				 required: false,
				 maxlength: 500
			 }

	 }
});

		   
		   //Enable the button in case someone uses the back button
		   $(".dbutton").attr("disabled", false);
});

//wait until that button's clicked, then disable it if the form is valid

//now works in IE!

function disableButton() {
	
$(function() {
		   var isValid = $('#signup').valid(); //is signup valid?
		   
		   
		   if (isValid == true) {
				$('#signup').submit(function(){
					 $('input[type=submit]', this).attr('disabled', 'disabled');
				});
		   };
		   
		  //console.log( isValid); //log value to console

});

}



  $(function( ) {
  //Add striping to table
	$('table.striped tr:even').addClass('even');
	});
		


