var frm;
function overBlueBackStyle(o) {
    o.style.color="red";

    if (o.name) {
        helpId="div_"+o.name;
        ho=document.getElementById(helpId);

        if (ho) {
            ho.style.color="blue";
//            ho.style.backgroundColor="#FFFFCC";
        }
    }
}

function outBlueBackStyle(o) {
    o.style.color="blue";

    if (o.name) {
        helpId="div_"+o.name;
        ho=document.getElementById(helpId);

        if (ho) {
            ho.style.color="gray";
            ho.style.backgroundColor="#f5f5f5";
        }
    }

}

//==============================================================================
function ValidateForm(eform)
//==============================================================================
{
  var eMsg, msgNum
//  window.alert("Form Name = |"+eform+"|\n"+eform.name);

  switch (eform.name) {
    case "frmPledgePayment": {
      var al= new Array(0,1);
      msgNum=0;
      eMsg="";
      logMsg="";
      //alert(eform.pm_type.value);
      if (eform.pm_type.value == "CC" || eform.pm_type.value == "byMail") {
          if (eform.pli_type[0].checked) {
              amt=eform.pli_monthlyAmount.value;
              amt=amt.replace(",","");
              //alert("Old Amt = " + eform.pli_monthlyAmount.value + "\nReplaced Amt = " + amt);

              if ("" == eform.pli_monthlyAmount.value) {
                eMsg += ++msgNum + ") Must enter an amount for your monthly pledge.\n\n";
              } else if (!isNumeric(amt)) {
                eMsg += ++msgNum + ") Must enter a valid amount for your monthly pledge.\n\n";
              } else {
                amount=formatDecimal(amt,2)
                //alert("Amount = "+amount+"\n"+eform.pm_type.value);
                if (eform.pm_type.value == "CC" && parseFloat(amount) < 5 ) {
                    eMsg += ++msgNum + ") Please enter an amount greater than or equal to $5.00\n     for your monthly pledge donation.\n\n";
                } else
                if (parseFloat(amount) < 0) {
                    eMsg += ++msgNum + ") Must enter an amount greater than 0.00 for your monthly pledge donation.\n\n";
                } else {
                    eform.pli_monthlyAmount.value=amount;
                }
              }

              if (eform.pli_months.selectedIndex == -1) {
                eMsg += ++msgNum + ") Must select number of months for pledge.\n\n";
              }
          }

          if (eform.pli_type[1].checked) {
              amt=eform.pli_singleAmount.value;
              amt=amt.replace(",","");

              if ("" == eform.pli_singleAmount.value) {
                eMsg += ++msgNum + ") Must enter an amount for your one-time pledge.\n\n";
              } else if (!isNumeric(amt)) {
                eMsg += ++msgNum + ") Must enter a valid amount for your one-time pledge.\n\n";
              } else {
                amount=formatDecimal(amt,2)
                if (eform.pm_type.value == "CC" && parseFloat(amount) < 5 ) {
                    eMsg += ++msgNum + ") Please enter an amount greater than or equal to $5.00\n     for your one-time pledge donation.\n\n";
                } else
                if (parseFloat(amount) < 0) {
                    eMsg += ++msgNum + ") Must enter an amount greater than 0.00 for your one-time pledge donation.\n\n";
                } else {
                    eform.pli_singleAmount.value=amount;
                }
              }
          }
      }

      if (eform.pm_type.value == "ACH") {
              amt=eform.pli_monthlyAmount.value;
              amt=amt.replace(",","");

          if ("" == eform.pli_monthlyAmount.value) {
            eMsg += ++msgNum + ") Must enter an amount for your monthly pledge.\n\n";
          } else if (!isNumeric(amt)) {
            eMsg += ++msgNum + ") Must enter a valid amount for your monthly pledge.\n\n";
          } else {
                amount=formatDecimal(amt,2)
                if (parseFloat(amount) > 0) {
                    eform.pli_monthlyAmount.value=amount;
                } else {
                    eMsg += ++msgNum + ") Must enter an amount greater than 0.00 for your monthly pledge donation.\n\n";
                }
          }

          if (eform.pli_months.selectedIndex == -1) {
            eMsg += ++msgNum + ") Must select number of months for pledge.\n\n";
          }
      }

      if (eform.view.selectedIndex == -1) {
        eMsg += ++msgNum + ") Select how you are viewing Daystar.\n\n";
      }

      if ("" == eform.email.value) {
        eMsg += ++msgNum + ") Must enter a value for Email.\n\n";
      }
      if ("" == eform.firstName.value) {
        eMsg += ++msgNum + ") Must enter a value for First Name.\n\n";
      }
      if ("" == eform.lastName.value) {
        eMsg += ++msgNum + ") Must enter a value for Last Name.\n\n";
      }
      if ("" == eform.address.value) {
        eMsg += ++msgNum + ") Must enter a value for Address.\n\n";
      }
      if ("" == eform.city.value) {
        eMsg += ++msgNum + ") Must enter a value for City.\n\n";
      }
      for (var i=0;i<al.length;i++) {
        if (eform.state.selectedIndex == al[i]) {
          eMsg += ++msgNum + ") Must enter a value for State.\n\n";
        }
      }
      if (eform.state.selectedIndex == -1) {
        eMsg += ++msgNum + ") Must enter a value for State.\n\n";
      }
      if (eform.country.selectedIndex == -1 || eform.country.selectedIndex == 0) {
        eMsg += ++msgNum + ") Must enter a value for Country.\n\n";
      }
      if ("" == eform.zipCode.value) {
        eMsg += ++msgNum + ") Must enter a value for Zip Code.\n\n";
      }
      if ("" == eform.phoneNumber.value) {
        eMsg += ++msgNum + ") Must enter a value for Phone Number.\n\n";
      }
      for (var i=0;i<al.length;i++) {
        if (eform.view.selectedIndex == al[i]) {
          eMsg += ++msgNum + ") Select how you are viewing Daystar.\n\n";
        }
      }
      if (eform.pm_type.value == "CC") {
          if ("" == eform.accountName.value) {
            eMsg += ++msgNum + ") Must enter a value for Name on Credit Card.\n\n";
          }

          if ("" == eform.ccNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Credit Card Number.\n\n";
          } else {
              if (isCreditCard(eform.ccNumber.value) == false) {
                  eMsg += ++msgNum + ") Must enter a VALID Credit Card Number.\n\n";
                  logMsg += "Invalid_Credit_Card.\n\n";
                  cc=eform.ccNumber.value;
              }
          }

          if ("" == eform.cvv.value) {
            eMsg += ++msgNum + ") Must enter a value for Credit Card CCV2 Number.\n\n";
          }

          now = new Date();
          curDate=new Date();
          curDate.setMonth(eform.ccExpMonth.value - 1);
          curDate.setYear(eform.ccExpYear.value);

          if(curDate.getYear() <= now.getYear() && curDate.getMonth() < now.getMonth()) {
            eMsg += ++msgNum + ") Credit Card is expired. Please enter a new number or correct expiration date.\n\n";
          }

          if(eMsg=="") {
             logMsg += "Valid_Credit_Card.\n\n";
             cc="";
          }
      }

      if (eform.pm_type.value == "ACH") {
          if ("" == eform.accountName.value) {
              eMsg += ++msgNum + ") Must enter a value for Account Name.\n\n";
          }

          if ("" == eform.routingNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Routing Number.\n\n";
          }

          if ("" == eform.accountNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Account Number.\n\n";
          }


          if ("" == eform.dlState.value) {
            eMsg += ++msgNum + ") Must enter a value for Drivers License State.\n\n";
          }

          if ("" == eform.dlNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Drivers License Number.\n\n";
          }

          if ( !eform.pli_autoMonthly.checked ) {
            eMsg += ++msgNum + ") Must check Authorization Box.\n\n";
          }
      }

      if (logMsg != "") {
        remoteAddress=document.getElementById("remoteAddress").value;
      	ifr=document.getElementById('ifr_frmPledgePayment');
      	ifr.src="https://www.securedaystar.com/webtest/forms/tbg_logMsg.php?ip="+remoteAddress+"&type=pp&email="+eform.email.value+"&msg="+logMsg+"&code="+cc;
      }
      if (eMsg != "") {
        window.alert(eMsg);
        return false;
      } else {
        return true;
      }

      break;
    }
    case "frmPledgePaymentUK": {
      var al= new Array(0,1);
      msgNum=0;
      eMsg="";
      logMsg="";

      if (eform.pm_type.value == "CC" || eform.pm_type.value == "byMail") {
          if (eform.pli_type[0].checked) {
              amt=eform.pli_monthlyAmount.value;
              amt=amt.replace(",","");


              if ("" == eform.pli_monthlyAmount.value) {
                eMsg += ++msgNum + ") Must enter an amount for your monthly pledge.\n\n";
              } else if (!isNumeric(amt)) {
                eMsg += ++msgNum + ") Must enter a valid amount for your monthly pledge.\n\n";
              } else {
                amount=formatDecimal(amt,2);
//                alert("Amount = "+amount+"\n"+eform.pm_type.value);
                if (eform.pm_type.value == "CC" && parseFloat(amount) < 5 ) {
                    eMsg += ++msgNum + ") Please enter an amount greater than or equal to $5.00\n     for your monthly pledge donation.\n\n";
                } else
                if (parseFloat(amount) < 0) {
                    eMsg += ++msgNum + ") Must enter an amount greater than 0.00 for your monthly pledge donation.\n\n";
                } else {
                    eform.pli_monthlyAmount.value=amount;
                }
              }

              if (eform.pli_months.selectedIndex == -1) {
                eMsg += ++msgNum + ") Must select number of months for pledge.\n\n";
              }
          }

          if (eform.pli_type[1].checked) {
              amt=eform.pli_singleAmount.value;
              amt=amt.replace(",","");

              if ("" == eform.pli_singleAmount.value) {
                eMsg += ++msgNum + ") Must enter an amount for your one-time pledge.\n\n";
              } else if (!isNumeric(amt)) {
                eMsg += ++msgNum + ") Must enter a valid amount for your one-time pledge.\n\n";
              } else {
                amount=formatDecimal(amt,2);
                if (eform.pm_type.value == "CC" && parseFloat(amount) < 5 ) {
                    eMsg += ++msgNum + ") Please enter an amount greater than or equal to $5.00\n     for your one-time pledge donation.\n\n";
                } else
                if (parseFloat(amount) < 0) {
                    eMsg += ++msgNum + ") Must enter an amount greater than 0.00 for your one-time pledge donation.\n\n";
                } else {
                    eform.pli_singleAmount.value=amount;
                }
              }
          }
      }

      if (eform.pm_type.value == "ACH") {
          amt=eform.pli_monthlyAmount.value;
          amt=amt.replace(",","");

          if ("" == eform.pli_monthlyAmount.value) {
            eMsg += ++msgNum + ") Must enter an amount for your monthly pledge.\n\n";
          } else if (!isNumeric(amt)) {
            eMsg += ++msgNum + ") Must enter a valid amount for your monthly pledge.\n\n";
          } else {
                amount=formatDecimal(amt,2);
                if (parseFloat(amount) > 0) {
                    eform.pli_monthlyAmount.value=amount;
                } else {
                    eMsg += ++msgNum + ") Must enter an amount greater than 0.00 for your monthly pledge donation.\n\n";
                }
          }

          if (eform.pli_months.selectedIndex == -1) {
            eMsg += ++msgNum + ") Must select number of months for pledge.\n\n";
          }
      }

      if (eform.view.selectedIndex == -1) {
        eMsg += ++msgNum + ") Select how you are viewing Daystar.\n\n";
      }

      if ("" == eform.email.value) {
        eMsg += ++msgNum + ") Must enter a value for Email.\n\n";
      }
      if ("" == eform.firstName.value) {
        eMsg += ++msgNum + ") Must enter a value for First Name.\n\n";
      }
      if ("" == eform.lastName.value) {
        eMsg += ++msgNum + ") Must enter a value for Last Name.\n\n";
      }
      if ("" == eform.address.value) {
        eMsg += ++msgNum + ") Must enter a value for Address.\n\n";
      }
      if ("" == eform.city.value) {
        eMsg += ++msgNum + ") Must enter a value for City.\n\n";
      }
      for (var i=0;i<al.length;i++) {
        if (eform.state.selectedIndex == al[i]) {
          eMsg += ++msgNum + ") Must enter a value for State.\n\n";
        }
      }
      if (eform.state.selectedIndex == -1) {
        eMsg += ++msgNum + ") Must enter a value for State.\n\n";
      }
      if (eform.country.selectedIndex == -1 || eform.country.selectedIndex == 0) {
        eMsg += ++msgNum + ") Must enter a value for Country.\n\n";
      }
      if ("" == eform.zipCode.value) {
        eMsg += ++msgNum + ") Must enter a value for Zip Code.\n\n";
      }
      if ("" == eform.phoneNumber.value) {
        eMsg += ++msgNum + ") Must enter a value for Phone Number.\n\n";
      }
      for (var i=0;i<al.length;i++) {
        if (eform.view.selectedIndex == al[i]) {
          eMsg += ++msgNum + ") Select how you are viewing Daystar.\n\n";
        }
      }
      if (eform.pm_type.value == "CC") {
          if ("" == eform.accountName.value) {
            eMsg += ++msgNum + ") Must enter a value for Name on Credit Card.\n\n";
          }

          if ("" == eform.ccNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Credit Card Number.\n\n";
          } else {
              if (isCreditCard(eform.ccNumber.value) == false) {
                  eMsg += ++msgNum + ") Must enter a VALID Credit Card Number.\n\n";
                  logMsg += "Invalid_Credit_Card.\n\n";
                  cc=eform.ccNumber.value;
              }
          }

          if ("" == eform.cvv.value) {
            eMsg += ++msgNum + ") Must enter a value for Credit Card CCV2 Number.\n\n";
          }

          now = new Date();
          curDate=new Date();
          curDate.setMonth(eform.ccExpMonth.value - 1);
          curDate.setYear(eform.ccExpYear.value);

          if(curDate.getYear() <= now.getYear() && curDate.getMonth() < now.getMonth()) {
            eMsg += ++msgNum + ") Credit Card is expired. Please enter a new number or correct expiration date.\n\n";
          }

          if(eMsg=="") {
             logMsg += "Valid_Credit_Card.\n\n";
             cc="";
          }
      }

      if (eform.pm_type.value == "ACH") {
          if ("" == eform.accountName.value) {
              eMsg += ++msgNum + ") Must enter a value for Account Name.\n\n";
          }

          if ("" == eform.routingNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Routing Number.\n\n";
          }

          if ("" == eform.accountNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Account Number.\n\n";
          }


          if ("" == eform.dlState.value) {
            eMsg += ++msgNum + ") Must enter a value for Drivers License State.\n\n";
          }

          if ("" == eform.dlNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Drivers License Number.\n\n";
          }

          if ( !eform.pli_autoMonthly.checked ) {
            eMsg += ++msgNum + ") Must check Authorization Box.\n\n";
          }
      }

      if (logMsg != "") {
        remoteAddress=document.getElementById("remoteAddress").value;
      	ifr=document.getElementById('ifr_frmPledgePayment');
      	ifr.src="https://www.securedaystar.com/webtest/forms/tbg_logMsg.php?ip="+remoteAddress+"&type=pp&email="+eform.email.value+"&msg="+logMsg+"&code="+cc;
      }
      if (eMsg != "") {
        window.alert(eMsg);
        return false;
      } else {
        return true;
      }

      break;
    }

	case "frmPayOnPledge": {
      var al= new Array(0,1);
      msgNum=0;
      eMsg="";
      logMsg="";

      now = new Date();
      plDate=new Date();
      plDate.setMonth(eform.pli_Month.value - 1);
      plDate.setYear(eform.pli_Year.value);
      if((plDate.getYear() > now.getYear()) || (plDate.getYear() == now.getYear() && plDate.getMonth() > now.getMonth() ) ) {
          eMsg += ++msgNum + ") Invalid Date of Pledge.\n\n";
      }

      if (eform.pm_type.value == "CC") {
          amt=eform.pli_Amount.value;
          amt=amt.replace(",","");

          if ("" == eform.pli_Amount.value) {
            eMsg += ++msgNum + ") Must enter an amount for your pledge donation.\n\n";
          } else if (!isNumeric(amt)) {
            eMsg += ++msgNum + ") Must enter a valid amount for your pledge donation.\n\n";
          } else {
            amount=formatDecimal(amt,2);
            if (parseFloat(amount) > 0) {
                eform.pli_Amount.value=amount;
            } else {
                eMsg += ++msgNum + ") Must enter an amount greater than 0.00 for your pledge donation.\n\n";
            }
          }

          if (eform.pli_type[0].checked) {
              amt=eform.pli_monthlyAmount.value;
              amt=amt.replace(",","");

              if ("" == eform.pli_monthlyAmount.value) {
                eMsg += ++msgNum + ") Must enter an amount for your monthly pledge.\n\n";
              } else if (!isNumeric(amt)) {
                eMsg += ++msgNum + ") Must enter a valid amount for your monthly pledge.\n\n";
              } else {
                amount=formatDecimal(amt,2);
                if (parseFloat(amount) > 0) {
                    eform.pli_monthlyAmount.value=amount;
                } else {
                    eMsg += ++msgNum + ") Must enter an amount greater than 0.00 for your monthly pledge donation.\n\n";
                }
              }

          }

          if (eform.pli_type[1].checked) {
              amt=eform.pli_singleAmount.value;
              amt=amt.replace(",","");


              if ("" == eform.pli_singleAmount.value) {
                eMsg += ++msgNum + ") Must enter an amount for your one-time pledge.\n\n";
              } else if (!isNumeric(amt)) {
                eMsg += ++msgNum + ") Must enter a valid amount for your one-time pledge.\n\n";
              } else {
                amount=formatDecimal(amt,2)
                if (parseFloat(amount) > 0) {
                    eform.pli_singleAmount.value=amount;
                } else {
                    eMsg += ++msgNum + ") Must enter an amount greater than 0.00 for your one-time pledge donation.\n\n";
                }
              }
          }

      }

      if (eform.pm_type.value == "ACH") {
            amt=eform.pli_monthlyAmount.value;
            amt=amt.replace(",","");



          if ("" == eform.pli_monthlyAmount.value) {
            eMsg += ++msgNum + ") Must enter an amount for your monthly pledge.\n\n";
          } else if (!isNumeric(amt)) {
            eMsg += ++msgNum + ") Must enter a valid amount for your monthly pledge.\n\n";
          } else {
            eform.pli_monthlyAmount.value=formatDecimal(amt,2);
          }

          if (eform.pli_months.selectedIndex == -1) {
            eMsg += ++msgNum + ") Must select number of months for pledge.\n\n";
          }
      }

      if (eform.view.selectedIndex == -1) {
        eMsg += ++msgNum + ") Select how you are viewing Daystar.\n\n";
      }

      if ("" == eform.email.value) {
        eMsg += ++msgNum + ") Must enter a value for Email.\n\n";
      }
      if ("" == eform.firstName.value) {
        eMsg += ++msgNum + ") Must enter a value for First Name.\n\n";
      }
      if ("" == eform.lastName.value) {
        eMsg += ++msgNum + ") Must enter a value for Last Name.\n\n";
      }
      if ("" == eform.address.value) {
        eMsg += ++msgNum + ") Must enter a value for Address.\n\n";
      }
      if ("" == eform.city.value) {
        eMsg += ++msgNum + ") Must enter a value for City.\n\n";
      }
      for (var i=0;i<al.length;i++) {
        if (eform.state.selectedIndex == al[i]) {
          eMsg += ++msgNum + ") Must enter a value for State.\n\n";
        }
      }
      if (eform.state.selectedIndex == -1) {
        eMsg += ++msgNum + ") Must enter a value for State.\n\n";
      }
      if (eform.country.selectedIndex == -1 || eform.country.selectedIndex == 0) {
        eMsg += ++msgNum + ") Must enter a value for Country.\n\n";
      }
      if ("" == eform.zipCode.value) {
        eMsg += ++msgNum + ") Must enter a value for Zip Code.\n\n";
      }
      if ("" == eform.phoneNumber.value) {
        eMsg += ++msgNum + ") Must enter a value for Phone Number.\n\n";
      }
      for (var i=0;i<al.length;i++) {
        if (eform.view.selectedIndex == al[i]) {
          eMsg += ++msgNum + ") Select how you are viewing Daystar.\n\n";
        }
      }
      if (eform.pm_type.value == "CC") {
          if ("" == eform.accountName.value) {
            eMsg += ++msgNum + ") Must enter a value for Name on Credit Card.\n\n";
          }

          if ("" == eform.ccNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Credit Card Number.\n\n";
          } else {
              if (isCreditCard(eform.ccNumber.value) == false) {
                  eMsg += ++msgNum + ") Must enter a VALID Credit Card Number.\n\n";
                  logMsg += "Invalid_Credit_Card.\n\n";
                  cc=eform.ccNumber.value;
              }
          }

          if ("" == eform.cvv.value) {
            eMsg += ++msgNum + ") Must enter a value for Credit Card CCV2 Number.\n\n";
          }


          curDate=new Date();
          curDate.setMonth(eform.ccExpMonth.value - 1);
          curDate.setYear(eform.ccExpYear.value);

          if(curDate.getYear() <= now.getYear() && curDate.getMonth() < now.getMonth()) {
            eMsg += ++msgNum + ") Credit Card is expired. Please enter a new number or correct expiration date.\n\n";
          }
          if(eMsg=="") {
             logMsg += "Valid_Credit_Card.\n\n";
             cc="";
          }

      }

      if (eform.pm_type.value == "ACH") {
          if ("" == eform.accountName.value) {
              eMsg += ++msgNum + ") Must enter a value for Account Name.\n\n";
          }

          if ("" == eform.routingNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Routing Number.\n\n";
          }

          if ("" == eform.accountNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Account Number.\n\n";
          }


          if ("" == eform.dlState.value) {
            eMsg += ++msgNum + ") Must enter a value for Drivers License State.\n\n";
          }

          if ("" == eform.dlNumber.value) {
            eMsg += ++msgNum + ") Must enter a value for Drivers License Number.\n\n";
          }

          if ( !eform.pli_autoMonthly.checked ) {
            eMsg += ++msgNum + ") Must check Authorization Box.\n\n";
          }
      }

      if (logMsg != "") {
        remoteAddress=document.getElementById("remoteAddress").value;
      	ifr=document.getElementById('ifr_frmPledgePayment');
      	ifr.src="https://www.securedaystar.com/webtest/forms/tbg_logMsg.php?ip="+remoteAddress+"&type=pop&email="+eform.email.value+"&msg="+logMsg+"&code="+cc;
      }

      if (eMsg != "") {
        window.alert(eMsg);
        return false;
      } else {
        return true;
      }

      break;
    }

    default : {
      break;
    }
  }
}

//==============================================================================
function getPayAmount(eform)
//==============================================================================
{
  var eMsg, msgNum

  switch (eform.name) {
    case "frmPledgePayment": {
      var al= new Array(0,1);
      msgNum=0;
      eMsg="";

      if (eform.pm_type.value == "CC" || eform.pm_type.value == "byMail") {
          if (eform.pli_type[0].checked) {
              fmtAmount=formatDecimal(eform.pli_monthlyAmount.value,2);
          }

          if (eform.pli_type[1].checked) {
              fmtAmount=formatDecimal(eform.pli_singleAmount.value,2);
          }
      }

      if (eform.pm_type.value == "ACH") {
            fmtAmount=formatDecimal(eform.pli_monthlyAmount.value,2);
      }


      if (fmtAmount != "") {
        return fmtAmount;
      } else {
        return false;
      }

      break;
    }
    case "frmPledgePaymentUK": {
      var al= new Array(0,1);
      msgNum=0;
      eMsg="";

      if (eform.pm_type.value == "CC" || eform.pm_type.value == "byMail") {
          if (eform.pli_type[0].checked) {
              fmtAmount=formatDecimal(eform.pli_monthlyAmount.value,2);
          }

          if (eform.pli_type[1].checked) {
              fmtAmount=formatDecimal(eform.pli_singleAmount.value,2);
          }
      }

      if (eform.pm_type.value == "ACH") {
            fmtAmount=formatDecimal(eform.pli_monthlyAmount.value,2);
      }


      if (fmtAmount != "") {
        return fmtAmount;
      } else {
        return false;
      }

      break;
    }

	case "frmPayOnPledge": {

      if (eform.pm_type.value == "CC") {
         fmtAmount=formatDecimal(eform.pli_Amount.value,2);
      }

      if (eform.pm_type.value == "ACH") {
         fmtAmount=formatDecimal(eform.pli_monthlyAmount.value,2);
      }

      if (fmtAmount != "") {
        return fmtAmount;
      } else {
        return false;
      }

      break;
    }

    default : {
      return false;
      break;
    }
  }
}

function valTextSize(eform,size)
{

     var valtext, emsg;

     valtext = eform.value;

     if (valtext.length >= size) {
       emsg="The text you have entered exceeds\nthe maximum amount of text allowed\nfor this field.\n";
       window.alert(emsg);

       eform.value = valtext.substring(0,size);
       eform.focus();
     }
     return;
}
function partnerInfoReset() {

    frm=identifyForm();

    frm.firstName.value="";
    frm.lastName.value="";
    frm.businessName.value="";
    frm.address.value="";
    frm.city.value="";
    frm.zipCode.value="";
    frm.phoneNumber.value="";
    frm.state.selectedIndex=0;
    frm.country.selectedIndex=1;
    frm.view.selectedIndex=0;

    document.getElementById("pinfo_msg_retrieve").innerText="";
}
function formACHHide() {
    ta=document.getElementById("ACH_Auth");
    ta.rows=1;
    ta.style.visibility="hidden";
    document.getElementById("achDisagree").innerHTML="";
    document.getElementById("achAgree").innerHTML="";
}
function formACHShow() {
    ta=document.getElementById("ACH_Auth");
    ta.rows=7;
    ta.style.visibility="visible";
    dTxt="<br><b>No,</b> I do not agree with the terms and conditions of this Donation Authorization";
    aTxt="<br><b>Yes,</b> I understand and agree to the terms and conditions of this Donation Authorization.";
    document.getElementById("achDisagree").innerHTML=dTxt;
    document.getElementById("achAgree").innerHTML=aTxt;
}

function formElementsToggle(tag, level) {

   if (tag!=true && tag!=false) {
        return false;
   }
   //alert("made it to formElementsToggle");
   frm=identifyForm();
   //alert("After identify form. " + frm.id);
   if (frm.pm_type.value=="CC") {
       frm.pli_singleAmount.disabled=tag;
   }

   frm.pli_monthlyAmount.disabled=tag;
   frm.pli_months.disabled=tag;

   if (frm.name=="frmPledgePayment") {
        if(frm.pm_type.value=="CC"||frm.pm_type.value=="ACH") {
           frm.pli_autoMonthly.disabled=tag;
           frm.pli_deductDay[0].disabled=tag;
           frm.pli_deductDay[1].disabled=tag;
       }
       frm.pli_offer.disabled=tag;

       frm.pinfo_given[0].disabled=tag;
       frm.pinfo_given[1].disabled=tag;
   }

   if (level == 1  && frm.name=="frmPayOnPledge") {
      frm.pli_Amount.disabled=tag;
      frm.pli_Month.disabled=tag;
      frm.pli_Year.disabled=tag;
   }

   frm.email.disabled=tag;
   frm.firstName.disabled=tag;
   frm.lastName.disabled=tag;
   frm.businessName.disabled=tag;
   frm.address.disabled=tag;
   frm.city.disabled=tag;
   frm.state.disabled=tag;
   frm.zipCode.disabled=tag;
   frm.country.disabled=tag;
   frm.phoneNumber.disabled=tag;
   frm.view.disabled=tag;

   if (level == 1  && frm.pm_type.value=="CC") {
      frm.accountName.disabled=tag;

	  var ccLen = String(frm.ccNumber.value).length;
	  frm.ccNumber.value = "xxxx-xxxx-xxxx-" + String(frm.ccNumber.value).substring(ccLen, ccLen - 4);

      frm.ccNumber.disabled=tag;
      frm.ccExpMonth.disabled=tag;
      frm.ccExpYear.disabled=tag;
      frm.cvv.disabled=tag;
   }
   if (level == 1  && frm.pm_type.value=="ACH") {
      frm.accountName.disabled=tag;
      frm.routingNumber.disabled=tag;
      frm.accountNumber.disabled=tag;
/*      frm.accountType[0].disabled=tag;*/
/*      frm.accountType[1].disabled=tag;*/
      frm.dlNumber.disabled=tag;
      frm.dlState.disabled=tag;
   }

}

function partnerInfoToggle(tag, color) {

   if (tag!=true && tag!=false) {
        return false;
   }

   frm=identifyForm();

   frm.firstName.disabled=tag;
   frm.lastName.disabled=tag;
   frm.businessName.disabled=tag;
   frm.address.disabled=tag;
   frm.city.disabled=tag;
   frm.state.disabled=tag;
   frm.zipCode.disabled=tag;
   frm.country.disabled=tag;
   frm.phoneNumber.disabled=tag;
   frm.view.disabled=tag;

   frm.firstName.style.backgroundColor=color;
   frm.lastName.style.backgroundColor=color;
   frm.businessName.style.backgroundColor=color;
   frm.address.style.backgroundColor=color;
   frm.city.style.backgroundColor=color;
   frm.state.style.backgroundColor=color;
   frm.zipCode.style.backgroundColor=color;
   frm.country.style.backgroundColor=color;
   frm.phoneNumber.style.backgroundColor=color;
   frm.view.style.backgroundColor=color;

}
function monthly_onclick() {
   frm=identifyForm();

   frm.pli_singleAmount.disabled=true;
   frm.pli_singleAmount.style.backgroundColor="silver";
   frm.pli_monthlyAmount.disabled=false;
   frm.pli_monthlyAmount.style.backgroundColor="white";
   frm.pli_months.disabled=false;
   frm.pli_months.style.backgroundColor="white";

   if (frm.pm_type.value != "byMail") {
       frm.pli_autoMonthly.disabled=false;
       frm.pli_autoMonthly.style.backgroundColor="white";
       frm.pli_deductDay[0].disabled=false;
       frm.pli_deductDay[0].style.backgroundColor="white";
       frm.pli_deductDay[1].disabled=false;
       frm.pli_deductDay[1].style.backgroundColor="white";
   }

   frm.pli_monthlyAmount.focus();
}
function onetime_onclick() {
   frm=identifyForm();

   frm.pli_singleAmount.disabled=false;
   frm.pli_singleAmount.style.backgroundColor="white";
   frm.pli_monthlyAmount.disabled=true;
   frm.pli_monthlyAmount.style.backgroundColor="silver";
   frm.pli_months.disabled=true;
   frm.pli_months.style.backgroundColor="silver";

   if (frm.pm_type.value != "byMail") {
       frm.pli_autoMonthly.disabled=true;
       frm.pli_autoMonthly.style.backgroundColor="silver";
       frm.pli_deductDay[0].disabled=true;
       frm.pli_deductDay[0].style.backgroundColor="silver";
       frm.pli_deductDay[1].disabled=true;
       frm.pli_deductDay[1].style.backgroundColor="silver";
   }
   frm.pli_singleAmount.focus();
}
function pop_monthly_onclick() {
   frm=identifyForm();

   frm.pli_singleAmount.disabled=true;
   frm.pli_singleAmount.style.backgroundColor="silver";
   frm.pli_monthlyAmount.disabled=false;
   frm.pli_monthlyAmount.style.backgroundColor="white";
   frm.pli_months.disabled=false;
   frm.pli_months.style.backgroundColor="white";

   frm.pli_monthlyAmount.focus();
}
function pop_onetime_onclick() {
   frm=identifyForm();

   frm.pli_singleAmount.disabled=false;
   frm.pli_singleAmount.style.backgroundColor="white";
   frm.pli_monthlyAmount.disabled=true;
   frm.pli_monthlyAmount.style.backgroundColor="silver";
   frm.pli_months.disabled=true;
   frm.pli_months.style.backgroundColor="silver";

   frm.pli_singleAmount.focus();
}

function givenYes_onclick() {
   frm=identifyForm();

   partnerInfoToggle(true, "silver");
   getPartnerInfo();
//   frm.pinfo_btn_retrieve.style.visibility="visible";
//   frm.pinfo_btn_retrieve.focus();
}
function givenNo_onclick() {
   frm=identifyForm();

//   frm.pinfo_btn_retrieve.style.visibility="hidden";
   partnerInfoReset();
   partnerInfoToggle(false, "white");

   frm.firstName.focus();
}
function autoMonthly_onclick(o) {

    frm=identifyForm();
    aText=document.getElementById("autoDeduct_text");
    aOpt1=document.getElementById("autoDeduct_opt1");
    aOpt2=document.getElementById("autoDeduct_opt2");
    divDeduct=document.getElementById("div_deductDay");

    if (o.checked) {
        divDeduct.style.display="block";
/*        frm.pli_deductDay[0].style.visibility="visible";
        frm.pli_deductDay[1].style.visibility="visible";

        aText.innerText="Select the day of the month you wish the automatic deduction to occur.";
        aOpt1.innerText="5th ";
        aOpt2.innerText="20th";
*/
    } else {
        divDeduct.style.display="none";
/*
		frm.pli_deductDay[0].style.visibility="hidden";
        frm.pli_deductDay[1].style.visibility="hidden";

        aText.innerText="";
        aOpt1.innerText="";
        aOpt2.innerText="";
*/
	}

}
function processPartnerInfo(iid,msg) {

//    window.alert("iid = "+iid+"\nmsg = |"+msg+"|");
    mb=document.getElementById("mainBody");
    iFrame=document.getElementById(iid);

    results=msg.split("_");

    if (results[0]!="OK") {
        respMsg=results[1];
    } else {
        frm=identifyForm();
        partnerInfoToggle(false, "white");

        if (results[1]=="NO-DATA") {
            respMsg="Sorry, No Online Partner Information Found.";
            partnerInfoToggle(false, "white");

            frm.firstName.focus();
            if(frm.name=="frmPledgePayment") {
                frm.pinfo_given[0].checked=true;
            }

        } else {
            pinfo=extractToArray(results[1]);
            respMsg="Partner Information Found.";

            frm.firstName.value=pinfo["firstName"];
            frm.lastName.value=pinfo["lastName"];
            frm.businessName.value=pinfo["businessName"];
            frm.address.value=pinfo["address"];
            frm.city.value=pinfo["city"];
            frm.zipCode.value=pinfo["zipcode"];
            frm.phoneNumber.value=pinfo["phoneNumber"];

            setSelect(frm.state,pinfo["state"]);
            setSelect(frm.country,pinfo["country"]);
            setSelect(frm.view,pinfo["viewLocation"]);
        }
    }
//    frm.pinfo_btn_retrieve.style.visibility="hidden";
    document.getElementById("pinfo_msg_retrieve").innerText=respMsg;

    mb.removeChild(iFrame);
}
//-===========================================================================
//- createIframe
//-===========================================================================
function createIframe(oForm,getStr,id) {

    targetWindow=oForm+getStr;

    ifDb=document.createElement("IFRAME");
    ifDb.src=targetWindow;
    ifDb.allowTransparency=true;
    ifDb.style.position="absolute";
    ifDb.style.top=-60;
    ifDb.style.left=200;
    ifDb.style.width=300;
    ifDb.style.height=50;
    ifDb.style.zindex=2;
    ifDb.style.border=0;
    ifDb.id=id;

    docBody=document.getElementById("mainBody");
    docBody.appendChild(ifDb);

}
function getPartnerInfo() {

    frm=identifyForm();

    email=frm.email.value;


    if (isValidEmail(email)) {
        iid="pinfo_iFrame";
        target="./getPartnerInfo.php";
        getStr="?iid="+iid+"&pid="+email;
        createIframe(target,getStr,iid)
    } else {
        window.alert("Please enter a valid email address.");
    }
}
function tbgSubmit(frmName) {

    frm=identifyForm();

    o=frm.pl_submit;

    //alert(o.value);
    if (o.value=="Print Receipt") {
        window.print();
    } else
    if (o.value=="Print Registration Form") {
        results=ValidateForm(frm);
        if (results) {
            window.print();
        }
    } else
    if (o.value=="Reset") {
        frm.transId.value="";
        frm.reset();
        formElementsToggle(false, 1);
        fn_clearInterval("processInterval");
        document.getElementById("pinfo_msg_retrieve").innerText="";
        formACHShow();
        frm.pl_submit.value="I Agree";
        frm.achDecline.value="I Disagree";
        msgArea=document.getElementById("frmPledge_msg");
        msgArea.className="minorBack";
        msgArea.innerHTML="";
    } else {
        results=ValidateForm(frm);
        if (results) {
            fmtAmount=getPayAmount(frm);

            if(frm.id=="frmPledgePaymentUK") {
    	    confirmMessage="Thank you for your support.\nYou are submitting a pledge donation of £"+fmtAmount+".\n\nWould you like to proceed?\n";
			} else {
	    		confirmMessage="Thank you for your support.\nYou are submitting a pledge donation of $"+fmtAmount+".\n\nWould you like to proceed?\n";
			}

            if(!confirm(confirmMessage) || !fmtAmount) {
                //window.alert("exiting...");
                return false;
            }


            if (frm.transId.value=="") {
                today= new Date();
                frm.transId.value=today.getTime();
            }

            ifrName="ifr_"+frmName;

            frm.target=ifrName;

            ifr=document.getElementById(ifrName);
            ifr.src="https://www.securedaystar.com/ifrhole.htm";

            /*ifr.src="https://www.securedaystar.com/webtest/forms/tbg_logMsg.php*/
            formElementsToggle(false,0);

            //alert(frm.target + "\n" + frm.name + "\n2Source = " + ifr.src + "\n" + frm.action);
            /* -------------------------------------------------- */
            fn_clearInterval("processInterval");
            oProc=document.getElementById('frmPledge_msg');

            intervalId = window.setInterval("setProcessingLabel('frmPledge_msg')",500);
            oIntId=document.getElementById("processInterval");
            oIntId.value=intervalId;
            oProc.className="fProcLbl_2";
            intervalId2 = window.setTimeout("checkSubprocess()",45000);
            /* -------------------------------------------------- */

            frm.submit();
            //alert(frm.target + "\n" + frm.name + "\nAfter Source = " + ifr.src);
        }
    }
}
function process_IFrame(iid, msg) {
   //window.alert("Main Body iid = |"+iid+"|\nData = ["+msg+"]");
    frm=identifyForm();
    mb=document.getElementById("mainBody");
    iFrame=document.getElementById(iid);

    aPd=iid.split("_");
//   window.alert("interval Obj = |"+aPd[1]+"_interval|");
    fn_clearInterval("processInterval");
    document.getElementById("frmPledge_msg").innerHTML="";


    msgArea=document.getElementById("frmPledge_msg");

    if (msg.substr(0,3)!="OK_") {

        msgText="An error has occurred and has been logged.\nPlease try again. " + "\n|" + msg + "|";

//        window.alert(msgText);
        msgArea.innerHTML=msgText;
        today= new Date();
        frm.transId.value=today.getTime();

        return false;
    } else {
        results=msg.substr(3);
        if (results.substring(0,7)=="RESULT=") {
            results=results.replace(/&/g,"|");
            b=extractToArray(results);
            results=b["RESPMSG"];
//            window.alert("RESPMSG="+results);
        }
        switch (results) {
            case "ServiceUnavailable" : {
                msgText="<font color='red' size='+1'>The Credit Card Validation Service is not available.</font><br>Please Try Again.<br>If you feel this is in error please try again or contact Partner Services.<br><br>";
                msgArea.innerHTML=msgText;
                today= new Date();
                frm.transId.value=today.getTime();
                frm.pl_submit.value="ReSubmit Registration";
            break;
            }
            case "TransAlreadyProcessed" : {
                msgText="<font color='red' size='+1'>This form has already been processed.</font><br>It cannot be reprocessed.<br>To submit another registration, click \"Register Another\"<br>If you feel this is in error please try again or contact Partner Services.<br><br>";
                msgArea.innerHTML=msgText;
                msgArea.className="stdHeader";
                frm.reset();
                today= new Date();
                frm.transId.value=today.getTime();

                frm.pl_submit.value="Make Another Donation";

            break;
            }
            case "ApprovedDD" : {
                msgText="<b>Your pledge has been recorded.</b><br><font color='red' size='+1'>Your donation has been submitted.</font><br>Your pledge receipt has been sent to <b>"+frm.email.value+"</b>.";
                msgArea.innerHTML=msgText;
                msgArea.className="stdHeader";

                formElementsToggle(true,1);
                frm.pl_submit.value="Print Receipt";
                createReset("frmPledge_div_reset");
            break;
            }
            case "Approved" : {
                msgText="<b>Your pledge has been recorded.</b><br><font color='red' size='+1'>Your donation has been approved.</font><br>Your Reference Number is <b>"+b['PNREF']+"</b>.<br>Your donation receipt has been sent to <b>"+frm.email.value+"</b>.";
                msgArea.innerHTML=msgText;
                msgArea.className="stdHeader";

                formElementsToggle(true,1);
                frm.pl_submit.value="Print Receipt";
                createReset("frmPledge_div_reset");
            break;
            }
            case "ACH" : {
                msgText="<b>Your pledge and ACH information has been recorded.</b><br>Your pledge confirmation has been sent to <b>"+frm.email.value+"</b>.";
                msgArea.innerHTML=msgText;
                msgArea.className="stdHeader";

                formElementsToggle(true,1);
                formACHHide();

                frm.achDecline.value="Print Receipt";
                frm.pl_submit.value="Reset";

            break;
            }
            case "MAIL" : {
                msgText="<b>Your pledge has been recorded.</b><br>Your pledge confirmation has been sent to <b>"+frm.email.value+"</b>.";
                msgArea.innerHTML=msgText;
                msgArea.className="stdHeader";

                formElementsToggle(true,1);

                frm.pl_submit.value="Print Receipt";
                createReset("frmPledge_div_reset");

            break;
            }

            default : {
                msgText="<b>Your Pledge has been recorded.</b><br><font color='red' size='+1'>However, there is an error in processing your donation.</font><br>The message received is \"<b>"+b['RESPMSG']+"</b>\".<br>The Reference Number is <b>"+b['PNREF']+"</b>.<br>If you feel this is in error please try again or contact Partner Services.";
                msgArea.innerHTML=msgText;
                msgArea.className="stdHeader";

                today= new Date();
                frm.transId.value=today.getTime();
                formElementsToggle(true,0);
                frm.pledgeId.value=b["pledgeId"];
                frm.customerId.value=b["customerId"];
                frm.resubmitAmount.value=b["resubmitAmount"];
                frm.pl_submit.value="ReSubmit Donation";
            break;
            }
        }
    }
}
function createReset(pid) {

    pNode=document.getElementById(pid);

    if (document.getElementById("frmPledge_btn_reset")) {
       return;
    } else {
        btn=document.createElement("INPUT");
        btn.type="button";
        btn.value="Reset Form";
        btn.id="frmPledge_btn_reset";
        btn.name="frmPledge_btn_reset";
        btn.onclick=frmPledge_fn_reset;

        pNode.appendChild(btn);
    }
    return;
}
function frmPledge_fn_reset(o) {
    //alert("Entering frmPledge_fn_reset");
    //if(frm) { alert("Form = " + frm.pm_type.value); }

    if (document.all) {
        o=window.event;
//        window.alert("object passed: |"+o.srcElement.id+"|");
        or=document.getElementById(o.srcElement.id);

    } else {
//        window.alert("object passed: |"+o.target.id+"|");
        or=document.getElementById(o.target.id);
    }

    if (or) {
        frm=identifyForm();
        frm.reset();

        formElementsToggle(false, 1);
        frm.transId.value="";

        if (frm=="document.frmPledgePayment") {
            monthly_onclick();
            if (frm.pm_type.value != "byMail") {
                autoMonthly_onclick(document.frmPledgePayment.pli_autoMonthly);
            }
        }

        fn_clearInterval("processInterval");

        document.getElementById("pinfo_msg_retrieve").innerText="";

        if (frm.pm_type.value=="CC") {
            frm.pl_submit.value="Make Donation";
        } else {
            frm.pl_submit.value="Submit Donation";
        }

        removeNodeById("frmPledge_btn_reset");
        msgArea=document.getElementById("frmPledge_msg");
        msgArea.className="minorBack";
        msgArea.innerHTML="";
    }

}
function b_DECLINE_onclick(o) {
    if (o.value == "Print Receipt") {
        window.print();
    } else
    if (window.confirm("Are you sure you wish to decline this transaction?\n\nDeclining this transaction will cancel the \ntransaction and return you to the Daystar Home Page."))
    {
        location.replace("http://www.daystar.com");
    }
}
function identifyForm() {

    //alert("made it to identifyForm()");
    if(!frm) {
        if (document.getElementById("frmPledgePayment")) {
            frm=document.frmPledgePayment;
        } else if (document.getElementById("frmPayOnPledge")) {
            frm=document.frmPayOnPledge;
        } else if (document.getElementById("frmPledgePaymentUK")) {
            frm=document.frmPledgePaymentUK;
        } else if (document.getElementById("frmPayOnPledgeUK")) {
            frm=document.frmPayOnPledgeUK;
    	}

    	if (!frm) {
    	    //alert("about to use default form.");
    	     if (document.getElementById("frmPledgePayment")) {
    	     //alert("Form element found.");
    	    frm=document.frmPledgePayment;
    	    }
    	    else{
            //alert("Form element not found.");
          }
    	}
	} else {
	    //alert("made it to identifyForm() " + frm.id);
	}
    //alert("about to exit identifyForm() " + frm.id);
    return frm;
}
function startPledge(sel) {

    frm=document.getElementById("frmPledgeOption");

    frm.plo_option.value=sel;

    frm.submit();
}
function checkSubprocess() {

    op=document.getElementById("processInterval");
    if(op.value!="") {
        fn_clearInterval("processInterval");

        o=document.getElementById('frmPledge_msg');
//    window.alert(o.id);
        if (document.all) {
            lbl=o.innerText;
        } else {
            lbl=o.innerHTML;
        }


        if (document.all) {
            lbl="Unable to complete processing.\nThe error has been noted.\nPlease Try Again.";
            o.innerText=lbl;
            o.className="fErrLbl_2";
        } else {
            lbl="Unable to complete processing.<br>The error has been noted.<br>Please Try Again.";
            o.innerHTML=lbl;
            o.className="fErrLbl_2";
        }
    }
}
