function togglediv(divsection) {
    //if (document.getObjectById(divsection).style.display == "block") {
    //  document.getObjectById(divsection).style.display="none";
    //} else {
    //  document.getObjectById(divsection).style.display="block";
    //}

  if (document.getElementById(divsection).style.display == "block") {
    document.getElementById(divsection).style.display="none";
  } else {
    document.getElementById(divsection).style.display="block";
  }
}

    function more(id) {
        document.getElementById(id).style.display="block";
    }

    function less(id) {
        document.getElementById(id).style.display="none";
    }

    // simple script to put the chosen category into the form
    // requires a field named 'category' exist
	function onChoose(formObject, formStuff) {
	    formObject.category.value=formStuff;
	}

//========================================================================
    function passwordStrengthChecker(inputname, outputhelp) {
        var htmlHelp = "Start...<br/>" + inputname + outputhelp;
//alert(htmlHelp);
alert(htmlHelp);

togglediv(outputhelp);

        // check the password strength

        var passwordInput = document.getElementById(inputname);
alert(passwordInput.value);
if (passwordInput == null) alert("bad element name!");
        // guilty until proven innocent
        //passwordInput.style.color="red";
htmlHelp += "has ";

        //passwordInput.value=inputname;
        var hasLower = ! (passwordInput.value.match(/[a-z]/) == null);
alert(htmlHelp);
        var hasUpper = ! (passwordInput.value.match(/[A-Z]/) == null);
        var hasDigit = ! (passwordInput.value.match(/\d/) == null);
        var hasGoodOther = ! (passwordInput.value.match(/[\!\@\#\$\%\^\&\*\(\)\-\_\=\+\,\;\:\<\>\{\}\]\[]/) == null);
        var hasBadOther = ! (passwordInput.value.match(/[\`\~\\\/\.'"\s]/) == null);

//alert(htmlHelp);
        if (hasLower) htmlHelp += "has an lower case letter<br/>";
        if (hasUpper) htmlHelp += "has an upper case letter<br/>";
        if (hasDigit) htmlHelp += "has a digit<br/>";
        if (hasGoodOther) htmlHelp += "has other character<br/>";
        if (hasBadOther) htmlHelp += "HAS BAD CHARACTER, such as a period or a space<br/>";
//alert(htmlHelp);

        if (passwordInput.value.length >=8) htmlHelp += "is at least 8 chars long<br/>";

        // 2 of 4
        if ( ((hasLower || hasUpper) && (hasDigit || hasGoodOther)) ||
             ((hasLower || hasDigit) && (hasUpper || hasGoodOther)) ) {
           passwordInput.style.color="blue";
           htmlHelp += "Meets 2 of 4 rule<br/>";
        }
        // 3 of 4
        if ( ((hasLower || hasUpper) && (hasDigit && hasGoodOther)) ||
             ((hasLower && hasUpper) && (hasDigit || hasGoodOther)) ) {
          passwordInput.style.color="green"; 
          htmlHelp += "Meets 3 of 4 rule";
          if (passwordInput.value.length >=8)
            document.getElementById("passwordStrengthOK").style.display="block";
        }
        
alert(htmlHelp);
        document.getElementById(outputhelp).innerHTML = htmlHelp;
    }

//-------------------------------------------------------------------------
// hard coded field name version

function passwdStrChk() {
        var htmlHelp = "Start s...<br/>";

togglediv("passwdmsglower");

        // check the password strength
//document.msg_lower.display="block";
//document.getElementById("passwdmsglower").display="block";

        var passwordInput = document.form.pwdin4;
//passwordInput = document.passwdinput;
if (passwordInput == null) alert("bad element name!");
        // guilty until proven innocent
        //passwordInput.style.color="red";

document.getElementById("pwdin4").style.color="red";
htmlHelp += "-1- ";

        //passwordInput.value=inputname;
        var hasLower = ! (document.getElementById("pwdin4").value.match(/[a-z]/) == null);
alert(htmlHelp);
        var hasUpper = ! (document.getElementById("pwdin4").value.match(/[A-Z]/) == null);
        var hasDigit = ! (document.getElementById("pwdin4").value.match(/\d/) == null);
        var hasGoodOther = ! (document.getElementById("pwdin4").value.match(/[\!\@\#\$\%\^\&\*\(\)\-\_\=\+\,\;\:\<\>\{\}\]\[]/) == null);
        var hasBadOther = ! (document.getElementById("pwdin4").value.match(/[\`\~\\\/\.'"\s]/) == null);

//alert(htmlHelp);
        if (hasLower) document.passwdmsglower.display="block";
        if (hasUpper) htmlHelp += "has an upper case letter<br/>";
        if (hasDigit) htmlHelp += "has a digit<br/>";
        if (hasGoodOther) htmlHelp += "has other character<br/>";
        if (hasBadOther) htmlHelp += "HAS BAD CHARACTER, such as a period or a space<br/>";
//alert(htmlHelp);

        if (document.getElementById("pwdin4").value.length >=8) htmlHelp += "is at least 8 chars long<br/>";

        // 2 of 4
        if ( ((hasLower || hasUpper) && (hasDigit || hasGoodOther)) ||
             ((hasLower || hasDigit) && (hasUpper || hasGoodOther)) ) {
           document.getElementById("passwdinput").style.color="blue";
           htmlHelp += "Meets 2 of 4 rule<br/>";
        }
        // 3 of 4
        if ( ((hasLower || hasUpper) && (hasDigit && hasGoodOther)) ||
             ((hasLower && hasUpper) && (hasDigit || hasGoodOther)) ) {
          document.getElementById("passwdinput").color="green"; 
          htmlHelp += "Meets 3 of 4 rule";
          if (document.getElementById("pwdin4").value.length >=8)
            document.getElementById("passwordStrengthOK").style.display="block";
        }
        
alert(htmlHelp);
        document.getElementById(outputhelp).innerHTML = htmlHelp;
    }

//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// pull out the rule checks into their own functions

// Takes in a password string value
// does not allow spaces, slashes, period, quotes
function has3of4 (pwdstr) {
  var hasLower = pwdstr.match(/[a-z]/) != null;
  var hasUpper = pwdstr.match(/[A-Z]/) != null;
  var hasDigit = pwdstr.match(/\d/) != null;
  var hasGoodOther = pwdstr.match(/[\!\@\#\$\%\^\&\*\(\)\-\_\=\+\,\;\:\<\>\{\}\]\[]/) != null;
  var hasBadOther = pwdstr.match(/[\`\~\\\/\.'"\s]/) != null;

  // automatic failure if has characters not allowed in password
  if (hasBadOther) return false;

  if ( ((hasLower || hasUpper) && (hasDigit && hasGoodOther)) ||
       ((hasLower && hasUpper) && (hasDigit || hasGoodOther)) ) {
    return true;
  }
  return false;
}

function hasBadChar (pwdstr) {
  return (hasBadOther = pwdstr.match(/[\`\~\\\/\.'"\s]/) != null);
}

function repeatCheck(elem, pwdFieldID, okMsgID) {
  elem.style.color="black";
  if (document.getElementById(pwdFieldID).value == elem.value) {
    elem.style.color = "green";
    more(okMsgID);
  } else {
    less(okMsgID);
  }
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// from JavaScript and DHTML cookbook p194, updated version 
// validates that the entry is formatted as an e-mail address
function isEMailAddr(elem) {
	var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Verify the e-mail address format.");
        //setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        alert("Email address looks good");
        return true;
    }
}





function onType(formObject) {
    var len = formObject.cc_no1.value.length + 1;

    // insert a dash at these positions
    if ((len % 2) == 0) {
        formObject.cc_no1.value = formObject.cc_no1.value + "-";
    }
}

function onChoose2 (formObject, formStuff) {
  formObject.cc_no1.value = formStuff;
}