<?php
include('header.php');

session_unset();       
session_destroy();
?>
<style>
    .d-hide{display:none;}
    .fa-eye:before { content: "\f06e"; }
</style>
<!-- start main -->
<section class="user-form-part">
	<div class="container">
		<div class="row justify-content-center">
			<div class="col-12 col-sm-10 col-md-8 col-lg-6 col-xl-5 mb-4">
				<div class="user-form-card">
					<div class="user-form-title">
						<h2>Join Now!</h2>
						<p>Setup A New Account In A Minute</p>
					</div>
					<!--<form class="user-form" id="registerform" method="POST" action="<?=base_url('register/form');?>">-->
						<div class="form-group"><input type="text" class="form-control" onkeypress="return isNumberKey(event)" maxlength="10" pattern="[0-9]{10}" id="mobile_number" placeholder="Enter your Mobile Number" required></div>
					
                        
						<input type="hidden" id="form_open" class="form-control" value="1" required>
						
						<div class="form-group  name"><input type="text" id="sid" class="form-control" <?php if(isset($_SESSION['nsponsor'])){?> readonly value="<?php echo $_SESSION['nsponsor'] ?>"<?php } ?>placeholder="Enter Sponsor Phone number"></div>
					
						<div class="form-group  name"><input type="text" id="name" class="form-control" placeholder="Enter your name"></div>
						<div class="form-group  email"><input type="email" id="email" class="form-control" placeholder="Enter your email" ></div>
						<div class="form-group  email"><select  id="side" class="form-control"  >
						    
						    <option value="1">Left</option>
						    <option value="2">Right</option>
						</select></div>
						<div class="input-group mb-3  password">
                            <input type="password" id="password" name="password" class="form-control" placeholder="Enter your password">
                            <button class="bg-theme-color text-white rounded px-3" type="button" onclick="if($('#password').attr('type')=='password'){$('#password').attr('type','text');}else{$('#password').attr('type','password');}$('#eye').toggleClass('fa-eye');"><i id="eye" class="fa fa-eye-slash"></i></button>
                        </div>
						<div class="input-group mb-3 repeat_pass">
                            <input type="password" id="repeat_pass" name="repeat_pass" class="form-control" placeholder="Enter repeat password">
                            <button class="bg-theme-color text-white rounded px-3" type="button" onclick="if($('#repeat_pass').attr('type')=='password'){$('#repeat_pass').attr('type','text');}else{$('#repeat_pass').attr('type','password');}$('#eye2').toggleClass('fa-eye');"><i id="eye2" class="fa fa-eye-slash"></i></button>
                        </div>
						<div class="form-button"><button id="register_btn" type="submit">Continue</button></div>
					<!--</form>-->
				</div>
				<div class="user-form-remind">
					<p>Already Have An Account?<a href="<?=base_url('login');?>">login here</a></p>
				</div>
			</div>
		</div>
	</div>
</section>
<!-- end main -->

<?php
include('footer.php');
?>

<? // register verification process;?>
<script>
    $(document).ready(function(){
        $('#register_btn').click(function(){
            var mobile_number = $("#mobile_number").val();
            var otp = '123456';
            var cust_name = $("#name").val();
            var side = $("#side").val();
            var cust_email = $("#email").val();
            var reg_password = $("#password").val();
            var sid=$('#sid').val();
            var reg_confirm_password = $("#repeat_pass").val();
            var form2 = 3;
           // $('#register_btn').attr('disabled',true);
                
            var a = mobile_number[0];
            var a1 = mobile_number[1];
            var a2 = mobile_number[2];
            var a3 = mobile_number[3];
            var a4 = mobile_number[4];
            var a5 = mobile_number[5];
            var a6 = mobile_number[6];
            var a7 = mobile_number[7];
            var a8 = mobile_number[8];
            var a9 = mobile_number[9];
            
            var pattern = /[0-9]/;
            
            var result = pattern.test(a);
            var result1 = pattern.test(a1);
            var result2 = pattern.test(a2);
            var result3 = pattern.test(a3);
            var result4 = pattern.test(a4);
            var result5 = pattern.test(a5);
            var result6 = pattern.test(a6);
            var result7 = pattern.test(a7);
            var result8 = pattern.test(a8);
            var result9 = pattern.test(a9);
                
                
            if((mobile_number.length == 10) && result && result1 && result2 && result3 && result4 && result5 && result6 && result7 && result8 && result9)
            {}
            else{
                $('#register_btn').attr('disabled',false);
                sweetalert('warning', 'Please enter a valid mobile number.');
                return false;
            }
            
             
                
                if(mobile_number !='' && otp!='' && cust_name!='' && cust_email!='' && reg_password!='' && reg_confirm_password!='' && '3'==form2){
                    var form = 3;
                                $.ajax({
                    	            type: "POST",
                    	            url: "<?=base_url('Register/final_form');?>",
                    	            data: {
                    	                mobile_number: mobile_number,
                    	                sid: sid,
                    	                otp: otp,
                    	                cust_name: cust_name,
                    	                cust_email: cust_email,
                    	                reg_password: reg_password,
                    	                reg_confirm_password: reg_confirm_password,
                    	                form: form,
                    	                side:side
                    	            },
                    	            success: function(data) {
                    	                var obj = JSON.parse(data);
                                        if(obj.log == 0){
                                            $('#register_btn').attr('disabled',false);
                                            sweetalert('warning', obj.error);
                                        }
                    	                if(obj.log == 1){
                                            $('#register_btn').attr('disabled',false);
                                            sweetalert('success', obj.succ);
                                            setTimeout(function(){ window.location='<?=base_url();?>';}, 3000);
                    	                }
                    	            }
                    	        });
                    	        }
                    	        if(form2 == '3' && mobile_number =='' || form2 == '3' && otp ==''  || form2 == '3' &&  cust_name ==''  || form2 == '3' &&  cust_email ==''  || form2 == '3' &&  reg_password ==''  || form2 == '3' &&  reg_confirm_password ==''){
                                    $('#register_btn').attr('disabled',false);
                                    sweetalert('warning', 'Please Fill All details Correctly.');
                                }
            return false;
        });
    });
</script>
<script>
    $(document).ready(function(){
        $('#resend_otp').click(function(){
            $('#register_btn').attr('disabled',true);
            $('#resend_otp').attr('disabled',true);
            var mobile_number = $("#mobile_number").val();
            var form = $("#form_open").val();
            $.ajax({
                type: "POST",
                url: "<?=base_url('Register/get_otp');?>",
                data: {
                mobile_number: mobile_number,
                form: form
            },
            success: function(data) {
                var obj = JSON.parse(data);
                if(obj.log == 0){
                    $('#register_btn').attr('disabled',false);
                    $('#resend_otp').attr('disabled',false);
                    sweetalert('warning', obj.error);
                    setTimeout(function(){ window.location='<?=base_url('login');?>';}, 3000);
                }
                if(obj.log == 1){
                    $('#register_btn').attr('disabled',false);
                    $('#resend_otp').attr('disabled',false);
                    sweetalert('success', 'OTP is Resend Successfully. ==' + obj.succ + '== ');
                    $("#form_open").val('2');
                }
            }
            });
        });
    });
</script>
<script>

    $(document).ready(function(){
        $('#email').blur(function(){
            var email = $("#email").val();
            var form = $("#form_open").val();
            $.ajax({
                type: "POST",
                url: "<?=base_url('Register/check_email');?>",
                data: {
                cust_email: email
            },
            success: function(data) {
                var obj = JSON.parse(data);
                if(obj.log == 0){
                    $("#email").val('');
                    sweetalert('warning', obj.error);
                }
            }
            });
        });
    });
    
</script>
<? // register verification process;?>