<?php 
// Check to ensure this file is included in osConcert!
defined('_FEXEC') or die();
?>

<!--Add Extra Fields begin-->
<script>
    function echeck(str) {
        var at = "@";
        var dot = ".";
        var lat = str.indexOf(at);
        var lstr = str.length;
        var ldot = str.indexOf(dot);
        if (str.indexOf(at) == -1) {
            alert("Invalid E-mail ID");
            return false;
        }
        if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
            alert("Invalid E-mail ID");
            return false;
        }
        if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
            alert("Invalid E-mail ID");
            return false;
        }
        if (str.indexOf(at, (lat + 1)) != -1) {
            alert("Invalid E-mail ID");
            return false;
        }
        if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
            alert("Invalid E-mail ID");
            return false;
        }
        if (str.indexOf(dot, (lat + 2)) == -1) {
            alert("Invalid E-mail ID");
            return false;
        }
        if (str.indexOf(" ") != -1) {
            alert("Invalid E-mail ID");
            return false;
        }
        return true;
    }

    function checkvalidate() {
        // Check if the bypass checkbox is checked
        if (document.getElementById('bypass_validation').checked) {
            return true;
        }

        <?php if (tep_not_null(FIELD_1)) { ?>
        if (document.checkout_payment.field_1.value.length < <?php echo FIELD_1_VALIDATE; ?>) {
            alert("<?php echo PLEASE_ENTER_YOUR; ?><?php echo FIELD_1; ?>");
            document.checkout_payment.field_1.focus();
            return false;
        }
        <?php } ?>

        <?php if (tep_not_null(FIELD_2)) { ?>
        if (document.checkout_payment.field_2.value.length < <?php echo FIELD_2_VALIDATE; ?>) {
            alert("<?php echo PLEASE_ENTER_YOUR; ?><?php echo FIELD_2; ?>");
            document.checkout_payment.field_2.focus();
            return false;
        }
        <?php } ?>

        <?php if (tep_not_null(FIELD_3)) { ?>
        if (document.checkout_payment.field_3.value.length < <?php echo FIELD_3_VALIDATE; ?>) {
            alert("<?php echo PLEASE_ENTER_YOUR; ?><?php echo FIELD_3; ?>");
            document.checkout_payment.field_3.focus();
            return false;
        }
        <?php } ?>

        <?php if (tep_not_null(FIELD_4)) { ?>
        var emailID = document.checkout_payment.field_4.value;
        if ((emailID == null) || (emailID == "")) {
            alert("<?php echo PLEASE_ENTER_YOUR; ?>email address");
            document.checkout_payment.field_4.focus();
            return false;
        }
        if (!echeck(emailID)) {
            document.checkout_payment.field_4.focus();
            return false;
        }
        <?php } ?>

        <?php if (tep_not_null(FIELD_5)) { ?>
        if (document.checkout_payment.other.value.length < <?php echo FIELD_5_VALIDATE; ?>) {
            alert("<?php echo PLEASE_ENTER_YOUR; ?><?php echo FIELD_5; ?>");
            document.checkout_payment.other.focus();
            return false;
        }
        <?php } ?>

        return true;
    }
</script>

<br>
<h4><?php echo NEW_FIELDS_HEADING; ?></h4>
<div class="container-fluid my-3">

  <div class="card shadow-sm">
    <div class="card-body">

      <div class="form-check form-switch mb-4">
        <input class="form-check-input" type="checkbox" id="bypass_validation" name="bypass_validation">
        <label class="form-check-label fw-semibold" for="bypass_validation">
          <?php echo TEXT_NOT_REQUIRED; ?> — <?php echo TEXT_CHECK_BOX; ?>
        </label>
      </div>

      <div class="row g-3">

        <?php if (tep_not_null(FIELD_1)) { ?>
        <div class="col-12 col-md-6">
          <label for="field_1" class="form-label fw-semibold"><?php echo FIELD_1; ?></label>
          <input type="text" class="form-control" name="field_1" id="field_1"
                 value="<?php echo $FSESSION->get('field_1'); ?>" maxlength="60">
        </div>
        <?php } ?>

        <?php if (tep_not_null(FIELD_2)) { ?>
        <div class="col-12 col-md-6">
          <label for="field_2" class="form-label fw-semibold"><?php echo FIELD_2; ?></label>
          <input type="text" class="form-control" name="field_2" id="field_2"
                 value="<?php echo $FSESSION->get('field_2'); ?>" maxlength="60">
        </div>
        <?php } ?>

        <?php if (tep_not_null(FIELD_3)) { ?>
        <div class="col-12 col-md-6">
          <label for="field_3" class="form-label fw-semibold"><?php echo FIELD_3; ?></label>
          <input type="text" class="form-control" name="field_3" id="field_3"
                 value="<?php echo $FSESSION->get('field_3'); ?>" maxlength="60">
        </div>
        <?php } ?>

        <?php if (tep_not_null(FIELD_4)) { ?>
        <div class="col-12 col-md-6">
          <label for="field_4" class="form-label fw-semibold"><?php echo FIELD_4; ?></label>
          <input type="text" class="form-control" name="field_4" id="field_4"
                 value="<?php echo $FSESSION->get('field_4'); ?>" maxlength="60">
        </div>
        <?php } ?>

        <?php if (tep_not_null(FIELD_5)) { ?>
        <div class="col-12">
          <label for="other" class="form-label fw-semibold"><?php echo FIELD_5; ?></label>
          <?php echo tep_draw_textarea_field('other', 'soft', '60', '5', '', 'class="form-control" id="other"'); ?>
        </div>
        <?php } ?>

      </div>

      <div class="text-center mt-4">
        <button type="reset" class="btn btn-outline-secondary px-4">
          Reset
        </button>
      </div>

    </div>
  </div>

</div>
<!--Add Extra Fields end-->
