﻿/*
This file is Copyright (c) 2010 Bankrate, Inc.
No part of this file may be modified in any way without expressed written permission from an authorized representative from Bankrate Inc.
*/

var strPID = "";
var BRMcdRateTable = {
    RequestServer: "partnerservices.bankrate.com",
    checkForIE: false,
    oRow: null,
    rowCount: 1,
    Partner: '',
    Key: '',
    ReportSuite: null,
    widgetWidth: '800',
    DefaultZipOverride: '90033',
    Market: 0,
    Zip: '',
    Natl: true,
    widgetHeight: '800',
    widgetType: false,
    ieVersion: '',
    is_chrome: false,
    ServiceStatus: false,
    cdrateProduct: '15',
    CDNoRecord: false,
    Init: function () {
        if (typeof (BRMcdRateTableVars) != 'undefined' && BRMcdRateTableVars != null) {

            var Defaults = BRMcdRateTableVars;

            if (typeof (Defaults.Partner) != "undefined" && Defaults.Partner != null && typeof (Defaults.Key) != "undefined" && Defaults.Key != null) {
                this.Partner = Defaults.Partner;
                this.Key = Defaults.Key;
            }
            if (typeof (Defaults.ReportSuite) != "undefined" && Defaults.ReportSuite != null && Defaults.ReportSuite != '') {
                this.ReportSuite = Defaults.ReportSuite;
            }

            if (typeof (Defaults.Market) != "undefined" && Defaults.Market != null && Defaults.Market != '') {
                this.Market = Defaults.Market;
            }
            if (typeof (Defaults.ZipCode) != "undefined" && Defaults.ZipCode != null) {
                if (Defaults.ZipCode != "") {
                    if (this.ValidateZip(Defaults.ZipCode.replace(' ', ''))) {
                        this.Zip = Defaults.ZipCode.replace(' ', '');
                        this.Natl = false;
                    }
                }
            }
            if (typeof (Defaults.Width) != "undefined" && Defaults.Width != null) {
                if (!isNaN(Defaults.Width.replace('px', '')) && Defaults.Width.replace('px', '') != "") {
                    if (parseInt(Defaults.Width.replace('px', '')) < 470)
                        this.widgetWidth = '470';
                    else if (parseInt(Defaults.Width.replace('px', '')) > 980)
                        this.widgetWidth = '980';
                    else
                        this.widgetWidth = Defaults.Width.replace('px', '');
                }
            }

            if (typeof (Defaults.Height) != "undefined" && Defaults.Height != null) {
                if (!isNaN(Defaults.Height.replace('px', '')) && Defaults.Height.replace('px', '') != "") {
                    if (parseInt(Defaults.Height.replace('px', '')) < 650)
                        this.widgetHeight = '650';
                    else if (parseInt(Defaults.Height.replace('px', '')) > 2000)
                        this.widgetHeight = '2000';
                    else
                        this.widgetHeight = Defaults.Height.replace('px', '');
                }
            }
            if (typeof (Defaults.Product) != "undefined" && Defaults.Product != null && Defaults.Product != '') {
                this.cdrateProduct = Defaults.Product;
            }
        }
        else {
            try {
                var RateTableValues = WidgetsCommon.GetPIDfromCookie();
                RateTableValues = RateTableValues.split(',');

                this.Partner = RateTableValues[0].substr(2);
                this.Key = RateTableValues[1];
            } catch (e) {

            }
        }
        var ie = (typeof window.ActiveXObject != 'undefined');
        if (ie) {
            this.checkForIE = true;
        }

        var match = navigator.userAgent.match('MSIE (.)');
        this.ieVersion = match && match.length > 1 ? match[1] : 'unknown';

        this.is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

        this.CreateCDRHTMLwrap();
        this.SetCDDefaultProduct(this.cdrateProduct);
        this.FetchCDRate(true);

    },

    ValidateZip: function (zipValue) {
        if (isNaN(zipValue)) {
            return false;
        }
        for (i = 0; i < zipValue.length; i++) {
            var c = zipValue.charAt(i);
            if (c == "-" || ((c < "0") || (c > "9"))) {
                return false;
            }
        }
        if (zipValue != "") {
            if (zipValue.length == 5) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return true;
        }
    },

    SetCDDefaultProduct: function (productVal) {
        var cdValueNotFound = true;
        for (var i = 0; i < document.getElementById('cdRateProducts').length; i++) {
            if (document.getElementById('cdRateProducts')[i].value == productVal) {
                document.getElementById('cdRateProducts').selectedIndex = i;
                cdValueNotFound = false;
            }
        }
        if (cdValueNotFound)
            document.getElementById('cdRateProducts').selectedIndex = 0;
    },

    CDServiceDownAdjustments: function () {
        if (this.CDNoRecord) {
            document.getElementById('cdResize').style.width = this.widgetWidth + 'px';
            document.getElementById('cdResize').style.height = this.widgetHeight + 'px';
        }

        if (this.ieVersion == '7') {
            document.getElementById('cdResizeHeight').style.height = (parseInt(this.widgetHeight) - 220) + 'px';
        }
        else {
            document.getElementById('cdResizeHeight').style.height = (parseInt(this.widgetHeight) - 180) + 'px';
        }

    },

    SetDynamicAdjustments: function () {
        // check if we are in the affiliate center:
        var dynamicSliderInput = document.getElementById("rateTableDynamicWidth");
        if (dynamicSliderInput != null) {
            this.widgetWidth = dynamicSliderInput.value.replace('px', '');
        }

        var dynamicSliderHeightInput = document.getElementById("rateTableDynamicHeight");
        if (dynamicSliderHeightInput != null) {
            this.widgetHeight = dynamicSliderHeightInput.value.replace('px', '');
        }

        if (this.CDNoRecord) {
            this.CDServiceDownAdjustments();
        }
        else {
            var heightVal = 0;

            if (this.ieVersion == '7') {
                if (parseInt(this.widgetWidth) >= 470 && (parseInt(this.widgetWidth) < 573))
                    heightVal = parseInt(this.widgetHeight) - 385;
                else if (parseInt(this.widgetWidth) >= 573 && (parseInt(this.widgetWidth) < 577))
                    heightVal = parseInt(this.widgetHeight) - 370;
                else if (parseInt(this.widgetWidth) >= 577 && (parseInt(this.widgetWidth) < 585))
                    heightVal = parseInt(this.widgetHeight) - 355;
                else if (parseInt(this.widgetWidth) >= 585 && (parseInt(this.widgetWidth) < 674))
                    heightVal = parseInt(this.widgetHeight) - 345;
                else if (parseInt(this.widgetWidth) >= 674)
                    heightVal = parseInt(this.widgetHeight) - 330;
            }
            else if (this.ieVersion == '8') {
                if (parseInt(this.widgetWidth) >= 470 && (parseInt(this.widgetWidth) < 574))
                    heightVal = parseInt(this.widgetHeight) - 355;
                else if (parseInt(this.widgetWidth) >= 574 && (parseInt(this.widgetWidth) < 585))
                    heightVal = parseInt(this.widgetHeight) - 330;
                else if (parseInt(this.widgetWidth) >= 585)
                    heightVal = parseInt(this.widgetHeight) - 305;
            }
            else if (this.ieVersion == '9') {
                if (parseInt(this.widgetWidth) >= 470 && (parseInt(this.widgetWidth) < 575))
                    heightVal = parseInt(this.widgetHeight) - 345;
                else if (parseInt(this.widgetWidth) >= 575 && (parseInt(this.widgetWidth) < 592))
                    heightVal = parseInt(this.widgetHeight) - 320;
                else if (parseInt(this.widgetWidth) >= 592)
                    heightVal = parseInt(this.widgetHeight) - 295;
            }
            else {
                if (parseInt(this.widgetWidth) >= 470 && (parseInt(this.widgetWidth) < 575))
                    heightVal = parseInt(this.widgetHeight) - 355;
                else if (parseInt(this.widgetWidth) >= 575 && (parseInt(this.widgetWidth) < 591))
                    heightVal = parseInt(this.widgetHeight) - 320;
                else if (parseInt(this.widgetWidth) >= 591)
                    heightVal = parseInt(this.widgetHeight) - 305;
            }

            document.getElementById('cdResizeHeight').style.height = heightVal + "px";
            document.getElementById('cdResize').style.width = this.widgetWidth + 'px';
        }
        //Header Adjustments
        if (this.checkForIE) {
            if (this.widgetWidth <= 600) {
                document.getElementById("cd_institution_column").style.width = "32%";
                document.getElementById("cd_apr_column").style.width = "18%";
                document.getElementById("cd_rate_column").style.width = "15.5%";
                document.getElementById("cd_deposit_column").style.width = "16%";
                document.getElementById("cdcommentsTh").style.width = "18%";
            }
            else {
                document.getElementById("cd_institution_column").style.width = "27%";
                document.getElementById("cd_apr_column").style.width = "15%";
                document.getElementById("cd_rate_column").style.width = "13%";
                document.getElementById("cd_deposit_column").style.width = "13%";
                document.getElementById("cdcommentsTh").style.width = "auto";
            }
        }
        else {
            if (this.widgetWidth <= 600) {
                document.getElementById("cd_institution_column").style.width = "32%";
                document.getElementById("cd_apr_column").style.width = "18%";
                document.getElementById("cd_rate_column").style.width = "16%";
                document.getElementById("cd_deposit_column").style.width = "16%";
            }
            else {
                document.getElementById("cd_institution_column").style.width = "26%";
                document.getElementById("cd_apr_column").style.width = "15%";
                document.getElementById("cd_rate_column").style.width = "13%";
                document.getElementById("cd_deposit_column").style.width = "13%";
            }
        }
        this.ShowCDComments();
    },

    ShowCDComments: function () {
        var showBottomComments = 0;
        if (this.widgetWidth <= 600) {
            document.getElementById("cdcommentsThDiv").style.visibility = 'hidden';
            showBottomComments = 1;
        } else {
            document.getElementById("cdcommentsThDiv").style.visibility = 'visible';
        }

        var tdSelections = document.getElementsByTagName('td');
        var len = tdSelections.length;

        for (var i = 0; i < len; i++) {

            if (tdSelections[i].className == "braff-cd-bottom-comments") {
                tdSelections[i].style.display = showBottomComments == 1 ? "" : "none";
            }

            if (tdSelections[i].className == "comments") {
                if (this.checkForIE) {
                    tdSelections[i].firstChild.style.display = showBottomComments == 0 ? "block" : "block";
                    if (this.widgetWidth <= 600) {
                        if (this.ieVersion == 7) {
                            tdSelections[i].style.width = "0%";
                        }
                        else {
                            tdSelections[i].style.width = "1%";
                        }
                        tdSelections[i].firstChild.style.display = "none";
                    }
                    else {
                        tdSelections[i].style.width = "20%";
                        tdSelections[i].firstChild.style.display = "block";
                    }
                }
                else {
                    tdSelections[i].firstElementChild.style.display = showBottomComments == 0 ? "block" : "none";
                    if (this.widgetWidth <= 600) {
                        tdSelections[i].style.width = "0%";
                    }
                    else {
                        tdSelections[i].style.width = "20%";
                    }
                }
            }
        }
    },

    GetCDRateJSONP: function () {
        var domainLoc = window.location.hostname == 'localhost' ? 'live.dev.bankrate.com' : window.location.hostname;
        var url = 'http://' + this.RequestServer + '/channels/partners/rates/cds/' + this.Partner + '/' + this.Key + '/' + domainLoc + '?market=0&format=json';
        this.cdrateProduct = document.getElementById("cdRateProducts").value;
        if (this.Zip == '')
            this.Natl = true;
        else
            this.Natl = false;
        url += "&products=" + this.cdrateProduct + "&zip=" + this.Zip + "&def=" + this.DefaultZipOverride;
        url += "&natl=" + this.Natl;
        if (typeof (this.ReportSuite) != "undefined" && this.ReportSuite != null) {
            url += "&omni=true";
        }
        url += "&method=BRMcdRateTable.CDRateTableCallback";

        if (this.Partner == '' || this.Key == '') {
            document.getElementById("cdLoadingImgDiv").style.display = 'none';
            document.getElementById('cdServiceTurnOff').style.display = 'block';
        }
        else {
            javascript: setTimeout("BRMcdRateTable.CDCheckServiceStatus()", 10000);
            var script = document.createElement("script");
            script.id = "BRMcdRateTableJSONPScript";
            script.setAttribute("src", url);
            script.setAttribute("type", "text/javascript");
            document.getElementsByTagName('head')[0].appendChild(script);
        }
    },
    CDCheckServiceStatus: function () {
        if (!BRMcdRateTable.ServiceStatus) {
            this.CDNoRecord = true;
            this.SetDynamicAdjustments();
            document.getElementById("cdLoadingImgDiv").style.display = 'none';
            document.getElementById('cdServiceTurnOff').style.display = 'block';
        }
    },
    RemoveScript: function (scriptToRemove) {
        var s = document.getElementById(scriptToRemove);
        if (s != null && typeof (s) != "undefined") {
            document.getElementsByTagName('head')[0].removeChild(s);
        }
    },

    CDRateTableCallback: function (strXML) {
        BRMcdRateTable.ServiceStatus = true;
        document.getElementById('cdServiceTurnOff').style.display = 'none';
        document.getElementById("cdLoadingImgDiv").style.display = 'block';
        this.RemoveScript('BRMcdRateTableJSONPScript');
        if (strXML != null) {
            this.SetCDDefaultProduct(this.cdrateProduct);
            this.CDRateFillBody(strXML);
        }
    },

    FetchCDRate: function (updateDropdownValues) {
        try {
            if (this.checkForIE) {
                document.getElementById("BRcdRateTB").innerText = '';
            } else {
                document.getElementById("BRcdRateTB").innerHTML = '';
            }
        } catch (e) {
            var test = true;
        }

        this.GetCDRateJSONP();
    },

    SetRowMouseOver: function (rID) {
        document.getElementById(rID).setAttribute('class', 'p');
    },

    SetRowMouseOut: function (rID) {
        document.getElementById(rID).setAttribute('class', 'np');
    },

    FormatCurrency: function (num) {
        num = num.toString().replace(/\$|\,/g, '');
        if (isNaN(num))
            num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num * 100 + 0.50000000001);
        cents = num % 100;
        num = Math.floor(num / 100).toString();
        if (cents < 10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' +
				num.substring(num.length - (4 * i + 3));
        return (((sign) ? '' : '-') + '$' + num + '.' + cents);
    },

    CustomDate: function (xmlDate) {
        var date = xmlDate.split("/");
        if (date[2].length == 2)
            xmlDate = date[0] + "/" + date[1] + "/" + "20" + date[2];

        var mydate = new Date(xmlDate);
        var day = mydate.getDay();
        var month = mydate.getMonth();
        var daym = mydate.getDate();

        if (daym < 10)
            daym = "0" + daym;

        var dayarray = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
        var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
        var returnDate = dayarray[day] + " " + montharray[month] + " " + daym;

        return returnDate;
    },

    CreateCDRHTMLwrap: function () {
        document.write("<div>");
        document.write("<div class=\"braff-brate-maincontainer\" id=\"cdResize\" style=\"width:470px;height:650;\">");
        document.write("<span class=\"braff-brate-topright\"></span><span class=\"braff-brate-topleft\"></span>");
        document.write("<div class=\"braff-brate-rail\">");
        document.write("<div id=\"CDRoTableContainer\" class=\"braff-brate-contents\">");
        document.write("<h1 id=\"BRCDrateHeader\"></h1>");
        document.write("<p id=\"BRCDrateSeoheading\"></p>");
        document.write("<div class=\"braff-searchtabs\">");
        document.write("<div class=\"braff-cdhed\">Find Your Best Rate</div>");
        document.write("<div class=\"braff-tabcontainer1\">");
        document.write("<ul class=\"braff-searchcontrols\">");

        document.write("<li style=\"margin:0px;\"><span>Products:</span>");
        document.write("<select id=\"cdRateProducts\" name=\"CDprods\">");
        document.write("<option value=\"15\">1 year CD</option>");
        document.write("<option value=\"159\">1 month CD</option>");
        document.write("<option value=\"13\">3 month CD</option>");
        document.write("<option value=\"14\">6 month CD</option>");
        document.write("<option value=\"439\">9 month CD</option>");
        document.write("<option value=\"16\">2 year CD</option>");
        document.write("<option value=\"18\">3 year CD</option>");
        document.write("<option value=\"19\">5 year CD</option>");
        document.write("<option value=\"24\">1 year jumbo CD</option>");
        document.write("<option value=\"26\">5 year jumbo CD</option>");
        document.write("</select>");
        document.write("</li>");

        document.write("<li>");
        document.write("<input type=\"button\" class=\"braff-brate-search-btn\" style=\"margin-top:18px;\" onclick=\"BRMcdRateTable.ShowCDSearchPage()\" />");
        document.write("</li>");
        document.write("</ul>");
        document.write("</div>");
        document.write("</div>");

        document.write("<table id=\"cdTableHeaders\" class=\"braff-brate-static-header\" cellpadding=\"0\" cellspacing=\"0\" >");
        document.write("<thead>");
        document.write("<tr>");
        document.write("<th id=\"cd_institution_column\"  class=\"braff-lender\" >");
        document.write("<div id=\"CD_institution_header\"  style = \"text-decoration:underline;cursor:pointer; float:left; margin-top:13px;\">Institution</div>");
        document.write("</th>");
        document.write("<th id=\"cd_apr_column\" class=\"braff-cd-apr\" >");
        document.write("<div id=\"CD_apr_header\" style = \"text-decoration:underline;cursor:pointer; float:left;margin-top:13px;\">APY</div>");
        document.write("</th>");
        document.write("<th id=\"cd_rate_column\" class=\"braff-cd-rate\" >");
        document.write("<div id=\"CD_rate_header\" style = \"text-decoration:underline;cursor:pointer; float:left; margin-top:13px; \">Rate</div>");
        document.write("</th>");
        document.write("<th id=\"cd_deposit_column\" class=\"braff-cd-cost\" >");
        document.write("<div id=\"CD_deposit_header\" style = \"text-decoration:underline;cursor:pointer; float:left; margin-top:13px;\">Min Deposit</div>");
        document.write("</th>");
        document.write("<th id=\"cdcommentsTh\" class=\"braff-comments\" >");
        document.write("<div id=\"cdcommentsThDiv\" style=\"color: #024E8A; text-decoration :none; cursor:default; margin-top:13px;\">Comments</div>");
        document.write("</th>");
        document.write("<th class=\"braff-cd-contact\" ></th>");

        document.write("</tr>");
        document.write("</thead>");
        document.write("</table>");

        document.write("<div id=\"cdResizeHeight\" class=\"braff-brate-results-container\">");
        document.write("<div id=\"cdLoadingImgDiv\" style = \"display:block; text-align: center\" >");
        document.write("<img src=\"http://www.bankrate.com/system/img/brspin.gif\" />");
        document.write("</div>");
        document.write("<div id=\"cdServiceTurnOff\" style = \"display:none; text-align: left;font-family:Arial, Helvetica, sans-serif;font-size:12px;font-weight:bold;color:#024E8A;padding:50px;\" >");
        document.write("Sorry, we are experiencing some technical difficulties. Please try again or contact the webmaster.");
        document.write("</div>");
        document.write("<table id=\"cdRateoTable\" class=\"braff-brate-results-tbl\" cellpadding=\"0\" cellspacing=\"0\" >");
        document.write("<div id=\"dvCDtableBody\" style = \"display:none\"><tbody id=\"BRcdRateTB\"></tbody></div>");
        document.write("</table>");
        document.write("</div>");

        document.write("<p id=\"BRCDmoreInfo\"></p>");
        document.write("<ul id=\"BRCDadditionalLinks\" class=\"braff-disc-pts\" style = \"font-size: 11px;\"></ul>");
        document.write("</div>");
        document.write("</div>");
        document.write("<span class=\"braff-brate-botright\"></span><span class=\"braff-brate-botleft\"></span>");
        document.write("<div class=\"braff-brate-attr\">");
        document.write("<span>Powered by:</span> <a href=" + "http://www.bankrate.com?pid=p:" + this.Partner + " target=\"_blank\"><img height=\"21\" border=\"0\" width=\"114\" src=\"http://www.bankrate.com/images/brm_logos/bankrate-logo.gif\"></a>");
        document.write("</div>");
        document.write("</div>");
        document.write("</div>");
    },

    ShowCDSearchPage: function () {
        this.rowCount = 1;
        document.getElementById("cdServiceTurnOff").style.display = 'none';
        document.getElementById("dvCDtableBody").style.display = 'none';
        document.getElementById("cdLoadingImgDiv").style.display = 'block';
        this.FetchCDRate(false);
    },

    FnCDRateInit: function (cdImgId, cdLenderId, cdStarRating, cdApy, cdDate, cdRate, cdCompounding, cdMinDeposit, cdComments, cdCPC,
					cdCommentsHyperlinked, cdNameHyperlinkAvailable, cdListingType, cdDefaultSort, cdLenderSort, cdApySort, cdRateSort, cdMinDepSort, cdSvyinstitutionId, count) {

        var oTable = document.getElementById("BRcdRateTB");
        var oDiv = document.createElement("div");
        var oCell, oCell1, oCell2, oCell3, oCell4, oCell5;
        var i, j;
        var cpcLink = cdCPC;

        oRow = document.createElement("tr");
        var rowID = 'oRow' + this.rowCount;

        if (cdComments.length > 10) {
            oRow.setAttribute('style', 'border-bottom:hidden');
        }

        oTable.appendChild(oRow);
        oCell = document.createElement("td");
        oCell.className = "lender";

        var fixedID = document.createElement('div');
        fixedID.style.display = "none";
        fixedID.innerHTML = count;
        fixedID.setAttribute('id', count);
        oCell.appendChild(fixedID);

        var lenderSortDiv = document.createElement('div');
        lenderSortDiv.style.display = "none";
        lenderSortDiv.innerHTML = cdLenderSort;
        oCell.appendChild(lenderSortDiv);

        var a = document.createElement('a');
        var clickOnLender = 'lender';
        if (cdListingType.toLowerCase() == 'paid' && cdImgId != null && cdImgId.length != 0) {
            var imeg = document.createElement('img');
            imeg.setAttribute('src', 'http://www.bankrate.com/system/img/inst/' + cdImgId + '_logo.gif');
            imeg.setAttribute('height', '45');
            imeg.setAttribute('border', '0');
            imeg.setAttribute('width', '125');
            if (cdNameHyperlinkAvailable.toLowerCase() == 'true') {
                if (this.checkForIE) {
                    a.onclick = new Function("BRMcdRateTable.CDRateTrackClick(8, this, '" + cpcLink + "', '" + clickOnLender + "');");
                } else {
                    a.setAttribute("onclick", "BRMcdRateTable.CDRateTrackClick(8, this, '" + cpcLink + "', '" + clickOnLender + "');");
                }

                a.style.cursor = 'pointer';
                a.appendChild(imeg);
                oCell.appendChild(a);
            } else {
                oCell.appendChild(imeg);
            }
            if (this.checkForIE) {
                oCell.style.verticalAlign = 'middle';
            }
        }
        else {
            var lenderName = document.createElement('div');
            lenderName.innerHTML = cdLenderId;
            if (cdListingType.toLowerCase() == 'paid' && cdNameHyperlinkAvailable.toLowerCase() == 'true') {
                if (this.checkForIE) {
                    a.onclick = new Function("BRMcdRateTable.CDRateTrackClick(2, this, '" + cpcLink + "', '" + clickOnLender + "');");
                } else {
                    a.setAttribute("onclick", "BRMcdRateTable.CDRateTrackClick(2,this,'" + cpcLink + "', '" + clickOnLender + "');");
                }

                a.appendChild(lenderName);
                a.style.cursor = 'pointer';
                oCell.appendChild(a);
            }
            else {
                oCell.appendChild(lenderName);
            }

            lenderName.style.width = "130px";
            lenderName.style.fontWeight = 'bold';
            if (this.checkForIE) {
                oCell.style.verticalAlign = 'middle';
            }
        }
        var starsRating = document.createElement('div');
        var imgStars = document.createElement('img');
        if (cdStarRating != '' && cdStarRating.toLowerCase() != 'nr') {
            imgStars.setAttribute('src', 'http://www.bankrate.com/system/img/stars' + cdStarRating + '.gif');
            //var starRedirectUrl = 'http://www.bankrate.com/funnel/star-ratings-explanation.aspx?a=' + cdSvyinstitutionId;
            // starsRating.setAttribute("onclick", "BRMcdRateTable.redirectStars('" + starRedirectUrl + "');");
            //starsRating.style.cursor = 'pointer';
            starsRating.style.height = "17px";
            starsRating.appendChild(imgStars);
            oCell.appendChild(starsRating);
        }
        else if (cdStarRating.toLowerCase() == 'nr')
            starsRating.innerHTML = 'NR';
        oCell.appendChild(starsRating);

        oRow.appendChild(oCell);
        oCell1 = document.createElement("td");
        oCell1.className = "cd-apr";

        var aprDiv1 = document.createElement('div');
        aprDiv1.className = "apr";
        aprDiv1.innerHTML = cdApy + "%";

        var aprDate1 = document.createElement('div');
        aprDate1.innerHTML = cdDate;

        var aprDivSort = document.createElement('div');
        aprDivSort.innerHTML = cdApySort;
        aprDivSort.style.display = "none";

        oCell1.appendChild(aprDivSort);
        oCell1.appendChild(aprDiv1);
        oCell1.appendChild(aprDate1);

        if (this.checkForIE) {
            oCell1.style.verticalAlign = 'middle';
        }
        oRow.appendChild(oCell1);

        oCell2 = document.createElement("td");
        oCell2.className = "cd-rate";
        var rateDiv1 = document.createElement('div');
        rateDiv1.innerHTML = cdRate + "%";
        var compoundType = document.createElement('div');
        if (cdCompounding.toLowerCase() == "d")
            compoundType.innerHTML = "Compounded daily";
        else if (cdCompounding.toLowerCase() == "m")
            compoundType.innerHTML = "Compounded monthly";
        else if (cdCompounding.toLowerCase() == "a")
            compoundType.innerHTML = "Compounded annually";
        else if (cdCompounding.toLowerCase() == "q")
            compoundType.innerHTML = "Compounded quartely";
        else if (cdCompounding.toLowerCase() == "s")
            compoundType.innerHTML = "Simple interest";

        var rateDivSort = document.createElement('div');
        rateDivSort.innerHTML = cdRateSort;
        rateDivSort.style.display = "none";

        oCell2.appendChild(rateDivSort);
        oCell2.appendChild(rateDiv1);
        oCell2.appendChild(compoundType);
        if (this.checkForIE) {
            oCell2.style.verticalAlign = 'middle';
        }
        oRow.appendChild(oCell2);

        oCell3 = document.createElement("td");
        oCell3.className = "cd-cost";
        var minDep = document.createElement('div');
        minDep.innerHTML = this.FormatCurrency(cdMinDeposit).replace(".00", "");

        var minDepDivSort = document.createElement('div');
        minDepDivSort.innerHTML = cdMinDepSort;
        minDepDivSort.style.display = "none";

        oCell3.appendChild(minDepDivSort);
        oCell3.appendChild(minDep);
        oRow.appendChild(oCell3);

        var dynamicWidgetWidth = parseInt(this.widgetWidth.replace('px', ''));

        var cdcommentsDiv = document.createElement('div');
        oCell4 = document.createElement("td");
        oCell4.className = "comments";
        if (cdListingType.toLowerCase() == 'paid' && cdCommentsHyperlinked.toLowerCase() == 'true') {
            var a1 = document.createElement('a');
            var clickOnComments = 'comment';
            if (this.checkForIE) {
                a1.onclick = new Function("BRMcdRateTable.CDRateTrackClick(5, this, '" + cpcLink + "', '" + clickOnComments + "');");
            } else {
                a1.setAttribute("onclick", "BRMcdRateTable.CDRateTrackClick(5,this,'" + cpcLink + "', '" + clickOnComments + "');");
            }

            a1.innerHTML = cdComments;
            a1.style.cursor = 'pointer';
            a1.setAttribute('target', '_blank');
            cdcommentsDiv.appendChild(a1);
            oCell4.appendChild(cdcommentsDiv);
        } else {
            var s1 = document.createElement('span');

            if (cdComments.length < 1) {
                cdComments = '&nbsp;';
            }

            s1.innerHTML = cdComments;
            cdcommentsDiv.appendChild(s1);
            oCell4.appendChild(cdcommentsDiv);
        }

        if (this.checkForIE) {
            oCell4.style.verticalAlign = 'middle';
        }
        oRow.setAttribute('style', 'border-bottom:1px solid #BFC4C8;');
        oRow.appendChild(oCell4);
        oCell5 = document.createElement("td");
        oCell5.className = "contact";
        var imeg1 = document.createElement('img');
        imeg1.setAttribute('src', 'http://www.bankrate.com/system/img/green-go-btn2.gif');
        if (cdListingType.toLowerCase() == 'paid' && cdNameHyperlinkAvailable.toLowerCase() == 'true') {
            var a2 = document.createElement('a');
            var clickOnGo = 'go';
            if (this.checkForIE) {
                a2.onclick = new Function("BRMcdRateTable.CDRateTrackClick(11, this, '" + cpcLink + "', '" + clickOnGo + "');");
            } else {
                a2.setAttribute("onclick", "BRMcdRateTable.CDRateTrackClick(11,this,'" + cpcLink + "', '" + clickOnGo + "');");
            }

            a2.style.cursor = 'pointer';
            a2.appendChild(imeg1);
            oCell5.appendChild(a2);
        } else {
            oCell5.innerHTML = '&nbsp;';
        }

        if (this.checkForIE) {
            oCell5.style.verticalAlign = 'middle';
        }
        oRow.appendChild(oCell5);

        oRow.setAttribute('id', rowID);

        oRow.className = 'np';

        var boolComment = false;
        var commentRowId = "";

        if (cdComments.length > 6) {
            boolComment = true;
            commentRowId = "comment" + this.rowCount;
            var ancherId = "ancher" + this.rowCount;

            oCommentRow = document.createElement("tr");
            oTable.appendChild(oCommentRow);
            oCell6 = document.createElement("td");
            oCell6.className = "braff-cd-bottom-comments";
            oCell6.setAttribute('colSpan', '6');
            oCell6.setAttribute('id', commentRowId);

            var commentsIdDiv = document.createElement('div');
            commentsIdDiv.innerHTML = rowID + "~" + commentRowId + "~" + boolComment + "~" + ancherId + "~" + cdComments;
            commentsIdDiv.style.display = "none";
            oCell6.appendChild(commentsIdDiv);

            if (this.checkForIE) {
                oCell6.onmouseover = new Function("BRMcdRateTable.MouseOver('" + rowID + "', '" + commentRowId + "', '" + boolComment + "');");
                oCell6.onmouseout = new Function("BRMcdRateTable.MouseOut('" + rowID + "', '" + commentRowId + "', '" + boolComment + "');");
            } else {
                oCell6.setAttribute("onmouseover", "BRMcdRateTable.MouseOver('" + rowID + "', '" + commentRowId + "', '" + boolComment + "');");
                oCell6.setAttribute("onmouseout", "BRMcdRateTable.MouseOut('" + rowID + "', '" + commentRowId + "', '" + boolComment + "');");
            }

            if (cdListingType.toLowerCase() == 'paid' && cdNameHyperlinkAvailable == 'true') {
                var a1 = document.createElement('a');
                a1.setAttribute('id', ancherId);
                commentsIdDiv.innerHTML = rowID + "~" + commentRowId + "~" + boolComment + "~" + ancherId + "~" + cdComments + "~" + cpcLink;
                var clickOnBottomComment = 'bottomComment';
                if (this.ieVersion == 7) {
                    a1.onclick = new Function("BRMcdRateTable.CDRateTrackClick(5, this, '" + cpcLink + "', '" + clickOnBottomComment + "');");
                } else {
                    a1.setAttribute("onclick", "BRMcdRateTable.CDRateTrackClick(5,this,'" + cpcLink + "', '" + clickOnBottomComment + "');");
                }

                a1.innerHTML = '<u>' + cdComments + '</u>';
                a1.style.cursor = 'pointer';
                a1.setAttribute('target', '_blank');
                oCell6.appendChild(a1);
            } else {
                var s1 = document.createElement('span');
                s1.innerHTML = cdComments;
                oCell6.appendChild(s1);
            }

            oCommentRow.appendChild(oCell6);
        }
        if (this.checkForIE) {
            oRow.onmouseover = new Function("BRMcdRateTable.MouseOver('" + rowID + "', '" + commentRowId + "', '" + boolComment + "');");
            oRow.onmouseout = new Function("BRMcdRateTable.MouseOut('" + rowID + "', '" + commentRowId + "', '" + boolComment + "');");
        } else {
            oRow.setAttribute("onmouseover", "BRMcdRateTable.MouseOver('" + rowID + "', '" + commentRowId + "', '" + boolComment + "');");
            oRow.setAttribute("onmouseout", "BRMcdRateTable.MouseOut('" + rowID + "', '" + commentRowId + "', '" + boolComment + "');");
        }
        fixedID.innerHTML = boolComment;
        this.rowCount = this.rowCount + 1;
    },

    MouseOut: function (dataRow, commentRow, commentStaus) {
        document.getElementById(dataRow).className = "np";
        if (commentStaus == 'true') {
            document.getElementById(commentRow).className = "braff-cd-bottom-comments";
        }
    },

    MouseOver: function (dataRow, commentRow, commentStaus) {
        document.getElementById(dataRow).className = "br-mouseover-data";
        if (this.checkForIE && this.ieVersion != 7 || this.is_chrome) {
            document.getElementById(dataRow).style.height = '74px';
        }

        if (commentStaus == 'true') {
            document.getElementById(commentRow).className = "br-mouseover-bottom-comments";
            document.getElementById(commentRow).style.borderRight = '1px solid #BFC4C8';
            document.getElementById(commentRow).style.borderLeft = '1px solid #BFC4C8';
        }
    },

    CDRateTrackClick: function (clickType, obj, url, clickOnType) {
        var today = new Date(); var year = today.getFullYear(); var month = today.getMonth() + 1; var date = today.getDate();
        var hour = today.getHours(); var minute = today.getMinutes(); var second = today.getSeconds(); var millisecond = today.getMilliseconds();
        var currentDT = month + '/' + date + '/' + year + ' ' + hour + ':' + minute + ':' + second + '.' + millisecond;
        var overrides = '';
        var v38_id = '';
        if (clickOnType == 'comment') {
            overrides = obj.parentNode.parentNode.parentNode.id.replace("oRow", "") + "," + clickType + ",,";
            v38_id = obj.parentNode.parentNode.parentNode.id.replace("oRow", "");
        }
        else if (clickOnType == 'lender' || clickOnType == 'go') {
            overrides = obj.parentNode.parentNode.id.replace("oRow", "") + "," + clickType + ",,";
            v38_id = obj.parentNode.parentNode.id.replace("oRow", "");
        }
        else if (clickOnType == 'bottomComment') {
            overrides = obj.parentNode.id.replace("comment", "") + "," + clickType + ",,";
            v38_id = obj.parentNode.id.replace("comment", "");
        }
        var cpcLink = url;
        if (url.indexOf('||') != -1) {
            var cpcValues = url.split('||');
            cpcLink = cpcValues[0];

            var omniValues = cpcValues[1].split(',');
            this.TrackLink(this, omniValues[0], omniValues[1], omniValues[1], omniValues[2], omniValues[3], omniValues[4], v38_id, omniValues[6], clickType);
        }

        var redirectTo = cpcLink + "&c=" + overrides + '&click_date=' + currentDT + '&ref_url=' + escape(location.href);
        window.open(redirectTo);
    },

    redirectStars: function (url) {
        window.open(url);
    },

    TrimAll: function (sString) {
        while (sString.substring(0, 1) == ' ') {
            sString = sString.substring(1, sString.length);
        }
        while (sString.substring(sString.length - 1, sString.length) == ' ') {
            sString = sString.substring(0, sString.length - 1);
        }
        return sString;
    },

    CDRateFillBody: function (json) {
        try {
            if (json.bankrate.data != null && json.bankrate.data != 'undefined') {
                var widgetHeader = (json.bankrate.data.response.global.header).toLowerCase();
                var strToFind = widgetHeader.match('national');
                if (strToFind != null)
                    document.getElementById("BRCDrateHeader").innerHTML = 'National High Yield Rates for CDs';
                else
                    document.getElementById("BRCDrateHeader").innerHTML = json.bankrate.data.response.global.header;

                document.getElementById("BRCDrateSeoheading").innerHTML = "Compare rates with confidence. Rates are accurate and available as of the date seen " +
				"for Bankrate customers.";

                document.getElementById("BRCDmoreInfo").innerHTML = "Institutions may have different rates on other sites.  Identify yourself as a Bankrate.com customer for these rates.  Rates are subject to change.  " +
				"Some institutions pay for links, though many do not.  All institutions insured by FDIC."

                document.getElementById("BRCDadditionalLinks").innerHTML =
				"<li>For more rates, products or information <a href=\"http://www.bankrate.com/compare-rates.aspx?pid=p:" + this.Partner + "\" target=\"_blank\" style= \"color:#024E8A; font-weight:bold; text-decoration:underline;\">click here</a>.</li>" +
				"<li>To advertise on Bankrate.com's rate tables, <a href=\"http://www.bankrate.com/mediakit/contactus.asp?pid=p:" + this.Partner + "\" target=\"_blank\" style= \"color:#024E8A; font-weight:bold; text-decoration:underline;\">click here</a> for more information.</li>" +
				"<li>To add free financial content to your site, including calculators and overnight average interest rates, <a href=\"http://www.bankrate.com/free-content/cd?pid=p:" + this.Partner + "\" target=\"_blank\" style= \"color:#024E8A; font-weight:bold; text-decoration:underline;\">click here</a>.</li>" +
                "<li>Bankrate.com's Safe & Sound® service provides ratings information on the relative financial strength and stability of U.S. commercial banks, savings institutions and credit unions. Five stars is superior, one star is lowest rated. For more information <a href=\"http://www.bankrate.com/rates/safe-sound/bank-ratings-search.aspx?t=cb&pid=p:" + this.Partner + "\" target=\"_blank\" style= \"color:#024E8A; font-weight:bold; text-decoration:underline;\">click here</a>.</li>";

                if (json.bankrate.data.response.result1 != null && typeof (json.bankrate.data.response.result1.length) != "undefined") {
                    this.FetchCDItemsUsingJson(json.bankrate.data.response.result1, 'paid');
                    this.FetchCDItemsUsingJson(json.bankrate.data.response.result1, 'editorial');
                    document.getElementById("cdLoadingImgDiv").style.display = 'none';
                    document.getElementById("cdServiceTurnOff").style.display = 'none';
                    document.getElementById("dvCDtableBody").style.display = 'block';
                }
                else {
                    this.CDNoRecord = false;
                    this.ShowNoRecordsFound();
                }

                var staticText = document.createElement('p');
                staticText.innerHTML = 'The rates on this table are valid for credit scores of 700 and above. For scores from 680 to 699, borrowers would typically see increased fees up to 1% of the loan value, or an adjustment in the rate. If you believe that you have received an inaccurate quote or are otherwise not satisfied with the services provided to you by the lender you choose, please <a href="mailto:qualitycontrol@bankrate.com">click here</a>.';
                if (document.getElementById("CDRoTableContainer").getElementsByTagName("p").length == 0) {
                    document.getElementById("CDRoTableContainer").appendChild(staticText);
                }
                var TableSorter1 = new this.TSorter;
                TableSorter1.initiation('cdTableHeaders');
                this.SetDynamicAdjustments();
            }
            else {
                this.CDNoRecord = true;
                this.ShowNoRecordsFound();
            }
        }
        catch (e) { }
    },

    ShowNoRecordsFound: function () {
        this.SetDynamicAdjustments();
        document.getElementById("cdLoadingImgDiv").style.display = 'none';
        document.getElementById("cdServiceTurnOff").style.display = 'block';
        document.getElementById("dvCDtableBody").style.display = 'none'; ;
    },

    FetchCDItemsUsingJson: function (items, strListingType) {
        for (var j = 0; j < items.length; j++) {
            var cdApy = '', cdRate = '', cdComments = '', cdDate = '', cdMinDeposit = '', cdCPC = '';
            var cdImgId = '', cdLenderId = '', cdCommentsHyperlinked = '', cdNameHyperlinkAvailable = '', cdListingType = '';
            var cdLenderSort = '', cdApySort = '', cdRateSort = '', cdMinDepSort = '', cdDefaultSort = '';
            var cdStarRating = '', cdCompounding = '', cdSvyinstitutionId = '';

            if (typeof (items[j].listingType) != 'undefined' && items[j].listingType != null)
                cdListingType = items[j].listingType;

            if (cdListingType.toLowerCase() == strListingType) {
                if (typeof (items[j].img) != 'undefined' && items[j].img != null)
                    cdImgId = items[j].img;
                if (typeof (items[j].lender) != 'undefined' && items[j].lender != null)
                    cdLenderId = items[j].lender;
                if (typeof (items[j].starRating) != 'undefined' && items[j].starRating != null)
                    cdStarRating = items[j].starRating;
                if (typeof (items[j].apy) != 'undefined' && items[j].apy != null)
                    cdApy = items[j].apy;
                if (typeof (items[j].date) != 'undefined' && items[j].date != null)
                    cdDate = this.CustomDate(items[j].date);
                if (typeof (items[j].rate) != 'undefined' && items[j].rate != null)
                    cdRate = items[j].rate;
                if (typeof (items[j].cm) != 'undefined' && items[j].cm != null)
                    cdCompounding = items[j].cm;
                if (typeof (items[j].minDeposit) != 'undefined' && items[j].minDeposit != null)
                    cdMinDeposit = items[j].minDeposit;

                if (typeof (items[j].comments) != 'undefined' && items[j].comments != null)
                    cdComments = items[j].comments;
                if (typeof (items[j].cpc) != 'undefined' && items[j].cpc != null)
                    cdCPC = items[j].cpc;
                if (typeof (items[j].commentsHyperlinked) != 'undefined' && items[j].commentsHyperlinked != null)
                    cdCommentsHyperlinked = items[j].commentsHyperlinked;
                if (typeof (items[j].nameHyperlinkAvailable) != 'undefined' && items[j].nameHyperlinkAvailable != null)
                    cdNameHyperlinkAvailable = items[j].nameHyperlinkAvailable;
                if (typeof (items[j].listingType) != 'undefined' && items[j].listingType != null)
                    cdListingType = items[j].listingType;

                if (typeof (items[j].defaultSort) != 'undefined' && items[j].defaultSort != null)
                    cdDefaultSort = items[j].defaultSort;
                if (typeof (items[j].publishnameSort) != 'undefined' && items[j].publishnameSort != null)
                    cdLenderSort = items[j].publishnameSort;
                if (typeof (items[j].yieldSort) != 'undefined' && items[j].yieldSort != null)
                    cdApySort = items[j].yieldSort;
                if (typeof (items[j].rateSort) != 'undefined' && items[j].rateSort != null)
                    cdRateSort = items[j].rateSort;
                if (typeof (items[j].minDepositSort) != 'undefined' && items[j].minDepositSort != null)
                    cdMinDepSort = items[j].minDepositSort;
                if (typeof (items[j].svyinstitutionId) != 'undefined' && items[j].svyinstitutionId != null)
                    cdSvyinstitutionId = items[j].svyinstitutionId;

                this.FnCDRateInit(cdImgId, cdLenderId, cdStarRating, cdApy, cdDate, cdRate, cdCompounding, cdMinDeposit, cdComments, cdCPC,
                    cdCommentsHyperlinked, cdNameHyperlinkAvailable, cdListingType, cdDefaultSort, cdLenderSort, cdApySort, cdRateSort, cdMinDepSort, cdSvyinstitutionId, j);
            }
        }
    },

    // Note the TSorter class has been modified from the original copy for this widget.
    TSorter: function () {
        var table = Object;
        var botComments = Array;
        var tempTrs = Array;

        var trs = Array;
        var ths = Array;
        var curSortCol = Object;
        var prevSortCol = '4';
        var sortType = Object;

        function getCell(index) {
            return trs[index].cells[curSortCol]
        }

        this.initiation = function (tableName) {
            headerTable = document.getElementById(tableName);
            ths = headerTable.getElementsByTagName("th");
            for (var i = 0; i < ths.length - 1; i++) {
                var headerID = getHeaderDivId(i);
                if (headerID != '') {
                    document.getElementById(headerID).onclick = function () {
                        sort(this);
                    }
                }
            }

            table = document.getElementById("cdRateoTable");
            return true;
        };

        function getHeaderDivId(indx) {
            var headerDivId = '';
            if (indx == 0)
                headerDivId = 'CD_institution_header';
            else if (indx == 1)
                headerDivId = 'CD_apr_header';
            else if (indx == 2)
                headerDivId = 'CD_rate_header';
            else if (indx == 3)
                headerDivId = 'CD_deposit_header';

            return headerDivId;
        }

        function getHeaderIndex(val) {
            var indx = '';
            if (val == 'Institution')
                indx = 0;
            else if (val == 'APY')
                indx = 1;
            else if (val == 'Rate')
                indx = 2;
            else if (val == 'Min Deposit')
                indx = 3;

            return indx;
        }
        function sort(oTH) {
            sortType = oTH.innerHTML;
            curSortCol = getHeaderIndex(sortType);

            if (sortType != null && sortType != "") {
                tempTrs = table.tBodies["BRcdRateTB"].getElementsByTagName("tr");
                var trCount = tempTrs.length;

                for (var i = 0; i < trCount; i++) {
                    if (tempTrs[i].className != 'np') {
                        botComments[tempTrs[i - 1].firstChild.firstChild.id] = tempTrs[i].firstChild.innerHTML;
                    }
                }

                for (var i = 0; i < trCount; i++) {
                    if (i < tempTrs.length) {
                        if (tempTrs[i].className != 'np') {
                            table.tBodies["BRcdRateTB"].deleteRow(i);
                        }
                    }
                }

                trs = table.tBodies["BRcdRateTB"].getElementsByTagName("tr");

                setGet(sortType);

                if (prevSortCol == curSortCol) {
                    oTH.lang = (oTH.lang != 'ascend' ? 'ascend' : 'descend');
                    reverseTable();
                }
                else {
                    oTH.lang = 'ascend';
                    if (ths[prevSortCol].lang != 'exc_cell') { ths[prevSortCol].lang = ''; }
                    quicksort(0, trs.length);
                    reverseTable();
                }
                prevSortCol = curSortCol;
            }

            if (botComments.length > 0) {
                for (var i = 1; i <= trs.length; i++) {
                    if (typeof (trs[i - 1]) != "undefined") {
                        if (trs[i - 1].firstChild != null) {
                            if (typeof (botComments[trs[i - 1].firstChild.firstChild.id]) != "undefined") {
                                var dataRowPos = trs[i - 1].id;
                                var rowPos = dataRowPos.replace('oRow', '');

                                oNewCommentRow = document.createElement("tr");
                                oDataCell = document.createElement("td");
                                oDataCell.className = "braff-cd-bottom-comments";
                                oDataCell.setAttribute('colSpan', '6');
                                oDataCell.setAttribute('background-color', '#F8F8F8');


                                var commentStr = botComments[trs[i - 1].firstChild.firstChild.id];

                                var strToFind = '/div';
                                var divPos = parseInt(commentStr.search(strToFind));
                                var startPos = 28;
                                if (divPos == -1) {
                                    strToFind = '/DIV';
                                    divPos = parseInt(commentStr.search(strToFind));
                                    startPos = 27;
                                }
                                var endPos = divPos + 5;
                                var strIds = commentStr.substring(startPos, endPos - 6);
                                strIds = strIds.replace('>', '').replace('<', '');
                                var arrIds = strIds.split('~');
                                var commentRowPos = 'comment' + rowPos;
                                oDataCell.setAttribute('id', commentRowPos);

                                try {
                                    var commentsIdDiv1 = document.createElement('div');
                                    commentsIdDiv1.innerHTML = strIds;
                                    commentsIdDiv1.style.display = "none";
                                    oDataCell.appendChild(commentsIdDiv1);

                                    if (arrIds.length == 6) {
                                        var a11 = document.createElement('a');
                                        a11.setAttribute('id', 'ancher' + rowPos);
                                        var clickOnBottomComment = 'bottomComment';
                                        if (BRMcdRateTable.ieVersion == 7) {
                                            a11.onclick = new Function("BRMcdRateTable.CDRateTrackClick(5, this, '" + arrIds[5] + "', '" + clickOnBottomComment + "');");
                                        }
                                        else {
                                            a11.setAttribute("onclick", "BRMcdRateTable.CDRateTrackClick(5,this,'" + arrIds[5] + "', '" + clickOnBottomComment + "');");
                                        }
                                        a11.innerHTML = '<u>' + arrIds[4] + '</u>';
                                        a11.style.cursor = 'pointer';
                                        a11.setAttribute('target', '_blank');
                                        oDataCell.appendChild(a11);
                                    }
                                    else {
                                        var s11 = document.createElement('span');
                                        var tempComment = arrIds[4];
                                        if (arrIds[4].length < 1) {
                                            tempComment = '&nbsp;';
                                        }

                                        s11.innerHTML = tempComment;
                                        oDataCell.appendChild(s11);
                                    }
                                }
                                catch (e) {
                                }

                                if (BRMcdRateTable.checkForIE) {
                                    oDataCell.onmouseover = new Function("BRMcdRateTable.MouseOver('" + dataRowPos + "', '" + commentRowPos + "', '" + arrIds[2] + "');");
                                    oDataCell.onmouseout = new Function("BRMcdRateTable.MouseOut('" + dataRowPos + "', '" + commentRowPos + "', '" + arrIds[2] + "');");
                                } else {
                                    oDataCell.setAttribute("onmouseover", "BRMcdRateTable.MouseOver('" + dataRowPos + "', '" + commentRowPos + "', '" + arrIds[2] + "');");
                                    oDataCell.setAttribute("onmouseout", "BRMcdRateTable.MouseOut('" + dataRowPos + "', '" + commentRowPos + "', '" + arrIds[2] + "');");
                                }

                                oNewCommentRow.appendChild(oDataCell);
                                oNewCommentRow.setAttribute('style', 'border-left:1px solid #BFC4C8;border-right:1px solid #BFC4C8');
                                if (typeof (trs[i]) != "undefined") {
                                    table.tBodies["BRcdRateTB"].insertBefore(oNewCommentRow, trs[i]);
                                }
                                else {
                                    if (BRMcdRateTable.checkForIE) {
                                        table.tBodies["BRcdRateTB"].appendChild(oNewCommentRow);
                                    }
                                    else {
                                        table.tBodies["BRcdRateTB"].insertBefore(oNewCommentRow, trs[i]);
                                    }
                                }
                            }
                        }
                    }
                }
                BRMcdRateTable.ShowCDComments();
            }
        }

        function setGet(sortType) {
            switch (sortType) {
                case "Institution":
                    get = function (index) {
                        return parseFloat(getCell(index).childNodes[1].innerHTML);
                    };
                    break;
                case "APY":
                    get = function (index) {
                        return parseFloat(getCell(index).firstChild.innerHTML);
                    };
                    break;
                case "Rate":
                    get = function (index) {
                        return parseFloat(getCell(index).firstChild.innerHTML);
                    };
                    break;
                case "Min Deposit":
                    get = function (index) {
                        return parseFloat(getCell(index).firstChild.innerHTML);
                    };
                    break;
                default:
                    get = function (index) {
                        return parseFloat(getCell(index).firstChild.innerHTML);
                    };
                    break;
            };
        }

        function exchange(i, j) {
            if (i == j + 1) {
                table.tBodies["BRcdRateTB"].insertBefore(trs[i], trs[j]);
            } else if (j == i + 1) {
                table.tBodies["BRcdRateTB"].insertBefore(trs[j], trs[i]);
            } else {
                var tmpNode = table.tBodies["BRcdRateTB"].replaceChild(trs[i], trs[j]);
                if (typeof (trs[i]) == "undefined") {
                    table.appendChild(tmpNode);
                } else {
                    table.tBodies["BRcdRateTB"].insertBefore(tmpNode, trs[i]);
                }
            }
        }

        function reverseTable() {
            for (var i = 1; i < trs.length; i++) {
                table.tBodies["BRcdRateTB"].insertBefore(trs[i], trs[0]);
            }

            for (var i = 0; i < trs.length; i++) {
                var botCommentStatus = table.tBodies["BRcdRateTB"].rows[i].firstChild.firstChild.innerHTML;
                table.tBodies["BRcdRateTB"].rows[i].setAttribute('id', 'oRow' + (i + 1));

                var rowID1 = 'oRow' + (i + 1);
                var commentRowId1 = ''
                if (botCommentStatus == 'true')
                    commentRowId1 = 'comment' + (i + 1);

                if (BRMcdRateTable.checkForIE) {
                    table.tBodies["BRcdRateTB"].rows[i].onmouseover = new Function("BRMcdRateTable.MouseOver('" + rowID1 + "', '" + commentRowId1 + "', '" + botCommentStatus + "');");
                    table.tBodies["BRcdRateTB"].rows[i].onmouseout = new Function("BRMcdRateTable.MouseOut('" + rowID1 + "', '" + commentRowId1 + "', '" + botCommentStatus + "');");
                } else {
                    table.tBodies["BRcdRateTB"].rows[i].setAttribute("onmouseover", "BRMcdRateTable.MouseOver('" + rowID1 + "', '" + commentRowId1 + "', '" + botCommentStatus + "');");
                    table.tBodies["BRcdRateTB"].rows[i].setAttribute("onmouseout", "BRMcdRateTable.MouseOut('" + rowID1 + "', '" + commentRowId1 + "', '" + botCommentStatus + "');");
                }
            }
        }

        function quicksort(lo, hi) {
            if (hi <= lo + 1) return;

            if ((hi - lo) == 2) {
                if (get(hi - 1) > get(lo)) exchange(hi - 1, lo);
                return;
            }

            var i = lo + 1;
            var j = hi - 1;

            if (get(lo) > get(i)) exchange(i, lo);
            if (get(j) > get(lo)) exchange(lo, j);
            if (get(lo) > get(i)) exchange(i, lo);

            var pivot = get(lo);

            while (true) {
                j--;
                while (pivot > get(j)) j--;
                i++;
                while (get(i) > pivot) i++;
                if (j <= i) break;
                exchange(i, j);
            }
            exchange(lo, j);

            if ((j - lo) < (hi - j)) {
                quicksort(lo, j);
                quicksort(j + 1, hi);
            } else {
                quicksort(j + 1, hi);
                quicksort(lo, j);
            }
        }
    },
    TrackLink: function (obj, s, st, m, pr, a, r, pos, w, h) {
        var sbrm = s_gi(this.ReportSuite);
        sbrm.eVar1 = BRMcdRateTable.ConvertToLowerCase(w);
        if (!sbrm.pageType && !sbrm.pageName) {
            var pageName = "";
            if (typeof (s_brm) == 'object' && typeof (s_brm.getPageName) == 'function') {
                pageName = s_brm.getPageName().toLowerCase();
            } else if (typeof (s) == 'object' && typeof (s.getPageName) == 'function') {
                pageName = s.getPageName().toLowerCase();
            } else {
                pageName = sbrm.pageName;
            }
            if (pageName != "") {
                sbrm.pageName = w + '>' + pageName;
                sbrm.eVar21 = sbrm.pageName;
            }
        }
        sbrm.eVar36 = BRMcdRateTable.ConvertToLowerCase(s);
        sbrm.eVar38 = BRMcdRateTable.ConvertToLowerCase(pos);
        sbrm.eVar39 = BRMcdRateTable.ConvertToLowerCase(h);
        sbrm.eVar40 = BRMcdRateTable.ConvertToLowerCase(st);
        sbrm.eVar41 = BRMcdRateTable.ConvertToLowerCase(m);
        sbrm.eVar42 = BRMcdRateTable.ConvertToLowerCase(pr);

        sbrm.products = "CCR;p_" + pr.toLowerCase() + ";1;" + a.toLowerCase();
        sbrm.events = "event6,purchase";
        sbrm.purchaseID = Math.round(Math.random() * 10000000).toString() + new Date().getTime();

        sbrm.tl(obj, 'o', 'Lender Referral');
        sbrm = null;
    },
    ConvertToLowerCase: function (pValue) {
        var lValue = BRMcdRateTable.Trim(" " + pValue);
        if ((lValue == null) || (lValue == "undefined")) {
            lValue = "";
        }
        if (lValue != "") {
            if (isNaN(parseFloat(lValue))) {
                return lValue.toLowerCase();
            }
            else {
                return lValue;
            }
        }
        else {
            return lValue;
        }
    },
    Trim: function (pValue) {
        var s;
        s = pValue.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, "");
        return s;
    }
}

BRMcdRateTable.Init();
