$(document).ready(function() {

    $("#section1").show();
    $("#section2").hide();
    $("#section3").hide();
    $("#section4").hide();
    $("#section5").hide();
    $("#complete1").hide();
    $("#complete2").hide();
    $("#complete3").hide();
    $("#complete4").hide();
    $("#complete5").hide();
    $("#resultsbutton").hide();
    $("#tab1").css({ 'border-bottom': 'none' });


    $("#tab1").click(function() {

        $("#section2").hide();
        $("#section3").hide();
        $("#section4").hide();
        $("#section5").hide();
        $("#section1").show();
        return false;
    });

    $("#tab2").click(function() {
        $("#section1").hide();
        $("#section3").hide();
        $("#section4").hide();
        $("#section5").hide();
        $("#section2").show();
        $("#tab2").css({ 'border-bottom': 'none' });
        return false;
    });
    
    $("#tab3").click(function() {
        $("#section1").hide();
        $("#section2").hide();
        $("#section4").hide();
        $("#section5").hide();
        $("#section3").show();
        $("#tab3").css({ 'border-bottom': 'none' });
        return false;
    });
    
    $("#tab4").click(function() {
        $("#section1").hide();
        $("#section3").hide();
        $("#section2").hide();
        $("#section5").hide();
        $("#section4").show();
        $("#tab4").css({ 'border-bottom': 'none' });
        return false;
    });
    
    $("#tab5").click(function() {
        $("#section1").hide();
        $("#section3").hide();
        $("#section4").hide();
        $("#section2").hide();
        $("#section5").show();
        $("#tab5").css({ 'border-bottom': 'none' });
        return false;
    });

    check_answer(1);
    check_answer(2);
    check_answer(3);
    check_answer(4);
    check_answer(5);
}


);
 
 function set_answer(question_id, section_id, answer)
 {
     $.get("send_answer.aspx", { question: question_id, answer: answer }, function(data) {
         switch (data) {
             case ("all"):
                 $("table tr td img#complete" + section_id).show();
                 //alert("all questions answered!");
                 $("#resultsbutton").show();
                 break;

             case ("complete"):
                 $("table tr td img#complete" + section_id).show();
                 break;
             case ("incomplete"):
                 $("table tr td img#complete" + section_id).hide();
                 break;
         }
     });
 }

 function check_answer(section_id) {
     $.get("check_answer.aspx", { section_id: section_id }, function(data) {
         switch (data) {
             case ("all"):
                 $("table tr td img#complete" + section_id).show();
                 //alert("all questions answered!");
                 $("#resultsbutton").show();
                 break;

             case ("complete"):
                 $("table tr td img#complete" + section_id).show();
                 break;
             case ("incomplete"):
                 $("table tr td img#complete" + section_id).hide();
                 break;
         }
     });
 }
 
 function set_project_name() {
     var project_name = $("#fprojectName").val();

     $.get("send_project_name.aspx", { project_name: project_name }, function(data) {
         switch (data) {
             case ("success"):
                 $("#projectname").text(project_name);
                 break;
             case ("fail"):
                 alert("failed to update project name, please try again");
                 break;

         }
         return false;

     });
 }

 function loadWindow(url, title, width, height) {
     window.open(url, title, 'scrollbars=yes,resizable=yes,menubar=no,width=' + width + ',height=' + height + ',toolbar=no');
 }

 function loadResults(url) {
     if ($.trim($("#projectname").text()) == "Project Name") {
        alert("You must enter your project name before getting the results");
     } else {
     window.open(url, "PASA Results", 'status=1,toolbar=1,location=1,menubar=1,scrollbars=yes,resizable=yes');
     }
     
 }
