﻿function DisplayCommunityReportsWhenLoaded() {
    if ($find("mpeCommunityReports") == null) {
        setTimeout(DisplayCommunityReportsWhenLoaded, 10);
    } else {
        DisplayCommunityReports();
    }; //end ifelse found
}; //end method

function DisplayCommunityReports() {
    $get("tblCommunityReportsCity").style.display = "none";
    $get("tblCommunityReportsCounty").style.display = "none";
    DisplayInlineTable("tblCommunityReports");
    $get("tblCommunityReportsLoading").style.display = "none";

    $("#ctl00_cphModal_pnlCommunityReports").css({ height: "200px", width: "500px" });
    $find("mpeCommunityReports").show();
}; //end method

function ShowCommunityReportForm(pType) {
    switch (pType) {
        case "CITY":
            var myProcessor = function(pResults) {
                var myListBox = $get("ctl00_cphModal_lboxCommunityReportsCities")
                for (var i = 0; i < pResults.length; i++) {
                    var opt = document.createElement("option");
                    opt.text = pResults[i].DisplayName;
                    opt.value = pResults[i].ID.substring(pResults[i].ID.length - 7);

                    myListBox.options.add(opt);

                };
                DisplayInlineTable("tblCommunityReportsCity");
                $get("tblCommunityReportsLoading").style.display = "none";          
            };    //end method
            TVAGoogle.common.services.Cities.GetCities(_GISP_Theme,myProcessor);
            break;
        case "COUNTY":
            var myProcessor = function(pResults) {
                var myListBox = $get("ctl00_cphModal_lboxCommunityReportsCounties")
                for (var i = 0; i < pResults.length; i++) {
                    var opt = document.createElement("option");
                    opt.text = pResults[i].DisplayName;
                    opt.value = pResults[i].ID;
                    myListBox.options.add(opt);
                };
                DisplayInlineTable("tblCommunityReportsCounty");
                $get("tblCommunityReportsLoading").style.display = "none";
            };    //end method
            TVAGoogle.common.services.Counties.GetCounties(_GISP_Theme,myProcessor);
            break;
    }; //end switch type

    $get("tblCommunityReports").style.display = "none";
    $get("tblCommunityReportsLoading").style.display = "block";
    $("#ctl00_cphModal_pnlCommunityReports").css({ height: "475px", width: "700px" });
    $find("mpeCommunityReports").show();


}; //end function

function LoadCommunityReport(pType) {
    var myListBoxID = (pType == "COUNTY" ? "ctl00_cphModal_lboxCommunityReportsCounties" : "ctl00_cphModal_lboxCommunityReportsCities");
    var mySelectedCommunity = GISP_NullOrInputValue(myListBoxID);

    CloseCommunityReport();
    switch (pType) {
        case "COUNTY": ViewCommunityReport(mySelectedCommunity, "FULL"); break;
        case "CITY": ViewCommunityReport(mySelectedCommunity, "FULL"); break;
    }; //end switch type

}; //end function

function CloseCommunityReport() {
    $find("mpeCommunityReports").hide();
}; //end function

function ResetCommunityReport(pType) {
    alert('Not Implemented Yet');
}; //end function

function SetCommunityReportEntity(pSender) {
    var myType = (pSender._id.indexOf("County") != -1 ? "COUNTY" : "CITY");
    var myListBoxID = (myType == "COUNTY" ? "ctl00_cphModal_lboxCommunityReportsCounties" : "ctl00_cphModal_lboxCommunityReportsCities");
    var myTextBox = $get((myType == "COUNTY" ? "ctl00_cphModal_tboxManulEnterCommunityReportCounty" : "ctl00_cphModal_tboxManualEnterCommunityReportCity"));
    var mySelectedCommunity = myTextBox.value;


    var myListBox = $get(myListBoxID);

    for (var i = 0; i < myListBox.options.length; i++) {
        var myOption = myListBox.options[i];
        if (myOption.innerText.toUpperCase() == mySelectedCommunity.toUpperCase()) {
            myOption.selected = true;
            break;
        }; //end if found
    }; //end for each option

    //reset the textbox
    myTextBox.value = "";
};