<!-- Begin
function openBeneficiaryWindow(newUrl) {
    window.open(newUrl,"myBeneWin","status=no,scrollbars=yes,toolbar=no,resizable=yes,location=no,menubar=no,width=700,height=550,top=50,left=100");
}
function hsaAppSetHealthPlanNm(formObj,indx) {
    document.HSAApplication.hpNm.value = formObj.options[indx].text;
}
function hsaAppBeneDelete(formAction,beneNbr) {
    newNbr = beneNbr + 1;
    if (confirm("Do you really want to delete beneficiary number " + newNbr + "? \nClick the OK button to proceed with the deletion.")) {
        document.HSAApplication.beneficiaryDeleteRow.value = beneNbr;
        document.HSAApplication.action = formAction;
        document.HSAApplication.submit();
    }
}
function hsaAppBeneEdit(formAction,beneNbr,beneSt) {
    document.HSAApplication.beneficiaryEditRow.value = beneNbr;
    document.HSAApplication.beneOneState.value = beneSt;
    document.HSAApplication.action = formAction;
    document.HSAApplication.submit();
}
function hsaAppEdit(formAction) {
    document.HSAApplication.action = formAction;
    document.HSAApplication.submit();
}
function openHSAPlanOption(openDiv, closeDiv) {
  document.getElementById(openDiv).style.display = "inline";
  document.getElementById(closeDiv).style.display = "none";
}
function cancelMember(formObj) {
    if (confirm("Do you really want to cancel? \nYou will lose the data you have entered. \nClick the OK button to proceed with the cancel.")) {
	    formObj.action = "myaccounts.action";
	    formObj.submit();
    }
}
function cancelPublic(formObj) {
    if (confirm("Do you really want to cancel? \nYou will lose the data you have entered. \nClick the OK button to proceed with the cancel.")) {
//	    formObj.action = "/../../";
//	    formObj.submit();

      var host = window.location.host;
      var path = window.location.pathname;
      path = path.substring(0, path.lastIndexOf("/"));
      var link = "http://" + host + path + "/../../";
      window.location = link;
    }


}
function cancelBrandPublic(formObj, action) {
    if (confirm("Do you really want to cancel? \nYou will lose the data you have entered. \nClick the OK button to proceed with the cancel.")) {
//      formObj.action = "/../../";
//      formObj.submit();

      // return to the static content using http protocol
      var host = window.location.host;
      var path = window.location.pathname;
      path = path.substring(0, path.lastIndexOf("/"));
      var link = "http://" + host + path + "/../.." + action;
      window.location = link;
    }
}
function openExpandedRules(newUrl, windowWidth) {
    if(arguments.length == 1) {
      window.open(newUrl,"myWin","status=no,scrollbars=yes,toolbar=no,resizable=yes,location=no,menubar=no,width=700,height=550,top=50,left=100");
    }  else {
      window.open(newUrl,"myWin","status=no,scrollbars=yes,toolbar=no,resizable=yes,location=no,menubar=no,width="+windowWidth+",height=550,top=50,left=50");
    }
}
function openLearnMore(newUrl) {
    window.open(newUrl,"myWin","status=no,scrollbars=yes,toolbar=no,resizable=yes,location=no,menubar=no,width=475,height=465,top=95,left=200");
}
function openCalendar(formName, fieldName) {
    newUrl = "/selectaccount/common/calendarPopup.jsp?";
    newUrl += "formName=" + formName + "&fieldName=" + fieldName;
    window.open(newUrl,"myWin","status=no,scrollbars=no,toolbar=no,resizable=no,location=no,menubar=no,width=300,height=165,top=125,left=325");
}
function submitInvAcct(formObj, formAction) { //submit HSAInvAcct form from options.jsp
    formObj.action = formAction;
    formObj.submit();
}
function validateCont() { //validation for HSAContribution form
    //see if account type is selected
//    var accountType = "";
//    accountType = valueOfRadio(document.HSAContribution.accountType);
//    if (!((accountType == "1") || (accountType == "2"))) {
//        alert("Please select an Account Type");
//        return false;
//    }
    //see if contribution option is selected
    var contribOpt = "";
    contribOpt = valueOfRadio(document.HSAContribution.contribOpt);
    if (!((contribOpt == "1") || (contribOpt == "2") || (contribOpt == "3") || (contribOpt == "4"))) {
        alert("Please select an Contribution Option");
        return false;
    }
    //validate contribution amount field
    if (document.HSAContribution.contribAmt.value == "") {
        alert("Contribution amount is a required field");
        return false;
    }
    //validate contribution tax year field
    if ((contribOpt == "3") || (contribOpt == "4")) {
//        if (document.HSAContribution.contribTaxYr.value == "") {
//            alert("Contribution tax year is a required field");
//            return false;
//        } else {
            if (document.HSAContribution.contribTaxYr.value.length > 4 || document.HSAContribution.contribTaxYr.value.length < 4) {
                alert("Contribution tax year has invalid length");
                return false;
            } else {
                if (document.HSAContribution.contribTaxYr.value.length == 4) {
                    var okay = true;
                    okay = validInput(document.HSAContribution.contribTaxYr);
                    if (!okay) {
                        alert("Contribution tax year does not contain valid characters");
                        return false;
                    }
                }
            }
//        }
    } else {
        if ((contribOpt == "1") || (contribOpt == "2")) {
            if (document.HSAContribution.contribTaxYr.value > 0) {
                alert("Contribution tax year is valid only when choosing the single or monthly bank draft option");
                return false;
            }
        }
    }
    //validation passed, go ahead and submit the form
	document.HSAContribution.submit()
}
function validateWith() { //validation for HSAWithdrawal form
    //see if distribution reason is selected
    var distribReason = "";
    distribReason = valueOfRadio(document.HSAWithdrawal.distribReason);
    if (!((distribReason == "1") || (distribReason == "2") || (distribReason == "3") ||(distribReason == "6"))) {
        alert("Please select an Distribution Reason");
        return false;
    }
    //validate withdrawal amount field
    if (document.HSAWithdrawal.withdrawalAmt.value == "") {
        alert("Withdrawal amount is a required field");
        return false;
    }
    //validation passed, go ahead and submit the form
	document.HSAWithdrawal.submit()
}
function validateDD() { //validation for HSADirectDeposit form
    //set contributionInd hidden field based on corresponding checkbox
    document.HSADirectDeposit.contributionInd.value = "F"; //by default, set to "F"
    if (document.HSADirectDeposit.contributionCheckbox) { //see if checkbox exists in form...
      if (document.HSADirectDeposit.contributionCheckbox.checked) {
        document.HSADirectDeposit.contributionInd.value = "T";
      } else {
        document.HSADirectDeposit.contributionInd.value = "F";
      }
    }

    //set withdrawalInd hidden field based on corresponding checkbox
    if (document.HSADirectDeposit.withdrawalCheckbox.checked) {
        document.HSADirectDeposit.withdrawalInd.value = "T";
    } else {
        document.HSADirectDeposit.withdrawalInd.value = "F";
    }
    //validate bank name field
    if (document.HSADirectDeposit.bankNm.value == "") {
        alert("Bank name is a required field");
        return false;
    }
    if (document.HSADirectDeposit.bankNm.value.length > 0) {
        var okay = true;
        okay = validInput(document.HSADirectDeposit.bankNm);
        if (!okay) {
            alert("Bank name does not contain valid characters");
            return false;
        }
    }
    //validate branch name field
    if (document.HSADirectDeposit.branchNm.value == "") {
        alert("Branch name is a required field");
        return false;
    }
    if (document.HSADirectDeposit.branchNm.value.length > 0) {
        var okay = true;
        okay = validInput(document.HSADirectDeposit.branchNm);
        if (!okay) {
            alert("Branch name does not contain valid characters");
            return false;
        }
    }
    //validate bank phone number field
    if (document.HSADirectDeposit.bankPhoneAc.value.length != 3) {
        alert("Area code has invalid length");
        return false;
    }
    if (document.HSADirectDeposit.bankPhoneAc.value.length > 0) {
        var okay = true;
        okay = validInput(document.HSADirectDeposit.bankPhoneAc);
        if (!okay) {
            alert("Area code does not contain valid characters");
            return false;
        }
    }
    if (document.HSADirectDeposit.bankPhoneNum1.value.length != 3) {
        alert("Phone number prefix has invalid length");
        return false;
    }
    if (document.HSADirectDeposit.bankPhoneNum1.value.length > 0) {
        var okay = true;
        okay = validInput(document.HSADirectDeposit.bankPhoneNum1);
        if (!okay) {
            alert("Phone number prefix does not contain valid characters");
            return false;
        }
    }
    if (document.HSADirectDeposit.bankPhoneNum2.value.length != 4) {
        alert("Phone number suffix has invalid length");
        return false;
    }
    if (document.HSADirectDeposit.bankPhoneNum2.value.length > 0) {
        var okay = true;
        okay = validInput(document.HSADirectDeposit.bankPhoneNum2);
        if (!okay) {
            alert("Phone number suffix does not contain valid characters");
            return false;
        }
    }
    //see if account type is selected
    var acctType = "";
    acctType = valueOfRadio(document.HSADirectDeposit.accountType);
    if (!((acctType == "1") || (acctType == "2"))) {
        alert("Please select an account type");
        return false;
    }
    //validate routing transit number field
    if (document.HSADirectDeposit.aba.value == "") {
        alert("Routing transit number is a required field");
        return false;
    }
    if (document.HSADirectDeposit.aba.value.length != 9) {
        alert("Routing transit number must be 9 characters in length");
        return false;
    }
    if (document.HSADirectDeposit.aba.value.length > 0) {
        var okay = true;
        okay = validInput(document.HSADirectDeposit.aba);
        if (!okay) {
            alert("Routing transit number does not contain valid characters");
            return false;
        }
    }
    //validate account number field
    if (document.HSADirectDeposit.accountNum.value == "") {
        alert("Account number is a required field");
        return false;
    }
    if (document.HSADirectDeposit.accountNum.value.length < 3) {
        alert("Account number must be at least 3 characters in length");
        return false;
    }
    if (document.HSADirectDeposit.accountNum.value.length > 0) {
        var okay = true;
        okay = validInput(document.HSADirectDeposit.accountNum);
        if (!okay) {
            alert("Account number does not contain valid characters");
            return false;
        }
    }

    //validation passed, go ahead and submit the form
	document.HSADirectDeposit.submit()
}
function validateXOVR(ptpAvailable, currentMedXovrStatus) { //validation for HSACrossover form
    //see if enrollment option is selected
    var enrollOpt = "";
    enrollOpt = valueOfRadio(document.HSACrossover.electionFlag);
    if(ptpAvailable == "T" && enrollOpt == "") {
      if(document.HSACrossover.electionFlagPTP != undefined) {
        ptpEnrollOpt = valueOfRadio(document.HSACrossover.electionFlagPTP);
        if(ptpEnrollOpt == "T" && currentMedXovrStatus == "F") {
          alert("You must enroll in Medical Crossover to enroll in Pay-the-provider.")
          return false;
        } else if(ptpEnrollOpt.length != 0) {
          document.HSACrossover.submit();
          return true;
        }
      }
    }
    if (!((enrollOpt == "T") || (enrollOpt == "F"))) {
        alert("Please select an Enrollment Option");
        return false;
    }
    //user cannot select "do not enroll" and specify a health plan id number
    if ((enrollOpt == "F") && (document.HSACrossover.subscriberId.value.length > 0)) {
        alert("You cannot choose the 'Do Not Enroll' option and specify a Health Plan Id Number");
        return false;
    }
    //see if health plan id number (if entered - its optional) has valid non-blank characters
    if (document.HSACrossover.subscriberId.value.length > 0) {
        var okay = true;
        okay = validInput(document.HSACrossover.subscriberId);
        if (!okay) {
            alert("Health Plan Id Number does not contain valid characters");
            return false;
        }
    }
    if(ptpAvailable == "T") {
      if(document.HSACrossover.electionFlagPTP != undefined) {
        ptpEnrollOpt = valueOfRadio(document.HSACrossover.electionFlagPTP);
        if(ptpEnrollOpt == "T" && (enrollOpt == "F" || (enrollOpt == "" && currentMedXovrStatus == "F"))) {
          alert("You must be enrolled in Medical Crossover to enroll in Pay-the-provider.")
          return false;
        }
      }
    }

    //validation passed, go ahead and submit the form
	document.HSACrossover.submit()
}
function valueOfRadio(radioObj) { //return the checked value of a radio element
    var retval = "";
    for (var i = 0; i < radioObj.length; i++) {
        if (radioObj[i].checked) {
            retval = radioObj[i].value;
            break;
        }
    }
    return retval;
}
function validInput(textObj) { //return true if text has non-blank characters
    var retval = false;
    for (var i = 0; i < textObj.value.length; i++) {
        if (textObj.value.substring(i,i+1) != " ") {
            retval = true;
            break;
        }
    }
    return retval;
}



// routines to check valid input for self registration
function validUserID(inputObj) {

    var testTxt = inputObj.value;
    if(testTxt.length == 0) return true;
    if(testTxt.length < 6 ||
       testTxt.length > 14 ||
       containsBlanks(testTxt) ||
       profanityCheck(testTxt)) {

        alert("The user name you entered is invalid or contains unacceptable characters.");
        inputObj.focus();
        inputObj.select();
        return false;
    }
    return true;
}

function validPassword(inputObj) {

    var testTxt = inputObj.value;
    if(testTxt.length == 0) return true;
    if(testTxt.length < 8 ||
       alphaNumericCheck(testTxt) ||
       containsBlanks(testTxt) ||
       profanityCheck(testTxt)) {

        alert("The password you entered is invalid or contains unacceptable characters.");
        inputObj.focus();
        inputObj.select();
        return false;
    }
    return true;
}

function validPasswordMatch(inputObj, thisForm) {

    var testTxt = inputObj.value;
    if(testTxt.length == 0) return true;

    if(thisForm.password1.value != testTxt) {
        alert("The passwords you entered do not match.");
        inputObj.value = "";
        inputObj.focus();
        inputObj.select();
        return false;
    }
    return true;
}

var naughtyWords = ["fuck",
                    "shit",
                    "damn",
                    "cunt",
                    "piss",
                    "cock",
                    "anonymous",
                    "fawq",
                    "bitch",
                    "dildo"];

function profanityCheck(text) {

    for(i=0; i<naughtyWords.length; i++) {
        if(text.toLowerCase().indexOf(naughtyWords[i]) != -1)
            return true;
    }
    return false;
}

function alphaNumericCheck(text) {

    // returns true if text does not contain
    // both alpha and numeric characters
    var retval = true;
    // test for numbers
    for(i=0; i<text.length; i++) {
        var oneChar = text.charAt(i);
        if (oneChar >= "0" && oneChar <= "9") {
            retval = false;
            break;
        }
    }

    // return true if no numbers
    if(retval) return retval;

    // test for alpha
    retval = true;
    for(i=0; i<text.length; i++) {
        var oneChar = text.charAt(i);
        if ((oneChar >= "A" && oneChar <= "Z") ||
            (oneChar >= "a" && oneChar <= "z")) {
            return false;
        }
    }
    // return true if no characters
    return retval;
}

function containsBlanks(text) {

    if(text.indexOf(" ") != -1) return true;
    return false;
}

function validateRegForms(thisForm) {

    if(thisForm.fname) {
        if(thisForm.fname.value.length == 0) {
          alert("Please enter a first name.");
          thisForm.fname.focus();
          thisForm.fname.select();
          return false;
        }
    }
    if(thisForm.lname) {
        if(thisForm.lname.value.length == 0) {
          alert("Please enter a last name.");
          thisForm.lname.focus();
          thisForm.lname.select();
          return false;
        }
    }
    if(thisForm.dob) {
        if(thisForm.dob.value.length == 0) {
          alert("Please enter a birth date.");
          thisForm.dob.focus();
          thisForm.dob.select();
          return false;
        }
    }
    if(thisForm.memberID) {
        if(thisForm.memberID.value.length == 0) {
          alert("Please enter a SelectAccount member ID.");
          thisForm.memberID.focus();
          thisForm.memberID.select();
          return false;
        }
    }
    if(thisForm.pinNumber) {
        if(thisForm.pinNumber.value.length == 0) {
          alert("Please enter a PIN number.");
          thisForm.pinNumber.focus();
          thisForm.pinNumber.select();
          return false;
        }
    }
    if(thisForm.userName) {
        if(thisForm.userName.value.length == 0) {
          alert("Please enter a  user name.");
          thisForm.userName.focus();
          thisForm.userName.select();
          return false;
        }
        if(!validUserID(thisForm.userName)) return false;
    }
    if(thisForm.maidenName) {
        if(thisForm.maidenName.value.length == 0) {
          alert("Please enter your mother's maiden name.");
          thisForm.maidenName.focus();
          thisForm.maidenName.select();
          return false;
        }
    }
    if(thisForm.password1) {
        if(thisForm.password1.value.length == 0) {
          alert("Please enter a password.");
          thisForm.password1.focus();
          thisForm.password1.select();
          return false;
        }
        if(!validPassword(thisForm.password1)) return false;
    }
    if(thisForm.password2) {
        if(thisForm.password2.value.length == 0) {
          alert("Please enter the password a second time.");
          thisForm.password2.focus();
          thisForm.password2.select();
          return false;
        if(!validPasswordMatch(thisForm.password2, thisForm)) return false;
        }
    }
}

//
// Script to trap a carriage return. This prevents the user from
// submitting a form with a Return key from a text element and
// forces the user to click on a submit button to submit a form.
//
// Original script from The JavaScript Source
// Author:  Volker Schubert (js@volker-schubert.de)
//
  function checkCR(evt) {

    var evt  = (evt) ? evt : ((event) ? event : null);

    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}

  }

// function used to set the protocol to https when requested
// and execute the link transfer
//
  function httpsTransfer(relLink) {


    var path = window.location.pathname;
    path = path.substring(0, path.lastIndexOf("/"));

    // check for branded links
    // we skip generalmills and nwa because the relative links are already configured
    var brand = "";
    if(path.indexOf("ATK") != -1) {
        brand = "ATK";
        path = path + "/../..";
    }

    if(brand != "") {
        // check for a link to service or landing
        if(relLink.indexOf("service") != -1) {
            // add the brand name after service
            var pos = relLink.indexOf("service");
            relLink = relLink.substring(0,pos+8) + brand + "/" + relLink.substring(pos+8);
        }
        if(relLink.indexOf("landing") != -1) {
            // add the ID parameter as an input parameter
            relLink = relLink + "?id=" + brand
        }
    }

    var host = window.location.host;
    if(relLink.indexOf("/") == 0) relLink = relLink.substring(1);
    var link = "https://" + host + path + "/" + relLink;
    window.location = link;
    return false;
  }

// function used to set the protocol to http when requested
// and execute the link transfer
//
  function httpLinkToNewWindow(relLink, target) {
    var host = window.location.host;
    var path = window.location.pathname;
    path = path.substring(0, path.lastIndexOf("/"));
    if(relLink.indexOf("/") == 0) relLink = relLink.substring(1);
    var link = "http://" + host + path + "/" + relLink;
    window.open(link, target);
  }

// function used to access all pdfs from a common directory
//
  function httpLinkToPDF(pdfDoc, target) {
    var host = window.location.host;
    var path = window.location.pathname;
    var pos = path.indexOf("public/");
    path = path.substring(0, pos+6);
    if(pdfDoc.indexOf("/") == 0) pdfDoc = pdfDoc.substring(1);
    var link = "http://" + host + path + "/pdfs/" + pdfDoc;
    window.open(link, target);
  }

// function used to access all pdfs from a common directory from Weblogic
//
  function httpLinkToPDFfromWeblogic(pdfDoc, target) {
    var host = window.location.host;
    var path = window.location.pathname;
    // get path in front of the weblogic portion
    var pos = path.indexOf("eConsumer");
    path = path.substring(0, pos);
    if(pdfDoc.indexOf("/") == 0) pdfDoc = pdfDoc.substring(1);
    var link = "http://" + host + path + "public/pdfs/" + pdfDoc;
    window.open(link, target);
  }

  document.onkeypress = checkCR;

//  End -->