(function ($) {
  "use strict";

  $(document).on('click','.not_selected', function () {
    swal({
      title: "please select and save any option",
    });
  });

  $(".submit_test").on("click", function (q) {
    q.preventDefault();

    var names = []
    var checked = true;
    $('input:radio').each(function () {
        var rname = $(this).attr('name');
        if ($.inArray(rname, names) === -1) names.push(rname);
    });

    //do validation for each group
    $.each(names, function (i, name) {
        if ($('input[name="' + name + '"]:checked').length === 0) {
          console.log('Please check ' + name);
          q.preventDefault(false);

          swal({
            title: "Not all answers have been given yet.",
          });
          checked = false;
          return false;
          
        }

    });

    
if (checked)
{
    var test_submit = "submit";
    $.ajax({
      type: "POST",
      url: BASE_URL + "test-submit-request",
      data: {
        test_submit: test_submit
      },

      success: function (data) {
        if (data) {
          data = JSON.parse(data);
          if (data.status == "success") {
            swal({
                title: are_you_sure,
                text: "",
              //  text: total_attemp + " " + data.attemp,
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#3085d6",
                cancelButtonColor: "#d33",
                confirmButtonText: yes_submit_now,
              },
              function (isConfirm) {
                if (isConfirm == true) {
                  var input = $("<input>")
                    .attr("type", "hidden")
                    .attr("name", "submit_test")
                    .val("submit_test");

                  $("#myform").append($(input));
                  $("#myform").submit();
                }
              }
            );
          } else {
            alert(data.msg);
          }
        } else {
          alert("Server Error");
        }
      },
      error: function (e) {
        console.log(e);
      },
    });
  
}
  }
  );


  $(".answer_given").on("click", function (q) {
    var checked_or_not = $(".answer_input:checked").val();
    if (checked_or_not) {
      console.log(checked_or_not);
    } else {
      q.preventDefault(false);

      swal({
        title: "No answer have been given yet",
      });
    }
  });



  $(document).ready(function(){
   // alert('load');
   
  });      

})(jQuery); 