$(document).ready(function(){
  
  /* age stuff */
  var minor_warning = 'Sorry, you must be 13 or older to sign up. Please have your parent or guardian sign up.';
  var warning_24hr = 'Sorry, you must be 13 or older to sign up. Please have your parent or guardian sign up. You can try to sign up again after 24 hours.';
  var fill_out_date = 'Please fill out your date of birth';
  var fill_out_email = 'Please fill out your email address';
  
  $("#signup").submit(function() {   
    
    // check if we have a cookie
    if ($.cookie('legal')) {
      alert(warning_24hr);
      return false;
    }
	
	var email = $("#Email").val();
	if(email == '') {
		alert(fill_out_email);
		return false;
	}
    
    // check if person is 13 years or older
    var year = $("#dob_y").val();
    var month = $("#dob_m").val();
    var day = $("#dob_d").val();
    if (year == 0 || day == 0 || month == 0) {
      alert(fill_out_date);
      return false;
    } else {
      var dob = new Date(year, (month-1), day);
      var today = new Date();
      var diff = today.getTime() - dob.getTime();
      var age = Math.floor(diff / (1000 * 60 * 60 * 24 * 365.25));
      if (age < 13) {
        $.cookie('legal', 'no', { expires: 1 });
        alert(minor_warning);
        return false;
      } else {
        $.cookie('legal', null);
        return true;
      }
    }
  });  
  
  /* basic input stuff */
  $('input[type="text"]').focus(function() {
    if (this.value == this.defaultValue){
      this.value = '';
    }
    if(this.value != this.defaultValue){
  	  this.select();
    }
  });
  $('input[type="text"]').blur(function() {
    if (this.value == ''){
      this.value = this.defaultValue;
    }
  });
  	
  
});
