{{> local_signin/header}}
<div class="login-left-sec">
       <h3>Start Learning!</h3>
       <p class="go_back_btn">Change number? <a href="index.php">Go back</a></p>
       <div class="form-sec">
           <form name ="signup_detail" id="signup_detail" method="post" action="signup.php">
               <div class="form-inner-otp-sec form-inner-sec active_pareent">
                 <div class="form-inner-otp">
                   <div class="col">
                       <span>First Name</span>
                       <input type="text" name="fname" id="fname" class="form-control" placeholder="Please enter first name" value="{{#fname}}{{fname}}{{/fname}}">
                   </div>
                   <div class="col">
                       <span>Last Name</span>
                       <input type="text" name="lname" id="lname" class="form-control" placeholder="Please enter last name" value="{{#lname}}{{lname}}{{/lname}}">
                   </div>
                   {{#phone}} <div class="col">
                     <span>E- mail</span>
                     <input type="text" class="form-control" name="email" id="email" placeholder="Please enter your email ID" value="{{#email}}{{email}}{{/email}}">
                     <input type="hidden" name="phone" id="phone" value="{{phone}}">
                   </div>{{/phone}}
                     <input type="hidden" name="leadid" id="leadid" value="{{leadid}}">
                     <div class="error-msg" id = "error-msg">
                    </div>
                     <div class="form-check form-check-tc">
                       <label class="form-check-label">
                       <input type="checkbox" class="form-check-input" id="tnc" value="tnc">I’ve read and accept the <a href="https://herovired.com/privacy-tc/" target="_blank">terms & conditions *</a>
                       </label>
                   </div>
                 </div>
                 <div class="col col-signup">
                   <input type="submit" class="btn btn-primary mb-2"  name="signup" value="Sign up">
                 </div>
                 <div class="left-sec-content">
                  <div class="error-msg" id="error-msg">
                  </div>
                   <p>Your personal data will be used to support your experience throughout this website, to manage access to your account, and for other purposes described in our  
                       <a href="https://herovired.com/privacy-tc/" target="_blank">privacy policy</a>.</p>
                 </div>
               </div>
           </form>
       </div>
</div>
       {{> local_signin/slider}}
       {{> local_signin/footer}}

<script>
 $("#signup_detail").submit(function(e) {
        e.preventDefault(); // avoid to execute the actual submit of the form.
        var form = $(this);
        var url = form.attr('action');
        var fname = $('#fname').val();
        var lname = $('#lname').val();
        var phone_val = $('#phone').val();
        var email = $('#email').val();
        var checkBox = document.getElementById("tnc");
        if(fname.length == 0 || lname.length == 0 || email.length == 0){
          document.getElementById("error-msg").innerHTML = '<img src="img/error_icon.svg" alt="error"><label class="errors" name="error">Please enter all the fields.</label>';
              return;
        }
        if (phone_val) {
            var phone_temp = phone_val;
            var phone ="+91"+phone_temp.substr(phone_temp.length - 10);
        }
        if (validateEmail(email)) {
            console.log('Validation');
          // $('.active_pareent').wrapAll('<div class="active_otpflow"></div>');
        }else {
            document.getElementById("error-msg").innerHTML = '<img src="img/error_icon.svg" alt="error"><label class="errors" name="error">Please enter the email address in the correct format.</label>';
            return;
        }

        if (checkBox.checked == true){
          formValidation = true;
        } else {
          // formValidation = false;
          document.getElementById("error-msg").innerHTML = '<img src="img/error_icon.svg" alt="error"><label class="errors" name="error">Please accept the terms and conditions</label>';
            return;
        }
        $.ajax({
           type: "POST",
           url: url,
           data: form.serialize(), // serializes the form's elements.
           success: function(result)
           {
            //  alert(result);
             console.log(result);
             const obj = JSON.parse(result);
             if(obj.status == 0){
               document.getElementById("error-msg").innerHTML = '<img src="img/error_icon.svg" alt="error"><label class="errors" name="error">'+obj.msg+'</a></label>';
                // alert("error");
             }else{
              var eventValue = {
                        'Source': 'VLearn',
                        'UID': phone,
                        'appuid':phone,
                        'city': '',
                        'state': '',
                        'country': '',
                        'email': email,
                        'MobileNumber': phone,
                        'LatestProgramName': '',
                        'LatestCourseName':'',
                        'UserAccesstype': 'Trial',
                        'SignupStatus': "SignedUp"
                    }
                    console.log("SIGNUP_Mobile_OTP_Entered");
                    upshot.createEventByName('SIGNUP_Mobile_OTP_Entered', eventValue, false);
                    upshot.createEvent('UpshotEventPageView', 'SIGNUP_Mobile_OTP_Entered');
                    upshot.getActivity('UpshotActivityTypeAny', 'SIGNUP_Mobile_OTP_Entered');

              var url = "login.php?id="+obj.userid;
               window.location.href = url;
                // alert(result);
                // console.log("existing user");
             }
             
           }
         });


    })

</script>