<!-- // *** contact.js ***

// --- global variables ---

var oForm = 0;       // object set by initPage

var eFirst = "@";
var eSecond = "louisenayer";
var eThird = "com";

// --- functions ---

function msgDone()
{
  var wName = sTrim(oForm.realname.value,'B');
  var wEmail = sTrim(oForm.email.value,'B');
  var wSubject = sTrim(oForm.subject.value,'B');
  var wMessage = sTrim(oForm.theMessage.value,'B');


  if (wName.length <= 0)
  {
    showError(oForm.realname,"Name is required.");
    return false;
  }
  if (oForm.email.value.length <= 0)
  {
    showError(oForm.email,"eMail address is required.")
    return false;
  }

  if (!isValidEmail(oForm.email.value))
  {
    showError(oForm.email,"You entered an invalid eMail address.")
    return false;
  }

  if (wMessage.length <= 0)
  {
    showError(oForm.theMessage,"There is no message.");
    return false;
  }

  if (wSubject.length <= 0)
  {
     wSubject = "(No subject entered)";
     oForm.subject.value = wSubject;
  }

  oForm.realname.value = wName;
  oForm.subject.value  = "(LN) "+wSubject;
  oForm.theMessage.value = wMessage;

  oForm.redirect.value = "http://louisenayer.com/contact_ty.htm";
  oForm.recipient.value = "contact"+eFirst+eSecond+"."+eThird;
  oForm.submit();
  oForm.theMessage.focus();
}

function showError(oFField,imsg)
{
  alert(imsg+"\nPlease try again.");
  oFField.focus();
}

function initPage()
{
  // *** set contact text ***
  document.getElementById('eContact').childNodes[0].nodeValue = "contact"+eFirst+eSecond+"."+eThird;
  // *** set globals ***
  oForm = document.getElementById('fContact');

  // *** reset message area ***
  oForm.email.value = "";
  oForm.theMessage.value = "";
  oForm.realname.value = "";
  oForm.email.value = "";
  oForm.subject.value = "";

  // *** set focus ***
  oForm.realname.focus();
}

// ***** common functions ******

function isValidEmail(sText)
{
  var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
  return reEmail.test(sText);
}

// ---- Trim a string of leading or trailing spaces or both ----

function sTrim(iString,iFlag)
{
  // iFlag:  L = Leading space(s) removal
  //         T = Trailing space(s) removal
  //         B = Both leading and trailing space(s) removal

  iFlag = iFlag.toUpperCase();
  if ((iFlag == "L") || (iFlag == "B"))
  {
    while (''+iString.charAt(0)==' ')
       iString = iString.substr(1,iString.length);
  }
  if ((iFlag == "T") || (iFlag == "B"))
  {
    while (''+iString.charAt(iString.length-1)==' ')
       iString = iString.substr(0,iString.length-1);
  }

  return iString;
}


