/*
 * Copyright (c) 2006, ScanHealth, Inc. All Rights Reserved.
 */

 function showStatus(msg) {
    window.status = msg;
    return true ;
}
function openMatrixGood(ajax) {
    log.debug(ajax.responseText);
    var response = ajax.responseXML.documentElement;
    var agencies = response.getElementsByTagName('agency');
    var matrix = response.getElementsByTagName('matrix');
    log.debug("agencies: "+agencies.length);
    log.debug("printable? "+matrix[0].getAttribute("printable"));
    var win;
    if("false" == matrix[0].getAttribute("printable")) {
//      win = new Window('window_id', {className: "mac_os_x", wiredDrag:true, maximizable:false, showEffect:Element.show, title: "GetHomeCare.com&trade; Agency Comparison Matrix", width:675, height:650});
    }
    log.debug("after window create");
    var colspan = (agencies.length * 2) + 2;
    log.debug("colspan: " + colspan)

    var content =
            "    <div id=\"detailsWrapper\">\n" +
            "        <div id=\"detailsWrapper_1\">\n" +
            "            <div id=\"detailsWrapper_2\">\n" +
            "                <div id=\"detailsWrapper_3\">\n" +
            "                    <div id=\"detailsWrapper_4\">\n" +
            "                        <table border=\"0\" width=\"99%\" cellpadding=\"0\" cellspacing=\"0\" id=\"matrixTable\">\n";
//            "                         <tr><td style=\"padding:0px;\" width=\"60%\">&nbsp;</td><td style=\"padding:0px;\" colspan=\""+colspan+"\">\n";
                        if("false" == matrix[0].getAttribute("printable")) {
// content += "                             <div id=\"print\"><a href=\"javascript:printMatrix()\">Printer Friendly Version</a></div></td></tr>\n";
                        } else {
// content += "                             <div id=\"print\"><a href=\"javascript:window.print()\"><img src=\"images/icons/print-16.gif\" border=\"0\" alt=\"Print this page\" title=\"Print this Page\"/></a></div></td></tr>\n";
                        }
// content += "                         <tr>\n" +
//            "                             <td style=\"padding-left:0px\" width=\"60%\" nowrap=\"true\">&nbsp;</td>\n" +
//            "                             <td colspan=\""+colspan+"\" id=\"matrixAgencies\">Agencies</td>\n" +
//            "                          </tr>\n" +
content +=  "                          <tr>\n" +
            "                           <th style=\"vertical-align:top;padding-left:0px\" width=\"60%\" nowrap=\"true\">\n" +
            "                             <div id=\"matrixTitle\"><img src=\"images/locator/GHC_AgencyMatrix_Corner.png\" /></div>\n" +
            "                             <div id=\"matrixMeasures\">Medicare and Medicaid Scorecard</div>\n" +
            "                           </th>\n";

    //var agencies = response.getElementsByTagName('agency');
    var allAgencies = new Array();
    var isTop20 = "false";
    for (var j = 0; j < agencies.length; j++) {
        var thisAgency = agencies[j];
        allAgencies[j] = thisAgency;
        name = thisAgency.childNodes[1].firstChild.nodeValue;     //agency name
        log.debug("agency: "+name)
        isTop20 = thisAgency.childNodes[9].firstChild.nodeValue;  //top 20
        log.debug("top20: "+isTop20)
        agencyState = thisAgency.childNodes[2].firstChild.nodeValue; // state
        log.debug("state: "+agencyState)
        content += "                            <th class=\"siteHeader1\">" + (isTop20 == "true"?"<div style='vertical-align:top'><img src=\"images/locator/GHC_AgencyMatrix_Award.png\"/></div>":"")+"<div>" + name + "</div></th>\n" +
                   "                            <th class=\"siteStateHeader\"><img src=\"images/locator/states/" + agencyState.toLowerCase() + ".gif\" alt=\"\"/></th>\n";
    }

    content += "                            <th id=\"nationalAvg\"><img src=\"images/locator/states/nation.gif\" alt=\"\"/></th>\n" +
               "                            </tr>\n";

    if(allAgencies.length > 0) {
        agency1 = allAgencies[0];
        percentile1 = agency1.childNodes[10].firstChild.nodeValue;
        score1 = agency1.childNodes[11].firstChild.nodeValue;
        adjustment1 = agency1.childNodes[11].getAttribute("adjustment");
        measures = agency1.getElementsByTagName("measure");
    }
    if(allAgencies.length > 1) {
        agency2 = allAgencies[1];
        percentile2 = agency2.childNodes[10].firstChild.nodeValue;
        score2 = agency2.childNodes[11].firstChild.nodeValue;
        adjustment2 = agency2.childNodes[11].getAttribute("adjustment");
        measures2 = agency2.getElementsByTagName("measure");
    }
    if(allAgencies.length > 2) {
        agency3 = allAgencies[2];
        percentile3 = agency3.childNodes[10].firstChild.nodeValue;
        score3 = agency3.childNodes[11].firstChild.nodeValue;
        adjustment3 = agency3.childNodes[11].getAttribute("adjustment");
        measures3 = agency3.getElementsByTagName("measure");
    }
    if(allAgencies.length > 3) {
        agency4 = allAgencies[3];
        percentile4 = agency4.childNodes[10].firstChild.nodeValue;
        score4 = agency4.childNodes[11].firstChild.nodeValue;
        adjustment4 = agency4.childNodes[11].getAttribute("adjustment");
        measures4 = agency4.getElementsByTagName("measure");
    }
    var percentage = 0;
    var percentageBefore = 0;
    var statePercentage = 0;
    var trendUp = false;

 //###########################################################  A M B U L A T I O N #######################################################################
    content += "                            <tr>\n"+
               "                                <td colspan=\""+colspan+"\" class=\"groupMatrixHeader\"><a onclick=\"javascript:displayAmbulationGroup()\">Ambulation</a></td>\n"+
               //"                                <td style=\"border-left:2px solid #000;\">&nbsp;</td></tr>\n"+
               "                            <tr><td class=\"measureMatrixDescription\"><img src=\"images/locator/asterisk.gif\" border=\"0\"/>Patients who get better at walking or moving around.</td>\n";
    // ###########################################  Measure 1
    log.debug("measure 1");
    if(allAgencies.length >= 1) {
        statePercentage = measures[0].getAttribute("statePercentage");
        percentage = measures[0].getAttribute("percentage");
        percentageBefore = measures[0].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);
        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
           if(trendUp) {
//               content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
               content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";

           }else {
//               content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
               content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
           }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    log.debug("measure1.1");
    if (allAgencies.length > 1) {
        statePercentage = measures2[0].getAttribute("statePercentage");
        percentage = measures2[0].getAttribute("percentage");
        percentageBefore = measures2[0].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);
        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}

        if(percentage != -1) {
            if(trendUp) {
//                content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";

            }else {
//                content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 2) {
        statePercentage = measures3[0].getAttribute("statePercentage")
        percentage = measures3[0].getAttribute("percentage");
        percentageBefore = measures3[0].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
//                content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
//                content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 3) {
        statePercentage = measures4[0].getAttribute("statePercentage")
        percentage = measures4[0].getAttribute("percentage");
        percentageBefore = measures4[0].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
//                content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
//                content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    content += "                                <td class=\"nationalMatrixRating\">43%</td>\n" +
               "                            </tr>\n" +
               "                            <tr><td class=\"measureMatrixDescription\"><img src=\"images/locator/asterisk.gif\" border=\"0\"/>Patients who get better at getting in and out of bed.</td>\n";

    // ###########################################  Measure 2
    log.debug("measure 2");
    if (allAgencies.length >= 1) {
        statePercentage = measures[1].getAttribute("statePercentage")
        percentage = measures[1].getAttribute("percentage");
        percentageBefore = measures[1].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
//                content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
//                content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 1) {
        statePercentage = measures2[1].getAttribute("statePercentage")
        percentage = measures2[1].getAttribute("percentage");
        percentageBefore = measures2[1].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
//                content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
//                content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 2) {
        statePercentage = measures3[1].getAttribute("statePercentage")
        percentage = measures3[1].getAttribute("percentage");
        percentageBefore = measures3[1].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
//                content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";

            }else {
//                content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 3) {
        statePercentage = measures4[1].getAttribute("statePercentage")
        percentage = measures4[1].getAttribute("percentage");
        percentageBefore = measures4[1].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
                //content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
               // content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    content += "                                <td class=\"nationalMatrixRating\">54%</td>\n" +
               "                            </tr>\n" +
               "                            <tr><td class=\"measureMatrixDescription\"><img src=\"images/locator/asterisk.gif\" border=\"0\"/>Patients who have less pain moving around.</td>\n";

    // ###########################################  Measure 3
    log.debug("measure 3");
    if (allAgencies.length >= 1) {
        statePercentage = measures[2].getAttribute("statePercentage")
        percentage = measures[2].getAttribute("percentage");
        percentageBefore = measures[2].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
               // content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
              //  content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 1) {
        statePercentage = measures2[2].getAttribute("statePercentage")
        percentage = measures2[2].getAttribute("percentage");
        percentageBefore = measures2[2].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
            //    content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
           //     content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 2) {
        statePercentage = measures3[2].getAttribute("statePercentage")
        percentage = measures3[2].getAttribute("percentage");
        percentageBefore = measures3[2].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
           //     content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
          //      content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 3) {
        statePercentage = measures4[2].getAttribute("statePercentage")
        percentage = measures4[2].getAttribute("percentage");
        percentageBefore = measures4[2].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
             //   content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    content += "                                <td class=\"nationalMatrixRating\">64%</td>\n" +
               "                            </tr>\n";
    //###########################################################  A D L S #######################################################################
    content += "                            <tr> \n"+
               "                            <td colspan=\""+colspan+"\" class=\"groupMatrixHeader\"><a onclick=\"javascript:displayADLSGroup()\">ADLS</a></td>\n"+
//               "                            <td style=\"border-left:2px solid #000;\">&nbsp;</td></tr>\n"+
               "                            <tr><td class=\"measureMatrixDescription\"><img src=\"images/locator/asterisk.gif\" border=\"0\"/>Patients whose bladder control improves.</td>\n";

    // ###########################################  Measure 4
    log.debug("measure 4");
    if (allAgencies.length >= 1) {
        statePercentage = measures[3].getAttribute("statePercentage")
        percentage = measures[3].getAttribute("percentage");
        percentageBefore = measures[3].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
             //   content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
             //   content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 1) {
        statePercentage = measures2[3].getAttribute("statePercentage")
        percentage = measures2[3].getAttribute("percentage");
        percentageBefore = measures2[3].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
              //  content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 2) {
        statePercentage = measures3[3].getAttribute("statePercentage")
        percentage = measures3[3].getAttribute("percentage");
        percentageBefore = measures3[3].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
            //    content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 3) {
        statePercentage = measures4[3].getAttribute("statePercentage")
        percentage = measures4[3].getAttribute("percentage");
        percentageBefore = measures4[3].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
           //     content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
          //      content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    content += "                                <td class=\"nationalMatrixRating\">50%</td>\n" +
               "                            </tr>\n" +
               "                            <tr><td class=\"measureMatrixDescription\"><img src=\"images/locator/asterisk.gif\" border=\"0\"/>Patients who get better at bathing.</td>\n";

    // ###########################################  Measure 5
    log.debug("measure 5");
    if (allAgencies.length >= 1) {
        statePercentage = measures[4].getAttribute("statePercentage")
        percentage = measures[4].getAttribute("percentage");
        percentageBefore = measures[4].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }

    if (allAgencies.length > 1) {
        statePercentage = measures2[4].getAttribute("statePercentage")
        percentage = measures2[4].getAttribute("percentage");
        percentageBefore = measures2[4].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
              //  content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 2) {
        statePercentage = measures3[4].getAttribute("statePercentage")
        percentage = measures3[4].getAttribute("percentage");
        percentageBefore = measures3[4].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
             //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
             //   content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 3) {
        statePercentage = measures4[4].getAttribute("statePercentage")
        percentage = measures4[4].getAttribute("percentage");
        percentageBefore = measures4[4].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
             //   content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    content += "                                <td class=\"nationalMatrixRating\">65%</td>\n" +
               "                            </tr>\n" +
               "                            <tr><td class=\"measureMatrixDescription\"><img src=\"images/locator/asterisk.gif\" border=\"0\"/>Patients who get better at taking their oral medicines correctly.</td>\n";

    // ###########################################  Measure 6
    log.debug("measure 6");
    if (allAgencies.length >= 1) {
        statePercentage = measures[5].getAttribute("statePercentage")
        percentage = measures[5].getAttribute("percentage");
        percentageBefore = measures[5].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
             //   content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }

    if (allAgencies.length > 1) {
        statePercentage = measures2[5].getAttribute("statePercentage")
        percentage = measures2[5].getAttribute("percentage");
        percentageBefore = measures2[5].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
               // content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 2) {
        statePercentage = measures3[5].getAttribute("statePercentage")
        percentage = measures3[5].getAttribute("percentage");
        percentageBefore = measures3[5].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
             //   content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
              //  content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 3) {
        statePercentage = measures4[5].getAttribute("statePercentage")
        percentage = measures4[5].getAttribute("percentage");
        percentageBefore = measures4[5].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
           //     content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }

    content += "                                <td class=\"nationalMatrixRating\">43%</td>\n" +
               "                            </tr>\n"+
               "                            <tr><td class=\"measureMatrixDescription\"><img src=\"images/locator/asterisk.gif\" border=\"0\"/>Patients who get are short of breath less often.</td>\n";
    // ###########################################  Measure 7
    log.debug("measure 7");
    if (allAgencies.length >= 1) {
        statePercentage = measures[6].getAttribute("statePercentage")
        percentage = measures[6].getAttribute("percentage");
        percentageBefore = measures[6].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
             //   content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
             //   content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 1) {
        statePercentage = measures2[6].getAttribute("statePercentage")
        percentage = measures2[6].getAttribute("percentage");
        percentageBefore = measures2[6].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
            //    content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 2) {
        statePercentage = measures3[6].getAttribute("statePercentage")
        percentage = measures3[6].getAttribute("percentage");
        percentageBefore = measures3[6].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
             //   content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 3) {
        statePercentage = measures4[6].getAttribute("statePercentage")
        percentage = measures4[6].getAttribute("percentage");
        percentageBefore = measures4[6].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        statePercentage = parseInt(statePercentage);

        if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    content += "                                <td class=\"nationalMatrixRating\">61%</td>\n" +
               "                            </tr>\n";

    //###########################################################  D I S C H A R G E   S U C C E S S #######################################################################
            content += "                            <tr> \n"+
                       "                              <td colspan=\""+colspan+"\" class=\"groupMatrixHeader\"><a onclick=\"javascript:displayDischargeGroup()\">Discharge Success</a></td> \n"+
                       //"                              <td style=\"border-left:2px solid #000;\">&nbsp;</td></tr>\n"+
                       "                            <tr><td class=\"measureMatrixDescription\"><div>&nbsp;</div><img src=\"images/locator/asterisk.gif\" border=\"0\"/>Patients who stay at home after an episode of home health care ends. </td>\n";
    // ###########################################  Measure 8
    log.debug("measure 8");
        if (allAgencies.length >= 1) {
            statePercentage = measures[7].getAttribute("statePercentage")
            percentage = measures[7].getAttribute("percentage");
            percentageBefore = measures[7].getAttribute("percentageBefore");
            percentage = parseInt(percentage);
            percentageBefore = parseInt(percentageBefore);
            statePercentage = parseInt(statePercentage);
            if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
             //   content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
        }
        if (allAgencies.length > 1) {
            statePercentage = measures2[7].getAttribute("statePercentage")
            percentage = measures2[7].getAttribute("percentage");
            percentageBefore = measures2[7].getAttribute("percentageBefore");
            percentage = parseInt(percentage);
            percentageBefore = parseInt(percentageBefore);
            statePercentage = parseInt(statePercentage);

            if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
             //   content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
        }
        if (allAgencies.length > 2) {
            statePercentage = measures3[7].getAttribute("statePercentage")
            percentage = measures3[7].getAttribute("percentage");
            percentageBefore = measures3[7].getAttribute("percentageBefore");
            percentage = parseInt(percentage);
            percentageBefore = parseInt(percentageBefore);
            statePercentage = parseInt(statePercentage);

            if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
             //   content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
              //  content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
        }
        if (allAgencies.length > 3) {
            statePercentage = measures4[7].getAttribute("statePercentage")
            percentage = measures4[7].getAttribute("percentage");
            percentageBefore = measures4[7].getAttribute("percentageBefore");
            percentage = parseInt(percentage);
            percentageBefore = parseInt(percentageBefore);
            statePercentage = parseInt(statePercentage);

            if(percentage >= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentage != -1) {
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages';  return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Higher Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
        }
    content += "                                <td class=\"nationalMatrixRating\">68%</td>\n" +
               "                            </tr>\n";

//###########################################################  E M E R G E N T    C A R E #######################################################################
    content += "                            <tr>\n"+
               "                             <td colspan=\""+colspan+"\" class=\"groupMatrixHeader\"><a onclick=\"javascript:displayEmergentCareGroup()\">Emergent Care</a></td>\n" +
               //"                              <td style=\"border-left:2px solid #000;\">&nbsp;</td></tr>\n"+
               "                            <tr><td class=\"measureMatrixDescription\"><img src=\"images/locator/asterisk2.gif\" border=\"0\"/>Patients who had to be admitted to the hospital.</td>\n";
// ###########################################  Measure 8
    log.debug("measure 9");
    if (allAgencies.length >= 1) {
        statePercentage = measures[8].getAttribute("statePercentage")
        percentage = measures[8].getAttribute("percentage");
        percentageBefore = measures[8].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        percentage = 100-percentage;
        statePercentage = parseInt(statePercentage);

        if(percentage <= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentageBefore == -1) {percentageBefore = "N/A";}
        if(percentage != -1) {
            //percentage = 100-percentage;
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 1) {
        statePercentage = measures2[8].getAttribute("statePercentage")
        percentage = measures2[8].getAttribute("percentage");
        percentageBefore = measures2[8].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        percentage = 100-percentage;
        statePercentage = parseInt(statePercentage);

        if(percentage <= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentageBefore == -1) {percentageBefore = "N/A";}
        if(percentage != -1) {
//            percentage = 100-percentage;

            if(trendUp) {
               // content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
             //   content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 2) {
        statePercentage = measures3[8].getAttribute("statePercentage")
        percentage = measures3[8].getAttribute("percentage");
        percentageBefore = measures3[8].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        percentage = 100-percentage;
        statePercentage = parseInt(statePercentage);

        if(percentage <= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentageBefore == -1) {percentageBefore = "N/A";}
        if(percentage != -1) {
          //  percentage = 100-percentage;
            if(trendUp) {
             //   content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 3) {
        statePercentage = measures4[8].getAttribute("statePercentage")
        percentage = measures4[8].getAttribute("percentage");
        percentageBefore = measures4[8].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        percentage = 100-percentage;
        statePercentage = parseInt(statePercentage);

        if(percentage <= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentageBefore == -1) {percentageBefore = "N/A";}
        if(percentage != -1) {
        //    percentage = 100-percentage;
            if(trendUp) {
              //  content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
               // content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    content += "                                <td class=\"nationalMatrixRating\">28%</td>\n" +
               "                            </tr>\n"+
               "                            <tr><td class=\"measureMatrixDescription\"><img src=\"images/locator/asterisk2.gif\" border=\"0\"/>Patients who need urgent, unplanned medical care.</td>\n";
    // ###########################################  Measure 9
    log.debug("measure 10");
    if (allAgencies.length >= 1) {
        statePercentage = measures[9].getAttribute("statePercentage")
        percentage = measures[9].getAttribute("percentage");
        percentageBefore = measures[9].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        percentage = 100-percentage;
        statePercentage = parseInt(statePercentage);

        if(percentage <= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentageBefore == -1) {percentageBefore = "N/A";}
        if(percentage != -1) {
           // percentage = 100-percentage;
            if(trendUp) {
               // content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
              //  content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 1) {
        statePercentage = measures2[9].getAttribute("statePercentage")
        percentage = measures2[9].getAttribute("percentage");
        percentageBefore = measures2[9].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        percentage = 100-percentage;
        statePercentage = parseInt(statePercentage);

        if(percentage <= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentageBefore == -1) {percentageBefore = "N/A";}
        if(percentage != -1) {
        //    percentage = 100-percentage;
            if(trendUp) {
               // content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
              //  content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 2) {
        statePercentage = measures3[9].getAttribute("statePercentage")
        percentage = measures3[9].getAttribute("percentage");
        percentageBefore = measures3[9].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        percentage = 100-percentage;
        statePercentage = parseInt(statePercentage);

        if(percentage <= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentageBefore == -1) {percentageBefore = "N/A";}
        if(percentage != -1) {
        //    percentage = 100-percentage;
            if(trendUp) {
            //    content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
             //   content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }
    if (allAgencies.length > 3) {
        statePercentage = measures4[9].getAttribute("statePercentage")
        percentage = measures4[9].getAttribute("percentage");
        percentageBefore = measures4[9].getAttribute("percentageBefore");
        percentage = parseInt(percentage);
        percentageBefore = parseInt(percentageBefore);
        percentage = 100-percentage;
        statePercentage = parseInt(statePercentage);
        if(percentage <= percentageBefore) {trendUp = true;}else{trendUp = false;}
        if(percentageBefore == -1) {percentageBefore = "N/A";}
        if(percentage != -1) {
//           percentage = 100-percentage;
            if(trendUp) {
            //    content += "                                <td class=\"measureMatrixRating\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRating\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#D5E2F5'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }else {
            //    content += "                                <td class=\"measureMatrixRatingDown\" onmouseout=\"return showStatus('');\" onmouseover=\"return showStatus('Last quarter: "+percentageBefore+"%');\"><a class=\"percentage\">" + percentage +"%</a></td>\n";
                content += "                                <td class=\"measureMatrixRatingDown\"><a style=\"text-decoration:underline; cursor:pointer;\" onmouseout=\"return showStatus('');\" onmouseover=\"this.T_ABOVE= true; this.T_BGCOLOR = '#FD959C'; this.T_SHADOW = true; this.T_SHADOWWIDTH = 7; this.T_TITLE = 'Past Percentages'; return escape('<b>Note</b>: Lower Percentages are better.<br/><br/>&nbsp;&nbsp;Percentage last quarter: "+percentageBefore+"%');\">"+percentage+"%</a>";
            }
        }else {
              content += "                                <td class=\"measureMatrixRatingNA\">N/A</td>\n";
        }
        content += "                                <td class=\"measureMatrixRatingState\">&nbsp;" + statePercentage + "%&nbsp;</td>\n";
    }

   content += "                                <td class=\"nationalMatrixRating\">21%</td>\n" +
               "                            </tr>\n"+
               "                            <tr>\n" +
               "                               <td colspan=\""+colspan+"\" style=\"border-left:1px solid #000;line-height:5px;background:#D5E2F5\">&nbsp;</td>\n" +
               "                            </tr>\n"+
               "                         <tr>\n" +
               "                             <td class=\"totals\" width=\"60%\"><div id=\"scoreDescription\">GetHomeCare.com&trade; Performance Score: </div></td>\n";
  if (allAgencies.length >= 1) {
      if(allAgencies.length == 1 && isTop20 == "true") {
          content +=  "                      <td colspan=\"1\" class=\"score\">" + score1 + "%</td><td rowspan='4' valign='middle' style='border:none'><img src=\"images/GHC_070110_Award_Spikey.jpg\"/></td>\n";
      } else {
          content +=  "                             <td colspan=\"2\" class=\"score\">" + score1 + "</td>\n";
      }
   }
    if (allAgencies.length > 1) {
        content +=  "                             <td colspan=\"2\" class=\"score\">" + score2 + "</td>\n";
     }
    if (allAgencies.length > 2) {
        content +=  "                             <td colspan=\"2\" class=\"score\">" + score3 + "</td>\n";
     }
    if (allAgencies.length > 3) {
        content +=  "                             <td colspan=\"2\" class=\"score\">" + score4 + "</td>\n";
     }
        content +=  "                         </tr>\n" +
                    "                         <tr>\n" +
                    "                             <td class=\"totals\" width=\"60%\"><div id=\"scoreDescription\">Improvement Bonus: </div></td>\n";
       if (allAgencies.length >= 1) {
             content +=  "                             <td colspan=\"2\" class=\"score\">" + adjustment1 + "</td>\n";
        }
         if (allAgencies.length > 1) {
             content +=  "                             <td colspan=\"2\" class=\"score\">" + adjustment2 + "</td>\n";
          }
         if (allAgencies.length > 2) {
             content +=  "                             <td colspan=\"2\" class=\"score\">" + adjustment3 + "</td>\n";
          }
         if (allAgencies.length > 3) {
             content +=  "                             <td colspan=\"2\" class=\"score\">" + adjustment4 + "</td>\n";
          }
             content +=  "                         </tr>\n" +

                "                         <tr>\n"+
                "                             <td class=\"totals\" width=\"60%\"><div id=\"scoreDescription\"><a href=\"javascript: showGetHomeCareScore();\"><img src=\"images/locator/whats_this2.gif\" alt=\"What is the GetHomeCare.com Score?\" title=\"What is the GetHomeCare.com Score?\" align=\"top\" border=\"0\"></a>&nbsp;&nbsp;GetHomeCare.com&trade; Score: </div></td>\n";
    if (allAgencies.length >= 1) {
          content +=  "                             <td colspan=\"2\" class=\"score\">" + (parseFloat(score1)+parseFloat(adjustment1)).toFixed(2) + "</td>\n";
     }
      if (allAgencies.length > 1) {
          content +=  "                             <td colspan=\"2\" class=\"score\">" + (parseFloat(score2)+parseFloat(adjustment2)).toFixed(2) + "</td>\n";
       }
      if (allAgencies.length > 2) {
          content +=  "                             <td colspan=\"2\" class=\"score\">" + (parseFloat(score3)+parseFloat(adjustment3)).toFixed(2) + "</td>\n";
       }
      if (allAgencies.length > 3) {
          content +=  "                             <td colspan=\"2\" class=\"score\">" + (parseFloat(score4)+parseFloat(adjustment4)).toFixed(2) + "</td>\n";
       }
          content+= "                       </tr>"+
                    "                       <tr>\n" +
                    "                           <td class=\"totals\" width=\"60%\"> <div id=\"percentileDescription\">GetHomeCare.com&trade; Percentile Rank: </div> </td>\n";
    if (allAgencies.length >= 1) {
          content +=  "                            <td colspan=\"2\" class=\"percentile\">" + percentile1 + "%</td>\n";
     }
      if (allAgencies.length > 1) {
        content +=  "                            <td colspan=\"2\" class=\"percentile\">" + percentile2 + "%</td>\n";
       }
      if (allAgencies.length > 2) {
        content +=  "                            <td colspan=\"2\" class=\"percentile\">" + percentile3 + "%</td>\n";
       }
      if (allAgencies.length > 3) {
        content +=  "                            <td colspan=\"2\" class=\"percentile\">" + percentile4 + "%</td>\n";
       }
    content += "                       </tr>\n"+
               "                       </table>\n<br/>\n" +
               "                       <table border=\"0\" width=\"98%\" align='center' class=\"legendTable\"> \n" +
               "                         <tr> \n"+
               "                            <td colspan=\"2\" style=\" border:1px solid #999; background:#D5E2F5; line-height: 5px;\">&nbsp;</td> \n"+
               "                          </tr> \n"+
               "                          <tr>\n" +
               "                            <td width=\"50%\" style=\"whitespace:nowrap;\">\n" +
               "                               <div id=\"legendImg\"><img src=\"images/locator/asterisk.gif\" border=\"0\"/></div>\n" +
               "                               <div>= HIGHER percentages are better</div>\n" +
               "                               <div id=\"legendImg\"><img src=\"images/locator/asterisk2.gif\" border=\"0\"/></div>\n" +
               "                               <div>= LOWER Percentages are better</div>\n" +
               "                             </td>\n" +
               "                             <td width=\"50%\" style=\"whitespace:nowrap;\">\n" +
               "                                <div id=\"trendUpImg\">&nbsp;</div>\n" +
               "                                <div id=\"trendUp\">= Agency performance is improving</div>\n" +
               "                                <div id=\"trendDownImg\">&nbsp;</div>\n" +
               "                                <div id=\"trendDown\">= Agency performance is declining</div>\n" +
               "                             </td>\n" +
               "                           </tr>\n" +
               "                           <tr>\n" +
               "                             <td colspan=\"3\">\n" +
               "                                 <P style=\"padding-top:5px;\"><b>Important notice:</b> Results based on latest publicly available Home Health Compare data from <a href=\"http://www.cms.hhs.gov/\"><b>CMS</b></a></P>\n" +
               "                             </td>\n" +
               "                           </tr> \n" +
               "                       </table>\n" +
               "                    </div>\n" +
               "                </div>\n" +
               "            </div>\n" +
               "        </div>\n" +
               "    </div>\n"+
               "<script language=\"JavaScript\" type=\"text/javascript\" src=\"/javascript/wz_tooltip.js\"></script>\n";


    log.debug("OK");
    if("false" == matrix[0].getAttribute("printable")) {
//    win.getContent().update(content);
//    win.setDestroyOnClose();
//    win.showCenter();
        popUpMatrix(content);
    }else {
      popUpMatrix(content);
    }
}
function openMatrixBad(ajax) {
    alert("Cannot generate Agency Matrix!");
    var response = ajax.responseXML.documentElement;
}
function printMatrix() {
    compareAgencies(true);
}
function buildMatrix() {
    compareAgencies(false);
}
function buildDetails(agencyId) {
    getAgencyDetails(agencyId,false);
}

function popUpMatrix(content){
    log.debug("inside popUpMatrix");
var matrix = window.open("","Medicare_Medicaid_Scorecard","width=770,height=650,scrollbars=1,status=1,resizable=1")
var html =
        "<html>\n"+
        "<head>\n"+
        "   <link rel=\"stylesheet\" href=\"css/locator/matrix.css\" type=\"text/css\" />\n"+
        "   <link rel=\"stylesheet\" href=\"css/ghc-template1-8pt.css\" type=\"text/css\" />\n" +
        "   <script language=\"javascript\" type=\"text/javascript\" src=\"javascript/locator/matrix.js\"></script>\n" +
        "   <script language=\"javascript\" type=\"text/javascript\" src=\"javascript/locator/locator.js\"></script>\n" +
        "   <link href=\"javascript/windows_js_1.0/themes/mac_os_x.css\" rel=\"stylesheet\" type=\"text/css\"/>\n"+
        "   <link href=\"javascript/windows_js_1.0/themes/darkX.css\" rel=\"stylesheet\" type=\"text/css\"/>\n"+
        "   <script type=\"text/javascript\" src=\"javascript/windows_js_1.0/javascripts/prototype.js\"></script>\n" +
        "   <script type=\"text/javascript\" src=\"javascript/windows_js_1.0/javascripts/window.js\"></script>\n" +
        "   <script type=\"text/javascript\" src=\"javascript/windows_js_1.0/javascripts/tooltip.js\"></script>\n" +
        "   <script type=\"text/javascript\" src=\"javascript/windows_js_1.0/javascripts/effects.js\"></script>\n" +
        "</head>\n"+
        "<body>\n" +content+"</body>\n"+
        "</html>";

//variable name of window must be included for all three of the following methods so that
//javascript knows not to write the string to this window, but instead to the new window

matrix.document.open();
    log.debug("1");
matrix.document.write(html);
    log.debug("2");
matrix.document.close();
    log.debug("3");

}

