function openform(fdate, edate){
    $(".fluid-container.data-form").show();
    $("#send_time").attr('data-jDate', fdate);
    $("#send_time").attr('data-gDate', edate);
    $("#send_time").val(fdate);
    $("#gsend_time").val(edate);
    
}
function close_form(){
    $(".fluid-container.data-form").hide();
}
$(document).ready(function () {


  date_status();       
         
         

  $("#time").change(function(){
   //console.log($("#time").val());
   let time=[];
   $("#gsend_time").val().split(" ")[1]=$("#time").val();
   time [0]=$("#gsend_time").val().split(" ")[0];
   time [1]=$("#time").val();
   let datetime=time.toString().replace(",", " ");
   
   $("#gsend_time").val(datetime);
   $("#send_time").attr('data-gDate', datetime);
   

   let jtime=[];
   
   $("#send_time").attr("data-jdate").split(" ")[1]=$("#time").val();
   jtime [0]= $("#send_time").attr("data-jdate").split(" ")[0];
   jtime [1]=$("#time").val();
   let jdatetime=jtime.toString().replace(",", " ");
   $("#send_time").attr('data-jDate', jdatetime);
   $("#send_time").val(jdatetime);
   
  });
$("#send_time").change(function(){
    $("#gsend_time").val(this.val());
  });

  
  $("#main-form").submit(function (event) {
      
    var formData = {
        phone: $("#phone").val(),
        massage: $("#massage").val(),
        gsend_time: $("#gsend_time").val(),
        pattern_code: $("#pattern_code").val(),
    };
   
    $.ajax({
      type: "POST",
      url: "form.php",
      data: formData,
      dataType: "json",
      encode: true,
    }).done(function (data) {
      if(data){
        $("#result-notice").fadeIn(1000).delay(1000).fadeOut(1000);
         let selected_date=$("#gsend_time").val().split(" ")[0];
         let selected_day_el=$(".day.cell[data-gdate='"+ selected_date +"']");
        selected_day_el.addClass("bg-warning");
        
      }
    });

    event.preventDefault();
  });
  $("#send-test").click(function (event) {
      
    var formData = {
      action:"send-test",
        phone: $("#phone").val(),
        massage: $("#massage").val(),
        pattern_code: $("#pattern_code").val(),
    };

    $.ajax({
      type: "POST",
      url: "send_sms.php",
      data: formData,
      dataType: "json",
      encode: true,
    }).done(function (data) {
      if(data){
        $("#result-notice").fadeIn(1000).delay(1000).fadeOut(1000);
      }
    });

    event.preventDefault();
  });

   
});