﻿function CheckAll(sender) {
       for (var i = 0; i < checkboxes.length-1; i++) {
            checkboxes[i].checked = sender.checked; 
        }
    }
    function Taggle(sender) {
        if (checkboxList.style.display == "none") {
            checkboxList.style.display = "block";
            sender.innerHTML = "Hide all modules >>";
        }
        else {
            checkboxList.style.display = "none";
            sender.innerHTML = "Show all modules >>";
        } 
    }

    function check(source, arguments) {
        if (arguments.Value == "0") {
            arguments.IsValid = false;
        }
        else {
            arguments.IsValid = true;
        }

    }
  function checkModule(source, arguments) {
    var t = $(moduleSel).val();
    if (t.indexOf("Solution") >= 0) {
        $(moduleSel).parent().find("span").remove();
        arguments.IsValid = true;
        return;
    }
    if ($(moduleSel).val() == "") {
        $(moduleSel).parent().append("<span class = 'red'>this field can't be empty!</span>");
        return;
    }
      var flag = false;
      for (var i = 0; i < checkboxes.length-1; i++) {
          if (checkboxes[i].checked) {
              flag = true;
              
          }
      }
      if (!flag) {
          
          arguments.IsValid = false;

      }
      else {
          arguments.IsValid = true;
      }
  }
  
  function checkSolution(source, arguments)
  {
      var t = $(moduleSel).val();
    if (t.indexOf("Modules") >= 0) {
        $(moduleSel).parent().find("span").remove();
        arguments.IsValid = true;
        return;
    }

    var flag = false;
    for (var i=0; i<checkboxesSol.length; i++){
        if (checkboxesSol[i].checked){
            flag = true;
        }
    }
    if (!flag){
        arguments.IsValid = false;
    }
    else {
        arguments.IsValid = true;
    }

}
function GoToPic(i) {
    var i = i ? i : $("#checkSuc [name='success']:checked").val();
    var s = i - 1;
    if (s > 0)
        $("#imgContent").animate({ right: '+' + (s * 515) + "px" }, 1000);
    else {
        $("#imgContent").animate({ right: (s * 515) + "px" }, 1000);
    }
    currentSuc = i;
    
}
function autoPlay() {
    if (currentSuc > 4) {
        $("#imgContent").animate({ right: 0 }, 1);
        currentSuc = 1;
    }
    else {
        currentSuc++;
       // GoToPic(currentSuc);

    }
    $("#checkSuc [value='" + currentSuc + "']").trigger("click","1");
}
  var currentSuc = 1;
  $(function() {
      $("#radioModules").bind("change", function() {
          if (this.value == "1") {
              $("#trModules").hide();
              $("#trSolution").show();
              $(moduleSel).val("Solution");
          }
          else if (this.value == "0") {
              $("#trModules").show();
              $("#trSolution").hide();
              $(moduleSel).val("Modules");
          }
          else {
              $("#trModules").hide();
              $("#trSolution").hide();
              $(moduleSel).val("");
          }

      }
     );
      $("#checkSuc [name='success']:first").attr("checked",true);
      var timer;
      $("#pic-container").bind("mouseover", function() {
          clearInterval(timer);
      });
      $("#pic-container").bind("mouseout", function() {
          timer = setInterval("autoPlay()", 2000);
      });
      $("#checkSuc :radio").bind("click", function(e,t) {
      // clearInterval(timer);
      if (!t)
          clearInterval(timer);
          GoToPic($(this).val());
      });

      timer = setInterval("autoPlay()", 2000);

  })

