function checkUsername(){
 if($("#member_username").val().length < 5 || $("#member_username").val().length > 32){
  alert("Usernames must be between 5 and 32 characters.");
  return true;
 }

 if(! $("#member_username").val().match(/^([_a-z0-9\-]+)$/i)){
  alert("Usernames can only contain letters, numbers, dashes (-) and underscores (_).");
  return true;
 }

 return false;
}

function checkEmailFormat(){
 if(! $("#member_email").val().match(/^([_a-z0-9\-]+)(\.[_a-z0-9\-]+)*@([a-z0-9\-]+)(\.[a-z0-9\-]+)*(\.[a-z]{2,4})$/i)){
  alert("The email address you provided was not valid.");
  return true;
 }

 return false;
}

function checkEmailMatch(){
 if($("#member_email").val() != $("#member_email_2").val()){
  alert("The email addresses you provided were not identical.");
  return true;
 }

 return false;
}

function checkPassword(){
 if($("#member_password_1").val().length < 5 || $("#member_password_2").val().length > 32){
  alert("Passwords must be between 5 and 32 characters.");
  return true;
 }

 if($("#member_password_1").val() != $("#member_password_2").val()){
  alert("The passwords you provided were not identical.");
  return true;
 }

 return false;
}

function checkBirthdate(){
 if($("#member_birth_year").val() > 0 && $("#member_birth_month").val() > 0 && $("#member_birth_day").val() > 0){
  return false;
 }

 alert("The birthdate you provided was not valid.");
 return true;
}

function checkCountry(){
 if($("#member_country").val() > 0){
  return false;
 }

 alert("You must select a country.");
 return true;
}

// Submit the upload form
function accountRegister(){
 if(checkUsername()){ return false; }
 if(checkPassword()){ return false; }
 if(checkEmailFormat()){ return false; }
 if(checkEmailMatch()){ return false; }
 if(checkBirthdate()){ return false; }
 if(checkCountry()){ return false; }
}

function accountSettings(){
 if(checkEmailFormat()){ return false; }
 if(checkCountry()){ return false; }
}

function accountChangepassword(){
 if(checkPassword()){ return false; }
}

function usernameAvailability(){
 if(checkUsername()){ return false; }
 $.ajax( { url: '/registerchkun.php', cache: false, data: { member_username: $("#member_username").val() }, success: function (html) { alert (html); } } );
}
