var table;
$(document).ready(function(){
       var productheaderid =    $("#productheaderid").val();
      // alert(productheaderid);
  table = $("#exhibitionSWTable").DataTable({
    "paging":   true,
    "scrollX": true,
    "scrollY": false,
    "processing": true, 
    "serverSide": true, 
    "pageLength": 20, 
    "order": [],
    "ajax": {
      "url": CI_ROOT+'exhibitionseminarwebinar/getExhibitionseminarwebinar',
      "type": "POST"
    },
    "columnDefs": [
      { 
        "targets": "_all",
        "orderable": false
      },
      {"targets":[0,1],"width":150},
      {"targets":[2],"width":150},
      {"targets":[3],"width":150},
      {"targets":[4],"width":150},
      {"targets":[5,6,7],"width":130}
    ],
    dom: 'Bfrtip',
    buttons: []
  });
  
    table = $("#bookedmembersSWTable").DataTable({
    "paging":   true,
    "scrollX": true,
    "scrollY": false,
    "processing": true, 
    "serverSide": true, 
    "pageLength": 20, 
    "order": [],
    "ajax": {
      "url": CI_ROOT+'exhibitionseminarwebinar/getExhibitionseminarwebinarbookedmembers/'+productheaderid,
      "type": "GET",
       //"data" : "{productheaderid:7}"
    },
    "columnDefs": [
      { 
        "targets": "_all",
        "orderable": false
      },
      {"targets":[0,1,2],"width":60},
      {"targets":[3],"width":350},
      {"targets":[4],"width":100},
      {"targets":[5],"width":80},
      {"targets":[6,7],"width":130}
    ],
    dom: 'Bfrtip',
    buttons: []
  });
  
  
  $('#from_date').datepicker({
    uiLibrary: 'bootstrap4',
    format: 'dd-mm-yyyy'
  });

  $('#to_date').datepicker({
    uiLibrary: 'bootstrap4',
    format: 'dd-mm-yyyy'
  });
  
  $("#add_exhibitionseminarwebinar").on("submit", function(e){
    e.preventDefault();
    $(".error").html("");
    $(".error").css("display", "none");

    var t = new FormData(this);
    $.ajax({
      type: "POST",
      data: t,
      url: CI_ROOT + "exhibitionseminarwebinar/addExhibitionseminarwebinarAction",
      mimeType: "multipart/form-data",
      contentType: !1,
      processData: !1,
      dataType: "json",
      beforeSend: function(){
        $(".preloader").fadeIn()
      },
      success: function(result) {
        $(".preloader").fadeOut();
        
        if(result.status == "success"){
          window.location.href = CI_ROOT + "exhibitionseminarwebinar/list";
        }else{
          $.each(result, function(e, t) {
            $("label[for='" + e + "']").html(t)
          });
          var t = Object.keys(result);
          $(".error").css("display", "block");
          $('input[name="' + t[0] + '"]').focus();
        }
      }
    })
  });
  
  $("#update_exhibitionseminarwebinar").on("submit", function(e){
    e.preventDefault();
    $(".error").html("");
    $(".error").css("display", "none");

    var t = new FormData(this);
    $.ajax({
      type: "POST",
      data: t,
      url: CI_ROOT + "exhibitionseminarwebinar/updateExhibitionseminarwebinarAction",
      mimeType: "multipart/form-data",
      contentType: !1,
      processData: !1,
      dataType: "json",
      beforeSend: function(){
        $(".preloader").fadeIn();
      },
      success: function(result) {
        $(".preloader").fadeOut();
        if(result.status == "success"){
          window.location.href = CI_ROOT + "exhibitionseminarwebinar/list";
        }else{
          $.each(result, function(e, t) {
            $("label[for='" + e + "']").html(t)
          });
          var t = Object.keys(result);
          $(".error").css("display", "block");
          $('input[name="' + t[0] + '"]').focus();
        }
      }
    })
  });
  
    $(".notforseminar").css("display","block");
    $(".notforexhibition").css("display","none");
    
  $("#txtoption").on("click",function(){
        var option  =   $(this).val();
        if(option == 1) //exhibition
        {
            $(".notforseminar").css("display","block");
            $(".notforexhibition").css("display","none");
        }
        else if(option == 2) //seminar
        {
            $(".notforseminar").css("display","none");
            $(".notforexhibition").css("display","block");
        }
        else if(option == 3) //webinar
        {
            $(".notforwebinar").css("display","none");
        }
        else if(option == 4) //seminar
        {
            //$(".notforseminar").css("display","none");
            //$(".notforexhibition").css("display","block");
              $(".notforexhibition").css("display","block");
            $(".notforeducation").css("display","none");
            //$("#venue").val("1");
            //$("#year").val("1");
        }
  });
    var option  =   $('#txtoption').val();
        if(option == 1) //exhibition
        {
            $(".notforseminar").css("display","block");
            $(".notforexhibition").css("display","none");
        }
        else if(option == 2) //seminar
        {
            $(".notforseminar").css("display","none");
            $(".notforexhibition").css("display","block");
        }
        else if(option == 3) //webinar
        {
            $(".notforwebinar").css("display","none");
        }
        else if(option == 4) //Education
        {
            //$(".notforseminar").css("display","none");
            //$(".notforexhibition").css("display","block");
             $(".notforexhibition").css("display","block");
            $(".notforeducation").css("display","none");
           
        }
        
  $("#memberprice").on("keyup",function(){
    var memberprice    =    $("#memberprice").val();  
    var memberdiscount =    $("#memberdiscount").val();
    var gst            =    $("#gst").val();
    if(memberdiscount > 0)
    {
        if(gst > 0)
        {
            var totalgstamt =   parseFloat(memberprice) * parseFloat(gst) /100;
            var totalamtaftergst    =   parseFloat(memberprice) + parseFloat(totalgstamt);
            //alert(totalamtaftergst);
            var discount   =   parseFloat(memberprice) * parseFloat(memberdiscount)/ 100;
            //alert(discount);
            var membertotalprice   =   parseFloat(totalamtaftergst) - parseFloat(discount);
            //alert(membertotalprice);
        }
        else
        {
            var discount   =   parseFloat(memberprice) * parseFloat(memberdiscount)/ 100;
            var membertotalprice   =   parseFloat(memberprice) - parseFloat(discount);
        }    
    }
    else
    {
        if(gst > 0)
        {
            var totalgstamt =   parseFloat(memberprice) * parseFloat(gst) /100;
            var totalamtaftergst    =   parseFloat(memberprice) + parseFloat(totalgstamt);
            var membertotalprice   =   parseFloat(totalamtaftergst);
        }
        else
        {
            var membertotalprice   =   parseFloat(memberprice);
        }    
    }
    $("#membertotalprice").val(membertotalprice);
     
  }); 
  
  $("#nonmemberprice").on("keyup",function(){
    var memberprice    =    $("#nonmemberprice").val();  
    var memberdiscount =    $("#nonmemberdiscount").val();
    var gst            =    $("#gst").val();
    if(memberdiscount > 0)
    {
        if(gst > 0)
        {
            var totalgstamt =   parseFloat(memberprice) * parseFloat(gst) /100;
            var totalamtaftergst    =   parseFloat(memberprice) + parseFloat(totalgstamt);
            var discount   =   parseFloat(memberprice) * parseFloat(memberdiscount)/ 100;
            var membertotalprice   =   parseFloat(totalamtaftergst) - parseFloat(discount);
        }
        else
        {
            var discount   =   parseFloat(memberprice) * parseFloat(memberdiscount)/ 100;
            var membertotalprice   =   parseFloat(memberprice) - parseFloat(discount);
        }    
    }
    else
    {
        if(gst > 0)
        {
            var totalgstamt =   parseFloat(memberprice) * parseFloat(gst) /100;
            var totalamtaftergst    =   parseFloat(memberprice) + parseFloat(totalgstamt);
            var membertotalprice   =   parseFloat(totalamtaftergst);
        }
        else
        {
            var membertotalprice   =   parseFloat(memberprice);
        }    
    }
    $("#nonmembertotalprice").val(membertotalprice);
     
  }); 
  
});