<?php
  $Currency = getCurrency();
  
?>
<!-- PAGE-INDEX-STARTS -->

<div class="breadcrumbs">
    <div class="breadcrumbs-inner">
        <div class="row m-0">
            <div class="col-sm-4">
                <div class="page-header float-left">
                    <div class="page-title">
                        <h1><?= $pTitle ?></h1>
                    </div>
                </div>
            </div>
            <div class="col-sm-8">
                <div class="page-header float-right">
                    <div class="page-title">
                        <ol class="breadcrumb text-right">
                            <li><a href="<?= base_url() ?>">Dashboard</a></li>
                            <li><a ><?= $menu ?></a></li>
                            <li class="active"><?= $smenu ?></li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- PAGE-INDEX-ENDS -->

<!-- PAGE-CONTENT-STARTS -->

<div class="content">
  <div class="animated fadeIn">
      <div class="row">
        <div class="col-lg-12">
        <?php 
        $url = (!isset($customer_id)||empty($customer_id))
        ?'Customer/createCustomer':'Customer/updateCustomer/'.$customer_id;
        if($this->session->flashdata('message')) { 
        $flashdata = $this->session->flashdata('message'); ?>
          <div class="alert alert-<?= $flashdata['class'] ?>">
            <button class="close" data-dismiss="alert" type="button">×</button>
            <?= $flashdata['message'] ?>
          </div>
          <?php } ?>
          <form role="form" action="<?= base_url($url) ?>" method="post" class="validate" data-parsley-validate="" enctype="multipart/form-data">
            <div class="card">
              <div class="card-header">
                <strong><?= $pDescription ?></strong>
              </div>
              <div class="card-body card-block">
                <div class="form-group">
                  <div class="row">
                    <div class="col-md-6">

                      <label for="nf-email" class=" form-control-label">Name</label>
                      <input type="text" data-parsley-trigger="change" data-parsley-minlength="2" data-parsley-pattern="^[a-zA-Z0-9\ . _ - ' \/]+$" id="nf-brand" name="name" placeholder="Enter Name" class="form-control required" value="<?= (isset($customer_data->name))?$customer_data->name:'' ?>" >
                       </div>
                      <?php $req = (!isset($customer_id)||empty($customer_id))?'form-control required':'form-control';?>
                    <div class="col-md-6">
                      <label>Profile Picture</label><br>
                     
                        <img id="image_id_1" src="<?= (isset($customer_data->profile_photo))?base_url($customer_data->profile_photo):'' ?>" onerror="this.src='<?=base_url("assets/images/user_avatar.jpg")?>';" height="75" width="75" />
                        <input name="profile_photo" type="file" accept="image/*" onchange="setImg(this,'image_id_1');" class="<?= base_url($req) ?>"/>
                    </div>
                  </div>
                </div>
                
                <div class="form-group">
                  <div class="row">
                    <div class="col-md-6">
                    <label for="nf-email" class=" form-control-label">Phone Code</label>
                    <select name="phone_code" id="selectSm" class="form-control required">
                        <option value="">Please select</option>    
                        <?php foreach($Currency as $crny) { ?> 
                        <?php  if  (isset($customer_id)||!empty($customer_id)) { ?>
                        <option <?= $customer_data->code == $crny['code'] ? "selected" : "" ; ?> value="<?= $crny['code'] ?>"><?= $crny['code'] ?></option>
                        <?php }else { ?> 
                        <option  value="<?= $crny['code'] ?>"><?= $crny['code'] ?></option>
                        <?php }} ?> 
                      </select>

                  
                    </div>
                    <div class="col-md-6">
                      <label for="nf-email" class=" form-control-label">Phone</label>
                      <input type="text" data-parsley-trigger="change" data-parsley-trigger="change"  data-parsley-minlength="2"  data-parsley-pattern="^[0-9\ , - + \/]+$" id="nf-brand" name="phone_no" placeholder="Enter Phone Number" class="form-control required" value="<?= (isset($customer_data->phone_no))?$customer_data->phone_no:'' ?>" >
                    </div>
                  </div>
                </div>

                <div class="form-group">
                  <div class="row">
                    <div class="col-md-6">
                      <label for="nf-email" class=" form-control-label">Email</label>
                      <input type="email" id="email_id" name="email_id" placeholder="Enter Email" class="form-control required" onfocusout="myFunction()" value="<?= (isset($customer_data->email_id))?$customer_data->email_id:'' ?>" >
                      <br>
                        <div id="email_req" style="color: red"></div>
                    </div>
                    <div class="col-md-6">
                    <label for="nf-email" class=" form-control-label">Password</label>
                    <input type="text" data-parsley-trigger="change" data-parsley-trigger="change"  data-parsley-minlength="2"  data-parsley-pattern="^[a-zA-Z0-9\ . _ - ' \/]+$" id="nf-brand" name="password" placeholder="Enter Password" class="form-control required" value="<?= (isset($customer_data->password))?$customer_data->password:'' ?>" >
                    </div>
                  </div>
                </div>
                 <div class="form-group">
                    <div class="row">
                     <div class="col-md-6">
                      <label for="nf-email" class=" form-control-label">Area</label>
                       <input type="text" name="area" id="location"  required class="form-control required" placeholder="Enter Area" onkeypress="ratelocation()" value="<?= (isset($customer_data->area))?$customer_data->area:'' ?>">
                      <input type="hidden" name="lat" id="lat" value="<?= (isset($customer_data->lat))?$customer_data->lat:'' ?>">
                    <input type="hidden" name="lng" id="lng" value="<?= (isset($customer_data->lng))?$customer_data->lng:'' ?>">
                    </div>         
                     <div class="col-md-6"> 
                       <label for="nf-email"  class=" form-control-label">Address</label>
                        <textarea type="text" data-parsley-trigger="change" data-parsley-minlength="2" data-parsley-pattern="^[a-zA-Z0-9\ . _ - ' \/]+$" id="nf-brand" name="address" placeholder="Enter Address" class="form-control required" ><?= (isset($customer_data->address))?$customer_data->address:'' ?></textarea> 
                       
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="row">
                      <div class="col-md-12">
                          <button type="submit" class="btn btn-primary">
                                <i class="fa fa-arrow-circle-right"></i> Next
                          </button>
                      </div>
                    </div>
                  </div>   
                </div>
              </div>
            </form>
          </div>
         </div>
      </div>
   </div>
   <div class="clear-fix"></div>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
   
<script type="text/javascript">

function myFunction(){
alert("ddfgd");
var email = document.getElementById('pd_email').value;

var site_url = '<?php echo SITE_URL; ?>';

$.ajax({
type: "POST",
url: "Customer/check_email_availability",
data: {email:email},

success: function(result){
var val = JSON.parse(result);
console.log(val.data.is_email_avaliable);



if(val.data.is_email_avaliable==true){
var email = val.email;



}
else { 

var message = "This email is already being used!!";
document.getElementById("email_req").innerHTML = '<div style="margin:-20px;" class="normal"><font color="red" font size="2px" vertical-align="top" text-align="center"> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+message+'</b></font></div>';


}




}
});

}
</script> 
        

















        