// --------------------------------------------------------------------------------
// rc_reportcard.js
// Dale Schimpf 2009-06-17
// Contains Javascript relevant to the ReportCard application
// --------------------------------------------------------------------------------

var fieldPrefixRegister = "tmpl_ecRegistration_ec_";


// cancel flag
var ec_cancelled = false;

// --- Attach JS to document elements and execute simple statements. ---
ow_f_AppendLoadEvent(
function() {
    //School comparison report - step 1 next button
if (document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_StartNavigationTemplateContainerID_StartNextButton") != null) ow_f_AddEvent(document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_StartNavigationTemplateContainerID_StartNextButton"), "click", rc_SchoolReportProvinceSelected, false);
//School comparison report - step 2 next button
if (document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_StepNavigationTemplateContainerID_StepNextButton") != null) ow_f_AddEvent(document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_StepNavigationTemplateContainerID_StepNextButton"), "click", rc_SchoolReportValidateStep2, false);

//School outcome comparison report - step 1 next button
if (document.getElementById("tmpl_appmain_ctl00_wizSchoolOutcomeComparison_StartNavigationTemplateContainerID_StartNextButton") != null) ow_f_AddEvent(document.getElementById("tmpl_appmain_ctl00_wizSchoolOutcomeComparison_StartNavigationTemplateContainerID_StartNextButton"), "click", rc_SchoolOutcomeReportValidateStep1, false);

//School outcome comparison report - step 2 next button
if (document.getElementById("tmpl_appmain_ctl00_wizSchoolOutcomeComparison_StepNavigationTemplateContainerID_StepNextButton") != null) ow_f_AddEvent(document.getElementById("tmpl_appmain_ctl00_wizSchoolOutcomeComparison_StepNavigationTemplateContainerID_StepNextButton"), "click", rc_SchoolOutcomeReportValidateStep2, false);

//School outcome comparison report - step 4 next button

if (document.getElementById("tmpl_appmain_ctl00_wizSchoolOutcomeComparison_StepNavigationTemplateContainerID_StepNextButton") != null) ow_f_AddEvent(document.getElementById("tmpl_appmain_ctl00_wizSchoolOutcomeComparison_StepNavigationTemplateContainerID_StepNextButton"), "click", rc_SchoolOutcomeReportValidateStep4, false);

//print link
if (document.getElementById("rc_print") != null) ow_f_AddEvent(document.getElementById("rc_print"), "click", rc_print, false);

}
);

//School comparison report - wizard step 1
function rc_SchoolReportProvinceSelected() {
    //nextBtn = document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_StartNavigationTemplateContainerID_StartNextButton");
    rc = document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_ucReportCardSelectionProvince_rc_ddlProvince");
    if (rc != null) {
        if (rc.selectedIndex == 0) {
            alert("Select a province.");
            return false;
        }
    }
}

//School comparison report - wizard step 2
function rc_SchoolReportValidateStep2() {
    //nextBtn = document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_StepNavigationTemplateContainerID_StepNextButton");
    rc1 = document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_ucReportCardSelectionSchool1_rc_ddlReportCard");
    rc2 = document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_ucReportCardSelectionSchool2_rc_ddlReportCard");
    rc3 = document.getElementById("tmpl_appmain_ctl00_wizSchoolComparison_ucReportCardSelectionSchool3_rc_ddlReportCard");
    counter = 0;
    
    if (rc1 != null) {
        if (rc1.selectedIndex > 0) {
            counter++;
        }
    }
    if (rc2 != null) {
        if (rc2.selectedIndex > 0) {
            counter++;
        }
    }
    if (rc3 != null) {
        if (rc3.selectedIndex > 0) {
            counter++;
        }
    }
    if (rc1 != null) {
        if (counter < 2) {
            alert("Select at least 2 schools to compare.");
            return false;
        }
    }
}

//School outcome comparison report - wizard step 1
function rc_SchoolOutcomeReportValidateStep1() {
    rc = document.getElementById("tmpl_appmain_ctl00_wizSchoolOutcomeComparison_ucReportCardSelectionReportCard_rc_ddlReportCard");
    if (rc != null) {
        if (rc.selectedIndex == 0) {
            alert("Select a report card.");
            return false;
        }
    }
}

//School outcome comparison report - wizard step 2
function rc_SchoolOutcomeReportValidateStep2() {
    rc = document.getElementById("tmpl_appmain_ctl00_wizSchoolOutcomeComparison_ucReportCardSelectionDistrict_rc_ddlProvince");
    if (rc != null) {
        if (rc.selectedIndex == 0) {
            alert("You must at least select a province to proceed.");
            return false;
        }
    }
}

//School outcome comparison report - wizard step 4
function rc_SchoolOutcomeReportValidateStep4() {
    chk = document.getElementById("tmpl_appmain_ctl00_wizSchoolOutcomeComparison_rc_chkach_con");
    counter = 0;
    var inp = document.getElementsByTagName("input");
    for (var i = 0; i < inp.length; i++) {
        if (inp[i].type == "checkbox") {
            if (inp[i].checked == true) {
                counter ++
            }
        }
    }
    if (chk != null){
        if (counter == 0) {
            alert("You must select at least one outcome to continue.");
            return false;
        }
    }
}

//print
function rc_print() {
    window.print();
}
