// person.js
//
// JavaScript for functions inside the Person page.
//
//


// Show/Hide own activity in feed
function test() { 
	alert("test");
}

// Show add-memory form
function showMemoryForm() {

   var e=document.getElementById('memoryform');
   e.style.display='block';

}

// Show add-message form
function showMessageForm() {

   var e=document.getElementById('messageform');
   e.style.display='block';

}

// Count/limit Text length
function limitText(limitField, limitCount, limitNum) {
   if (limitField.value.length > limitNum) {
      limitField.value = limitField.value.substring(0,limitNum);
   } 
   limitCount.value = limitNum - limitField.value.length;
}


// Confirm a captcha code
var captcha_ok = false;
var captcha_form = null;
function confirmCaptcha( code, form ) {
   captcha_form = form
   sajax_do_call("Captcha::ajaxCaptchaIsValid", [code], confirmCaptchaCallback);
   return false;
}

function confirmCaptchaCallback( result ) { 
   var ok     = result.responseText;
   var status = document.getElementById('STATUS');
   if (ok.indexOf("OK") > 0) { 
      captcha_ok = true;
      if (status) { 
         status.innerHTML = "";
      } 
      captcha_form.submit();
      return true;
   } else {
      captcha_ok = false;
      if (status) { 
         status.innerHTML = "The confirmation code did not match. Please try again.";
      } else {
         alert("The confirmation code did not match. Please try again.");
      }
      return false;
   }
}

// If the email address is removed on an active user, warn the editor that
// the user will be removed from Networks and they can no longer be logged in
function emailWarning(e,isSysop) { 

   var val = e.value;
   if (val == '') {
      if (isSysop) {
         alert('Removing the e-mail address from the profile will mean the user cannot login and they will be removed from all Trusted Lists. To proceed, click OK. Click Save Changes again to remove the account. DO NOT click Save Changes unless you want to remove the account.');
      } else {
         alert('Removing your e-mail address deactivates your WikiTree account. You will be logged-out and unable to make any further changes. To proceed, click OK. Click Save Changes again to remove your e-mail address and deactivate your account. DO NOT click Save Changes unless you want to leave WikiTree immediately.');
      }
   }

}

// If a field is left blank, replace it with "Anonymous" instead
function anonNotBlank(e){
	var val = e.value;
	if (val == '') { e.value = "Anonymous"; }
}
