      var xmlhttp = null;
      var attempts = 0;
      var em_username;
      var cuid;
//alert("HOST NAME = " + location.hostname);
      function getFormElementsByTagType(formName, tagName, tagType) {
        this.$ = new Array();
        var el = null;
        var nameArr = document.getElementsByTagName(tagName);
        for (var i=0; i<nameArr.length -1; i++) {
          el = nameArr[i];
          if ('undefined' != typeof el.form) {
//if ('undefined'==typeof el.form.id || ''==el.form.id) { alert('A INPUT ' + i + ' = ' + el.name); continue; } else { alert('B INPUT ' + i + ' = ' + el.name + ' AND FORM ID = ' + el.form.id); }
//alert('INPUT ' + i + ' (OF ' + nameArr.length + ') = ' + el.name + ' AND FORM ID = ' + el.form.id);
            if (('undefined'!=typeof el.form) && formName==el.form.id && 'undefined'!=typeof el.type) {
              if ('object' == typeof tagType) {
                for (var j=0; j<tagType.length; j++) {
                  if (tagType[j] == el.type) {
                    this.$.push(el);
                  }
                }
              } else {
                if (tagType == el.type) {
                  this.$.push(el);
                }
              } // if object
            }
          }
        }
        return this.$;
      }
      var login_user = function(_cuid) {
        var f = document.getElementById('loginForm');
        var args = '';
        cuid = _cuid;
        var inputs = getFormElementsByTagType('loginForm', 'input', ['text', 'password']);
//        if (1 < document.getElementById('username').value.length) { formFunctions.userFirstName = document.getElementById('name_first').value; }
        for (var i=0; i<inputs.length; i++) {
//alert('INPUTS['+i+'] = |' +  inputs[i].value + '|');
          args += (inputs[i].value && 0<inputs[i].value.length) ? '&'+inputs[i].name+'='+inputs[i].value : '';
        }
//        if (document.getElementById('save1').checked) { args += '&save=1'; }
        if (0 < args.length) {
          args = '?' + args.substr(1);
//          document.getElementById('loginDiv').style.display = 'none';
          var cbFunction = 'login_user_response';
          var url = '/check_user.php' + args;
          url += '&location=' + encodeURIComponent(location.pathname);
//window.location.href=url; return false;
//alert('URL = ' + url); //return false;
          xmlhttp = null;
          try { // IE
            xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
          } catch (err) {
            try {
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (err) {
              xmlhttp = null;
            }
          }
          // FF
          if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            xmlhttp = new XMLHttpRequest();
          }
          if (xmlhttp) {
            xmlhttp.onreadystatechange = function() {
              login_user_response();
            }
            try {
              xmlhttp.open("GET",url,true);
            } catch(err) {
              alert('ERROR: ' + err);
            }
            if (window.ActiveXObject) {
              xmlhttp.send();
            } else if (window.XMLHttpRequest) {
              xmlhttp.send(null);
            }
          }
        } // if 0<args.length
      }

      var login_user_response = function() {
        var _response;
        if (4==xmlhttp.readyState && 200==xmlhttp.status) {
          _response = new String(xmlhttp.responseText);
//alert('LOG MMIX USER LINE 85: |' +  _response + '|');
          ++attempts;
          rarr = _response.split('::');
          if ('Password does not match' == rarr[0]) {
            if (3>attempts) {
              var f = document.getElementById('loginForm');
              f.log_password.value = '';
              f.log_password.focus();
//              if (capsOn) {
//                alert(_response + '\\nNOTE: Your Caps Lock key is on');
//              } else {
                  //alert(_response + "\\nAttempts: " + attempts);
                  alert("Wrong User Name or Password.\\n Please try again.");
//              }
            } else {
              // redirect to reset page, then home page; use replace so that back won't return to this page
              window.location.replace("/"+cuid+"/login_fail.php");
//              var rf = document.getElementById('redirectForm');
//              var f  = document.getElementById('loginForm');
//              document.getElementById('username').value = f.log_username.value;
//              document.getElementById('rf_cuid').value = cuid;
//alert('LOG USERNAME = ' + f.log_username.value + "; RF USERNAME  = " + rf.username.value);
              //rf.username.value = f.log_username.value;
//              closeDiv('login');
//              document.getElementById('redirectDiv').style.display = 'block';

//             rf.submit();
//              window.location.replace("./login_fail.html");
              return false;
            }
          } else {
            username = rarr[1];
            if (formFunctions) { formFunctions.userFirstName = (rarr[1].substring(0,1).toUpperCase() + rarr[1].substr(1).toLowerCase()); }
            switch(rarr[0]) {
              case 'Old user':
                message  = "<b>Welcome back, " + (rarr[1].substring(0,1).toUpperCase() + rarr[1].substr(1).toLowerCase()) + "!</b>";
                document.getElementById('loginDiv').innerHTML = message;
                closeIt();
                if (formFunctions) { formFunctions.isValidUser = true; }
                break;
              case 'New user':
                alert('New users must register first');
                window.location.replace("/"+cuid+"/register.php");
                //message  = "Welcome to My MoneyMix, " + (rarr[1].substring(0,1).toUpperCase() + rarr[1].substr(1).toLowerCase()) + "!";
                //document.getElementById('loginDiv').innerHTML = message;
                //closeIt();
                //if (formFunctions) { formFunctions.isValidUser = true; }
                break;
            } // switch rarr0
          } // if 'Password...'
        } //if 4
      }

      var resetPW = function() {
        //var emailexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
        var emailexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        var email = prompt("If you would like to reset your password, enter your username email address","")
        if (email) {
          em_username = email;
          if (emailexp.test(email)) {
            var cbFunction = 'resetPW_response';
            var url = '/include/check_username.php?email=' + email;
            url += '&location=' + encodeURIComponent(location.pathname);
//window.location.href=url; return false;
//alert('URL = ' + url);// return false;
            xmlhttp = null;
            try { // IE
              xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
            } catch (err) {
              try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
              } catch (err) {
                xmlhttp = null;
              }
            }
            // FF
            if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
              xmlhttp = new XMLHttpRequest();
            }
            if (xmlhttp) {
              xmlhttp.onreadystatechange = function() {
                resetPW_response();
              }
              try {
                xmlhttp.open("GET",url,true);
              } catch(err) {
                alert('ERROR: ' + err);
              }
              if (window.ActiveXObject) {
                xmlhttp.send();
              } else if (window.XMLHttpRequest) {
               xmlhttp.send(null);
              }
            }
          } else {
            alert(email + " is not a valid email address. Please try again.")
          }
        }
      } // resetPW

      var resetPW_response = function() {
        var _response;
        if (4==xmlhttp.readyState && 200==xmlhttp.status) {
          var msg = '';
          switch(xmlhttp.responseText) {
           case '-1': case -1:
             msg = "An error occurred when attempting to email. Please contact CUNA Web Services at (800) 356-9655, ext. 8083";
             break;
           case '0': case 0:
             msg = "Username not found. Please try again.";
             break;
           case '1': case 1:
             msg = "An email with information about resetting your password was sent to " + em_username;
             break;
          } // switch
          alert(msg);
        } // if 4
      }
