function logoutMessage()
{
   alert('Close all browser windows to log out of the gallery.');
}

function editAlbum_updateRadio() {
   var radio = document.forms["edit_album"].elements.featured;
   if (radio.length == null) return;
   for (var i=radio.length - 1; i > -1; i--) {
	  radio[i].parentNode.className = (radio[i].checked ? "featuredContainer" : "nonFeaturedContainer");
   }
}

function editAlbum_validate() {
   var timestamp = document.forms["edit_album"]["timestamp"].value;
   if (!timestamp || timestamp == '') {
      alert("ERROR: missing timestamp");
	  return false;
   }
   var pattern = /[^0-9_]/;
   if (pattern.test(timestamp)) {
      alert("ERROR: timestamp must contain only digits and underscores");
	  return false;
   }
   return true;
}

function changeAuth_validate() {
   var newUsername = document.forms["settings"]["newUsername"].value;
   var newPassword1 = document.forms["settings"]["newPassword1"].value;
   var newPassword2 = document.forms["settings"]["newPassword2"].value;
   var newUsernameGiven = (newUsername != null && newUsername != "");
   var newPasswordGiven = (newPassword1 != null && newPassword1 != "");
   var passwordsMatch = (newPassword1 == newPassword2);
   if (!newUsernameGiven) {
      alert("ERROR: missing username");
	  return false;
   }
   if (!newPasswordGiven) {
      alert("ERROR: missing password");
	  return false;
   }
   if (!passwordsMatch) {
      alert("ERROR: passwords don't match");
	  return false;
   }
   return true;
}

function settings_validate() {
//   var newName = document.forms["settings"]["galleryName"].value;
   return true;
}

function uploadToAlbum_validateForm() {
   var newAlbumName = document.forms["uploader_page1"]["newalbumname"].value;
   var newAlbumNameGiven = (newAlbumName != null && newAlbumName != "");
   var radio = document.forms["uploader_page1"].elements.albumname;
   var radioSel = -1;
   if (radio.length == null) {
      radioSel = 0;
   } else {
      for (var i=radio.length - 1; i > -1; i--) {
	     if (radio[i].checked) {radioSel = i; i = -1;}
      }
   }
   if (newAlbumNameGiven && radioSel != 0) {
      alert("Do you want to create a new album? If so, fix the radio button selection. Otherwise clear the album name field.");
      return false;
   }
   if (!newAlbumNameGiven && radioSel == 0) {
      alert("Please provide a name for the new album");
      return false;
   }
   if (radioSel == -1) {
      alert("Please select an existing album or create a new album");
      return false;
   }
}
