0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.135.206.19


Current Path : /var/www/oasis/js/
Upload File :
Current File : /var/www/oasis/js/marksentryquestionwise.js

function callEnablemarksentryquestionwise() {
  $("#page_main_div").load(
    "../html_modules/marksentryquestionwise.html?v=1122",
    function () {
      document.getElementById("display_module_name").innerHTML =
        "Marks Entry (Question Wise)";
      document.getElementById("module_name_for_save").value =
        "Marks Entry (Question Wise)";
      getDefaultHeadFooterLinks("Marks Entry Coursewise(Questionwise)");
      $("#unit_row").hide();
      marksentrytwoteachloadNew();
    }
  );
}

function marksentrytwoteachloadNew() {
  $.blockUI({
    message:
      "<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
  });
  $.ajax({
    type: "POST",
    url: $host_url + "loadIAteachcodenew",
    //async: false,
    success: function (response) {
      var res = JSON.parse(response);
      var teachnameoptions = "";

      teachnameoptions = "<option value=''>---Select Teacher---</option>";

      for (var i = 0; i < res.data.length; i++) {
        teachnameoptions += `<option value='${res.data[i].fteachcode}'>${res.data[i].fteachcode} - ${res.data[i].fteachname}</option>`;
      }

      $("#teachname").html(teachnameoptions);
      $.unblockUI();
    },
  });
}

function marksentrytwoloadclassnamesnew() {
  var techcode = document.getElementById("teachname").value;
  if (techcode == "") {
    return;
  }
  $.blockUI({
    message:
      "<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
  });
  $.ajax({
    type: "POST",
    data: "&techcode=" + techcode,
    url: $host_url + "getIAclassnamesnew",
    success: function (response) {
      var res = JSON.parse(response);
      var classnameoption = "<option value=''>---Select Class Name---</option>";
      for (var i = 0; i < res.data.length; i++) {
        classnameoption += `<option value='${res.data[i].fclassid}'>${res.data[i].fclassname} - ${res.data[i].fclassid}</option>`;
      }
      $("#classnameoptions").html(classnameoption);
      $.unblockUI();
    },
  });
}

function getSubjectElementnew() {
  var teachcode = document.getElementById("teachname").value;
  var classid = document.getElementById("classnameoptions").value;
  let parameter = "&techcode=" + teachcode + "&classid=" + classid;
  if (teachcode == "") {
    return;
  }
  $.blockUI({
    message:
      "<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
  });
  $.ajax({
    method: "GET",
    url: $host_url + "getDegSemSubDetnew",
    data: parameter,
    success: function (res) {
      var response = JSON.parse(res);
      var sub_options = "";
      if (response.error_code == 0) {
        sub_options += `<option>---Select---</option>`;
        for (var i = 0; i < response.data.subelement.length; i++) {
          let subname_opt = response.data.subelement[i].subname;
          let subname = subname_opt.split(" ").join("_");
          sub_options += `<option value=${
            response.data.subelement[i].fsubcode + "*" + subname
          }>${response.data.subelement[i].fsubshort} - ${
            response.data.subelement[i].subname
          }</option>`;
        }
        $("#subElement").html(sub_options);
        $.unblockUI();
      } else {
        alert(response.data.msg);
        $.unblockUI();
        return;
      }
    },
  });
}

function getTestMaxQnnew() {
  var teachcode = document.getElementById("teachname").value;
  var classid = document.getElementById("classnameoptions").value;
  var subelement = document.getElementById("subElement").value;
  let splitSub = subelement.split("*");

  let parameter =
    "&teachname=" +
    teachcode +
    "&classid=" +
    classid +
    "&subelemnt=" +
    splitSub[0];

  if (teachcode == "") {
    return;
  }
  $.blockUI({
    message:
      "<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
  });
  $.ajax({
    method: "GET",
    url: $host_url + "getTestMaxQnnew",
    data: parameter,
    success: function (res) {
      var response = JSON.parse(res);
      console.log(response);

      var test_options = "";
      if (response.error_code == 0) {
        for (let i = 1; i <= response.data.sub.ftest; i++) {
          test_options += `<option value='Test ${i}'>Test ${i}</option>`;
        }
      }
      if (splitSub[1].toLowerCase() !== "cie") {
        $("#row_remarks").show();
      } else {
        $("#row_remarks").hide();
      }
      $("#testName").html(test_options);
      $("#remarks").val(response.data.remarks.fremarks);
      $("#txtmarks").val(response.data.sub.fvalmax);
      $("#txtmarks").attr("disabled", true);
      $.unblockUI();
    },
  });
}

function viewIAUnitwisenew() {
  var teachcode = document.getElementById("teachname").value;
  var classid = document.getElementById("classnameoptions").value;
  var subelement = document.getElementById("subElement").value;
  var txtmarks = document.getElementById("txtmarks").value;
  var testName = document.getElementById("testName").value;
  var fsort = document.getElementById("fsort").value;

  if (teachcode == "") {
    alert("Please select teacher");
    return;
  }

  if (classid == "") {
    alert("Please select class");
    return;
  }

  if (subelement == "") {
    alert("Please select Subject");
    return;
  }

  if (testName == "" || testName == null) {
    alert("Test can be Empty");
    return;
  }

  $.blockUI({
    message:
      "<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
  });

  let parameter =
    "teachcode=" +
    teachcode +
    "&classid=" +
    classid +
    "&subelement=" +
    subelement +
    "&txtmarks=" +
    txtmarks +
    "&testName=" +
    testName +
    "&fsort=" +
    fsort;

  $.ajax({
    method: "GET",
    url: $host_url + "viewIAQuestionWisewise",
    data: parameter,
    success: function (res) {
      var response = JSON.parse(res);
      console.log(response);
      if (response.error_code == 0) {
        $("#createview").html(response.data.html);
        var tdElements = document.querySelectorAll("#max_marks .column");
        i = 0;
        tdElements.forEach(function (tdElement) {
          var spanElement = tdElement.querySelector("span");
          if (spanElement) {
            var spanId = spanElement.id;
            let spanVal = document.getElementById(spanId).innerText;

            console.log(spanVal, spanId);
          }
          i++;
        });
        document.getElementById("createview").style.height = "500px";
        $.unblockUI();
      } else {
        alert(response.data.msg);
        $("#createview").html("");
        $.unblockUI();
        return;
      }
    },
  });
}

function frezstd(i, element) {
  var absents = document.getElementById("absent_" + i).checked;

  var a1 = $("#1amax").text();
  var b1 = $("#1bmax").text();
  var c1 = $("#1cmax").text();
  var d1 = $("#1dmax").text();
  var a2 = $("#2amax").text();
  var b2 = $("#2bmax").text();
  var c2 = $("#2cmax").text();
  var d2 = $("#2dmax").text();
  var a3 = $("#3amax").text();
  var b3 = $("#3bmax").text();
  var c3 = $("#3cmax").text();
  var d3 = $("#3dmax").text();
  var a4 = $("#4amax").text();
  var b4 = $("#4bmax").text();
  var c4 = $("#4cmax").text();
  var d4 = $("#4dmax").text();

  var mark1A = $("#mark1A_" + i).val();
  var mark1B = $("#mark1B_" + i).val();
  var mark1C = $("#mark1C_" + i).val();
  var mark1D = $("#mark1D_" + i).val();
  var mark2A = $("#mark2A_" + i).val();
  var mark2B = $("#mark2B_" + i).val();
  var mark2C = $("#mark2C_" + i).val();
  var mark2D = $("#mark2D_" + i).val();
  var mark3A = $("#mark3A_" + i).val();
  var mark3B = $("#mark3B_" + i).val();
  var mark3C = $("#mark3C_" + i).val();
  var mark3D = $("#mark3D_" + i).val();
  var mark4A = $("#mark4A_" + i).val();
  var mark4B = $("#mark4B_" + i).val();
  var mark4C = $("#mark4C_" + i).val();
  var mark4D = $("#mark4D_" + i).val();
  var total = $("#total_" + i).val();

  if (absents !== false) {
    if (
      mark1A !== "-1" ||
      mark1B !== "-1" ||
      mark1C !== "-1" ||
      mark1D !== "-1" ||
      mark2A !== "-1" ||
      mark2B !== "-1" ||
      mark2C !== "-1" ||
      mark2D !== "-1" ||
      mark3A !== "-1" ||
      mark3B !== "-1" ||
      mark3C !== "-1" ||
      mark3D !== "-1" ||
      mark4A !== "-1" ||
      mark4B !== "-1" ||
      mark4C !== "-1" ||
      mark4D !== "-1"
    ) {
      var alert = "Do you want make Absent";
      if (confirm(alert) == false) {
        $("#absent_" + i).prop("checked", false);
        return;
      } else {
        if (absents == true) {
          $("#mark1A_" + i).val("Ab");
          $("#mark1B_" + i).val("Ab");
          $("#mark1C_" + i).val("Ab");
          $("#mark1D_" + i).val("Ab");
          $("#mark2A_" + i).val("Ab");
          $("#mark2B_" + i).val("Ab");
          $("#mark2C_" + i).val("Ab");
          $("#mark2D_" + i).val("Ab");
          $("#mark3A_" + i).val("Ab");
          $("#mark3B_" + i).val("Ab");
          $("#mark3C_" + i).val("Ab");
          $("#mark3D_" + i).val("Ab");
          $("#mark4A_" + i).val("Ab");
          $("#mark4B_" + i).val("Ab");
          $("#mark4C_" + i).val("Ab");
          $("#mark4D_" + i).val("Ab");
          $("#total_" + i).val("Ab");
          $("#act_tot_" + i).val("Ab");
          $("#total1_" + i).val("Ab");
          $("#total2_" + i).val("Ab");
          $("#total3_" + i).val("Ab");
          $("#total4_" + i).val("Ab");

          $("#mark1A_" + i).prop("disabled", true);
          $("#mark1B_" + i).prop("disabled", true);
          $("#mark1C_" + i).prop("disabled", true);
          $("#mark1D_" + i).prop("disabled", true);
          $("#mark2A_" + i).prop("disabled", true);
          $("#mark2B_" + i).prop("disabled", true);
          $("#mark2C_" + i).prop("disabled", true);
          $("#mark2D_" + i).prop("disabled", true);
          $("#mark3A_" + i).prop("disabled", true);
          $("#mark3B_" + i).prop("disabled", true);
          $("#mark3C_" + i).prop("disabled", true);
          $("#mark3D_" + i).prop("disabled", true);
          $("#mark4A_" + i).prop("disabled", true);
          $("#mark4B_" + i).prop("disabled", true);
          $("#mark4C_" + i).prop("disabled", true);
          $("#mark4D_" + i).prop("disabled", true);
        }
      }
    } else {
      $("#mark1A_" + i).val("Ab");
      $("#mark1B_" + i).val("Ab");
      $("#mark1C_" + i).val("Ab");
      $("#mark1D_" + i).val("Ab");
      $("#mark2A_" + i).val("Ab");
      $("#mark2B_" + i).val("Ab");
      $("#mark2C_" + i).val("Ab");
      $("#mark2D_" + i).val("Ab");
      $("#mark3A_" + i).val("Ab");
      $("#mark3B_" + i).val("Ab");
      $("#mark3C_" + i).val("Ab");
      $("#mark3D_" + i).val("Ab");
      $("#mark4A_" + i).val("Ab");
      $("#mark4B_" + i).val("Ab");
      $("#mark4C_" + i).val("Ab");
      $("#mark4D_" + i).val("Ab");
      $("#total_" + i).val("Ab");
      $("#act_tot_" + i).val("Ab");
      $("#total1_" + i).val("Ab");
      $("#total2_" + i).val("Ab");
      $("#total3_" + i).val("Ab");
      $("#total4_" + i).val("Ab");
      $("#mark1A_" + i).prop("disabled", true);
      $("#mark1B_" + i).prop("disabled", true);
      $("#mark1C_" + i).prop("disabled", true);
      $("#mark1D_" + i).prop("disabled", true);
      $("#mark2A_" + i).prop("disabled", true);
      $("#mark2B_" + i).prop("disabled", true);
      $("#mark2C_" + i).prop("disabled", true);
      $("#mark2D_" + i).prop("disabled", true);
      $("#mark3A_" + i).prop("disabled", true);
      $("#mark3B_" + i).prop("disabled", true);
      $("#mark3C_" + i).prop("disabled", true);
      $("#mark3D_" + i).prop("disabled", true);
      $("#mark4A_" + i).prop("disabled", true);
      $("#mark4B_" + i).prop("disabled", true);
      $("#mark4C_" + i).prop("disabled", true);
      $("#mark4D_" + i).prop("disabled", true);
    }
  } else {
    $("#mark1A_" + i).val("-1");
    $("#mark1B_" + i).val("-1");
    $("#mark1C_" + i).val("-1");
    $("#mark1D_" + i).val("-1");
    $("#mark2A_" + i).val("-1");
    $("#mark2B_" + i).val("-1");
    $("#mark2C_" + i).val("-1");
    $("#mark2D_" + i).val("-1");
    $("#mark3A_" + i).val("-1");
    $("#mark3B_" + i).val("-1");
    $("#mark3C_" + i).val("-1");
    $("#mark3D_" + i).val("-1");
    $("#mark4A_" + i).val("-1");
    $("#mark4B_" + i).val("-1");
    $("#mark4C_" + i).val("-1");
    $("#mark4D_" + i).val("-1");
    $("#total_" + i).val("0");
    $("#act_tot_" + i).val("0");
    $("#total1_" + i).val("0");
    $("#total2_" + i).val("0");
    $("#total3_" + i).val("0");
    $("#total4_" + i).val("0");
    $("#mark1A_" + i).prop("disabled", false);
    $("#mark1B_" + i).prop("disabled", false);
    $("#mark1C_" + i).prop("disabled", false);
    $("#mark1D_" + i).prop("disabled", false);
    $("#mark2A_" + i).prop("disabled", false);
    $("#mark2B_" + i).prop("disabled", false);
    $("#mark2C_" + i).prop("disabled", false);
    $("#mark2D_" + i).prop("disabled", false);
    $("#mark3A_" + i).prop("disabled", false);
    $("#mark3B_" + i).prop("disabled", false);
    $("#mark3C_" + i).prop("disabled", false);
    $("#mark3D_" + i).prop("disabled", false);
    $("#mark4A_" + i).prop("disabled", false);
    $("#mark4B_" + i).prop("disabled", false);
    $("#mark4C_" + i).prop("disabled", false);
    $("#mark4D_" + i).prop("disabled", false);
  }

  if (a1 == 0) {
    $("#mark1A_" + i).prop("disabled", true);
  }
  if (b1 == 0) {
    $("#mark1B_" + i).prop("disabled", true);
  }
  if (c1 == 0) {
    $("#mark1C_" + i).prop("disabled", true);
  }
  if (d1 == 0) {
    $("#mark1D_" + i).prop("disabled", true);
  }
  if (a2 == 0) {
    $("#mark2A_" + i).prop("disabled", true);
  }
  if (b2 == 0) {
    $("#mark2B_" + i).prop("disabled", true);
  }
  if (c2 == 0) {
    $("#mark2C_" + i).prop("disabled", true);
  }
  if (d2 == 0) {
    $("#mark2D_" + i).prop("disabled", true);
  }
  if (a3 == 0) {
    $("#mark3A_" + i).prop("disabled", true);
  }
  if (b3 == 0) {
    $("#mark3B_" + i).prop("disabled", true);
  }
  if (c3 == 0) {
    $("#mark3C_" + i).prop("disabled", true);
  }
  if (d3 == 0) {
    $("#mark3D_" + i).prop("disabled", true);
  }
  if (a4 == 0) {
    $("#mark4A_" + i).prop("disabled", true);
  }
  if (b4 == 0) {
    $("#mark4B_" + i).prop("disabled", true);
  }
  if (c4 == 0) {
    $("#mark4C_" + i).prop("disabled", true);
  }
  if (d4 == 0) {
    $("#mark4D_" + i).prop("disabled", true);
  }
}

function saveIAEntryQuestionwise() {
  var techcode = document.getElementById("teachname").value;
  var classid = document.getElementById("classnameoptions").value;
  var subelement = document.getElementById("subElement").value;
  var testName = document.getElementById("testName").value;
  var remarks = document.getElementById("remarks").value;

  if (techcode == "") {
    alert("Please select teacher");
    return;
  }

  if (classid == "") {
    alert("Please select class");
    return;
  }

  if (subelement == "") {
    alert("Please select Subject");
    return;
  }

  if (testName == "" || testName == null) {
    alert("Test cannot be Empty");
    return;
  }

  $.blockUI({
    message:
      "<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
  });

  let split = subelement.split("*");
  subject = split[1];

  if (subject.toLowerCase() === "cie") {
    var table = document.getElementById("tabledata");
    var data = [];
    console.log(table);
    let k = 1;
    for (var i = 3; i < table.rows.length; i++) {
      var usn = table.rows[i].cells[1].textContent;
      var fname = table.rows[i].cells[2].textContent;
      var absents = table.rows[i].querySelector("#absent_" + k).checked;
      console.log(absents);
      if (absents == true) {
        var absent = "T";
      } else {
        var absent = "F";
      }

      var marks1A = table.rows[i].querySelector(".mark1A_" + k).value;
      if (marks1A == "") {
        marks1A = "-1";
      }
      var marks1B = table.rows[i].querySelector(".mark1B_" + k).value;
      if (marks1B == "") {
        marks1B = "-1";
      }
      var marks1C = table.rows[i].querySelector(".mark1C_" + k).value;
      if (marks1C == "") {
        marks1C = "-1";
      }
      var marks1D = table.rows[i].querySelector(".mark1D_" + k).value;
      if (marks1D == "") {
        marks1D = "-1";
      }
      var total1 = table.rows[i].querySelector(".total1_" + k).value;
      if (total1 == "") {
        total1 = "-1";
      }

      var marks2A = table.rows[i].querySelector(".mark2A_" + k).value;
      if (marks2A == "") {
        marks2A = "-1";
      }
      var marks2B = table.rows[i].querySelector(".mark2B_" + k).value;
      if (marks2B == "") {
        marks2B = "-1";
      }
      var marks2C = table.rows[i].querySelector(".mark2C_" + k).value;
      if (marks2C == "") {
        marks2C = "-1";
      }
      var marks2D = table.rows[i].querySelector(".mark2D_" + k).value;
      if (marks2D == "") {
        marks2D = "-1";
      }
      var total2 = table.rows[i].querySelector(".total2_" + k).value;
      if (total2 == "") {
        total2 = "-1";
      }

      var marks3A = table.rows[i].querySelector(".mark3A_" + k).value;
      if (marks3A == "") {
        marks3A = "-1";
      }
      var marks3B = table.rows[i].querySelector(".mark3B_" + k).value;
      if (marks3B == "") {
        marks3B = "-1";
      }
      var marks3C = table.rows[i].querySelector(".mark3C_" + k).value;
      if (marks3C == "") {
        marks3C = "-1";
      }
      var marks3D = table.rows[i].querySelector(".mark3D_" + k).value;
      if (marks3D == "") {
        marks3D = "-1";
      }
      var total3 = table.rows[i].querySelector(".total3_" + k).value;
      if (total3 == "") {
        total3 = "-1";
      }

      var marks4A = table.rows[i].querySelector(".mark4A_" + k).value;
      if (marks4A == "") {
        marks4A = "-1";
      }
      var marks4B = table.rows[i].querySelector(".mark4B_" + k).value;
      if (marks4B == "") {
        marks4B = "-1";
      }
      var marks4C = table.rows[i].querySelector(".mark4C_" + k).value;
      if (marks4C == "") {
        marks4C = "-1";
      }
      var marks4D = table.rows[i].querySelector(".mark4D_" + k).value;
      if (marks4D == "") {
        marks4D = "-1";
      }
      var total4 = table.rows[i].querySelector(".total4_" + k).value;
      if (total4 == "") {
        total4 = "-1";
      }

      var total = table.rows[i].querySelector(".total_" + k).value;
      if (total == "") {
        total = "-1";
      }
      var actTot = table.rows[i].querySelector(".act_tot_" + k).value;
      if (actTot == "") {
        actTot = "-1";
      }

      var rowData = {
        fregno: usn,
        fname: fname,
        absent: absent,
        marks1A: marks1A,
        marks1B: marks1B,
        marks1C: marks1C,
        marks1D: marks1D,
        marks2A: marks2A,
        marks2B: marks2B,
        marks2C: marks2C,
        marks2D: marks2D,
        marks3A: marks3A,
        marks3B: marks3B,
        marks3C: marks3C,
        marks3D: marks3D,
        marks4A: marks4A,
        marks4B: marks4B,
        marks4C: marks4C,
        marks4D: marks4D,
        total1: total1,
        total2: total2,
        total3: total3,
        total4: total4,
        acttot: actTot,
        total: total,
      };
      data.push(rowData);
      k++;
    }
  } else {
    var table = document.getElementById("tabledata");
    var data = [];
    console.log(table);
    let k = 1;
    for (var i = 3; i < table.rows.length; i++) {
      var usn = table.rows[i].cells[1].textContent;
      var fname = table.rows[i].cells[2].textContent;
      var absents = table.rows[i].querySelector("#coabsent_" + k).checked;
      console.log(absents);
      if (absents == true) {
        var absent = "T";
      } else {
        var absent = "F";
      }

      var marks1A = table.rows[i].querySelector(".CO1_" + k).value;
      if (marks1A == "") {
        marks1A = "-1";
      }
      var marks1B = table.rows[i].querySelector(".CO2_" + k).value;
      if (marks1B == "") {
        marks1B = "-1";
      }
      var marks1C = table.rows[i].querySelector(".CO3_" + k).value;
      if (marks1C == "") {
        marks1C = "-1";
      }
      var marks1D = table.rows[i].querySelector(".CO4_" + k).value;
      if (marks1D == "") {
        marks1D = "-1";
      }
      var marks1E = table.rows[i].querySelector(".CO5_" + k).value;
      if (marks1E == "") {
        marks1E = "-1";
      }
      var marks1F = table.rows[i].querySelector(".CO6_" + k).value;
      if (marks1F == "") {
        marks1F = "-1";
      }
      var total = table.rows[i].querySelector(".COTotal_" + k).value;
      if (total == "") {
        total = "-1";
      }

      var rowData = {
        fregno: usn,
        fname: fname,
        absent: absent,
        marks1A: marks1A,
        marks1B: marks1B,
        marks1C: marks1C,
        marks1D: marks1D,
        marks1E: marks1E,
        marks1F: marks1F,
        total: total,
      };
      data.push(rowData);
      k++;
    }
  }

  $.ajax({
    type: "POST",
    url: $host_url + "saveIAEntryQuestionwise",
    data:
      "techcode=" +
      techcode +
      "&classid=" +
      classid +
      "&subelement=" +
      subelement +
      "&testName=" +
      testName +
      "&remarks=" +
      remarks +
      `&subarry=` +
      JSON.stringify(data),
    success: function (res) {
      let response = JSON.parse(res);
      if (response.error_code === 0) {
        alert(response.data);
        $.unblockUI();
      } else {
        alert(response.data);
        $.unblockUI();
        return;
      }
    },
  });
  //   $.unblockUI();
  console.log(data, "data");
}

function getTotal(index) {
  let marks1A = document.getElementById("mark1A_" + index).value;
  let marks1B = document.getElementById("mark1B_" + index).value;
  let marks1C = document.getElementById("mark1C_" + index).value;
  let marks1D = document.getElementById("mark1D_" + index).value;

  let marks2A = document.getElementById("mark2A_" + index).value;
  let marks2B = document.getElementById("mark2B_" + index).value;
  let marks2C = document.getElementById("mark2C_" + index).value;
  let marks2D = document.getElementById("mark2D_" + index).value;

  let marks3A = document.getElementById("mark3A_" + index).value;
  let marks3B = document.getElementById("mark3B_" + index).value;
  let marks3C = document.getElementById("mark3C_" + index).value;
  let marks3D = document.getElementById("mark3D_" + index).value;

  let marks4A = document.getElementById("mark4A_" + index).value;
  let marks4B = document.getElementById("mark4B_" + index).value;
  let marks4C = document.getElementById("mark4C_" + index).value;
  let marks4D = document.getElementById("mark4D_" + index).value;
  let total = 0;

  if (marks1A === "" || marks1A < 0 || marks1A == "-") {
    marks1A = 0;
  }
  if (marks1B === "" || marks1B < 0 || marks1B == "-") {
    marks1B = 0;
  }
  if (marks1C === "" || marks1C < 0 || marks1C == "-") {
    marks1C = 0;
  }
  if (marks1D === "" || marks1D < 0 || marks1D == "-") {
    marks1D = 0;
  }
  if (marks2A === "" || marks2A < 0 || marks2A == "-") {
    marks2A = 0;
  }
  if (marks2B === "" || marks2B < 0 || marks2B == "-") {
    marks2B = 0;
  }
  if (marks2C === "" || marks2C < 0 || marks2C == "-") {
    marks2C = 0;
  }
  if (marks2D === "" || marks2D < 0 || marks2D == "-") {
    marks2D = 0;
  }
  if (marks3A === "" || marks3A < 0 || marks3A == "-") {
    marks3A = 0;
  }
  if (marks3B === "" || marks3B < 0 || marks3B == "-") {
    marks3B = 0;
  }
  if (marks3C === "" || marks3C < 0 || marks3C == "-") {
    marks3C = 0;
  }
  if (marks3D === "" || marks3D < 0 || marks3D == "-") {
    marks3D = 0;
  }
  if (marks4A === "" || marks4A < 0 || marks4A == "-") {
    marks4A = 0;
  }
  if (marks4B === "" || marks4B < 0 || marks4B == "-") {
    marks4B = 0;
  }
  if (marks4C === "" || marks4C < 0 || marks4C == "-") {
    marks4C = 0;
  }
  if (marks4D === "" || marks4D < 0 || marks4D == "-") {
    marks4D = 0;
  }

  let tot1 =
    parseFloat(marks1A) +
    parseFloat(marks1B) +
    parseFloat(marks1C) +
    parseFloat(marks1D);

  let tot2 =
    parseFloat(marks2A) +
    parseFloat(marks2B) +
    parseFloat(marks2C) +
    parseFloat(marks2D);

  let tot3 =
    parseFloat(marks3A) +
    parseFloat(marks3B) +
    parseFloat(marks3C) +
    parseFloat(marks3D);

  let tot4 =
    parseFloat(marks4A) +
    parseFloat(marks4B) +
    parseFloat(marks4C) +
    parseFloat(marks4D);

  $("#total1_" + index).val(tot1);
  $("#total2_" + index).val(tot2);
  $("#total3_" + index).val(tot3);
  $("#total4_" + index).val(tot4);

  let actTot = 0;

  let tot12 = 0;
  let tot34 = 0;
  if (tot1 >= tot2) {
    tot12 = tot1;
  } else {
    tot12 = tot2;
  }

  if (tot3 >= tot4) {
    tot34 = tot3;
  } else {
    tot34 = tot4;
  }

  actTot = tot12 + tot34;

  $("#act_tot_" + index).val(actTot);

  total +=
    parseFloat(marks1A) +
    parseFloat(marks1B) +
    parseFloat(marks1C) +
    parseFloat(marks1D) +
    parseFloat(marks2A) +
    parseFloat(marks2B) +
    parseFloat(marks2C) +
    parseFloat(marks2D) +
    parseFloat(marks3A) +
    parseFloat(marks3B) +
    parseFloat(marks3C) +
    parseFloat(marks3D) +
    parseFloat(marks4A) +
    parseFloat(marks4B) +
    parseFloat(marks4C) +
    parseFloat(marks4D);

  $("#total_" + index).val(total);
}

let scrollLeftPosition = 0;

function checkValidMarks(ids, index, qnno, element) {
  getTotal(index);
  let txtmarks = $("#txtmarks").val();
  // let total = $("#total_" + index).val();
  let total = $("#act_tot_" + index).val();

  let A1max = $("#1amax").text();
  let B1max = $("#1bmax").text();
  let C1max = $("#1cmax").text();
  let D1max = $("#1dmax").text();

  let A2max = $("#2amax").text();
  let B2max = $("#2bmax").text();
  let C2max = $("#2cmax").text();
  let D2max = $("#2dmax").text();

  let A3max = $("#3amax").text();
  let B3max = $("#3bmax").text();
  let C3max = $("#3cmax").text();
  let D3max = $("#3dmax").text();

  let A4max = $("#4amax").text();
  let B4max = $("#4bmax").text();
  let C4max = $("#4cmax").text();
  let D4max = $("#4dmax").text();

  let marks1A = document.getElementById("mark1A_" + index).value;
  let marks1B = document.getElementById("mark1B_" + index).value;
  let marks1C = document.getElementById("mark1C_" + index).value;
  let marks1D = document.getElementById("mark1D_" + index).value;

  let marks2A = document.getElementById("mark2A_" + index).value;
  let marks2B = document.getElementById("mark2B_" + index).value;
  let marks2C = document.getElementById("mark2C_" + index).value;
  let marks2D = document.getElementById("mark2D_" + index).value;

  let marks3A = document.getElementById("mark3A_" + index).value;
  let marks3B = document.getElementById("mark3B_" + index).value;
  let marks3C = document.getElementById("mark3C_" + index).value;
  let marks3D = document.getElementById("mark3D_" + index).value;

  let marks4A = document.getElementById("mark4A_" + index).value;
  let marks4B = document.getElementById("mark4B_" + index).value;
  let marks4C = document.getElementById("mark4C_" + index).value;
  let marks4D = document.getElementById("mark4D_" + index).value;

  console.log(
    marks1A > parseFloat(A1max),
    parseFloat(marks1A),
    parseFloat(A1max)
  );

  if (parseFloat(marks1A) > parseFloat(A1max)) {
    alert("Maximum marks reached");
    document.getElementById("mark1A_" + index).value = "";
    document.getElementById("mark1A_" + index).focus();
    return;
  }
  if (parseFloat(marks1B) > parseFloat(B1max)) {
    alert("Maximum marks reached");
    document.getElementById("mark1B_" + index).value = "";
    document.getElementById("mark1B_" + index).focus();
    return;
  }
  if (parseFloat(marks1C) > parseFloat(C1max)) {
    alert("Maximum marks reached");
    document.getElementById("mark1C_" + index).value = "";
    document.getElementById("mark1C_" + index).focus();
    return;
  }
  if (parseFloat(marks1D) > parseFloat(D1max)) {
    alert("Maximum marks reached");
    document.getElementById("mark1D_" + index).value = "";
    document.getElementById("mark1D_" + index).focus();
    return;
  }
  if (parseFloat(marks2A) > parseFloat(A2max)) {
    alert("Maximum marks reached");
    document.getElementById("mark2A_" + index).value = "";
    document.getElementById("mark2A_" + index).focus();
    return;
  }
  if (parseFloat(marks2B) > parseFloat(B2max)) {
    alert("Maximum marks reached");
    document.getElementById("mark2B_" + index).value = "";
    document.getElementById("mark2B_" + index).focus();
    return;
  }
  if (parseFloat(marks2C) > parseFloat(C2max)) {
    alert("Maximum marks reached");
    document.getElementById("mark2C_" + index).value = "";
    document.getElementById("mark2C_" + index).focus();
    return;
  }
  if (parseFloat(marks2D) > parseFloat(D2max)) {
    alert("Maximum marks reached");
    document.getElementById("mark2D_" + index).value = "";
    document.getElementById("mark2D_" + index).focus();
    return;
  }
  if (parseFloat(marks3A) > parseFloat(A3max)) {
    alert("Maximum marks reached");
    document.getElementById("mark3A_" + index).value = "";
    document.getElementById("mark3A_" + index).focus();
    return;
  }
  if (parseFloat(marks3B) > parseFloat(B3max)) {
    alert("Maximum marks reached");
    document.getElementById("mark3B_" + index).value = "";
    document.getElementById("mark3B_" + index).focus();
    return;
  }
  if (parseFloat(marks3C) > parseFloat(C3max)) {
    alert("Maximum marks reached");
    document.getElementById("mark3C_" + index).value = "";
    document.getElementById("mark3C_" + index).focus();
    return;
  }
  if (parseFloat(marks3D) > parseFloat(D3max)) {
    alert("Maximum marks reached");
    document.getElementById("mark3D_" + index).value = "";
    document.getElementById("mark3D_" + index).focus();
    return;
  }
  if (parseFloat(marks4A) > parseFloat(A4max)) {
    alert("Maximum marks reached");
    document.getElementById("mark4A_" + index).value = "";
    document.getElementById("mark4A_" + index).focus();
    return;
  }
  if (parseFloat(marks4B) > parseFloat(B4max)) {
    alert("Maximum marks reached");
    document.getElementById("mark4B_" + index).value = "";
    document.getElementById("mark4B_" + index).focus();
    return;
  }
  if (parseFloat(marks4C) > parseFloat(C4max)) {
    alert("Maximum marks reached");
    document.getElementById("mark4C_" + index).value = "";
    document.getElementById("mark4C_" + index).focus();
    return;
  }
  if (parseFloat(marks4D) > parseFloat(D4max)) {
    alert("Maximum marks reached");
    document.getElementById("mark4D_" + index).value = "";
    document.getElementById("mark4D_" + index).focus();
    return;
  }

  if (qnno == 1) {
    let totalA = 0;
    totalA +=
      parseFloat(marks1A) +
      parseFloat(marks1B) +
      parseFloat(marks1C) +
      parseFloat(marks1D);

    if (totalA > 25) {
      alert("Maximum marks for 1st question has reached");
      document.getElementById(ids + index).value = "";
      document.getElementById(ids + index).focus();
      return;
    }
  }

  if (qnno == 2) {
    let totalB = 0;
    totalB +=
      parseFloat(marks2A) +
      parseFloat(marks2B) +
      parseFloat(marks2C) +
      parseFloat(marks2D);

    if (totalB > 25) {
      alert("Maximum marks for 2nd question has reached");
      document.getElementById(ids + index).value = "";
      document.getElementById(ids + index).focus();
      return;
    }
  }

  if (qnno == 3) {
    let totalC = 0;
    totalC +=
      parseFloat(marks3A) +
      parseFloat(marks3B) +
      parseFloat(marks3C) +
      parseFloat(marks3D);

    if (totalC > 25) {
      alert("Maximum marks for 3rd question has reached");
      document.getElementById(ids + index).value = "";
      document.getElementById(ids + index).focus();
      return;
    }
  }

  if (qnno == 4) {
    let totalD = 0;
    totalD +=
      parseFloat(marks4A) +
      parseFloat(marks4B) +
      parseFloat(marks4C) +
      parseFloat(marks4D);

    if (totalD > 25) {
      alert("Maximum marks for 4th question has reached");
      document.getElementById(ids + index).value = "";
      document.getElementById(ids + index).focus();
      return;
    }
  }

  if (parseFloat(total) > parseFloat(txtmarks)) {
    alert("Maximum marks reached");
    document.getElementById(ids + index).value = "";
    $("#total_" + index).val("");
    document.getElementById(ids + index).focus();
    return;
  }

  if (document.getElementById(ids + index).value < -2) {
    alert("Enter valid marks");
    document.getElementById(ids + index).focus();
    document.getElementById(ids + index).value = "";
    return;
  }
}

function generateQuestionWiseIAReport() {
  console.log("anitaaa");
  // document.getElementById("batch_popup_div").show();
  var win_width = window.screen.width;
  $("#batch_dialog").dialog("open");
  $("#batch_dialog").data("width.dialog", 400);
  $("#batch_dialog").data("position.dialog", [(win_width - 400) / 2, 90]);
  $("#ui-dialog-title-batch_dialog").html("Select Report Type");
  var path = "../html_modules/qnmarksreportpopup.html";
  $("#batch_dialog").load(path, function () {});
  // $("#qnreportpopup").show();
}
function reportExcelAndPdf() {
  // console.log("axcvnsb");
  var teachcode = document.getElementById("teachname").value;
  var classid = document.getElementById("classnameoptions").value;
  var subelement = document.getElementById("subElement").value;
  var txtmarks = document.getElementById("txtmarks").value;
  var testName = document.getElementById("testName").value;
  var report = document.getElementById("rtype").value;
  var stype = document.getElementById("stype").value;
  console.log(report);
  if(stype == 'Summary')
  {
    
  }else
  {

    if (report == "pdf") {
      if (teachcode == "") {
        alert("Please select teacher");
        return;
      }

      if (classid == "") {
        alert("Please select class");
        return;
      }

      if (subelement == "") {
        alert("Please select Subject");
        return;
      }

      if (testName == "" || testName == null) {
        alert("Test cannot be Empty");
        return;
      }

      

      window.open(
        $host_url +
          "generateQuestionWiseIAReport" +
          "&teachcode=" +
          teachcode +
          "&classid=" +
          classid +
          "&subelement=" +
          subelement +
          "&txtmarks=" +
          txtmarks +
          "&testName=" +
          testName
      );
    }

    if (report == "excel") {
      if (teachcode == "") {
        alert("Please select teacher");
        return;
      }

      if (classid == "") {
        alert("Please select class");
        return;
      }

      if (subelement == "") {
        alert("Please select Subject");
        return;
      }

      if (testName == "" || testName == null) {
        alert("Test cannot be Empty");
        return;
      }
      window.open(
        $host_url +
          "getIaMarksQnWiseReportExcel" +
          "&teachcode=" +
          teachcode +
          "&classid=" +
          classid +
          "&subelement=" +
          subelement +
          "&txtmarks=" +
          txtmarks +
          "&testName=" +
          testName
      );
    }

    
  }
}

function isNumber(evt) {
  console.log(evt);
  evt = evt ? evt : window.evt;
  var charCode = evt.which ? evt.which : evt.keyCode;
  if (charCode > 31 && (charCode < 45 || charCode > 57)) {
    return false;
  }
  return true;
}

function saveQnMarksDetails() {
  let testName = document.getElementById("testName").value;
  var classid = document.getElementById("classnameoptions").value;
  var subElement = document.getElementById("subElement").value;

  let rowQnno = document.getElementById("qnno_row");
  let cells = rowQnno.getElementsByTagName("td");
  let columnLength = cells.length;

  let rowmarks = document
    .getElementById("marks_row")
    .getElementsByTagName("input");

  let marks_data_id = [];
  for (var z = 0; z < rowmarks.length; z++) {
    marks_data_id.push(rowmarks[z].id);
  }

  let corow = document.getElementById("co_row").getElementsByTagName("input");
  let corowid = [];
  for (var z = 0; z < corow.length; z++) {
    corowid.push(corow[z].id);
  }

  let porow = document.getElementById("po_row").getElementsByTagName("input");
  let porowid = [];
  for (var z = 0; z < porow.length; z++) {
    porowid.push(porow[z].id);
  }

  let psorow = document.getElementById("pso_row").getElementsByTagName("input");
  let psorowid = [];
  for (var z = 0; z < psorow.length; z++) {
    psorowid.push(psorow[z].id);
  }

  let data = [];

  let total = 0;
  for (var i = 0; i < columnLength; i++) {
    let cellVal = rowQnno.getElementsByTagName("td")[i].innerText;
    var marksVal = parseFloat(document.getElementById(marks_data_id[i]).value);
    // if (document.getElementById(marks_data_id[i]).value === "") {
    //   alert("Enter valid marks");
    //   document.getElementById(marks_data_id[i]).focus();
    //   return;
    // }
    var coVal = parseFloat(document.getElementById(corowid[i]).value);
    var poVal = parseFloat(document.getElementById(porowid[i]).value);
    var psoVal = parseFloat(document.getElementById(psorowid[i]).value);
    total += marksVal;
    let values = {};
    values.qnno = cellVal;
    values.marks = marksVal == null || marksVal == "" ? -1 : marksVal;
    values.co = coVal;
    values.po = poVal;
    values.pso = psoVal;
    data.push(values);
  }

  $.ajax({
    type: "POST",
    url: $host_url + "saveMarksDetailsEntry",
    data:
      "testName=" +
      testName +
      "&classId=" +
      classid +
      "&subelement=" +
      subElement +
      "&data=" +
      JSON.stringify(data),
    success: function (res) {
      let response = JSON.parse(res);
      console.log(response);
      if (response.error_code === 0) {
        viewIAUnitwisenew();
        $("#marksDetails").hide();
        $("#comarks").hide();
      } else {
        alert(res.data);
        return;
      }
    },
  });
}

function showMarksScreen() {
  var techcode = document.getElementById("teachname").value;
  var classid = document.getElementById("classnameoptions").value;
  var subelement = document.getElementById("subElement").value;
  var testName = document.getElementById("testName").value;
  var subname = subelement.split("*");
  var subj = subname[1];
  if (techcode == "") {
    alert("Please select teacher");
    return;
  }

  if (classid == "") {
    alert("Please select class");
    return;
  }

  if (subelement == "") {
    alert("Please select Subject");
    return;
  }

  if (testName == "" || testName == null) {
    alert("Test cannot be Empty");
    return;
  }
  $.blockUI({
    message:
      "<h1 class='h1' style='font-size:12px'><img src='img/ajax-loader.gif' border='0'></h1>",
  });
  $.ajax({
    type: "POST",
    url: $host_url + "editQnMarksDetails",
    data:
      "&testName=" +
      testName +
      "&classid=" +
      classid +
      "&subject=" +
      subelement,
    success: function (res) {
      let response = JSON.parse(res);
      if (response.error_code === 0) {
        if (subj == "CIE") {
          for (var i = 0; i < response.data.length; i++) {
            document.getElementById(response.data[i].FQNNO).value =
              response.data[i].FMARKS;
            document.getElementById("co" + response.data[i].FQNNO).value =
              response.data[i].FCO;
            document.getElementById("po" + response.data[i].FQNNO).value =
              response.data[i].FPO;
            document.getElementById("pso" + response.data[i].FQNNO).value =
              response.data[i].FPSO;
          }
          $.unblockUI();
          $("#createview").hide();
          $("#marksDetails").show();
          $("#comarks").hide();
        } else {
          $.unblockUI();
          $("#createview").hide();
          $("#comarks").show();
          $("#marksDetails").hide();
          for (var i = 0; i < response.data.length; i++) {
            document.getElementById(response.data[i].FQNNO).value =
              response.data[i].FMARKS;
          }
        }
      }
    },
  });
}

function getMarksTotal(id) {
  let A1 = $("#1A").val();
  let B1 = $("#1B").val();
  let C1 = $("#1C").val();
  let D1 = $("#1D").val();
  let A2 = $("#2A").val();
  let B2 = $("#2B").val();
  let C2 = $("#2C").val();
  let D2 = $("#2D").val();
  let A3 = $("#3A").val();
  let B3 = $("#3B").val();
  let C3 = $("#3C").val();
  let D3 = $("#3D").val();
  let A4 = $("#4A").val();
  let B4 = $("#4B").val();
  let C4 = $("#4C").val();
  let D4 = $("#4D").val();

  if (A1 === "") {
    A1 = 0;
  }
  if (B1 === "") {
    B1 = 0;
  }
  if (C1 === "") {
    C1 = 0;
  }
  if (D1 === "") {
    D1 = 0;
  }
  if (A2 === "") {
    A2 = 0;
  }
  if (B2 === "") {
    B2 = 0;
  }
  if (C2 === "") {
    C2 = 0;
  }
  if (D2 === "") {
    D2 = 0;
  }
  if (A3 === "") {
    A3 = 0;
  }
  if (B3 === "") {
    B3 = 0;
  }
  if (C3 === "") {
    C3 = 0;
  }
  if (D3 === "") {
    D3 = 0;
  }
  if (A4 === "") {
    A4 = 0;
  }
  if (B4 === "") {
    B4 = 0;
  }
  if (C4 === "") {
    C4 = 0;
  }
  if (D4 === "") {
    D4 = 0;
  }

  if (parseFloat(A1) + parseFloat(B1) + parseFloat(C1) + parseFloat(D1) > 25) {
    alert("Maximum marks reached");
    document.getElementById(id).value = "";
    document.getElementById(id).focus();
    return;
  }
  if (parseFloat(A2) + parseFloat(B2) + parseFloat(C2) + parseFloat(D2) > 25) {
    alert("Maximum marks reached");
    document.getElementById(id).value = "";
    document.getElementById(id).focus();
    return;
  }
  if (parseFloat(A3) + parseFloat(B3) + parseFloat(C3) + parseFloat(D3) > 25) {
    alert("Maximum marks reached");
    document.getElementById(id).value = "";
    document.getElementById(id).focus();
    return;
  }
  if (parseFloat(A4) + parseFloat(B4) + parseFloat(C4) + parseFloat(D4) > 25) {
    alert("Maximum marks reached");
    document.getElementById(id).value = "";
    document.getElementById(id).focus();
    return;
  }

  console.log(A1, B1, "dssd");
  let total =
    parseFloat(A1) +
    parseFloat(B1) +
    parseFloat(C1) +
    parseFloat(D1) +
    parseFloat(A2) +
    parseFloat(B2) +
    parseFloat(C2) +
    parseFloat(D2) +
    parseFloat(A3) +
    parseFloat(B3) +
    parseFloat(C3) +
    parseFloat(D3) +
    parseFloat(A4) +
    parseFloat(B4) +
    parseFloat(C4) +
    parseFloat(D4);
  $("#totalMarks").val(total);
}

function checkCOAbsent(index) {
  var coAbsent = document.getElementById("coabsent_" + index).checked;
  var cototal = document.getElementById("COTotal_" + index);

  var co1 = document.getElementById("CO1_" + index);
  var co2 = document.getElementById("CO2_" + index);
  var co3 = document.getElementById("CO3_" + index);
  var co4 = document.getElementById("CO4_" + index);
  var co5 = document.getElementById("CO5_" + index);
  var co6 = document.getElementById("CO6_" + index);

  if (coAbsent) {
    if (
      co1.value !== "-1" ||
      co2.value !== "-1" ||
      co3.value !== "-1" ||
      co4.value !== "-1" ||
      co5.value !== "-1" ||
      co6.value !== "-1"
    ) {
      if (confirm("Do you want make Absent")) {
        co1.value = "Ab";
        co1.disabled = true;
        co2.value = "Ab";
        co2.disabled = true;
        co3.value = "Ab";
        co3.disabled = true;
        co4.value = "Ab";
        co4.disabled = true;
        co5.value = "Ab";
        co5.disabled = true;
        co6.value = "Ab";
        co6.disabled = true;
        cototal.value = "Ab";
      } else {
        $("#coabsent_" + index).prop("checked", false);
        return;
      }
    } else {
      co1.value = "Ab";
      co1.disabled = true;
      co2.value = "Ab";
      co2.disabled = true;
      co3.value = "Ab";
      co3.disabled = true;
      co4.value = "Ab";
      co4.disabled = true;
      co5.value = "Ab";
      co5.disabled = true;
      co6.value = "Ab";
      co6.disabled = true;
      cototal.value = "Ab";
    }
  } else {
    co1.value = "-1";
    co1.disabled = false;
    co2.value = "-1";
    co2.disabled = false;
    co3.value = "-1";
    co3.disabled = false;
    co4.value = "-1";
    co4.disabled = false;
    co5.value = "-1";
    co5.disabled = false;
    co6.value = "-1";
    co6.disabled = false;
    cototal.value = "0";
  }
}

function searchRegCode() {
  var input, filter, table, tr, td, i, txtValue;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("tabledata");
  tr = table.getElementsByTagName("tr");
  for (i = 0; i < tr.length; i++) {
    // td1 = tr[i].getElementsByTagName("td")[3];
    td2 = tr[i].getElementsByTagName("td")[2];
    if (td2) {
      txtValue =
        // (td1.textContent || td1.innerText) &&
        td2.textContent || td2.innerText;
      if (txtValue.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }
  }
}

function checkValidCO(id, index) {
  let marksCO1 = document.getElementById("CO1_" + index).value;
  let marksCO2 = document.getElementById("CO2_" + index).value;
  let marksCO3 = document.getElementById("CO3_" + index).value;
  let marksCO4 = document.getElementById("CO4_" + index).value;
  let marksCO5 = document.getElementById("CO5_" + index).value;
  let marksCO6 = document.getElementById("CO6_" + index).value;

  let co1max = $("#1amax").text();
  let co2max = $("#1bmax").text();
  let co3max = $("#1cmax").text();
  let co4max = $("#1dmax").text();
  let co5max = $("#1emax").text();
  let co6max = $("#1fmax").text();

  if (marksCO1 === "" || marksCO1 < 0 || marksCO1 == "-") {
    marksCO1 = 0;
  }
  if (marksCO2 === "" || marksCO2 < 0 || marksCO2 == "-") {
    marksCO2 = 0;
  }
  if (marksCO3 === "" || marksCO3 < 0 || marksCO3 == "-") {
    marksCO3 = 0;
  }
  if (marksCO4 === "" || marksCO4 < 0 || marksCO4 == "-") {
    marksCO4 = 0;
  }
  if (marksCO5 === "" || marksCO5 < 0 || marksCO5 == "-") {
    marksCO5 = 0;
  }
  if (marksCO6 === "" || marksCO6 < 0 || marksCO6 == "-") {
    marksCO6 = 0;
  }

  if (parseFloat(marksCO1) > parseFloat(co1max)) {
    alert("Maximum marks reached");
    document.getElementById("CO1_" + index).value = "";
    document.getElementById("CO1_" + index).focus();
    return;
  }
  if (parseFloat(marksCO2) > parseFloat(co2max)) {
    alert("Maximum marks reached");
    document.getElementById("CO2_" + index).value = "";
    document.getElementById("CO2_" + index).focus();
    return;
  }
  if (parseFloat(marksCO3) > parseFloat(co3max)) {
    alert("Maximum marks reached");
    document.getElementById("CO3_" + index).value = "";
    document.getElementById("CO3_" + index).focus();
    return;
  }
  if (parseFloat(marksCO4) > parseFloat(co4max)) {
    alert("Maximum marks reached");
    document.getElementById("CO4_" + index).value = "";
    document.getElementById("CO4_" + index).focus();
    return;
  }
  if (parseFloat(marksCO5) > parseFloat(co5max)) {
    alert("Maximum marks reached");
    document.getElementById("CO5_" + index).value = "";
    document.getElementById("CO5_" + index).focus();
    return;
  }
  if (parseFloat(marksCO6) > parseFloat(co6max)) {
    alert("Maximum marks reached");
    document.getElementById("CO6_" + index).value = "";
    document.getElementById("CO6_" + index).focus();
    return;
  }

  let coTotal =
    parseFloat(marksCO1) +
    parseFloat(marksCO2) +
    parseFloat(marksCO3) +
    parseFloat(marksCO4) +
    parseFloat(marksCO5) +
    parseFloat(marksCO6);
  document.getElementById("COTotal_" + index).value = coTotal;
}

function getTotalCO(id, index) {
  let marksCO1 = document.getElementById("CO1_" + index).value;
  let marksCO2 = document.getElementById("CO2_" + index).value;
  let marksCO3 = document.getElementById("CO3_" + index).value;
  let marksCO4 = document.getElementById("CO4_" + index).value;
  let marksCO5 = document.getElementById("CO5_" + index).value;
  let marksCO6 = document.getElementById("CO6_" + index).value;

  if (marksCO1 === "" || marksCO1 < 0 || marksCO1 == "-") {
    marksCO1 = 0;
  }
  if (marksCO2 === "" || marksCO2 < 0 || marksCO2 == "-") {
    marksCO2 = 0;
  }
  if (marksCO3 === "" || marksCO3 < 0 || marksCO3 == "-") {
    marksCO3 = 0;
  }
  if (marksCO4 === "" || marksCO4 < 0 || marksCO4 == "-") {
    marksCO4 = 0;
  }
  if (marksCO5 === "" || marksCO5 < 0 || marksCO5 == "-") {
    marksCO5 = 0;
  }
  if (marksCO6 === "" || marksCO6 < 0 || marksCO6 == "-") {
    marksCO6 = 0;
  }

  let coTotal =
    parseFloat(marksCO1) +
    parseFloat(marksCO2) +
    parseFloat(marksCO3) +
    parseFloat(marksCO4) +
    parseFloat(marksCO5) +
    parseFloat(marksCO6);

  document.getElementById("COTotal_" + index).value = coTotal;
}

function saveQnActMarksDetails() {
  let testName = document.getElementById("testName").value;
  var classid = document.getElementById("classnameoptions").value;
  var subElement = document.getElementById("subElement").value;

  let rowQnno = document.getElementById("qnno_act_row");
  let cells = rowQnno.getElementsByTagName("td");
  let columnLength = cells.length;

  let rowmarks = document
    .getElementById("marks_co_row")
    .getElementsByTagName("input");

  let marks_data_id = [];
  for (var z = 0; z < rowmarks.length; z++) {
    marks_data_id.push(rowmarks[z].id);
  }

  let data = [];
  let total = 0;
  for (var i = 0; i < columnLength; i++) {
    let cellVal = rowQnno.getElementsByTagName("td")[i].innerText;
    var marksVal = parseFloat(document.getElementById(marks_data_id[i]).value);

    total += marksVal;
    let values = {};
    values.qnno = cellVal;
    values.marks = marksVal;
    data.push(values);
  }

  $.ajax({
    type: "POST",
    url: $host_url + "saveActMarksEntry",
    data:
      "testName=" +
      testName +
      "&classId=" +
      classid +
      "&subelement=" +
      subElement +
      "&data=" +
      JSON.stringify(data),
    success: function (res) {
      let response = JSON.parse(res);
      if (response.error_code === 0) {
        $("#comarks").hide();
        alert(response.data);
      } else {
        alert(response.data);
        return;
      }
    },
  });
}

function getCOMarksTotal(id) {
  let A1 = $("#CO1").val();
  let B1 = $("#CO2").val();
  let C1 = $("#CO3").val();
  let D1 = $("#CO4").val();
  let E1 = $("#CO5").val();
  let F1 = $("#CO6").val();

  if (A1 === "") {
    A1 = 0;
  }
  if (B1 === "") {
    B1 = 0;
  }
  if (C1 === "") {
    C1 = 0;
  }
  if (D1 === "") {
    D1 = 0;
  }
  if (E1 === "") {
    E1 = 0;
  }
  if (F1 === "") {
    F1 = 0;
  }

  if (parseFloat(A1) + parseFloat(B1) + parseFloat(C1) + parseFloat(D1) > 25) {
    alert("Maximum marks reached");
    document.getElementById(id).value = "";
    document.getElementById(id).focus();
    return;
  }

  let total =
    parseFloat(A1) +
    parseFloat(B1) +
    parseFloat(C1) +
    parseFloat(D1) +
    parseFloat(E1) +
    parseFloat(F1);
  $("#totalMarks").val(total);
}