var best_value = 1000000;
var best_price = 1000000;

function showComparisonResponse(sku, image_path, referrer, user_display)
{    
   Element.hide($('comparisonImageDiv'));
   Element.show($('comparisonSection'));
    
    if(savedRequest == "")
    {
        Element.show('comparisonBody');
        Element.show('comparisonTable');
        $('comparisonBody').innerHTML = "<table width='100%' cellspacing=0 cellpadding=1><tr width='100%'><td width='100%'>No comparisons are available at this time.</td></tr></table>";
    }
    else
    {
        rText = savedRequest.parseJSON();
        var objects = new Array();
        objects["Sku"] = sku;
        objects["AffiliateProducts"] = rText.products;
        objects["Terms"] = rText.terms;
        
        try{
        $('comparisonBody').innerHTML = TrimPath.processDOMTemplate("affiliateProduct_jst", objects);        
        $('comparisonHeader').innerHTML = TrimPath.processDOMTemplate("affiliateHeader_jst", objects);
        }catch(exc){$('comparisonBody').innerHTML = '    <table width="100%" height="100px;"><tr valign="middle"><td align="center">No comparisons are available at this time.</td></tr></table>';}
        //$('comparisonBody').innerHTML = label;
        Element.show('comparisonBody');
        Element.show('comparisonTable');
        
        affiliate_string="";        
        for(var i=0; i<rText.products.length; i++)
        {
            var p = rText.products[i];
        
            //fill in the duplicates
            if (affiliate_string.indexOf(p.AffiliateId)==-1)
            {
                affiliate_string = affiliate_string + "," + p.AffiliateId;
            }
            else
            {
                objects["p"] = p;         
                $(p.AffiliateId + "_" + p.Term).innerHTML = TrimPath.processDOMTemplate("affiliateTermProduct_jst", objects);
            }
            
            if(p.BestPrice.toLowerCase() == "true")
            {
                //$(p.AffiliateId+"_"+p.Term+"_outer").style.background = "transparent url(http://www.magsdirect.com/sites/magsdirect/images/comparison/best_highlight.gif) repeat-x scroll 0% 0%";
                $('pIssues').innerHTML = p.Term;
                $('pAffiliateLink').innerHTML = (p.AffiliateId.toLowerCase().indexOf("magsdirect")!=-1 ? '<a href="#magsdirect" class="newLink">'+p.AffiliateId+'</a>' : '<a  href="javascript:void(0);" onclick="pageTracker._trackPageview(\'/affiliate_click_out\');window.open(\'process.aspx?type=affiliate&sku='+sku+'&our_price=0&price='+p.Price+'&affiliate_id='+p.AffiliateId+'&link='+p.Link+'&referrer='+referrer+'&user_display='+user_display+'\');"  class="newLink">'+p.AffiliateId+'</a>');
                $('pPrice').innerHTML = formatCurrency(p.Price-p.CouponAmount);
                $('pCoupon').innerHTML = (p.CouponAmount > 0 ? ("&nbsp;with coupon "+(p.PromoCode != "" ? "'<font class=&quotred&quot>"+p.PromoCode+"</font>'" : "")) : "");
            }
            if(p.BestValue.toLowerCase() == "true")
            {
                //$(p.AffiliateId+"_"+p.Term+"_outer").style.background = "transparent url(http://www.magsdirect.com/sites/magsdirect/images/comparison/best_highlight.gif) repeat-x scroll 0% 0%";
                $('vIssues').innerHTML = p.Term;
                $('vAffiliateLink').innerHTML = (p.AffiliateId.toLowerCase().indexOf("magsdirect")!=-1 ? '<a href="#magsdirect" class="newLink">'+p.AffiliateId+'</a>' : '<a  href="javascript:void(0);" onclick="pageTracker._trackPageview(\'/affiliate_click_out\');window.open(\'process.aspx?type=affiliate&sku='+sku+'&our_price=0&price='+p.Price+'&affiliate_id='+p.AffiliateId+'&link='+p.Link+'&referrer='+referrer+'&user_display='+user_display+'\');"  class="newLink">'+p.AffiliateId+'</a>');
                $('vPrice').innerHTML = formatCurrency(p.Price-p.CouponAmount);
                $('vCoupon').innerHTML = (p.CouponAmount >0 ? ("&nbsp;with coupon "+(p.PromoCode != "" ? "'<font class=&quotred&quot>"+p.PromoCode+"</font>'" : "")) : "");
            }
        }
        $('bestDiv').style.display = "inline";
    }
}
