var SelectReportView = function(){}
SelectReportView.Presenter = null;
SelectReportView.prototype = {
    Initialize: function() {

    },

    Dispose: function() {

    },

    DisplayError: function(exceptionType, message) {
        alert(message);
    },

    ShowHideLoadingPanel: function(loadingDivPlaceholder, loadingPanel, isVisible) {
        //ShowHideLoadingPanel($get("defaultLoadingDiv"), loadingPanel, true);
        ShowHideLoadingPanel(loadingDivPlaceholder, loadingPanel, isVisible);
    },

    GoButtonDisplay: function(buttonState) {
        theMainGoButton.className = "showElement";
        if ($get(classSelectID).options[$get(classSelectID).selectedIndex].value == 0) {
            theMainGoButton.className = "hideElement";

        }
        else {
            $get(classSelectID).options[0].className = "hideElement";
        }


    },


    GoInitialize: function() {
        hideShowClass($get("javascriptPanel")); // javascriptPanel set to off in CSS. Toggles to on if JS enabled
    },

    //Scale Percentage to 80% and add 10% so that graph is rendered between 10% and 90%
    CalculatePosition: function(value, Min, Max) {
        return ((value - Min) / (Max - Min)) * 90;
    },

    DisplaySummaryReport: function(searchResults) {


        var seoLinks = $get("seoLinks");
        seoLinks.className = "hideElement";

        var summary = $find("SalarySummary1");
        summary.Clear();

        var summaryNation = $find("SalarySummaryNation1");
        summaryNation.Clear();

        var summaryNationBelowThreshold = $find("SalarySummaryNationBelowThreshold");
        summaryNationBelowThreshold.Clear();

        var selLocVal = $get(locationSelectID).value;

        var selLocName = $get(locationSelectID).options[$get(locationSelectID).selectedIndex].text;

        var summaryData = new Array();
        var summaryNationData = new Array();
        var summaryNationDataBelowThreshold = new Array();

        var setMin = 0;
        var setMax = 0;

        for (var i = 0; i < searchResults.SubClassificationSummaries.length; i++) {
            if (setMin == 0 || setMin > searchResults.SubClassificationSummaries[i].SalaryRange.Q1) {
                setMin = searchResults.SubClassificationSummaries[i].SalaryRange.Q1;
            }

            if (setMax < searchResults.SubClassificationSummaries[i].SalaryRange.Q3)
                setMax = searchResults.SubClassificationSummaries[i].SalaryRange.Q3;
        }

        var fullRange = setMax - setMin;




        for (var i = 0; i < searchResults.SubClassificationSummaries.length; i++) {
            var shortTitleList = "";
            var hiddenCount = 0;
            var fullList = "";

            for (var j = 0; j < searchResults.SubClassificationSummaries[i].JobTitles.length; j++) {
                if ((shortTitleList.length < 60) && (searchResults.SubClassificationSummaries[i].JobTitles[j].Name != searchResults.SubClassificationSummaries[i].Name))
                    shortTitleList += ", " + searchResults.SubClassificationSummaries[i].JobTitles[j].Name;
                else
                    hiddenCount++;

                if (j < searchResults.SubClassificationSummaries[i].JobTitles.length - 1)
                    fullList += ", " + searchResults.SubClassificationSummaries[i].JobTitles[j].Name;
                else
                    fullList += " and " + searchResults.SubClassificationSummaries[i].JobTitles[j].Name;
            }

            shortTitleList = shortTitleList.substring(1);
            fullList = fullList.substring(1);
            searchResults.SubClassificationSummaries[i].LocationName = selLocName;
            searchResults.SubClassificationSummaries[i].ShortTitleList = shortTitleList;
            searchResults.SubClassificationSummaries[i].HiddenCount = hiddenCount;
            searchResults.SubClassificationSummaries[i].FullList = fullList;

            searchResults.SubClassificationSummaries[i].ShortStyle = "block";
            searchResults.SubClassificationSummaries[i].FullStyle = "none";

            var startPercent = this.CalculatePosition(searchResults.SubClassificationSummaries[i].SalaryRange.Q1, setMin, setMax) + 5;
            searchResults.SubClassificationSummaries[i].StartPercentage = startPercent;

            var meanPercent = this.CalculatePosition(searchResults.SubClassificationSummaries[i].SalaryRange.Q2Median, setMin, setMax) + 7;
            searchResults.SubClassificationSummaries[i].MeanPercentage = meanPercent - startPercent;

            var endPercent = this.CalculatePosition(searchResults.SubClassificationSummaries[i].SalaryRange.Q3, setMin, setMax);
            endPercent = endPercent - meanPercent;
            //Minimum 21.5% for EndPercentage
            searchResults.SubClassificationSummaries[i].EndPercentage = endPercent >= 5 ? endPercent : 5;

            if (searchResults.SubClassificationSummaries[i].LocationID == selLocVal) {
                searchResults.SubClassificationSummaries[i].ItemRowStyle = summaryData.length % 2 == 0 ? "altrow" : "";

                if (!searchResults.SubClassificationSummaries[i].IsBelowThreshold)
                    summaryData[summaryData.length] = searchResults.SubClassificationSummaries[i];


            }
            else {
                searchResults.SubClassificationSummaries[i].ItemRowStyle = summaryNationData.length % 2 == 0 ? "altrow" : "";
                searchResults.SubClassificationSummaries[i].LocationName = selLocName;

                if (!searchResults.SubClassificationSummaries[i].IsBelowThreshold)
                    summaryNationData[summaryNationData.length] = searchResults.SubClassificationSummaries[i];


            }

            if (searchResults.SubClassificationSummaries[i].IsBelowThreshold)
                summaryNationDataBelowThreshold.push(searchResults.SubClassificationSummaries[i]);


            var endCharsWidth = "";
            //alert(searchResults.SubClassificationSummaries[i].SalaryRange.Q3);
            if (searchResults.SubClassificationSummaries[i].SalaryRange.Q3 > 99)
                searchResults.SubClassificationSummaries[i].endCharsWidth = "right:-30px";
            else
                searchResults.SubClassificationSummaries[i].endCharsWidth = "";
        }




        if (summaryData.length != 0) {
            summaryData[summaryData.length - 1].ItemRowStyle = summaryData.length - 1 % 2 == 0 ? "altrow lastrow" : "lastrow";
            this.SummaryDataLength += summaryData.length;
        }
        if (summaryNationData.length != 0) {
            summaryNationData[summaryNationData.length - 1].ItemRowStyle = summaryNationData.length - 1 % 2 == 0 ? "altrow lastrow" : "lastrow";
            this.SummaryDataLength += summaryNationData.length;
        }

        if (summaryNationDataBelowThreshold.length != 0) {
            summaryNationDataBelowThreshold[summaryNationDataBelowThreshold.length - 1].ItemRowStyle = summaryNationDataBelowThreshold.length - 1 % 2 == 0 ? "altrow lastrow" : "lastrow";
            this.SummaryDataLength += summaryNationDataBelowThreshold.length;
        }


        summary.AddDataItem(summaryData);
        summaryNation.AddDataItem(summaryNationData);
        summaryNationBelowThreshold.AddDataItem(summaryNationDataBelowThreshold);

        if (summaryNationDataBelowThreshold.length > 0) {
            $get("summaryPromo").className = "showElement";
        }
        else {
            $get("summaryPromo").className = "hideElement";
        }


        if (this.SummaryDataLength != 0)
            $get("summaryFooter").className = "footer";
        else 
            $get("summaryFooter").className = "hideElement";

    },

    SummaryDataLength: 0,


    GetSelectedClassification: function() {
        return $get(classSelectID).value;
    },

    GetSelectedLocation: function() {
        return $get(locationSelectID).value;
    },

    HideShowTitles: function(id, mode) {
        $get(id).style.display = mode;
    }
}
SelectReportView.registerClass('SelectReportView');
