// ===================================================================
// Std. Validation Functions
// ===================================================================

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

// Removes leading spaces from a string.
function LTrim(str) {

  var whitespace = new String(" \t\n\r");
  var s = new String(str);

  if (whitespace.indexOf(s.charAt(0)) != -1) {
    var j=0, i = s.length;

    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
      j++;
      s = s.substring(j, i);
  }

  return s;

}

// Removes spaces from the end of a string.
function RTrim(str) {

  var whitespace = new String(" \t\n\r");
  var s = new String(str);

  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    var i = s.length - 1;
    
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;
      s = s.substring(0, i+1);
  }

  return s;

}

// Removes leading and trailing spaces from a string.
function Trim(str) {

  return RTrim(LTrim(str));

}

function isNumeric(field) {

  var valid = "0123456789"
  var ok = "yes";
  var temp;
  
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  
  if (ok == "no") {
    alert("Error: #GF0001\n\nNumeric characters only.");
    field.select();
    field.focus();
    return 0;
  }
  else { return 1; }

}

function isAlpha(field) {

  var valid = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKMLNOPQRSTUVWXYZ"
  var ok = "yes";
  var temp;
  
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  
  if (ok == "no") {
    alert("Error: #GF0002\n\nAlpha characters only.");
    field.select();
    field.focus();
    return 0;
  }
  else { return 1; }

}

function isName(field) {

  var valid = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKMLNOPQRSTUVWXYZ'-"
  var ok = "yes";
  var temp;
  
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  
  if (ok == "no") {
    alert("Error: #GF0003\n\nAlpha characters, apostrophes and dashes only.");
    field.focus();
    field.select();
    return 0;
  }
  else { return 1; }

}

function isEmail(field) {

  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

  if (!filter.test(field.value)) { 
    alert("Error: #GF0004\n\nInvalid e-mail address.");
    field.select();
    field.focus();
    return 0;
  }
  else { return 1; }

}

function isZip4(field) {

  var regex  = /^\d{5}$|^\d{5}-\d{4}$/;

  if (!regex.test(field.value)) { 
    alert("Error: #GF0005\n\nInvalid US Zip Code.\n\nRequired format: XXXXX or XXXXX-XXXX");
    field.select();
    field.focus();
    return 0;
  }
  else { return 1; }

}

function fieldCompare(thisfield,otherfield) {
  
  if (thisfield.value.toLowerCase() != otherfield.value.toLowerCase()) {
    alert("Error: #GF0006\n\nFields do not match.");
    thisfield.select();
    thisfield.focus();
    return 0;
  }
  else { return 1; }

}

function isTextField(field) {

  var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKMLNOPQRSTUVWXYZ 0123456789-.,'"
  var ok = "yes";
  var temp;
  
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  
  if (ok == "no") {
    alert("Error: #GF0007\n\nAlpha-numeric characters, apostrophes, dashes, commas and periods only.");
    field.select();
    field.focus();
    return 0;
  }
  else { return 1; }

}

function isSQLInj(field) {

  var filter  = /^(script)|(<)|(>)|(%3c)|(%3e)|(SELECT) |(UPDATE) |(INSERT) |(DELETE)|(GRANT) |(REVOKE)|(UNION)|(&lt;)|(&gt;)$/;

  if (!filter.test(field.value)) { 
    alert("Error: #GF0008\n\nInvalid input.");
    field.select();
    field.focus();
    return 0;
  }
  else { return 1; }

}



function disableObj(obj) {
  obj.disabled = true;
}

// Automatically tabs to the next designated field after the length of the current field has been met.
function autotab(object1, object2, objectsize) {

  if (object1.value.length == objectsize)
    object2.focus()

}

// ===================================================================

function parentRefresh() {
  opener.location.reload(true);
}

function promptEventDelete(id,pid) {
  
  var msg = "\nYou are about to delete this event.\n\n" +
            "Are you sure you want to do this?\n\n" +
            "All deletions are final!\n\n";

  if (confirm(msg)) {
    // disableButtons_01(document.button);
    if (pid == "1") {
      window.location='event_manager.cfm?cmd=delete&eid='+id;
    }
    else if (pid == "2") {
      window.location='event_manager_admin.cfm?cmd=delete&eid='+id;
    }
  }
  else {
    alert("Event not deleted.")
    return false;
  }

}

function toggleRentalFormVisibility() {
  
  /*
  try {
  //standards compliant browsers
  theTD.style.display = 'table-cell';
  } catch(e) {
  //IE stupidity
  theTD.style.display = 'block';
  }
  */
  
  // 'block' only works in IE.
  // standards compliant browsers use (table rows should use display: table-row;) and (table cells should use display: table-cell;)
  
  /*
  if (document.getElementById("private").checked == true) {
      
      document.getElementById("desc1").style.display='none';
      document.getElementById("desc2").style.display='none';
      document.getElementById("rental1").style.display='';
      document.getElementById("rental2").style.display='';
      document.getElementById("rental3").style.display='';
      document.getElementById("rental4").style.display='';
      document.getElementById("rental5").style.display='';
  }
  
  else {

      document.getElementById("desc1").style.display='';
      document.getElementById("desc2").style.display='';
      document.getElementById("rental1").style.display='none';
      document.getElementById("rental2").style.display='none';
      document.getElementById("rental3").style.display='none';
      document.getElementById("rental4").style.display='none';
      document.getElementById("rental5").style.display='none';
  }
  */
    
    document.getElementById("rental1").style.display=document.getElementById("rental1").style.display=='none'?'':'none';
    document.getElementById("rental2").style.display=document.getElementById("rental2").style.display=='none'?'':'none';
    document.getElementById("rental3").style.display=document.getElementById("rental3").style.display=='none'?'':'none';
    document.getElementById("rental4").style.display=document.getElementById("rental4").style.display=='none'?'':'none';
    document.getElementById("rental5").style.display=document.getElementById("rental5").style.display=='none'?'':'none';
  
}
  

function calcAttendanceTotal() {
  
  var adults=Number(document.getElementById("att_adult").value);
  var youth=Number(document.getElementById("att_youth").value);
  var total=adults+youth;
  
  if (total > 75) {
    alert("Total attendance cannot exceed 75 guest.");
    document.getElementById("att_total").innerHTML = 'Invalid';
  }
  else {
    document.getElementById("att_total").innerHTML = total;
  }

}

function calcEstHours(frm) {
  
  var start = Date.parse(frm.date_start.value+" "+frm.date_start_hrs.value+":"+frm.date_start_min.value+" "+frm.date_start_tt.value);
  var end = Date.parse(frm.date_end.value+" "+frm.date_end_hrs.value+":"+frm.date_end_min.value+" "+frm.date_end_tt.value);

  var t0 = end-start
  var t1 = t0 / 1000;
  var t2 = t1 / 60;
  var t3 = t2 / 60;
  
  /*
  alert("Start Time: "+start);
  alert("End Time: "+end);
  alert("Total Milliseconds: "+t0);
  alert("Total Sec: "+t1);
  alert("Total Min: "+t2);
  alert("Total Hours: "+t3);
  */
  
  document.getElementById("timecalc").innerHTML = t3.toFixed(2);
  document.getElementById("att_hrs").value = t3.toFixed(2);

}

// ===================================================================
// Admin - Create User Form
// ===================================================================

function testPassword(passwd,srcdoc) {

/* *******************************************************************
Password Strength Factors and Weightings

password length:
level 0 (3 point): less than 4 characters
level 1 (6 points): between 5 and 7 characters
level 2 (12 points): between 8 and 15 characters
level 3 (18 points): 16 or more characters

letters:
level 0 (0 points): no letters
level 1 (5 points): all letters are lower case
level 2 (7 points): letters are mixed case

numbers:
level 0 (0 points): no numbers exist
level 1 (5 points): one number exists
level 2 (7 points): 3 or more numbers exists

special characters:
level 0 (0 points): no special characters
level 1 (5 points): one special character exists
level 2 (10 points): more than one special character exists

combinatons:
level 0 (1 points): letters and numbers exist
level 1 (1 points): mixed case letters
level 2 (2 points): letters, numbers and special characters exist
level 3 (2 points): mixed case letters, numbers and special characters exist

********************************************************************** */

  var description = new Array();
  description[0] = "<table cellpadding=1 cellspacing=0><tr><td class=pwd_strength><a href=javascript:void(0) onclick=MM_openBrWindow(\'/hoa/pwd_help.cfm\',\'pwdhelp\','scrollbars=yes,width=600,height=400\')>Password Strength:</a> <b><font color=#ff0000>Weakest</font></b></td></tr><tr><td><table cellpadding=0 cellspacing=0><tr><td height=8 width=40 bgcolor=#ff0000></td><td height=8 width=160 bgcolor=#eeeeee></td></tr></table></td></tr></table>";
  description[1] = "<table cellpadding=1 cellspacing=0><tr><td class=pwd_strength><a href=javascript:void(0) onclick=MM_openBrWindow(\'/hoa/pwd_help.cfm\',\'pwdhelp\','scrollbars=yes,width=600,height=400\')>Password Strength:</a> <b><font color=#990000>Weak</font></b></td><tr><td><table cellpadding=0 cellspacing=0><tr><td height=8 width=80 bgcolor=#990000></td><td height=8 width=120 bgcolor=#eeeeee></td></tr></table></td></tr></table>";
  description[2] = "<table cellpadding=1 cellspacing=0><tr><td class=pwd_strength><a href=javascript:void(0) onclick=MM_openBrWindow(\'/hoa/pwd_help.cfm\',\'pwdhelp\','scrollbars=yes,width=600,height=400\')>Password Strength:</a> <b><font color=#990099>Improving</font></b></td><tr><td><table cellpadding=0 cellspacing=0><tr><td height=8 width=120 bgcolor=#990099></td><td height=8 width=80 bgcolor=#eeeeee></td></tr></table></td></tr></table>";
  description[3] = "<table cellpadding=1 cellspacing=0><tr><td class=pwd_strength><a href=javascript:void(0) onclick=MM_openBrWindow(\'/hoa/pwd_help.cfm\',\'pwdhelp\','scrollbars=yes,width=600,height=400\')>Password Strength:</a> <b><font color=#000099>Strong</font></b></td><tr><td><table cellpadding=0 cellspacing=0><tr><td height=8 width=160 bgcolor=#000099></td><td height=8 width=40 bgcolor=#eeeeee></td></tr></table></td></tr></table>";
  description[4] = "<table cellpadding=1 cellspacing=0><tr><td class=pwd_strength><a href=javascript:void(0) onclick=MM_openBrWindow(\'/hoa/pwd_help.cfm\',\'pwdhelp\','scrollbars=yes,width=600,height=400\')>Password Strength:</a> <b><font color=#0000ff>Strongest</font></b></td><tr><td><table cellpadding=0 cellspacing=0><tr><td height=8 width=200 bgcolor=#0000ff></td></tr></table></td></tr></table>";
  description[5] = "<table cellpadding=1 cellspacing=0><tr><td class=pwd_strength><a href=javascript:void(0) onclick=MM_openBrWindow(\'/hoa/pwd_help.cfm\',\'pwdhelp\','scrollbars=yes,width=600,height=400\')>Password Strength:</a> <b>Begin Typing</b></td><tr><td><table cellpadding=0 cellspacing=0><tr><td height=8 width=200 bgcolor=#eeeeee></td></tr></table></td></tr></table>";

  var intScore   = 0
  var strVerdict = 0
    
  // PASSWORD LENGTH
  if (passwd.length==0 || !passwd.length) { // length 0
    intScore = -1
  }
  else if (passwd.length>0 && passwd.length<5) { // length between 1 and 4
    intScore = (intScore+3)
  }
  else if (passwd.length>4 && passwd.length<8) { // length between 5 and 7
    intScore = (intScore+6)
  }
  else if (passwd.length>7 && passwd.length<12) { // length between 8 and 15
    intScore = (intScore+12)
  }
  else if (passwd.length>11) { // length 16 or more
    intScore = (intScore+18)
  }

  // LETTERS
  if (passwd.match(/[a-z]/)) { // [verified] at least one lower case letter
    intScore = (intScore+1)
  }
  if (passwd.match(/[A-Z]/)) { // [verified] at least one upper case letter
    intScore = (intScore+5)
  }
  
  // NUMBERS
  if (passwd.match(/\d+/)) { // [verified] at least one number
    intScore = (intScore+5)
  }
  if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)) { // [verified] at least three numbers
    intScore = (intScore+5)
  }

  // SPECIAL CHAR
  if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)) { // [verified] at least one special character
    intScore = (intScore+5)
  }
  if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) { // [verified] at least two special characters
    intScore = (intScore+5)
  }

  // COMBOS
  if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) { // [verified] both upper and lower case
    intScore = (intScore+2)
  }
  if (passwd.match(/(\d.*\D)|(\D.*\d)/)) { // [FAILED] both letters and numbers, almost works because an additional character is required
    intScore = (intScore+2)
  }
  if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)) { // [verified] letters, numbers, and special characters
   intScore = (intScore+2)
  }
  if(intScore == -1) {
    strVerdict = description[5];
  }
  else if(intScore > -1 && intScore < 16) {
    strVerdict = description[0];
  }
  else if (intScore > 15 && intScore < 25) {
    strVerdict = description[1];
  }
  else if (intScore > 24 && intScore < 35) {
    strVerdict = description[2];
  }
  else if (intScore > 34 && intScore < 45) {
    strVerdict = description[3];
  }
  else {
    strVerdict = description[4];
  }

  document.getElementById("pwd_strength").innerHTML = (strVerdict);
  
  if (srcdoc == 1) {
    parent.calcIfHeight();
  }
  else if (srcdoc == 0) {
    document.getElementById("pwd_strength").style.display = 'block';
  }

}

function secQUD(frm,srcdoc) { 

  var sec_question = frm.sec_question.selectedIndex;
  var is_sec_question = frm.sec_question.options[sec_question].value;

  if (is_sec_question == "Write my own question") {
    document.getElementById("sec_q_ud").style.display = 'block';
    // parent.document.getElementById("subframe").style.height = frameON+'px';
    if (srcdoc == 1) {
      parent.calcIfHeight();
    }
  }
  else {
    document.getElementById("sec_q_ud").style.display = 'none';
    frm.sec_question_ud.value = "";
    if (srcdoc == 1) {
      parent.calcIfHeight();
    }
  }
  
}

function showBoardTitle() {

  if (document.user.board_member.checked == true) {
    document.getElementById("board_title").style.display = 'block';
    parent.calcIfHeight();
  }
  else {
    document.getElementById("board_title").style.display = 'none';
    document.user.board_title.value = "";
    parent.calcIfHeight();
  }
  
}

// ===================================================================
// HOA - Registration Form 1
// ===================================================================

function hoaReg_Validate() {

   var doc = document.register;
   var account_id1 = Trim(doc.account_id1.value);
   var account_id2 = Trim(doc.account_id2.value);
   var account_id3 = Trim(doc.account_id3.value);
   var street_no = Trim(doc.street_no.value);
   var street_name = doc.street_name.selectedIndex;
   var is_street_name = Trim(doc.street_name.options[street_name].value);
   var first_name = Trim(doc.first_name.value);
   var last_name = Trim(doc.last_name.value);
   var email = Trim(doc.email.value);
   var email_confirm = Trim(doc.email_confirm.value);
   
   if (account_id1.length != 2) {
     alert("Registration Error #REGCLNT01\n\nAccount ID required.\n\nRequires 2 digits.");
     doc.account_id1.focus();
     return false;
   }
   
   if (isNumeric(doc.account_id1) == 0) {
    return false;
   }

   if (account_id2.length != 5) {
     alert("Registration Error #REGCLNT02\n\nAccount ID required.\n\nRequires 5 digits.");
     doc.account_id2.focus();
     return false;
   }
   
   if (isNumeric(doc.account_id2) == 0) {
    return false;
   }
   
   if (account_id3.length != 2) {
     alert("Registration Error #REGCLNT03\n\nAccount ID required.\n\nRequires 2 digits.");
     doc.account_id3.focus();
     return false;
   }
   
   if (isNumeric(doc.account_id3) == 0) {
     return false;
   }
   
   if (street_no.length < 2 || street_no.length > 4) {
     alert("Registration Error #REGCLNT04\n\nStreet # required.\n\nRequires between 2 and 4 digits.");
     doc.street_no.focus();
     return false;
   }
  
   if (isNumeric(doc.street_no) == 0) {
     return false;
   }
   
   if (is_street_name.length == 0) {
     alert("Registration Error #REGCLNT05\n\nStreet name required.");
     doc.street_name.focus();
     return false;
   }
   
   if (first_name.length == 0 || first_name.length > 50) {
     alert("Registration Error #REGCLNT06\n\nFirst name required.\n\nMaximum characters: 50");
     doc.first_name.focus();
     return false;
   }
   
   if (isName(doc.first_name) == 0) {
     return false;
   }

   if (last_name.length == 0 || last_name.length > 50) {
     alert("Registration Error #REGCLNT07\n\nLast name required.\n\nMaximum characters: 50");
     doc.last_name.focus();
     return false;
   }
   
   if (isName(doc.last_name) == 0) {
     return false;
   }

   if (email.length == 0 || email.length > 100) {
     alert("Registration Error #REGCLNT08\n\nE-mail address required.\n\nMaximum characters: 100");
     doc.email.focus();
     return false;
   }
   
   if (isEmail(doc.email) == 0) {
     return false;
   }
   
   if (email_confirm.length == 0 || email_confirm.length > 100) {
     alert("Registration Error #REGCLNT09\n\nPlease confirm your e-mail address.\n\nMaximum characters: 100");
     doc.email_confirm.focus();
     return false;
   }

   if (fieldCompare(doc.email_confirm,doc.email) == 0) {
     return false;
   }
   
   else { disableObj(doc.confirm); }

}

// ===================================================================
// HOA - Registration Form 2
// ===================================================================

function hoaFinalReg_Validate() {

   var doc = document.register;
   var first_name = Trim(doc.first_name.value);
   var middle_initial = Trim(doc.middle_initial.value);
   var last_name = Trim(doc.last_name.value);
   var company = Trim(doc.company.value);
   var title = Trim(doc.title.value);
   var phone_home_1 = Trim(doc.phone_home_1.value);
   var phone_home_2 = Trim(doc.phone_home_2.value);
   var phone_home_3 = Trim(doc.phone_home_3.value);
   var phone_work_1 = Trim(doc.phone_work_1.value);
   var phone_work_2 = Trim(doc.phone_work_2.value);
   var phone_work_3 = Trim(doc.phone_work_3.value);
   var phone_mobile_1 = Trim(doc.phone_mobile_1.value);
   var phone_mobile_2 = Trim(doc.phone_mobile_2.value);
   var phone_mobile_3 = Trim(doc.phone_mobile_3.value);
   var phone_other_1 = Trim(doc.phone_other_1.value);
   var phone_other_2 = Trim(doc.phone_other_2.value);
   var phone_other_3 = Trim(doc.phone_other_3.value);
   var password = Trim(doc.password.value);
   var password_confirm = Trim(doc.password_confirm.value);
   var sec_question = doc.sec_question.selectedIndex;
   var is_sec_question = Trim(doc.sec_question.options[sec_question].value);
   var sec_question_ud = Trim(doc.sec_question_ud.value);
   var security_answer = Trim(doc.security_answer.value);
   
   /* First Name */
   if (first_name.length == 0 || first_name.length > 50) {
     alert("Registration Error #REGCLNT10\n\nFirst name required.\n\nMaximum characters: 50");
     doc.first_name.focus();
     return false;
   }
   
   if (isName(doc.first_name) == 0) {
     return false;
   }

   /* Last Name */
   if (last_name.length == 0 || last_name.length > 50) {
     alert("Registration Error #REGCLNT11\n\nLast name required.\n\nMaximum characters: 50");
     doc.last_name.focus();
     return false;
   }
   
   if (isName(doc.last_name) == 0) {
     return false;
   }
   
   /* Middle Initial */
   if (middle_initial.length == 1) {
     
     if (isAlpha(doc.middle_initial) == 0) {
       return false;
     }
     
   }
   
   if (middle_initial.length > 1) {
     alert("Registration Error #REGCLNT12\n\nMiddle Initial\n\nMaximum characters: 1");
     doc.middle_initial.focus();
     return false;
   } 
   
   /* Company */
   if (company.length != 0) {

     if (isTextField(doc.company) == 0) {
       return false;
     }

   }
   
   if (company.length > 50) {
     alert("Registration Error #REGCLNT13\n\nCompany\n\nMaximum characters: 50");
     doc.company.focus();
     return false;
   } 

   /* Title */
   if (title.length != 0) {

     if (isTextField(doc.title) == 0) {
       return false;
     }

   }
   
   if (company.title > 50) {
     alert("Registration Error #REGCLNT14\n\nTitle\n\nMaximum characters: 50");
     doc.title.focus();
     return false;
   }

   /* Home Phone */
   if (phone_home_1.length != 3) {
     alert("Registration Error #REGCLNT15\n\nHome Phone (Area Code) required.\n\nRequires 3 digits.");
     doc.phone_home_1.focus();
     return false;
   }

   if (isNumeric(doc.phone_home_1) == 0) {
    return false;
   }

   if (phone_home_2.length != 3) {
     alert("Registration Error #REGCLNT16\n\nHome Phone (Prefix) required.\n\nRequires 3 digits.");
     doc.phone_home_2.focus();
     return false;
   }

   if (isNumeric(doc.phone_home_2) == 0) {
    return false;
   }   

   if (phone_home_3.length < 4) {
     alert("Registration Error #REGCLNT17\n\nHome Phone required.\n\nRequires at least 4 digits.");
     doc.phone_home_3.focus();
     return false;
   }

   /* Work Phone */
   // If the user types any characters in the fields validate them, else do nothing.
   if (phone_work_1.length != 0 || phone_work_2.length != 0 || phone_work_3.length != 0) {
   
     if (phone_work_1.length != 3) {
       alert("Registration Error #REGCLNT18\n\nWork Phone (Area Code) required.\n\nRequires 3 digits.");
       doc.phone_work_1.focus();
       return false;
     }

     if (isNumeric(doc.phone_work_1) == 0) {
      return false;
     }

     if (phone_work_2.length != 3) {
       alert("Registration Error #REGCLNT19\n\nWork Phone (Prefix) required.\n\nRequires 3 digits.");
       doc.phone_work_2.focus();
       return false;
     }

     if (isNumeric(doc.phone_work_2) == 0) {
      return false;
     }   

     if (phone_work_3.length < 4) {
       alert("Registration Error #REGCLNT20\n\nWork Phone required.\n\nRequires at least 4 digits.");
       doc.phone_work_3.focus();
       return false;
     }
     
   }

   /* Mobile Phone */
   // If the user types any characters in the fields validate them, else do nothing.
   if (phone_mobile_1.length != 0 || phone_mobile_2.length != 0 || phone_mobile_3.length != 0) {
   
     if (phone_mobile_1.length != 3) {
       alert("Registration Error #REGCLNT21\n\nMobile Phone (Area Code) required.\n\nRequires 3 digits.");
       doc.phone_mobile_1.focus();
       return false;
     }

     if (isNumeric(doc.phone_mobile_1) == 0) {
      return false;
     }

     if (phone_mobile_2.length != 3) {
       alert("Registration Error #REGCLNT22\n\nMobile Phone (Prefix) required.\n\nRequires 3 digits.");
       doc.phone_mobile_2.focus();
       return false;
     }

     if (isNumeric(doc.phone_mobile_2) == 0) {
      return false;
     }   

     if (phone_mobile_3.length < 4) {
       alert("Registration Error #REGCLNT23\n\nMobile Phone required.\n\nRequires at least 4 digits.");
       doc.phone_mobile_3.focus();
       return false;
     }
     
   }

   /* Other Phone */
   // If the user types any characters in the fields validate them, else do nothing.
   if (phone_other_1.length != 0 || phone_other_2.length != 0 || phone_other_3.length != 0) {
   
     if (phone_other_1.length != 3) {
       alert("Registration Error #REGCLNT24\n\nOther Phone (Area Code) required.\n\nRequires 3 digits.");
       doc.phone_other_1.focus();
       return false;
     }

     if (isNumeric(doc.phone_other_1) == 0) {
      return false;
     }

     if (phone_other_2.length != 3) {
       alert("Registration Error #REGCLNT25\n\nOther Phone (Prefix) required.\n\nRequires 3 digits.");
       doc.phone_other_2.focus();
       return false;
     }

     if (isNumeric(doc.phone_other_2) == 0) {
      return false;
     }   

     if (phone_other_3.length < 4) {
       alert("Registration Error #REGCLNT26\n\nOther Phone required.\n\nRequires at least 4 digits.");
       doc.phone_other_3.focus();
       return false;
     }
     
   }

   /* Password */
   if (password.length < 6) {
     alert("Registration Error #REGCLNT27\n\nPassword required.\n\nMinimum: 6 characters.");
     doc.password.focus();
     return false;
   }

   if (password_confirm.length == 0) {
     alert("Registration Error #REGCLNT28\n\nPassword confirmation required.");
     doc.password_confirm.focus();
     return false;
   }   

   if (fieldCompare(doc.password_confirm,doc.password) == 0) {
     return false;
   }

   /* Security Question */
   if (is_sec_question.length == 0) {
     alert("Registration Error #REGCLNT29\n\nSecurity question required.");
     doc.sec_question.focus();
     return false;
   }
   
   if (is_sec_question == "Write my own question" && sec_question_ud.length == 0) {
     alert("Registration Error #REGCLNT30\n\nYou have chosen to write your own security question.\nPlease do so now.\n\nRequired.");
     doc.sec_question_ud.focus();
     return false;
   }
   
   /* Security Answer */
   if (security_answer.length == 0) {
     alert("Registration Error #REGCLNT31\n\nSecurity answer required.");
     doc.security_answer.focus();
     return false;
   }

   else { disableObj(doc.confirm); }

}

// ===================================================================
// HOA - Login Form
// ===================================================================

function hoaLogin_Validate() {

   var doc = document.login;
   var user_name = Trim(doc.user_name.value);
   var password = Trim(doc.password.value);
   
   if (user_name.length == 0) {
     alert("Login Error #LOGINCLNT01\n\nUser name required.");
     doc.user_name.focus();
     return false;
   }
   
   if (password.length == 0) {
     alert("Login Error #LOGINCLNT02\n\nPassword required.");
     doc.password.focus();
     return false;
   }

}

// ===================================================================
// HOA - Forgot Password Form
// ===================================================================

function hoaForgotPwd_Validate() {

   var doc = document.sendpwd;
   var user_name = Trim(doc.user_name.value);
   
   if (user_name.length == 0) {
     alert("Send Password Error #SNDPWDCLNT01\n\nUser name required.");
     doc.user_name.focus();
     return false;
   }
   
   if (isEmail(doc.user_name) == 0) {
     return false;
   }

}

// ===================================================================
// HOA - Manage Profile Form (Edit)
// ===================================================================

function hoaProfileEdit_Validate() {

   var doc = document.profile;
   var first_name = Trim(doc.first_name.value);
   var middle_initial = Trim(doc.middle_initial.value);
   var last_name = Trim(doc.last_name.value);
   var company = Trim(doc.company.value);
   var title = Trim(doc.title.value);
   var phone_home_1 = Trim(doc.phone_home_1.value);
   var phone_home_2 = Trim(doc.phone_home_2.value);
   var phone_home_3 = Trim(doc.phone_home_3.value);
   var phone_work_1 = Trim(doc.phone_work_1.value);
   var phone_work_2 = Trim(doc.phone_work_2.value);
   var phone_work_3 = Trim(doc.phone_work_3.value);
   var phone_mobile_1 = Trim(doc.phone_mobile_1.value);
   var phone_mobile_2 = Trim(doc.phone_mobile_2.value);
   var phone_mobile_3 = Trim(doc.phone_mobile_3.value);
   var phone_other_1 = Trim(doc.phone_other_1.value);
   var phone_other_2 = Trim(doc.phone_other_2.value);
   var phone_other_3 = Trim(doc.phone_other_3.value);
   
   /* First Name */
   if (first_name.length == 0 || first_name.length > 50) {
     alert("Profile Edit Error #MNGPROFCLNT01\n\nFirst name required.\n\nMaximum characters: 50");
     doc.first_name.focus();
     return false;
   }
   
   if (isName(doc.first_name) == 0) {
     return false;
   }

   /* Last Name */
   if (last_name.length == 0 || last_name.length > 50) {
     alert("Profile Edit Error #MNGPROFCLNT02\n\nLast name required.\n\nMaximum characters: 50");
     doc.last_name.focus();
     return false;
   }
   
   if (isName(doc.last_name) == 0) {
     return false;
   }
   
   /* Middle Initial */
   if (middle_initial.length == 1) {
     
     if (isAlpha(doc.middle_initial) == 0) {
       return false;
     }
     
   }
   
   if (middle_initial.length > 1) {
     alert("Profile Edit Error #MNGPROFCLNT03\n\nMiddle Initial\n\nMaximum characters: 1");
     doc.middle_initial.focus();
     return false;
   } 
   
   /* Company */
   if (company.length != 0) {

     if (isTextField(doc.company) == 0) {
       return false;
     }

   }
   
   if (company.length > 50) {
     alert("Profile Edit Error #MNGPROFCLNT04\n\nCompany\n\nMaximum characters: 50");
     doc.company.focus();
     return false;
   } 

   /* Title */
   if (title.length != 0) {

     if (isTextField(doc.title) == 0) {
       return false;
     }

   }
   
   if (company.title > 50) {
     alert("Profile Edit Error #MNGPROFCLNT05\n\nTitle\n\nMaximum characters: 50");
     doc.title.focus();
     return false;
   }

   /* Home Phone */
   if (phone_home_1.length != 3) {
     alert("Profile Edit Error #MNGPROFCLNT06\n\nHome Phone (Area Code) required.\n\nRequires 3 digits.");
     doc.phone_home_1.focus();
     return false;
   }

   if (isNumeric(doc.phone_home_1) == 0) {
    return false;
   }

   if (phone_home_2.length != 3) {
     alert("Profile Edit Error #MNGPROFCLNT07\n\nHome Phone (Prefix) required.\n\nRequires 3 digits.");
     doc.phone_home_2.focus();
     return false;
   }

   if (isNumeric(doc.phone_home_2) == 0) {
    return false;
   }   

   if (phone_home_3.length < 4) {
     alert("Profile Edit Error #MNGPROFCLNT08\n\nHome Phone required.\n\nRequires at least 4 digits.");
     doc.phone_home_3.focus();
     return false;
   }

   /* Work Phone */
   // If the user types any characters in the fields validate them, else do nothing.
   if (phone_work_1.length != 0 || phone_work_2.length != 0 || phone_work_3.length != 0) {
   
     if (phone_work_1.length != 3) {
       alert("Profile Edit Error #MNGPROFCLNT09\n\nWork Phone (Area Code) required.\n\nRequires 3 digits.");
       doc.phone_work_1.focus();
       return false;
     }

     if (isNumeric(doc.phone_work_1) == 0) {
      return false;
     }

     if (phone_work_2.length != 3) {
       alert("Profile Edit Error #MNGPROFCLNT10\n\nWork Phone (Prefix) required.\n\nRequires 3 digits.");
       doc.phone_work_2.focus();
       return false;
     }

     if (isNumeric(doc.phone_work_2) == 0) {
      return false;
     }   

     if (phone_work_3.length < 4) {
       alert("Profile Edit Error #MNGPROFCLNT11\n\nWork Phone required.\n\nRequires at least 4 digits.");
       doc.phone_work_3.focus();
       return false;
     }
     
   }

   /* Mobile Phone */
   // If the user types any characters in the fields validate them, else do nothing.
   if (phone_mobile_1.length != 0 || phone_mobile_2.length != 0 || phone_mobile_3.length != 0) {
   
     if (phone_mobile_1.length != 3) {
       alert("Profile Edit Error #MNGPROFCLNT12\n\nMobile Phone (Area Code) required.\n\nRequires 3 digits.");
       doc.phone_mobile_1.focus();
       return false;
     }

     if (isNumeric(doc.phone_mobile_1) == 0) {
      return false;
     }

     if (phone_mobile_2.length != 3) {
       alert("Profile Edit Error #MNGPROFCLNT13\n\nMobile Phone (Prefix) required.\n\nRequires 3 digits.");
       doc.phone_mobile_2.focus();
       return false;
     }

     if (isNumeric(doc.phone_mobile_2) == 0) {
      return false;
     }   

     if (phone_mobile_3.length < 4) {
       alert("Profile Edit Error #MNGPROFCLNT14\n\nMobile Phone required.\n\nRequires at least 4 digits.");
       doc.phone_mobile_3.focus();
       return false;
     }
     
   }

   /* Other Phone */
   // If the user types any characters in the fields validate them, else do nothing.
   if (phone_other_1.length != 0 || phone_other_2.length != 0 || phone_other_3.length != 0) {
   
     if (phone_other_1.length != 3) {
       alert("Profile Edit Error #MNGPROFCLNT15\n\nOther Phone (Area Code) required.\n\nRequires 3 digits.");
       doc.phone_other_1.focus();
       return false;
     }

     if (isNumeric(doc.phone_other_1) == 0) {
      return false;
     }

     if (phone_other_2.length != 3) {
       alert("Profile Edit Error #MNGPROFCLNT16\n\nOther Phone (Prefix) required.\n\nRequires 3 digits.");
       doc.phone_other_2.focus();
       return false;
     }

     if (isNumeric(doc.phone_other_2) == 0) {
      return false;
     }   

     if (phone_other_3.length < 4) {
       alert("Profile Edit Error #MNGPROFCLNT17\n\nOther Phone required.\n\nRequires at least 4 digits.");
       doc.phone_other_3.focus();
       return false;
     }
     
   }

   disableObj(doc.confirm);

}

// ===================================================================
// HOA - Security Settings: Username/E-mail change
// ===================================================================

function hoaChgUNE_Validate() {

   var doc = document.send_request;
   var user_name = Trim(doc.user_name.value);
   
   if (user_name.length == 0) {
     alert("Change Username/E-mail Error #UNECLNT01\n\nE-mail address required.");
     doc.user_name.focus();
     return false;
   }
   
   if (isEmail(doc.user_name) == 0) {
     return false;
   }
   
   if (fieldCompare(doc.user_name_confirm,doc.user_name) == 0) {
     return false;
   }
   
   disableObj(doc.change);

}

function hoaChgUNEConfirm_Validate() {

  var doc = document.confirm_request;
  var confirm_id = Trim(doc.confirm_id.value);
  var regex  = /^[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{16}$/;
  // Sample: 555C3B53-EA33-70DB-45ABCB957A276F0C (8-4-4-16)

   if (confirm_id.length == 0) {
     alert("Change Username/E-mail Error #UNECLNT02\n\nConfirmation ID required.");
     doc.confirm_id.focus();
     return false;
   }

   if (regex.test(confirm_id)) { 
    // alert('Valid MS UUID');
   }
   else {
     alert("Change Username/E-mail Error #UNECLNT03\n\nInvalid confirmation id.");
     doc.confirm_id.select();
     doc.confirm_id.focus();
     return false;
   }

   disableObj(doc.confirm);

}

// ===================================================================
// Marketing - Contact Us Form
// ===================================================================

function mrktContactUs_Validate() {

   var doc = document.contact;
   var first_name = Trim(doc.first_name.value);
   var last_name = Trim(doc.last_name.value);
   var address1 = Trim(doc.address1.value);
   var address2 = Trim(doc.address2.value);
   var city = Trim(doc.city.value);
   var state = doc.state.selectedIndex;
   var is_state = Trim(doc.state.options[state].value);
   var zip = Trim(doc.zip.value);
   var phone_home = Trim(doc.phone_home.value);
   var phone_mobile_work = Trim(doc.phone_mobile_work.value);
   var email = Trim(doc.email.value);
   var email_confirm = Trim(doc.email_confirm.value);
   var message = Trim(doc.message.value);
   
   /* First Name */
   if (first_name.length == 0 || first_name.length > 50) {
     alert("Contact Us Error #CNTUSCLNT01\n\nFirst name required.\n\nMaximum characters: 50");
     doc.first_name.focus();
     return false;
   }
   
   if (isName(doc.first_name) == 0) {
     return false;
   }

   /* Last Name */
   if (last_name.length == 0 || last_name.length > 50) {
     alert("Contact Us Error #CNTUSCLNT02\n\nLast name required.\n\nMaximum characters: 50");
     doc.last_name.focus();
     return false;
   }
   
   if (isName(doc.last_name) == 0) {
     return false;
   }
   
   /* Address 1 */
   if (address1.length == 0 || address1.length > 50) {
     alert("Contact Us Error #CNTUSCLNT03\n\nAddress 1 required.\n\nMaximum characters: 50");
     doc.address1.focus();
     return false;
   }

   if (isTextField(doc.address1) == 0) {
     return false;
   }

   /* Address 2 */
   if (address2.length != 0) {
     if (isTextField(doc.address2) == 0) {
       return false;
     }
   }
   
   /* City */
   if (city.length == 0 || city.length > 50) {
     alert("Contact Us Error #CNTUSCLNT04\n\nCity required.\n\nMaximum characters: 50");
     doc.city.focus();
     return false;
   }

   if (isTextField(doc.city) == 0) {
     return false;
   }

   /* State */
   if (is_state.length == 0) {
     alert("Contact Us Error #CNTUSCLNT05\n\nState required.");
     doc.state.focus();
     return false;
   }

   /* Zip */
   if (zip.length == 0 || city.length > 10) {
     alert("Contact Us Error #CNTUSCLNT06\n\nZip required.\n\nMaximum characters: 10");
     doc.zip.focus();
     return false;
   }

   if (is_state != "International") {
     if (isZip4(doc.zip) == 0) {
       return false;
     }
   }

   /* Home Phone */
   if (phone_home.length == 0) {
     alert("Contact Us Error #CNTUSCLNT07\n\nHome Phone required.");
     doc.phone_home.focus();
     return false;
   }
   
   if (isTextField(doc.phone_home) == 0) {
     return false;
   }

   if (phone_mobile_work.length != 0) {
     if (isTextField(doc.phone_mobile_work) == 0) {
       return false;
     }
   }

   /* E-mail */
   if (email.length == 0 || email.length > 100) {
     alert("Contact Us Error #CNTUSCLNT08\n\nE-mail required.\n\nMaximum characters: 100");
     doc.email.focus();
     return false;
   }

   if (isEmail(doc.email) == 0) {
     return false;
   }

   /* E-mail Confirm */
   if (fieldCompare(doc.email_confirm,doc.email) == 0) {
     return false;
   }

   /* Message */
   if (message.length > 1000) {
     alert("Contact Us Error #CNTUSCLNT09\n\nMessage.\n\nMaximum characters: 1000");
     doc.message.select();
     return false;
   }

   disableObj(doc.contact_btn);

}