<?php
   $this->load->view('top');
   $mediaRes = $media_res;
   $overall_rating_product = product_overall_rating($res['products_id'], 'product');
   //print_r($res);
   $cat_res = get_db_single_row('wps_categories', '*', " category_id='$res[category_id]'");
   $sz = explode(',', $res['size_ids']);
   if ($res['color_ids'] != '' && $res['color_ids'] > 0) {
     $cl = explode(',', $res['color_ids']);
   } else {
     $cl = '';
     //print_r($cat_res['category_type']);
   }
   
   $cart_array = $this->cart->contents();
   $insert_flag = 0;
   if (is_array($cart_array) && !empty($cart_array)) {
     foreach ($this->cart->contents() as $item) {
       if (array_key_exists('pid', $item)) {
         if ($item['pid'] == $res['products_id']) {
           $insert_flag = 1;
         }
       }
     }
   }
   ?>

<link href="<?php echo theme_url(); ?>css/magiczoomplus.css" rel="stylesheet" type="text/css" />
<style>
.product_color_switch ul li.active a {
   border: 2px solid #7c0509;
   padding: 12px;
}
.newsletter-wrap input#newsletter_email{
    border-radius: 3px;
    overflow: hidden;
    background: rgb(255, 255, 255);
    width: 100%;
    color: rgb(80, 80, 80);
    padding: 17px 150px 17px 30px;
    outline: none;
    border: none;
}
.newsletter-wrap #newsletter_submit {
    position: absolute;
    right: 0px;
    top: 0px;
    background: #000;
    color: rgb(255, 255, 255);
    padding: 17px 40px;
    border-radius: 0px 5px 5px 0px;
    border: none;
    transition: all 0.3s ease 0s;
}
 .newsletter-wrap .col-md-6 {
    position: relative;
}
    @media screen and (max-width:650px){
        .newsletter-wrap .col-md-6:last-child{
            margin-top: 10px;
        }
    }
 
</style>
<link href="<?php echo theme_url();?>css/login.min.css" rel="stylesheet">  
<section class="banner_category" style="background-image: url('<?php echo theme_url(); ?>images/listing-banner.jpg');">
   <div class="container">
      <h1 class="banner_title"><?php echo $res['product_name']; ?></h1>
   </div>
</section>
<div class="page_breadcrumbs">
   <div class="container">
      <ul>
         <li><a href="<?= site_url(); ?>" title="Home">Home</a>
         </li>
         <?php echo category_breadcrumbs($res['category_id']); ?>
         <li><?php echo $res['product_name']; ?></li>
      </ul>
   </div>
</div>
<section class="product_listing">
   <div class="container">
   <div class="row">
   <div class="col-lg-6 col-md-6 col-sm-6  col-xs-12">
      <div class="app-figure" id="zoom-fig">
         <div class="details_zoom">
            <div class="row">
               <div class="col-xxl-2 col-xl-2 col-lg-2 col-md-2 col-sm-12 col-12 order-xxl-first order-xl-first order-lg-first order-md-first order-sm-last order-last">
                  <div class="selectors">
                     <?php foreach ($mediaRes as $mres) { ?>
                     <a data-slide-id="zoom" class="active" href="<?php echo get_image('products', $mres['media'], '', '', 'R'); ?>" data-image="<?php echo get_image('products', $mres['media'], '460', '690', 'R'); ?>" title="<?= $res['product_name']; ?>" title="mothers-day" data-zoom-id="zoom-v">
                     <img srcset="<?php echo get_image('products', $mres['media'], '85', '128', 'R'); ?>" src="<?php echo get_image('products', $mres['media'], '85', '128', 'R'); ?>" title="<?= $res['product_name']; ?>" alt="<?= $res['product_name']; ?>" />
                     </a>
                     <?php } ?>
                  </div>
               </div>
               <div class="col-xxl-10 col-xl-10 col-lg-10 col-md-10 col-sm-12 col-12">
                  <a id="zoom-v" class="MagicZoom" title="<?= $res['product_name']; ?>" href="<?php echo get_image('products', $res['media'], '2000', '2000', 'R'); ?>" data-options="zoomWidth:470; zoomHeight:470px">
                  <img src="<?php echo get_image('products', $res['media'], '460', '690', 'R'); ?>" alt="<?= $res['product_name']; ?>" title="<?= $res['product_name']; ?>" />
                  </a>
               </div>
            </div>
         </div>
      </div>
   </div>
   <div class="col-lg-6 col-md-6">
      <div class="product_details pd-detail-content">
         <?php echo form_open(site_url('cart/add_to_cart'), 'id="cart_form"'); ?>
         <h1><?= $res['product_name']; ?></h1>
         <?php if ($res['product_code'] != '') { ?>
         <div class="styles">
            <strong>SKU #</strong> <?= $res['product_code']; ?><?php } ?>
            <div class="product_review">
               <?php
                  $reviewsArray = $this->db->query("SELECT * FROM  wps_review WHERE entity_id='" . $res['products_id'] . "'")->result_array();
                  //echo "<pre>";print_r($reviewsArray);
                  if ($reviewsArray > 0) {
                    //$averagecount = count($reviews);
                    foreach ($reviewsArray as $ratingvalue) {
                      //$reviewsArray = array_filter($reviewsArray);
                      $rating[] = $ratingvalue['ads_rating'];
                      $average = array_sum($rating) / count($rating);
                      //echo $average;
                    }
                  }
                  if (!empty($average)) {
                    $average = $average;
                  } else {
                    $average = 0;
                  }
                  //echo $average;
                  ?>
               <div class="rating">   
                  <?php
                     $ads_rating = $average;
                     for ($i = 1; $i < 6; $i++) {
                       ?>
                  <?php if ($i <= $ads_rating) { ?>
                  <i class="fa fa-star"></i>
                  <?php } else { ?>
                  <i class="fa fa-star-o"></i>
                  <?php } ?>
                  <?php
                     }
                     ?>
                  <?php echo form_error('ads_rating'); ?>
               </div>
               <?php if ($this->session->userdata('user_id') > 0) { ?>
               <a href="<?php echo site_url(); ?>members/post_review/<?php echo $res['products_id']; ?>" class="rating_count">Write Review</a>
               <?php } else {
                  ?>
               <a href="<?= base_url('login'); ?>" class="rating_count">Write Review</a>  
               <?php } ?>
            </div>
            <div class="price pd-price" id="price">
               <?php
                  if ($res['product_discounted_price'] > 0) {
                    $percent = (($res['product_price'] - $res['product_discounted_price']) * 100) / $res['product_price'];
                    ?>
               <?php echo display_price($res['product_discounted_price']); ?>
               <span class="old_price"><?php echo display_price($res['product_price']); ?></span>   
               <div class="off_label"><?php echo round($percent); ?>% Off</div>
               <?php } else { ?>
               <?php echo display_price($res['product_price']); ?>
               <?php } ?>
            </div>
            <!--
               <div class="short_desc">
                   <ul>
                       <li>Battery Operated Ride on Car comes with Remote Control, Charger and Assembly Manua</li>
                       <li>Ride on Car is Suitable for Kids of age 2 to 5 Years and can Carry Weight Upto 35Kgs</li>
                       <li>Use it anywhere all you need is a smooth, flat surface to have your kids on-the-move with this toy bike</li>
                       <li>Kids can Ride this Car 40min-1hr Continously after Full Charge as It is Equipped with 2x6v Battery and Two Motors which Gives Speed of 4-5km/hr.</li>
                   </ul>
               </div>
               -->
           <div class="short_desc"> <?php echo $res['short_desc']; ?>  <br></div>
            
           
            <ul class="product_info">
               <li style="display:none" id="pincodeMsgSc"><small class="stock">Delivery available</small></li>
               <li style="display:none" id="pincodeMsgFl"><small class="" style="color: red;">The PIN code You have Entered is not Serviceable.</small></li>
            </ul>
            <div class="col-lg-6 col-md-6 col-xs-6">
               <div class="pd-pincode">
                  <div id="pincode_status"></div>
                  <div class="delivery_info_1">Delivery</div>
                  <input class="form-control" id="isPincodeValue" value="0" type="hidden" >
                  <div class="form-group check">
                     <i class="fa fa-map-marker"></i>
                     <input class="form-control" placeholder="Enter Pincode" name="pincode" id="pincode"  onkeyup="show_delivery_btn()" type="text" >
                     <button style="display: none;" class="check_btn check_pincodebtn" id="check-pincode-status-btn" type="button">Check</button>
                     <!-- onclick="check_delivery()" -->
                  </div>
                  <div class="clearfix"></div>
               </div>
            </div>
            <div class="row policy_option_1">
               <div class="col-md-6">
                  <h5><i class="fa fa-truck text-success"></i> 7 Day return policy <a href="<?php echo base_url();?>return-and-refund-policy" target="_blank"><i class="fa fa-info-circle"></i></a> </h5>
               </div>
               <div class="col-md-6">
                  <h5>
                     <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="text-success" viewBox="0 0 16 16">
                        <path d="M1 3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1H1zm7 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/>
                        <path d="M0 5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V5zm3 0a2 2 0 0 1-2 2v4a2 2 0 0 1 2 2h10a2 2 0 0 1 2-2V7a2 2 0 0 1-2-2H3z"/>
                     </svg>
                     Cash on Delivery available
                  </h5>
               </div>
               <div class="col-md-6">
                   
                  <h5><i class="fa <?= ($res['product_qty'] > 0) ? 'fa-check-circle text-success' : 'fa-times-circle text-danger'; ?>"></i> <?= ($res['product_qty'] > 0) ? 'In stock' : 'Out Of Stock'; ?></h5>
               </div>
               <br>
               <?php if ($res['color_ids'] != '') { ?>
               <div class="product_color_switch">
                  <h4>Color:</h4>
                  <ul>
                     <?php
                        $cl = explode(',', $res['color_ids']);
                        $clt = 0;
                        foreach ($cl as $cval) {
                          $name_color = $this->db->query("SELECT * FROM wps_colors WHERE color_id = '" . trim($cval) . "'")->row_array();
                          ?>
                     <li><a href="javascript:void(0);" title="<?php echo $name_color['color_name']; ?>" class="colorList" data-Val="<?php echo $name_color['color_id']; ?>" style="background: <?php echo $name_color['color_code']; ?>;"></a></li>
                     <?php
                        $clt++;
                        }
                        ?>  
                  </ul>
               </div>
               <?php } ?>
               <?php if ($res['size_ids'] != '') { ?>
               <div class="product_size_wrapper">
                  <h4>Size:</h4>
                  <ul>
                     <?php
                        $sz = explode(',', $res['size_ids']);
                        $sizeIds = $res['size_ids'];
                        $sizes = $this->db->query("SELECT size_id, size_name FROM wps_sizes WHERE size_id IN ($sizeIds) ORDER BY sort_order ASC")->result_array();
                        foreach ($sizes as $sval) {
                          ?>
                     <li><a href="javascript:void(0);" class="sizeList" data-Val="<?php echo $sval['size_id']; ?>"><?php echo $sval['size_name']; ?></a></li>
                     <?php
                        }
                        ?>
                  </ul>
               </div>
               <?php } ?>
               <div class="clearfix"></div>
               <?php if ($res['product_qty'] > 0) { ?>
               <div class="details_qty">
                  <input type="button" value="-" class="minus" />
                  <input type="text" name="qty" id="qty" value="1" class="qty" maxlength="10" readonly>
                  <input type="button" value="+" class="plus" />
               </div>
               <?php } ?>
               <div class="clearfix"></div>
               <div class="col-md-12">
                  <div class="pd-butnow-content">
                       <?php  if ($res['product_qty'] > 0) { ?>
                     <?php if ($this->session->userdata('user_id') > 0) { ?>
                     <!-- <a class="add_to_wishlist checkEnterPincode" style="cursor:pointer" href="<?php #echo site_url('cart/add_to_wishlist/' . $res['products_id']); ?>"><i class="fa fa-heart-o"></i> Add To Cart</a> -->
                     <a class="add_to_button cartButton checkEnterPincode pd-addcart-btn" style="cursor:pointer"><i class="fa fa-heart-o"></i> Add To Cart</a>
                     <?php } else { ?>
                     <!--  <a class="add_to_wishlist" style="cursor:pointer" onclick="alert('Please login to add the product in your wishlist!');"><i class="fa fa-heart-o"></i> Add To Cart</a> -->
                     <button class="add_to_button cartButton pd-addcart-btn checkEnterPincode" id="checkEnterPincode"><i class="fa fa-shopping-cart"></i>  Add To Cart</button>
                     <?php }} ?>
                     <?php if ($insert_flag == '1') { ?>
                     <button class="add_to_button pd-addcart-btn" type="button" onclick="window.location.href = '<?php echo base_url('cart'); ?>'">Go To Cart</button>
                     <?php } else { ?>
                     <input type="hidden" name="product_id" value="<?php echo $res['products_id']; ?>" />
                     <input type="hidden" name="stockValue" id="stockValue" class="stockValue" value="<?php echo $res['product_qty']; ?>" /> 
                     <input type="hidden" name="discount_id" id="discount_id" value="0" />
                     <input type="hidden" name="special_offer_id" value="0" />
                     <input type="hidden" name="color_id" id="color_id" value="" />
                     <input type="hidden" name="size_id" id="size_id" value="" />
                     <input type="hidden" name="codCharge" id="codCharge" value="">
                    
                     <?php
                        $userStatus = ($this->session->userdata('user_id') > 0) ? '' : 'loginmodal';
                        $addCartclass = ($this->session->userdata('user_id') > 0) ? 'cartButton' : '';
         
                        if ($res['product_qty'] > 0) { ?>
                     <button class="add_to_button checkEnterPincode pd-buy-btn <?=$addCartclass;?>" id="<?=$userStatus;?>" ><i class="fa fa-shopping-cart"></i> Buy Now</button>
                     <?php } ?>
                     <?php } ?>
                     <button type="button" class="send_enquiry_btn pd-inquire-btn" data-bs-toggle="modal" data-bs-target="#send_enquiry">
                     <i class="fa fa-envelope" aria-hidden="true"></i> Enquiry Now
                     </button>
                     <div class="clearfix"></div>
                     <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5cb9bcb2afbfc1df"></script>
                  </div>
                  <div class="addthis_inline_share_toolbox_x1h0">
                     <h5 class="share-head">SHARE THIS PRODUCT</h5>
                  </div>
               </div>
               <div class="clearfix"></div>
                
            </div>
         </div>
      </div>
   </div>
   <br/>
   <div class="container">
      <div class="product_overview">
         <ul class="nav nav-tabs" id="myTab" role="tablist">
            <li class="nav-item" role="presentation">
               <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Product Details</button>
            </li>
            <?php if ($res['specification'] != '') { ?>
            <li class="nav-item" role="presentation">
               <button class="nav-link" id="specification-tab" data-bs-toggle="tab" data-bs-target="#specification" type="button" role="tab" aria-controls="specification" aria-selected="true">Specification</button>
            </li>
            <?php } ?>
            <li class="nav-item" role="presentation">
               <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Ratings & Reviews</button>
            </li>
         </ul>
         <div class="tab-content" id="myTabContent">
            <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
               <?php echo html_entity_decode($res['products_description']); ?>
            </div>
            <div class="tab-pane fade show" id="specification" role="tabpanel" aria-labelledby="specification-tab">
               <?php echo html_entity_decode($res['specification']); ?>
            </div>
            <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
               <div class="row">
                  <div class="col-md-3">
                     <div class="review-style">
                        <h3>Review this product</h3>
                        <p>Share your thoughts with other customers</p>
                        <?php if ($this->session->userdata('user_id') > 0) { ?>
                        <a href="<?php echo site_url(); ?>members/post_review/<?php echo $res['products_id']; ?>" class="product_rate">Write Review</a><?php } else { ?>
                        <a href="<?= base_url('login'); ?>" class="product_rate">Write Review</a>
                        <?php }
                           ?>
                     </div>
                  </div>
                  <div class="col-md-9">
                     <h3>Ratings & Reviews</h3>
                     <?php
                        $reviews = $this->db->query("SELECT * FROM  wps_review WHERE entity_id='" . $res['products_id'] . "'")->result_array();
                        if (is_array($reviews) && !empty($reviews)) {
                          $starArray = $this->config->item('starArray');
                          krsort($starArray);
                          foreach ($reviews as $key => $revval) {
                            ?>
                     <div class="review">
                        <div class="review-title"><span class="summary"><i class="fa fa-user"></i> <span><?php echo $revval['author']; ?></span></span><span class="date"><i class="fa fa-calendar"></i><span><?php echo date('d M Y H:i A', strtotime($revval['review_date'])); ?></span></span>
                        </div>
                        <div class="product_ratings">
                           <?php
                              $ads_rating = $revval['ads_rating'];
                              for ($i = 1; $i < 6; $i++) {
                                ?>
                           <style>
                              .checked {
                              color: orange;
                              }
                           </style>
                           <span class="fa fa-star <?php
                              if ($i <= $ads_rating) {
                                echo 'checked';
                              }
                              ?>"></span>
                           <?php
                              # code...
                              }
                              ?>
                           <?php echo form_error('ads_rating'); ?>
                        </div>
                        <div class="text"><?php echo $revval['text']; ?></div>
                        <div class="">
                           <img src="<?php echo get_image('revies', $revval['upload_image'], '125', '125', 'R'); ?>" id="pic1" class="profile_picture" width="125" height="125"  />                       
                        </div>
                     </div>
                     <?php
                        }
                        }
                        ?>  
                  </div>
               </div>
            </div>
         </div>
      </div>
      </div>
    </div>
  </div>
</section>
<div class="clearfix"></div>
<?php if (is_array($related) && !empty($related)) { ?>
<section class="new_arrvals">
   <div class="container">
      <div class="heading wow fadeInLeft animated" data-wow-delay=".1s">
         <h2>Related Products</h2>
      </div>
      <div class="home_service">
         <?php
            foreach ($related as $key => $val) {
              $productImage = get_db_field_value("wps_products_media", "media", "WHERE products_id = '" . $val['products_id'] . "' ORDER BY id asc LIMIT 0, 1");
              ?>
         <div class="services_block  wow fadeInDown" data-wow-delay=".2s">
            <div class="services_margin service-item">
               <figure>
                  <a href="<?php echo base_url($val['friendly_url']); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>">
                     <div class="image"><img src="<?php echo get_image('products', $val['media'], '294', '259', 'R'); ?>" title="<?php echo $val['product_name']; ?>" alt="<?php echo $val['product_name']; ?>"></div>
                  </a>
                  <!-- <figcaption><a href="<?php //echo base_url($val['friendly_url']); ?>" class="fa fa-link"></a></figcaption>-->
               </figure>
               <div class="clearfix"></div>
               <div class="description03">
                  <h3 class="title"><a href="<?php echo base_url($val['friendly_url']); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>"><?php echo char_limiter($val['product_name'], 28); ?></a></h3>
                  <?php if ($val['product_discounted_price'] > 0) { ?>
                  <div class="price"><span class="ac-price"><?= display_price($val['product_price']); ?></span><?= display_price($val['product_discounted_price']); ?></div>
                  <?php }  else { ?>
                  <span class="price"><span> <?= display_price($val['product_price']); ?></span></span>
                  <?php } ?>
                  <?php
                     if ($val['product_discounted_price'] > 0) {
                       $percent = (($val['product_price'] - $val['product_discounted_price']) * 100) / $val['product_price'];
                       ?>
                  <div class="off_label2"><?= round($percent); ?>% off</div>
                  <?php } ?>
                  <!--                                                  <p class="earliest-delivery">Earliest Delivery: <span>Today</span></p>-->
               </div>
            </div>
         </div>
         <?php } ?>
      </div>
   </div>
</section>
<?php } ?>
<div class="clearfix"></div>
<?php $this->load->view("bottom"); ?>
<script type="text/javascript">
   setTimeout(function () {
     $('.colorList').eq(0).trigger('click');
     $('.sizeList').eq(0).trigger('click');
   }, 600);
   
   //Check Pincode
   jQuery('#pincode').on('input', function () {
     $('#isPincodeValue').val('0');
     $("#pincodeMsgFl,#pincodeMsgSc").css("display", "none");
     let content = $('#pincode').val();
     if (content.length == '6') {
       $("#check-pincode-status-btn").css("display", "block");
     } else {
       $("#check-pincode-status-btn").css("display", "none");
     }
   });
   
   //Validate Pincode
   $(".check_pincodebtn").click(function () {
     $("#pincodeMsgSc,#pincodeMsgFl").css("display", "none");
     if ($('#pincode').val().trim() == '') {
       swal('Please Enter Pincode and Check Servicibility.');
       return false;
     }
     var pindata = 'pincodeVal=' + $('#pincode').val().trim();
     jQuery.ajax({
       url: "<?php echo site_url(); ?>products/checkPincode",
       type: 'POST',
       data: pindata,
       success: function (data) {
          // alert(data);
         if (data) {
   //                  console.log(data);
             var obj = jQuery.parseJSON(data);
             var codCharge = obj.codcharge;
            //console.log(codCharge);
             if(codCharge > 0){
             $('#charge').html(codCharge);
           $('#isPincodeValue').val('1');
           $('#codCharge').val(obj.codcharge);
           $("#pincodeMsgSc").css("display", "block");
             }
             else{
                 //alert("hii");
               $("#pincodeMsgFl").css("display", "block"); 
             }
          
             } else {
             console.log("fail");
           $('#isPincodeValue').val('0');
            $("#pincodeMsgFl").css("display", "block");
         }
       }
     });
   });
   $(".checkEnterPincode").click(function (e) {
     e.preventDefault();
     var isEnable = $('#isPincodeValue').val();
     
     // if (isEnable === '0') {
       if ($('#pincode').val().trim() == '') {
         swal('Please Enter Pincode and Check Servicibility.');
         return false;
       } else {
         var pindata = 'pincodeVal=' + $('#pincode').val().trim();
         jQuery.ajax({
           url: "<?php echo site_url(); ?>products/checkPincode",
           type: 'POST',
           data: pindata,
           success: function (data) {
             if (data == true) {
               alert('true');
               $('#isPincodeValue').val('1');
                $('#cart_form').submit();
             } else {
               //alert('false');
               $('#isPincodeValue').val('0');
             }
           }
         });
       }
     // } else {
     //   $('#cart_form').submit();
     // }
   });
   // End Here
   
   //Quantity Buttons
   var dqty = jQuery(".super-attribute-select").find("option:selected").attr("qty");
   var MAX_QTY = $('.stockValue').val();
   ;
   var MIN_QTY = 1;
   jQuery(".super-attribute-select").change(function () {
     dqty = jQuery(".super-attribute-select").find("option:selected").attr("qty");
     if (typeof dqty == "undefined") {
       MAX_QTY = 10
     } else {
       MAX_QTY = dqty
     }
     jQuery("#qty").val(1)
   });
   jQuery(".plus").click(function () {
     var MAX_QTY = $('#stockValue').val();
     ;
     var MIN_QTY = 1;
     if (typeof MAX_QTY == "undefined") {
       MAX_QTY = 10
     }
     var a = parseInt(jQuery(this).prev(".qty").val());
     if (!a || a == "" || a == "NaN") {
       a = 0
     }
     if (a < MAX_QTY) {
       jQuery(this).prev(".qty").val(a + 1)
     } else {
       alert('You have reached to maximum available quantity.');
     }
   });
   jQuery(".minus").click(function () {
     var MAX_QTY = $('#stockValue').val();
     ;
     var MIN_QTY = 1;
     var a = parseInt(jQuery(this).next(".qty").val());
     if (a == "NaN") {
       a = 0
     }
     if (a > MIN_QTY) {
       jQuery(this).next(".qty").val(a - 1)
     }
   });
   
   //Size and Color Selection
   $('.sizeList, .colorList').click(function () {
     if ($(this).hasClass("sizeList")) {
       $('.sizeList').parent('li').removeClass('active');
       $(this).parent('li').addClass('active');
       $('#size_id').val($(this).attr('data-Val'));
     } else {
       $('.colorList').parent('li').removeClass('active');
       $(this).parent('li').addClass('active');
       $('#color_id').val($(this).attr('data-Val'));
     }
     //get value
     var sz = $('#size_id').val();
     var cl = 0;//$('#color_id').val();
     $.post('<?php echo site_url(); ?>products/get_product_price', {sid: sz, cid: cl, pid: '<?php echo $res['products_id']; ?>'}, function (msg) {
       if (msg) {
         var txt = msg.split('-');
         if (txt[2] > 0 && txt[0] > 0) {
           var percent = ((txt[1] - txt[2]) * 100) / txt[1];
           $('#price').html('');
           $('#price').html('<i class="fa fa-inr"></i> ' + txt[2] + ' <span class="old_price"><i class="fa fa-inr"></i> ' + txt[1] + '</span><div class="off_label">' + Math.round(percent) + '% Off</div>');
           $('.stock').html('In Stock');
           $('.cartButton').show(0);
           $('.stockValue').val(txt[0]);
         } else if (txt[1] > 0 && txt[0] > 0) {
           $('#price').html('<i class="fa fa-inr"></i> ' + txt[1]);
           $('.stock').html('In Stock');
           $('.cartButton').show(0);
           $('.stockValue').val(txt[0]);
         } else {
           $('#price').html('OUT OF STOCK');
           $('.stock').html('Out of Stock');
           $('.cartButton').hide(0);
           $('.stockValue').val('0');
         }
       } else {
         // $('#price').html('OUT OF STOCK');
         // $('.stock').html('Out of Stock');
         // $('.stockValue').val('0');
         // $('.cartButton').hide(0);
       }
     });
   });
   <?php if ($res['size_ids'] != '' && $res['color_ids'] != '') { ?>
     $('.cartButton').click(function () {
       var isEnable = $('#isPincodeValue').val();
       if ($('#size_id').val() == '' || $('#color_id').val() == '') {
         alert('please select size & color to add in the cart!');
         return false;
       } else {
         if(isEnable === '1')
          $('#cart_form').submit();
        else
         swal('Please Enter Pincode and Check Servicibility.');
       }
     });
   <?php } else if ($res['size_ids'] != '' && $res['color_ids'] == '') { ?>
     $('.cartButton').click(function () {
       var isEnable = $('#isPincodeValue').val();
       if ($('#size_id').val() == '') {
         alert('please select size to add in the cart!');
         return false;
       } else {
         if(isEnable === '1')
           $('#cart_form').submit();
         else
         swal('Please Enter Pincode and Check Servicibility.');
       }
     });
   <?php } else if ($res['size_ids'] == '' && $res['color_ids'] != '') { ?>
     $('.cartButton').click(function () {
       var isEnable = $('#isPincodeValue').val();
       if ($('#color_id').val() == '') {
         swal('please select color to add in the cart!');
         return false;
       } else {
         if(isEnable === '1')
           $('#cart_form').submit();
         else
         swal('Please Enter Pincode and Check Servicibility.');
       }
     });
   <?php } else { ?>
     $('.cartButton').click(function () {
       var isEnable = $('#isPincodeValue').val();
       if(isEnable === '1')
         $('#cart_form').submit();
       else
         swal('Please Enter Pincode and Check Servicibility.');
     });
   <?php } ?>
</script>
<script src="<?php echo theme_url(); ?>js/magiczoomplus.js" type="text/javascript"></script>
<script>
   jQuery('.zoom-gallery .selectors a').on('click touch', function (e) {
     var iframe = jQuery('.active iframe[src*="youtube"],.active iframe[src*="vimeo"]');
     if (iframe.length) {
       iframe.attr('src', iframe.attr('src'));
     }
     jQuery('.zoom-gallery .zoom-gallery-slide').removeClass('active');
     jQuery('.zoom-gallery .selectors a').removeClass('active');
     jQuery('.zoom-gallery .zoom-gallery-slide[data-slide-id="' + jQuery(this).attr('data-slide-id') + '"]').addClass('active');
     jQuery(this).addClass('active');
     e.preventDefault();
   });
   
</script>
<script type="text/javascript">
   $(document).ready(function () {
   <?php if ($this->session->flashdata('success') != '') { ?>
       swal({
         title: "<?php echo $this->session->flashdata('success'); ?>",
         text: "",
         type: "success",
         showCancelButton: true,
         cancelButtonText: "Continue Shopping",
         cancelButtonColor: '#01a1e3',
         confirmButtonColor: '#2d4640',
         confirmButtonText: 'Go to Cart',
         //closeOnConfirm: false,
         //closeOnCancel: false
       },
               function (isConfirm) {
                 if (isConfirm) {
                   window.location.href = "<?php echo base_url('cart'); ?>";
                 } else {
                   // window.location.href="<?php echo base_url('cart'); ?>";
                   //swal("Cancelled", "Your imaginary file is safe :)", "error");
                 }
               });
   <?php } ?>
   });
</script>
<script type="text/javascript">
    $(function() {
   <?php if ($this->session->flashdata('reviewstatus') != '') { ?>
       swal({
            title:"<?php echo $this->session->flashdata('reviewstatus'); ?>",
            confirmButtonColor: '#dc3545',
           });
   <?php } ?>
   });
</script>

<!-- login modal integration -->
<div class="modal fade" id="login_modal">
   <div class="modal-dialog modal-md">
      <div class="otp-modal">
          <div class="modal-content">
         <div class="modal-header">
            <h5 class="modal-title">Login</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
         </div>
          <div class="otp-modal-content">
              <div class="otp-body">
         <div class="dig_lrf_box dig_ma-box dig_pgmdl_2">
        <div class="dig_clg_bx">
            <div class="digloginpage">
            <form id="login-frm" class="digits_login">
               <div id="login-status"></div>
               <div class="form-group">
           
                    <div class="digits_fields_wrapper digits_login_fields">
                        <div class="minput">
                            <div class="minput_inner">
                                <div class="countrycodecontainer logincountrycodecontainer"
                                    style="display: inline-block;">
                                    <input type="text" class="input-text logincountrycode dark" value="+91" name="mobmail" placeholder="Email/Mobile Number">
                                </div>
                                <div class="digits-input-wrapper not-empty">
                                    <input type="text" class="mobile_field mobile_format dig-mobmail not-empty" id="login_mobile" name="login_mobile" aria-describedby="emailHelp"required="" placeholder="Email/Mobile Number">
                                </div>
                                <label>Email/Mobile Number</label>
                                <span class="bgdark"></span>
                            </div>
                        </div>
                    </div>
                 
<!--
                  <label for="exampleInputEmail1">Email Id/Mobile Number</label>
                  <input type="text" class="form-control" id="login_mobile" name="login_mobile" aria-describedby="emailHelp" placeholder="Enter Email Id / Mobile Number">
-->
               </div>
               <div class="form-group">
<!--                  <label for="exampleInputPassword1">Password</label>-->
                  <input type="password" class="form-control form-style" id="login_password" name="login_password" placeholder="Password">
               </div>
               <input type="hidden" class="form-control" id="productId" name="productId" value="<?=$res['products_id'];?>">
               <input type="hidden" class="form-control" id="friendly_url" name="friendly_url" value="<?=$res['friendly_url'];?>">
               <input type="hidden" class="form-control" id="product_name" name="product_name" value="<?=$res['product_name'];?>">
               <button type="submit" class="btn btn-modal-style w-100" id="login_auth">Submit</button>
            </form>
                         </div>
        </div>
    </div><!-- login-js -->
                  <div class="footer-otp">
                      <span>OR</span>
                  <button type="submit" class="btn btn-modal-style-2 w-100" id="otpmodal">Login with OTP</button>
                  <p class="label-m">Don't have an account?</p>
                  <button type="submit" class="btn btn-modal-style  w-100" id="regmodal">Sign Up</button>
                  </div>
         </div>
          
              </div>
      </div>
       </div>
   </div>
</div>
 
<!-- otp modal integration -->
<div class="modal fade" id="otp_modal">
   <div class="modal-dialog modal-md" style="margin-top:8%">
      <div class="otp-modal">
       <div class="modal-content">
         <div class="modal-header">
            <h5 class="modal-title" id="modaltitle">Login With OTP</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
         </div>
            <div class="otp-modal-content">
         <div class="otp-body">
          <div class=" ">
            <form id="otp-frm" method="post">
               <div id="style1">
                  <div id="otp-status"></div>
                  <div class="form-group" >
                     <!-- <label for="exampleInputEmail1">Mobile Number</label> -->
                     <input type="tel" class="form-control form-style" id="mobile_num"  aria-describedby="emailHelp" placeholder="Enter Mobile Number" maxlength="10" minlength="10" required>
                  </div>
                  <button  class="btn btn-modal-style w-100" id="otp_send" >Send OTP</button>
               </div>
               <div id="style2">
                  <div class="form-group mb-0">
                     
                     <h5 class="text-center confirm-message">Please Type the Verification Code sent to <?php if($this->session->userdata('mobnumber')) { echo $this->session->userdata('mobnumber');};?></h5>
                      <br>
                     <div id="otp-status2"></div>
                     <div class="form-group">
                         <div id="divOuter">
                                <div id="divInner">
                         <input type="text" class="chk" id="otp" name="otp"  maxlength="6" minlength="6" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" >
                                </div>
                                </div>
                       
                        <input type="hidden" class="form-control" id="productId" name="productId" value="<?=$res['products_id'];?>">
                        <input type="hidden" class="form-control" id="friendly_url" name="friendly_url" value="<?=$res['friendly_url'];?>">
                        <input type="hidden" class="form-control" id="product_name" name="product_name" value="<?=$res['product_name'];?>">
                     </div>
                     <input type="submit" class="btn btn-modal-style w-100" id="otp_auth" value="Verify OTP">
                  </div>
               </div>
            </form>
          </div>
         </div>
           </div>
      </div>
       </div>
   </div>
</div>
<!-- registration modal integration -->
<div class="modal fade" id="reg_modal" >
   <div class="modal-dialog" style="margin-top:8%">
       <div class="otp-modal">
      <div class="modal-content">
         <div class="modal-header">
            <h5 class="modal-title" id="regtitle">Register Now</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
         </div>
                <div class="otp-modal-content">
         <div class="otp-body">
            <form id="register-frm" method="post">
               <div id="section1">
                  <div id="reg-status"></div>
                  <div class="form-group" >
                     <label for="username">User Name*</label>
                     <input type="text" class="form-control form-style" id="first_name" name="first_name" aria-describedby="emailHelp"  required>
                  </div>
                    <div class="form-group" >
                     <label for="emailid">Email ID*</label>
                     <input type="email" class="form-control form-style" id="email_address" name="email_address"  aria-describedby="emailHelp" required>
                  </div>
                    <div class="form-group" >
                     <label for="phone">Mobile Number*</label>
                     <input type="tel" class="form-control form-style" id="mobile_number" name="mobile_number"  aria-describedby="emailHelp"  maxlength="10" minlength="10" required>
                  </div>
                    <div class="form-group" >
                     <label for="password">Password*</label>
                     <input type="password" class="form-control form-style" id="password" name="password" autocomplete="off"  required>
                  </div>
                    <div class="form-group" >
                     <label for="conformpassword">Confirm Password*</label>
                     <input type="password" class="form-control form-style" id="c_password" name="c_password"  autocomplete="off" autocomplete="off"  required>
                  </div>
                   <div class="form-group">
          <input type="checkbox" name="checkbox" checked="" required="" style="margin-right: 30%;width: 15px;"> 
            <label style="margin-left: -29%;">I agree to the <a href="https://www.webpulse.co/toyzoo/terms-conditions">Terms and Conditions</a>
             </label>
              </div>
                  <input type="hidden" name="action" value="register" id="action">
                  <button type="submit" class="btn-modal-style w-100" id="register_send" >Submit</button>
               </div>
               <div id="section2">
                  <div class="form-group" >
                      
                     <h5 class="text-center">Please Type the Verification Code sent to <?php if($this->session->userdata('mobnumber')) { echo $this->session->userdata('mobnumber');};?></h5>
                      <br>
                     <div id="reg-status1"></div>
                     <div class="form-group">
                          <div id="divOuter1">
                                <div id="divInner1">
                         <input type="text" class="chk1" id="otp_reg" name="otp_reg"  maxlength="6" minlength="6" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" >
                                </div>
                                </div>
                        <input type="hidden" class="form-control" id="productId" name="productId" value="<?=$res['products_id'];?>">
                        <input type="hidden" class="form-control" id="friendly_url" name="friendly_url" value="<?=$res['friendly_url'];?>">
                        <input type="hidden" class="form-control" id="product_name" name="product_name" value="<?=$res['product_name'];?>">
                     </div>
                     <input type="submit" class="btn-modal-style w-100" id="otp_auth_reg" value="Verify OTP">
                  </div>
               </div>
            </form>
         </div>
          </div>
      </div>
       </div>
   </div>
</div> 

<script>
$('.btn-close').click(function() {
    location.reload();
});
</script>
 <script>
        var dig_log_obj = {
            "direction": "ltr",
            "dig_mobile_no_formatting": "1",
            "dig_hide_ccode": "0",
            "dig_sortorder": "",
            "dig_dsb": "-1",
            "show_asterisk": "1",
            "login_mobile_accept": "1",
            "login_mail_accept": "1",
            "login_otp_accept": "1",
            "captcha_accept": "0",
            "Passwordsdonotmatch": "Passwords do not match!",
            "fillAllDetails": "Please fill all the required details.",
            "accepttac": "Please accept terms & conditions.",
            "resendOtpTime": "30",
            "useStrongPasswordString": "Please enter a stronger password.",
            "strong_pass": "0",
            "firebase": "1",
            "mail_accept": "2",
            "pass_accept": "2",
            "mobile_accept": "2",
            "username_accept": "0",
            //"ajax_url": "admin-ajax.php",
            "appId": "",
            //"uri": "my-account\/?&back=home&page=1",
            "state": "25bbfdc471",
            "left": "0",
            "verify_mobile": "0",
            "Registrationisdisabled": "Registration is disabled",
            "forgotPasswordisdisabled": "Forgot Password is disabled",
            "invalidlogindetails": "Invalid login credentials!",
            "invalidapicredentials": "Invalid API credentials!",
            "pleasesignupbeforelogginin": "Please signup before logging in.",
            "pleasetryagain": "Please try again!",
            "invalidcountrycode": "At the moment, we do not allow users from your country",
            "Mobilenumbernotfound": "Mobile number not found!",
            "MobileNumberalreadyinuse": "Mobile Number already in use!",
            "Error": "Error",
            "Thisfeaturesonlyworkswithmobilenumber": "This features only works with mobile number",
            "InvalidOTP": "Invalid OTP!",
            "ErrorPleasetryagainlater": "Error! Please try again later",
            "Passworddoesnotmatchtheconfirmpassword": "Password does not match the confirm password!",
            "Invaliddetails": "Invalid details!",
            "InvalidEmail": "Invalid Email!",
            "InvalidMobileNumber": "Invalid Mobile Number!",
            "eitherenterpassormob": "Either enter your mobile number or click on sign up with password",
            "login": "Log In",
            "signup": "Sign Up",
            "ForgotPassword": "Forgot Password",
            "Email": "Email",
            "Mobileno": "Mobile Number",
            "ohsnap": "Oh Snap!",
            "yay": "Yay!",
            "notice": "Notice!",
            "submit": "Submit",
            "SubmitOTP": "Submit OTP",
            "required": "Required",
            "select": "(select)",
            "login_success": "Login Successful, Redirecting..",
            "login_reg_success_msg": "1",
            "nonce": "eb790114e0"
        };
    </script>
    <script src="<?php echo theme_url(); ?>js/login.min.js" crossorigin="anonymous"></script>
