// Check dependencies
if (typeof mcd === undefined || !mcd.dom || !mcd.event || !mcd.http) {
	throw "rateFeed.js has unmet dependencies";
}

// Create the discover namespace if it doesn't already exist
if (typeof discover === 'undefined') {
	var discover = {};
}

/**
 * A Library for requsting rate information from Fusebox.com via SOAP
 * webservice.
 *
 * The MMA, CD, and IRA CD rates, both for Discover and for the
 * National Average, are provided by third party. The rates are not
 * part of the HTML-- they are injected into the page on load.
 *
 * There are two styles of injection, synchronous and
 * asynchronous. For the featured rates that display at a large font
 * size on several pages, the synchronous approach is appropriate
 * because it ensures the page does not display until the rate is
 * available.
 *
 * For other rates, such as those in the rate chart or rate comparison
 * pages, the synchronous approach would cause a noticeable delay in
 * page load. The asynchronous approach is more appropriate-- the user
 * sees the rest of the page and the rate data pops in a few moments
 * later.
 *
 * The synchronous and asynchronous approaches of rate injection
 * reflect the style of HTTP Ajax request. There are separate
 * initialization methods in this library for each. A page making a
 * synchronous request would invoke this library like so:
 *
 * <script type="text/javascript">
 * discover.rateFeed.initSynchronous("cd-overview");
 * </script>
 *
 * The above should appear as early in the document as possbile. Then
 * in the location where the rate should be displayed:
 *
 * <script type="text/javascript">
 * discover.rateFeed.write(keyword);
 * </script>
 *
 * In the example above, the keyword argument is expected to be the
 * propert of the internal content object which was populated during
 * initialization. For example, getSingleFeaturedRate() stores its
 * result in content.featured_rate. The keyword passed to write() on
 * the calling page would then be "featured_rate".
 *
 * The logic of asynchronous requests are not dependant on information
 * provided by the calling page.
 *
 * Requests cannot be switched from synchronous to asynchronous
 * without adjusting the code.
 *
 * @requires mcd.dom
 * @requires mcd.event
 * @requires mcd.http
 */
discover.rateFeed = function() {

    var config = {};
    config.months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    config.service_uri = "/fusebox_rate_ws";
    config.min_deposit = {};
    config.min_deposit["Money Market"] = 2500.00;
    config.min_deposit["CD"] = 2500.00;
    config.min_deposit["IRA"] = 2500.00;

    var content = {};
    content.featured_rate = "";
    var mma_footnote="";
    var cd_footnote="";
    var ira_footnote="";
    var prvrequest="";

    var decimalToPercentage = function(number, places) {
        if (typeof places === "undefined") places = 2;
        number = parseFloat(number) * 100;

        return number.toFixed(2);
    };

   var decimalToPercentageSnapshots = function(number, places) {
        if (typeof places === "undefined") places = 2;
        number = parseFloat(number);

        return number.toFixed(2);
    };

  var decimalToPercentagesupzero = function(number, places) {
        if (typeof places === "undefined") places = 2;
        number = parseFloat(number);

        var rtval = number.toFixed(2);
          if(rtval == '0.00' || rtval== '0') 
          return "-";
          else
           return rtval + '%'; 
    };

  
    var decimalToMoney = function(number) {
        number = Math.floor(number).toString();
        if (number.length > 3) {
        return number.replace(/(\d\d\d)$/, ",$1");
	}
       else{
      	     return number;
           }

    };


    /**
     * Extract namespaced nodes from an XML document in a
     * cross-browser fashion.
     */
    var getSoapNode = function(request, node_name) {
        var node;
        var setproperty_supported = (typeof request.responseXML.setProperty !== "undefined");
        var root = request.responseXML.documentElement;

        var namespace_uri = root.getAttribute("xmlns:soap");
        if (namespace_uri == null) {
            namespace_uri = root.getAttribute("soap"); // opera
        }

        if (setproperty_supported) {
            request.responseXML.setProperty("SelectionNamespaces", "xmlns:soap=\"" + namespace_uri + "\"");
        }

        if (typeof root.getElementsByTagNameNS !== "function") {
            node = root.selectSingleNode("soap:" + node_name); // internet explorer
        } else {
            node = root.getElementsByTagNameNS(namespace_uri, node_name)[0];
        }

        if (setproperty_supported) {
            request.responseXML.setProperty("SelectionNamespaces", "");
        }

        return node;
    };

    /**
     * Convert a date from mmmm, dd yyyy to mm/dd/yyyy
     *
     */
    var shortDate = function(string) {
        var pieces = string.split(" ");
        for (var i=0; i < config.months.length; i++) {
            if (pieces[0] == config.months[i]) break;
        }

        pieces[0] = (i > 9)? i: "0" + i;
        pieces[1] = pieces[1].replace(",", "");
        pieces[2] = pieces[2].substring(2,4);
        return pieces.join("/");
    };

    /**
     * Convert a date from mm/dd/yyyy to mmmm, dd yyyy
     */
    var longDate = function(string) {
        var pieces = string.split("/");
        pieces[0] = config.months[pieces[0]];
        pieces[1]+= ",";
        return pieces.join(" ");
    };

    /**
     * Infer the product name from the class assigned to the container div.
     *
     * In fusebox parlance, this product name corresponds to the value
     * of the inputInstrement node.
     */
    var getProductFromContainerClass = function() {
        
	var body_class = document.body.className;

	if(body_class.length == 0){
	var body_class = document.getElementById("container").className;}

        var section = body_class.replace(/.*section-([^ ]+)/, "$1");
	  var product ="";

        switch (section) {
        case "mma": product = "Money Market"; break;
        case "ira": product = "IRA"; break;
        case "cd": product = "CD"; break;
        case "osa": product = "Savings Product"; break;
        }

        return product;
    };

    return {
        /**
         * Initialization of synchronous requests based on a keyword
         * provided by the caller.
         */
        initSynchronous: function(page_id) {

        	if(page_id == "osa-overview" ||
                page_id == "mma-overview" ||
                page_id == "cd-overview" ||
                page_id == "ira-overview") {
                discover.rateFeed.getSingleFeaturedRate();
            } else if (page_id == "homepage") {
                     
		 	discover.rateFeed.getMultipleFeaturedRates();
                                                        
            }


        },

        /**
         * Initialization of asynchronous requests
         */
        initAsynchronous: function() {
	     var savings_comparison_table = document.getElementById("savings-ratecompare");
            if (savings_comparison_table) {
		discover.rateFeed.getCompetitorSnapshotsComparison(savings_comparison_table);
	     }
			     
            var comparison_table = document.getElementById("rate-comparison");
            if (comparison_table) {
                discover.rateFeed.getRateComparison(comparison_table);
            }
		    
            var rate_chart = document.getElementById("rate-chart");
            if (rate_chart) {
                discover.rateFeed.getRateChart(rate_chart);
            }

            var national_average_footnote = document.getElementById("national-average-footnote");
            if (national_average_footnote) {
			//discover.rateFeed.getNationalAverageDate(national_average_footnote);
			discover.rateFeed.getDiscNationalAverages(national_average_footnote);
			//discover.rateFeed.getSavingGoalDate(national_average_footnote);
		}
		
	    var savingsfoot = document.getElementById("savings_footnote");
	    if(savingsfoot){
	    discover.rateFeed.getSavingsDisclaimers(savingsfoot); }
	       
	    var cdpenalty_footnote = document.getElementById("cdpenalty_footnote");
	    if(cdpenalty_footnote){
	    discover.rateFeed.getCDDisclaimers(cdpenalty_footnote); }

	    var checkingfoot = document.getElementById("checking_footnote");
	    if(checkingfoot){
	    discover.rateFeed.getSavingsDisclaimers(checkingfoot); }

	    var onlinefoot = document.getElementById("online_footnote");
	    if(onlinefoot){
	    discover.rateFeed.getSavingsDisclaimers(onlinefoot); }
		
	    var mmafootnote = document.getElementById("mma_footnote");
	    if(mmafootnote){
	    mmafootnote.innerHTML=mma_footnote;}
	    var cdfootnote = document.getElementById("cd_footnote");
	    if(cdfootnote){
	    cdfootnote.innerHTML=cd_footnote;}
	    var irafootnote = document.getElementById("ira_footnote");
           if(irafootnote){
	    irafootnote.innerHTML=ira_footnote;}
	    		
	
            var why_chart = document.getElementById("why-chart");
            if (why_chart) {
		        discover.rateFeed.populateWhyChart(why_chart);
             }

            var cd_competitor_chart = document.getElementById("cd-chart");
            if (cd_competitor_chart) {
                //discover.rateFeed.populateCdCompetitorChart(cd_competitor_chart);
		  discover.rateFeed.getCompetitorSnapshotsCdChart(cd_competitor_chart);
            }

            var cd_penalty = document.getElementById("cd-penalty");
            if (cd_penalty) {
                discover.rateFeed.getCompetitorSnapshotsCdPenalty(cd_penalty);
            }
        },

        /**
         * Display a rate fetched synchrounously
         */
        write: function(content_id) {
            if (typeof content[content_id] !== "undefined") {
                document.write(content[content_id]);
            }
        },


        /**
         * The CD competitor chart on the homepage
         */
        populateCdCompetitorChart: function(container) {
            
           
	     var product = "CD";
            var table_headers = container.getElementsByTagName("TH");
            var table_cells = container.getElementsByTagName("TD");
            
            var parser = function(request) {
                var header = getSoapNode(request, "Header");
                var body = getSoapNode(request, "Body");

                var datasets = body.getElementsByTagName("DATASET");
                 
                 
                for (var i=0; i < datasets.length; i++) {
                    // the ranks should already be in the correct order (so rank - 1 == i), but we'll
                    // use the specified rank rather than the loop index just in case they're not
                    var rank = parseInt(datasets[i].getElementsByTagName("Rank")[0].firstChild.nodeValue) - 1;
                 
                    if (rank < 0 || rank > table_headers.length) {
                        continue;
                    }

                    var name = datasets[rank].getElementsByTagName("Name")[0].firstChild.nodeValue;
                   
                    var apy = datasets[rank].getElementsByTagName("APY")[0].firstChild.nodeValue;
                    
			
                    if (name.toLowerCase() == "national average") {
                        name += "<sup>6</sup>";
                    }
			

                    table_headers[i].innerHTML = name;
                    table_cells[i].innerHTML = "<p>" + decimalToPercentage(apy) + "% <span>APY</span></p>";
                     
                }

                discover.bank.publicSite.competitorChartAdjust();

                // disclaimers and footnotes
		
                var competitor_disclaimer = header.getElementsByTagName("Competitor_Disclaimer")[0].firstChild.nodeValue;
                //competitor_disclaimer = competitor_disclaimer.replace(/(www\..*?)([ ,])/g,"<a rel='external' href='http://$1'>$1</a>$2");
                var footnote_container = document.getElementById("competitor-chart-footnote");
		  
		  if(null != footnote_container){
			footnote_container.innerHTML = competitor_disclaimer;
		  }
		  var NatlAvg_Disclaimer = header.getElementsByTagName("NatlAvg_Disclaimer")[0].firstChild.nodeValue;
		  var national_average_footnote = document.getElementById("national-average-footnote");
		  if(null != national_average_footnote){
			national_average_footnote.innerHTML = NatlAvg_Disclaimer;
		  }
			 		
                if (mcd.util) {
		            mcd.util.externalLinkHandler();
                }

            };

            discover.rateFeed.getCompetitorRates(product, parser, true);

        },


        
        /**
         * The bar chart in the header of the Why Discover Bank page.
         */
        populateWhyChart: function(container) {
            var product = "CD";

            var col1_rate_container = document.getElementById("col1-rate");
            var col2_rate_container = document.getElementById("col2-rate");

            var parser = function(request) {
                var header = getSoapNode(request, "Header");
                var body = getSoapNode(request, "Body");
                var datasets = body.getElementsByTagName("DATASET");
                var dfs_min_dftier = parseFloat(header.getElementsByTagName("DFS_DefaultMinimumTier")[0].firstChild.nodeValue);
                var NatlAvg_ValidAsOf = header.getElementsByTagName("NatlAvg_ValidAsOf")[0].firstChild.nodeValue;
		  var NatlAvg_Disclaimer = header.getElementsByTagName("NatlAvg_Disclaimer")[0].firstChild.nodeValue;
  
			var national_average_footnote = document.getElementById("national-average-footnote");
            		
			if (national_average_footnote) {
			 
				//national_average_footnote.innerHTML = "National savings average courtesy of Bankrate.com, as of 	 " + NatlAvg_ValidAsOf + ".";
				national_average_footnote.innerHTML = NatlAvg_Disclaimer;
		       }

                    var DFS_DefaultDisclaimer = header.getElementsByTagName("DFS_DefaultDisclaimer")[0].firstChild.nodeValue;
  
			var DFS_DefaultDisclaimer_footnote = document.getElementById("DFS_DefaultDisclaimer-footnote");
            		
			if (DFS_DefaultDisclaimer_footnote) {
			 
				DFS_DefaultDisclaimer_footnote.innerHTML = DFS_DefaultDisclaimer;

		       }

		      

                for (var i=0; i < datasets.length; i++) {
                    var min_deposit = parseFloat(datasets[i].getElementsByTagName("Minimum_Deposit")[0].firstChild.nodeValue);
  
			if (min_deposit == dfs_min_dftier )
			{
			 
			 var DFS_Featured = datasets[i].getElementsByTagName("DFS_Featured")[0].firstChild.nodeValue;
			
			 if( DFS_Featured == 'false' || DFS_Featured == 'FALSE')
			  continue;
                       if( DFS_Featured == 'true' || DFS_Featured == 'TRUE')
                        break;
                       
			} else{
				continue;
                     }
                    
                }
                  
			
                var dfs_apy = parseFloat(datasets[i].getElementsByTagName("DFS_APY")[0].firstChild.nodeValue);
                var nat_avg = parseFloat(datasets[i].getElementsByTagName("NatlAvg_APY")[0].firstChild.nodeValue);
			
                col1_rate_container.innerHTML = decimalToPercentage(dfs_apy);
                col2_rate_container.innerHTML = decimalToPercentage(nat_avg);
                discover.bank.publicSite.whyChartAdjust();

            };
            discover.rateFeed.getNationalAverages(product, parser, true);

        },

        /**
         * Populate the tables on the Compare Rates & Fees pages for each product.
         */
        getRateComparison: function(table) {
            var product = getProductFromContainerClass();

            var parser = function(request) {

                var header = getSoapNode(request, "Header");
                var body = getSoapNode(request, "Body");

                var datasets = body.getElementsByTagName("DATASET");
		  
		  var dfsDefaultDisclaimer= header.getElementsByTagName("DFS_DefaultDisclaimer")[0].firstChild.nodeValue;
  		  
		  var DFSDefaultDisclaimer_footnote = document.getElementById("DFSDefaultDisclaimer-footnote");
		  if (DFSDefaultDisclaimer_footnote) {
			DFSDefaultDisclaimer_footnote.innerHTML = dfsDefaultDisclaimer;
		       }
		   	

                // valid as-of
                var nat_avg_as_of = header.getElementsByTagName("NatlAvg_ValidAsOf");
                var as_of_container = document.getElementById("valid-as-of-top");
                if (as_of_container && nat_avg_as_of.length > 0) {
                    as_of_container.innerHTML = "(Rates valid as of " +  longDate(nat_avg_as_of[0].firstChild.nodeValue) + ")";
                }


                var disclaimer_node = header.getElementsByTagName("NatlAvg_Disclaimer");
                var disclaimer_container = document.getElementById("national-average-footnote-compare");
                if (disclaimer_container && disclaimer_node.length > 0) {
                    var disclaimer_text = disclaimer_node[0].firstChild.nodeValue;
                    disclaimer_text = disclaimer_text.replace("<a", "<a rel=\"external\"");
                    disclaimer_container.innerHTML = disclaimer_text;

                    if (mcd.util) {
		                mcd.util.externalLinkHandler();
                    }

                    mcd.dom.removeClass(disclaimer_container.parentNode, "hide");

                }

                table = table.tBodies[0];
                var table_rows = table.getElementsByTagName("TR");
                var template_row = table_rows[table_rows.length-1];
                table.removeChild(template_row);
                template_row.className = "";
                var clone;

                for (var i=0; i < datasets.length; i++) {
                    var min_deposit = parseFloat(datasets[i].getElementsByTagName("Minimum_Deposit")[0].firstChild.nodeValue);

                    var dfs_apr = parseFloat(datasets[i].getElementsByTagName("DFS_APR")[0].firstChild.nodeValue);
                    var dfs_apy = parseFloat(datasets[i].getElementsByTagName("DFS_APY")[0].firstChild.nodeValue);
                    var nat_avg = parseFloat(datasets[i].getElementsByTagName("NatlAvg_APY")[0].firstChild.nodeValue);

                    var length = parseFloat(datasets[i].getElementsByTagName("Length")[0].firstChild.nodeValue);
                    var featured = datasets[i].getElementsByTagName("DFS_Featured")[0].firstChild.nodeValue;

                    if (product == "Money Market") {
                        if (min_deposit < config.min_deposit[product]) continue;
                        var label = "$" + decimalToMoney(min_deposit); 
                    } else if (product == "CD" || product == "IRA") {
                        if (min_deposit != config.min_deposit[product]) continue;
			    label = datasets[i].getElementsByTagName("Term")[0].firstChild.nodeValue;
                        /*if (length > 35) {
                            var label = length/12 + " Years";
                        } else {
                            var label = length + " Months";
                        }*/
                    }
                    else if (product == "Savings Product") {
                    	var savingsProductValues = [500, 5000, 25000];
                    	
                		if ((min_deposit !== 500) &&
                			(min_deposit !== 5000) &&
                			(min_deposit !== 25000)) continue;
                        var label = "$" + decimalToMoney(min_deposit);
                    }

                    clone = template_row.cloneNode(true);
                    var clone_cells = clone.getElementsByTagName("TD");

                    clone_cells[0].innerHTML = label;
                    clone_cells[1].innerHTML = decimalToPercentage(dfs_apr) + "%";
                    clone_cells[2].innerHTML = decimalToPercentage(dfs_apy) + "%";

                    if (nat_avg == 0){
                        clone_cells[3].innerHTML = "&mdash;";
                    } else {
                        clone_cells[3].innerHTML = decimalToPercentage(nat_avg) + "%";
                    }

                    if (featured == "true") {
                        clone.className = "featured";
                    }
                    table.appendChild(clone);
                }

            };
            discover.rateFeed.getNationalAverages(product, parser, true);
        },

        getSingleFeaturedRate: function() {
            var parser = function(request) {
                var product = getProductFromContainerClass();
                var body = getSoapNode(request, "Body");
		  var datasets = body.getElementsByTagName("DATASET");
                for (var i=0; i < datasets.length; i++) {

                    var name = datasets[i].getElementsByTagName("Name")[0].firstChild.nodeValue;
                    var apy = datasets[i].getElementsByTagName("APY")[0].firstChild.nodeValue;
		      var discliamer = datasets[i].getElementsByTagName("Disclaimer")[0].firstChild.nodeValue;
		      						
                    if (name == product) {
                        content.featured_rate = decimalToPercentage(apy);
			   content.featured_disclaimer = discliamer;
			if(name == "Money Market"){			    	
			    mma_footnote=discliamer;
			}
			if(name == "CD"){
			    cd_footnote=discliamer;
			}
			if(name == "IRA"){
			    ira_footnote=discliamer;
			}
			    
                        break;
                    }
                }
            };

            //discover.rateFeed.getFeaturedRates(parser, false);
		discover.rateFeed.getDefaultFeaturedRates(parser, false);
        },

        getMultipleFeaturedRates: function() {
            var parser = function(request) {
                var body = getSoapNode(request, "Body");
                var datasets = body.getElementsByTagName("DATASET");
                for (var i=0; i < datasets.length; i++) {

                    var name = datasets[i].getElementsByTagName("Name")[0].firstChild.nodeValue;
                    var apy = datasets[i].getElementsByTagName("APY")[0].firstChild.nodeValue;
			var discliamer = datasets[i].getElementsByTagName("Disclaimer")[0].firstChild.nodeValue;
			
                    if (name == "Money Market") {
                        content.mma_featured_rate = decimalToPercentage(apy);
			    mma_footnote=discliamer;
			} else if (name == "IRA" && (typeof content.ira_featured_rate == "undefined")) {
                        // there are 2 featured IRA rates for some reason. Only the first will be used.
                        content.ira_featured_rate = decimalToPercentage(apy);
			    ira_footnote=discliamer;
                    } else if (name == "CD") {
                        content.cd_featured_rate = decimalToPercentage(apy);
			    cd_footnote=discliamer; 
                    } else if (name == "Savings Product") {
                    	content.savings_featured_rate = decimalToPercentage(apy);
                    	content.savings_disclaimer = discliamer;
                    }

                }

            };

            //discover.rateFeed.getFeaturedRates(parser, false);
		discover.rateFeed.getDefaultFeaturedRates(parser, false);

        },

	
        getNationalAverageDate: function(container) {
            
            var parser = function(request) {
                var body = getSoapNode(request, "Body");
                var date = body.getElementsByTagName("GetDiscoverNationalAverageValidDateResult")[0].firstChild.nodeValue;
                var national_average_footnote = document.getElementById("national-average-footnote");

                if (national_average_footnote) {
                    national_average_footnote.innerHTML = "National savings average courtesy of Bankrate.com, as of 	 " + date + ".";
                }
            };

            discover.rateFeed.getValidDateNationalAverage(parser, true);

        },

	getDiscNationalAverages: function(container) {
            //var product = getProductFromContainerClass();
		var product = "CD";
	       var parser = function(request) {
		  var header = getSoapNode(request, "Header");	
                var body = getSoapNode(request, "Body");
		  //var NatlAvg_ValidAsOf = header.getElementsByTagName("NatlAvg_ValidAsOf")[0].firstChild.nodeValue;
		  var NatlAvg_Disclaimer = header.getElementsByTagName("NatlAvg_Disclaimer")[0].firstChild.nodeValue;
		  		         
                var national_average_footnote = document.getElementById("national-average-footnote");
                if (national_average_footnote) {
                    //national_average_footnote.innerHTML = "National savings average courtesy of Bankrate.com, as of 	 " + NatlAvg_ValidAsOf + ".";
			national_average_footnote.innerHTML = NatlAvg_Disclaimer;
                }
            };

            discover.rateFeed.getNationalAverages(product, parser, true);

        },
	

	/*getNationalAverageDisclaimer: function(container) {
            var parser = function(request) {

                var body = getSoapNode(request, "Body");
                var natl_disclaimer = body.getElementsByTagName("GetDiscoverNationalAverageDisclaimerResult")[0].firstChild.nodeValue;
                var national_average_footnote = document.getElementById("national-average-footnote");
                if (national_average_footnote) {
                    national_average_footnote.innerHTML = natl_disclaimer;
                }
            };

            discover.rateFeed.getDiscoverNationalAverageDisclaimer(parser, true);

        },*/

	getSavingGoalDate: function(container) {

	var product = "CD";

            // populate the as-of date
            var asOfParser = function(request) {
                var body = getSoapNode(request, "Body");
                var date = body.getElementsByTagName("GetInstrumentValidDateResult")[0].firstChild.nodeValue;
                
		  var national_average_footnote = document.getElementById("national-average-footnote");
            	  if (national_average_footnote) {
			national_average_footnote.innerHTML = "National savings average courtesy of Bankrate.com, as of 	 " + shortDate(date) + ".";
        	  }
            };

            discover.rateFeed.getValidDate(product, asOfParser, true);
	},

	
	getSavingsDisclaimers: function(container) {

	   var product = "Savings Product";

            var parser = function(request) {
              var body = getSoapNode(request, "Body"); 
		var parent = body.getElementsByTagName("GetDisclaimersResult")[0];

		var savingsfoot = document.getElementById("savings_footnote");
		if(savingsfoot){
	        if(parent.childNodes[0].attributes.getNamedItem("Code").nodeValue == 'SAVINGS'){
		 document.getElementById("savings_footnote").innerHTML = parent.childNodes[0].getAttribute('Copy');
		 }
		}
	       var checkingfoot = document.getElementById("checking_footnote");
     	       if(checkingfoot){
		 if(parent.childNodes[1].attributes.getNamedItem("Code").nodeValue == 'CHECKING'){
		 document.getElementById("checking_footnote").innerHTML = parent.childNodes[1].getAttribute('Copy');
		 }
		}
		var onlinefoot = document.getElementById("online_footnote");
	       if(onlinefoot){
		 if(parent.childNodes[2].attributes.getNamedItem("Code").nodeValue == 'ONLINE_SAVINGS'){
		 document.getElementById("online_footnote").innerHTML = parent.childNodes[2].getAttribute('Copy');
		 }
		}
		
            };

            discover.rateFeed.getDisclaimers(product, parser, true);
	},


	getCDDisclaimers: function(container) {

	   var product = "CD";

            var parser = function(request) {
              var body = getSoapNode(request, "Body"); 
				
	        if(body.getElementsByTagName("Disclaimer")[0].getAttribute('Code') == '12MCD_2500'){
		 container.innerHTML = body.getElementsByTagName("Disclaimer")[0].getAttribute('Copy');
		 }
	      		
            };

            discover.rateFeed.getDisclaimers(product, parser, true);
	},

		
        getRateChart: function(container) {

            var product = getProductFromContainerClass();

            // populate the as-of date
            var asOfParser = function(request) {

                var body = getSoapNode(request, "Body");
                var date = body.getElementsByTagName("GetInstrumentValidDateResult")[0].firstChild.nodeValue;
                document.getElementById("rate-chart-as-of").innerHTML = "As of " + shortDate(date);

                var rate_chart_as_of_footnote = document.getElementById("rate-chart-as-of-footnote");
                if (rate_chart_as_of_footnote) {
                    rate_chart_as_of_footnote.innerHTML = "All rates shown are valid as of " + date + ".";
                }

                var as_of_date = document.getElementById("as-of-date");
                if (as_of_date) {
                    as_of_date.innerHTML = shortDate(date);
                }

            };

            discover.rateFeed.getValidDate(product, asOfParser, true);

            
            // populate the table
            var tableParser = function(request) {
		  var header = getSoapNode(request, "Header");
                var body = getSoapNode(request, "Body");
                var datasets = body.getElementsByTagName("DATASET");

		  	
		
		var mmaDefaultDisclaimer = header.getElementsByTagName("mmaDefaultDisclaimer")[0].firstChild.nodeValue;
  
			var mmaDefaultDisclaimer_footnote = document.getElementById("mmaDefaultDisclaimer-footnote");
			            		
			if (mmaDefaultDisclaimer_footnote) {
			 
			mmaDefaultDisclaimer_footnote.innerHTML = mmaDefaultDisclaimer;

		       }

		
		  var iraDefaultDisclaimer = header.getElementsByTagName("iraDefaultDisclaimer")[0].firstChild.nodeValue;
  
			var iraDefaultDisclaimer_footnote = document.getElementById("iraDefaultDisclaimer-footnote");
			            		
			if (iraDefaultDisclaimer_footnote) {
			 
			iraDefaultDisclaimer_footnote.innerHTML = iraDefaultDisclaimer;

		       }

		var cdDefaultDisclaimer = header.getElementsByTagName("cdDefaultDisclaimer")[0].firstChild.nodeValue;
  
			var cdDefaultDisclaimer_footnote = document.getElementById("cdDefaultDisclaimer-footnote");
			            		
			if (cdDefaultDisclaimer_footnote) {
			 
				cdDefaultDisclaimer_footnote.innerHTML = cdDefaultDisclaimer;

		       }


                var table = container.getElementsByTagName("TABLE")[0].tBodies[0];
                var table_rows = table.getElementsByTagName("TR");
                var template_row = table_rows[table_rows.length-1];
                table.removeChild(template_row);
                template_row.className = "";
                var clone;
		  var term = '';
		
                for (var i=0; i < datasets.length; i++) {
                    var product_type = datasets[i].getElementsByTagName("Name")[0].firstChild.nodeValue;
                    if (product_type != product) continue;

                    if (product == "Money Market") {
                        var min_deposit = parseFloat(datasets[i].getElementsByTagName("Minimum_Deposit")[0].firstChild.nodeValue);
                        var max_deposit = parseFloat(datasets[i].getElementsByTagName("Maximum_Deposit")[0].firstChild.nodeValue);
                        if (min_deposit < config.min_deposit[product]) continue;

                        var label = "<div>$" + decimalToMoney(min_deposit);
                        //if (i != datasets.length - 1) {
	   		    if (max_deposit != '999999999.99') {	
                            label += "</div> to $" + decimalToMoney(max_deposit);
                        } else {
                            label += "</div> and up";
                        }
                    } else if (product == "IRA" || product == "CD") {
                        var min_deposit = parseFloat(datasets[i].getElementsByTagName("Minimum_Deposit")[0].firstChild.nodeValue);

                        //var length = parseInt(datasets[i].getElementsByTagName("Length")[0].firstChild.nodeValue);
			   term = datasets[i].getElementsByTagName("Term")[0].firstChild.nodeValue;	 
			   var label = term;
                        if (min_deposit != config.min_deposit[product]) continue;

                        /*if (length > 35) {
                            var label = length/12 + " Years";
                        } else {
                            var label = length + " Months";
                        }*/
                    }

                    var apr = parseFloat(datasets[i].getElementsByTagName("APR")[0].firstChild.nodeValue);
                    var apy = parseFloat(datasets[i].getElementsByTagName("APY")[0].firstChild.nodeValue);
	                
						
                    clone = template_row.cloneNode(true);
                    var clone_cells = clone.getElementsByTagName("TD");

		      clone_cells[0].innerHTML = label;
                    clone_cells[1].innerHTML = decimalToPercentage(apr) + "%";
                    clone_cells[2].innerHTML = decimalToPercentage(apy) + "%";
						
                    table.appendChild(clone);

                }

                clone.className = "last";

            };

            discover.rateFeed.getAllRates(tableParser, true);
        },

	
	/**
         * Populate the tables on the Compare Rates & Fees pages for All Products.
         */
        getCompetitorSnapshotsComparison: function(table) { 
            var product = getProductFromContainerClass(); 
	     var snaptype = "Table"; 
            var parser = function(request) {
                            
              var body = getSoapNode(request, "Body");
		
		var product_footnote = document.getElementById("otherbank-footnote");
		if(product_footnote){
			document.getElementById("otherbank-footnote").innerHTML = body.getElementsByTagName("CompetitorSnapshot")[0].childNodes[0].firstChild.nodeValue;
	       }
		var DFSDefaultDisclaimer_footnote = document.getElementById("DFSDefaultDisclaimer-footnote");
		if (DFSDefaultDisclaimer_footnote) {
		 document.getElementById("DFSDefaultDisclaimer-footnote").innerHTML = body.getElementsByTagName("CompetitorSnapshot")[0].childNodes[1].firstChild.nodeValue;
		}
		var nvlfootnote_compare = document.getElementById("national-average-footnote-compare");
		if (nvlfootnote_compare) {
		 document.getElementById("national-average-footnote-compare").innerHTML = body.getElementsByTagName("CompetitorSnapshot")[0].childNodes[2].firstChild.nodeValue;
		}

		var raterow = body.getElementsByTagName("CompetitorSnapshot")[0].getElementsByTagName("RatesTable")[0].getElementsByTagName("RateRow");	

				
		table = table.tBodies[0];
              var table_rows = table.getElementsByTagName("TR"); 
              var template_row = table_rows[table_rows.length-1]; 
              table.removeChild(template_row);
              //template_row.className = "";
              var clone;
		var check=0;
		
		
		for (var i=0; i < raterow.length; i++) {
		var rate = raterow[i].getElementsByTagName("Rate"); 

		var name = raterow[i].getElementsByTagName("Name")[0].firstChild.nodeValue;
		if(i == 0){	
		document.getElementById("name-discover").innerHTML = name.substring(0,name.indexOf("-")-1); }
		if(i == 2){
		document.getElementById("name-natlavg").innerHTML = name; }
		if(i == 3){
		document.getElementById("name-america").innerHTML = name; }
		if(i == 4){
		document.getElementById("name-chase").innerHTML = name; }
		var inc = 0;

		for (var j=0,k=0; j < rate.length; j=j+2,k++) {

		      if (product == "Savings Product" || product == "Money Market") {					
                    var min_deposit = parseFloat(rate[j].getElementsByTagName("Minimum")[0].firstChild.nodeValue); 
                    var max_deposit = parseFloat(rate[j].getElementsByTagName("Maximum")[0].firstChild.nodeValue); 
                    }
			if (product == "CD" || product == "IRA") {
			var term = rate[j].getElementsByTagName("ShortDescription")[0].firstChild.nodeValue; 
			}

			var apr = parseFloat(rate[j].getElementsByTagName("Rate")[0].firstChild.nodeValue); 
		       var featured = rate[j].getElementsByTagName("IsFeatured")[0].firstChild.nodeValue;
			
			if(product == 'Savings Product'){
			if ((min_deposit !== 500) && (min_deposit !== 5000) && (min_deposit !== 25000)) continue;
			    var label = "$" + decimalToMoney(min_deposit); inc++;
			}
			else if(product == 'Money Market'){
			if (min_deposit < config.min_deposit[product]) continue;
                        var label = "$" + decimalToMoney(min_deposit);
			}			
			else if (product == "CD" || product == "IRA") {
                        //if (min_deposit != config.min_deposit[product]) continue;
			    	var label = term;
			}

			if(i == 0){
		       clone = template_row.cloneNode(true); }
                     else
                     {
                       var t_rows = table.getElementsByTagName("TR"); 
			  if (product == "Money Market"){ 
        			var t_row = table_rows[k-1];
			  }else if (product == "CD" || product == "IRA") {
			 	var t_row = table_rows[k+1]; 
			  }else{ var t_row = table_rows[inc]; }

                     clone =  t_row; 
                     }

			var clone_cells = clone.getElementsByTagName("TD");
			
		 	if(check == 0){		
                     clone_cells[0].innerHTML = label; }
			
			if(i == 0){			
                     clone_cells[1].innerHTML = decimalToPercentagesupzero(apr);}
			if(i == 1){ 			
                     clone_cells[2].innerHTML = decimalToPercentagesupzero(apr);}
			if(i == 2){			
                     clone_cells[3].innerHTML = decimalToPercentagesupzero(apr);}
			if(i == 3){			
                     clone_cells[4].innerHTML = decimalToPercentagesupzero(apr);}
			if(i == 4){			
                     clone_cells[5].innerHTML = decimalToPercentagesupzero(apr);} 
	                   
                   
                   if (featured == "true") {
                        clone.className = "featured";
                    }
		    if(i == 0)	
                  table.appendChild(clone);
		   
		}
		check=1; 
		}
		 

            };
            discover.rateFeed.getCompetitorSnapshots(product, parser, true, snaptype);
        },

	/**
         * Populate the CD Bar Chart on Home Page.
         */
        getCompetitorSnapshotsCdChart: function(container) { 
            var product = "CD"; 
	     var snaptype = "Bar"; 
	     var table_headers = container.getElementsByTagName("TH");
            var table_cells = container.getElementsByTagName("TD");

            var parser = function(request) {
                            
            var body = getSoapNode(request, "Body");
	     var homechart_title = document.getElementById("homechart_title");
            if (homechart_title) {	
		homechart_title.innerHTML = body.getElementsByTagName("CompetitorSnapshot")[0].getAttribute('Title')+"<sup>5</sup>"; }

		var rate = body.getElementsByTagName("CompetitorSnapshot")[0].getElementsByTagName("Rate");
		
		for (var i=0; i < rate.length; i++) {
		var name = rate[i].getAttribute('Name');
              var apy = rate[i].getAttribute('APY'); 
               
		if (name.toLowerCase() == "discover bank") {
                        name += "<sup>5</sup>";
              }
     
              if (name.toLowerCase() == "national average") {
                        name += "<sup>6</sup>";
               }
		table_headers[i].innerHTML = name;
              table_cells[i].innerHTML = "<p>" + decimalToPercentagesupzero(apy) + " <span>APY</span></p>";

		}

		discover.bank.publicSite.competitorChartAdjust();
                		
                var competitor_disclaimer = body.getElementsByTagName("CompetitorSnapshot")[0].getElementsByTagName("Disclaimer")[0].firstChild.nodeValue;
                var competitorchart_disclaimer = document.getElementById("competitor-chart-footnote");
		  if(null != competitorchart_disclaimer){
			competitorchart_disclaimer.innerHTML = competitor_disclaimer;
		  }
		  /*var NatlAvg_Disclaimer = body.getElementsByTagName("CompetitorSnapshot")[0].getElementsByTagName("NationalAverageDisclaimer")[0].firstChild.nodeValue;
		  var national_average_footnote = document.getElementById("national-average-footnote");
		  if(null != national_average_footnote){
			national_average_footnote.innerHTML = NatlAvg_Disclaimer;
		  }*/
			 		
                if (mcd.util) {
		            mcd.util.externalLinkHandler();
                }

	    
	     };
            discover.rateFeed.getCompetitorSnapshots(product, parser, true, snaptype);
        },


	/**
         * Populate the CD Penalty Free Rate on Home Page and Penalty Free Page.
         */
        getCompetitorSnapshotsCdPenalty: function(container) { 
            var product = "CD"; 
	     var snaptype = "Bar"; 
	     
            var parser = function(request) {
                            
            var body = getSoapNode(request, "Body");
	     
		var rate = body.getElementsByTagName("CompetitorSnapshot")[0].getElementsByTagName("Rate");
		
		for (var i=0; i < rate.length; i++) {
		var name = rate[i].getAttribute('Name');
	       if (name.toLowerCase() == "discover bank") {
		var apy = rate[i].getAttribute('APY'); 
		break;
               }
		}
		container.innerHTML = decimalToPercentageSnapshots(apy);
		
		var featuredDisclaimer = body.getElementsByTagName("CompetitorSnapshot")[0].getElementsByTagName("FeaturedDisclaimer")[0].firstChild.nodeValue;
		var cd_disclaimer = document.getElementById("cd-footnote");
		  if(null != cd_disclaimer){
			cd_disclaimer.innerHTML = featuredDisclaimer;
		  }
	
			    
	     };
            discover.rateFeed.getCompetitorSnapshots(product, parser, true, snaptype);
        },



        /*getFeaturedRates: function(parser, async, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetAllFeaturedRates xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<inputAffiliate>DISCOVER</inputAffiliate>');
            request_lines.push('<inputRegion>DISCOVER-ALL</inputRegion>');
            request_lines.push('</GetAllFeaturedRates>');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, async, callback);
        },*/

	getDefaultFeaturedRates: function(parser, async, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetDefaultFeaturedRates xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<inputAffiliate>DISCOVER</inputAffiliate>');
            request_lines.push('<inputRegion>DISCOVER-ALL</inputRegion>');
            request_lines.push('</GetDefaultFeaturedRates>');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, async, callback);
        },

        getAllRates: function(parser, async, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetAllRatesByAffiliate xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<inputAffiliate>DISCOVER</inputAffiliate>');
            request_lines.push('<inputRegion>DISCOVER-ALL</inputRegion>');
            request_lines.push('</GetAllRatesByAffiliate>');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, async, callback);
        },


        getValidDate: function(product, parser, async, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetInstrumentValidDate xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<inputInstrument>' + product + '</inputInstrument>');
            request_lines.push('<inputAffiliate>DISCOVER</inputAffiliate>');
            request_lines.push('<inputRegion>DISCOVER-ALL</inputRegion>');
            request_lines.push('</GetInstrumentValidDate>');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, async, callback);
        },

        getValidDateNationalAverage: function(parser, async, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetDiscoverNationalAverageValidDate xmlns="https://aaadb.fusebox.com/" />');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, async, callback);
        },

	/*getDiscoverNationalAverageDisclaimer: function(parser, async, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetDiscoverNationalAverageDisclaimer xmlns="https://aaadb.fusebox.com/" />');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, async, callback);
        },*/


        getNationalAverages: function(product, parser, async, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetDiscoverNationalAverages xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<inputInstrument>' + product + '</inputInstrument>');
            request_lines.push('</GetDiscoverNationalAverages>');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, true, callback);
        },

        getCompetitorRates: function(product, parser, async, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetDiscoverCompetitorRates xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<inputInstrument>' + product + '</inputInstrument>');
            request_lines.push('</GetDiscoverCompetitorRates>');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, true, callback);
        },

	getDisclaimers: function(product, parser, async, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetDisclaimers xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<inputAffiliate>DISCOVER</inputAffiliate>');
            request_lines.push('<inputRegion>DISCOVER-ALL</inputRegion>');
	     request_lines.push('<inputInstrument>' + product + '</inputInstrument>');
            request_lines.push('</GetDisclaimers>');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, async, callback);
        },

	getCompetitorSnapshots: function(product, parser, async, snaptype, callback) {
            var request_lines = [];
            request_lines.push('<?xml version="1.0" encoding="utf-8"?>');
            request_lines.push('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">');
            request_lines.push('<soap12:Header>');
            request_lines.push('<AuthenticationHeader xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<Username></Username>');
            request_lines.push('<Password></Password>');
            request_lines.push('</AuthenticationHeader>');
            request_lines.push('</soap12:Header>');
            request_lines.push('<soap12:Body>');
            request_lines.push('<GetCompetitorSnapshots xmlns="https://aaadb.fusebox.com/">');
            request_lines.push('<affiliate>DISCOVER</affiliate>');
            request_lines.push('<region>DISCOVER-ALL</region>');
	     request_lines.push('<instrument>' + product + '</instrument>');
	     request_lines.push('<snapshotType>' + snaptype + '</snapshotType>');
            request_lines.push('</GetCompetitorSnapshots>');
            request_lines.push('</soap12:Body>');
            request_lines.push('</soap12:Envelope>');
            discover.rateFeed.sendRequest(request_lines.join(""), parser, async, callback);
        },

	
        sendRequest: function(request_data, parser, async, callback) {

            if (typeof callback === "undefined") {
                callback = function(response){
                    if (request.readyState != 4) return;
                    if (request.status != 200) return;

                    // IE will only populate responseXML if the content type of the response is text/xml.
                    // SOAP 1.2 responses will have Content-Type: application/soap+xml; charset=utf-8.
                    if (request.responseXML.documentElement == null) {
                        request.responseXML.load(request.responseBody);
                    }

                    if (typeof parser === "function") {
                        parser(request);
                    }
                };
            };

            var request = mcd.http.request({"uri": config.service_uri,
                                            "method": "POST",
                                            "async": (async === true)? "true":"false",
                                            "onreadystatechange": callback,
                                            "headers": {"Content-Type": "application/soap+xml; charset=utf-8"}});

            if (async) {
                mcd.http.send(request, request_data);
            } else {
                var response = mcd.http.send(request, request_data);
                callback(response);
            }
        },
        decMon : decimalToMoney
    };

}();