AJAX_PRICING_PKG.PLPAddToBasketPricingRenderer = function(options) {
  this.constructor.superclass.constructor.call(this, options);
  this._paratrackId = options.paratrackId;
  this._cmAddToBasketParams = options.cmAddToBasket;
};

// Extend the default renderer.
YAHOO.lang.extend(AJAX_PRICING_PKG.PLPAddToBasketPricingRenderer, AJAX_PRICING_PKG.DefaultPricingRenderer);

AJAX_PRICING_PKG.PLPAddToBasketPricingRenderer.prototype._renderNoSuccess = function(response) {
  return true;
};

AJAX_PRICING_PKG.PLPAddToBasketPricingRenderer.prototype._renderWidget = function(response, container) {
  var bestNewData = response.pricingInfoForBestNew;
  var bestUsedData = response.pricingInfoForBestUsed;

  var bestListingForDislay = null;
  var bookType = "";
  if(response.newExists) {
    bestListingForDislay = response.pricingInfoForBestNew;
    bookType = this._properties.atb_label_type_new;
  } else if(response.usedExists) {
    bestListingForDislay = response.pricingInfoForBestUsed;
    bookType = this._properties.atb_label_type_used;
  }

  var html = "";
  html += "<div class='sidebar-input'><div class='sidebar-input-top2'>&nbsp;</div><div class='sidebar-input-content2'>";

  var paratrack1 = "";
  var paratrack2 = ""

  if(this._paratrackId) {
    paratrack1 = "?paratrk=" + this._paratrackId;
    paratrack2 = "&paratrk=" + this._paratrackId;
  }
  var idprefix = container.id;

  if(bestListingForDislay == null) {
    html += "<div class='center'>" + this._properties.atb_nocopies + "</div>";
    html += "<div class='sidebar-input-separator2'>&nbsp;</div>";
    html += "<ul><li><a id='" + idprefix + "-link-searchentry" + "' href='/servlet/SearchEntry" + paratrack1 + "' title='" + this._properties.atb_link_advsearch + "'>" + this._properties.atb_link_advsearch + "</a></li>";
    html += "<li><a href='/' title='" + this._properties.atb_link_abehome + "'>" + this._properties.atb_link_abehome + "</a></li></ul>";
    html += "<div class='sidebar-input-separator2'>&nbsp;</div>";

    html += "<p style='padding-top:10px;margin-bottom:2px'><strong>" + this._properties.atb_search_title + "</strong></p>";
    html += "<form action='/servlet/SearchResults' method='post' id='plp-find-book' style='padding-top:10px;padding-left:10px'>";
    html += "<fieldset><input type='hidden' name='sts' value='t'/>";
    html += "<select name='sby' style='font-size:8pt;width:150px;margin-bottom:10px;'>"
    html += "<option value='key'>" + this._properties.qsSearchBy + "</option>";
    html += "<option value='tit'>" + this._properties.qsOpTitle + "</option>";
    html += "<option value='aut'>" + this._properties.qsOpAuthor + "</option>";
    html += "<option value='key'>" + this._properties.qsOpKeyword + "</option>";
    html += "<option value='isbn'>ISBN</option>";
    html += "<option value='pub'>" + this._properties.qsOpPublisher + "</option>";
    html += "</select><br/><input type='text' name='stext' maxlength='100'  style='font-size:8pt;width:146px;margin-bottom:10px;'/><br/><input type='image' src='/images/servlets/shared/btn-find-book-sm.gif' alt='' style='vertical-align: top;'/></fieldset></form>";
    html += "<div class='sidebar-input-separator2'>&nbsp;</div>";

    html += "<p style='padding-top:10px;margin-bottom:2px'><strong>" + this._properties.atb_create_want + "</strong></p>";
    html += "<p>" + this._properties.atb_create_want_text + "</p>";
    html += "<a href='/servlet/WantEntry?isbn=" + response.isbn + "' style='padding-left:10px'><img alt='" + this._properties.atb_create_want + "' src='/images/servlets/shared/btn-create-want.gif'/></a>";
  } else {
    var addBasketUrl = "/servlet/ShopBasketPL?ac=a&ik=" + bestListingForDislay.bestListingid + paratrack2;

    html += "<div style='margin-bottom:5px;text-align:center'><a id='add-to-basket-link' href='" + addBasketUrl + this._cmAddToBasketParams + "'>";
    html += "<img src='/images/servlets/AddToBasketServlet/add-to-basket-button.gif' alt='Add to Basket' /></a></div>";
    
    html += "<p><strong>" + this._properties.atb_label_price + "</strong> <span class='price'>" + bestListingForDislay.bestPriceInPurchaseCurrencyWithCurrencySymbol + "</span><br/>";
    html += bookType + " <a id='" + idprefix + "-link-plp" + "' href='/servlet/BookDetailsPL?bi=" + bestListingForDislay.bestListingid + paratrack2 + "' title='" + this._properties.atb_label_details + "'>" + this._properties.atb_label_details + "</a></p>";


    if(response.BTest) {
      if(bestListingForDislay.shippingToDestinationPriceInPurchaseCurrencyWithCurrencySymbol != "") {
		     html += "<p><strong>" + this._properties.atb_label_shipping + "</strong> " + "<span class='price'>" + bestListingForDislay.shippingToDestinationPriceInPurchaseCurrencyWithCurrencySymbol+ "</span>";
		     if(bestListingForDislay.vendorCountryNameInSurferLanguage == bestListingForDislay.shippingDestinationNameInSurferLanguage) {
		     	html += "<br/>" + this._properties.atb_label_within + " " + bestListingForDislay.vendorCountryNameInSurferLanguage;
		     } else {
		      html += "<br/>" + this._properties.atb_label_from + " " + bestListingForDislay.vendorCountryNameInSurferLanguage +" "+ this._properties.atb_label_to + " " + bestListingForDislay.shippingDestinationNameInSurferLanguage;
		     }
		     html += "<br/><a href='javascript:openNewWindow(\"/servlet/FrameBase?content=%2Fservlet%2FShipRates%3Fvid%3D" + bestListingForDislay.vendorId + "\",400, 500,\"yes\");' title='" + this._properties.atb_link_shippingrates_b + "'>" + this._properties.atb_link_shippingrates_b + "</a></p>";
      }
    }else {
      if(bestListingForDislay.domesticShippingPriceInPurchaseCurrencyWithCurrencySymbol != "") {
		     html += "<p><strong>" + this._properties.atb_label_shipping + "</strong> " + bestListingForDislay.domesticShippingPriceInPurchaseCurrencyWithCurrencySymbol;
		     html += "<br/><a href='javascript:openNewWindow(\"/servlet/FrameBase?content=%2Fservlet%2FShippingRatesPL%3Fvid%3D" + bestListingForDislay.vendorId + "\",400, 500,\"yes\");' title='" + this._properties.atb_link_shippingrates + "'>" + this._properties.atb_link_shippingrates + "</a></p>";
      }

    }
    var currencyUrl = "/servlet/FrameBase?content=%2Fservlet%2FCEPL%3Fvp%3D" + bestListingForDislay.nonPaddedPriceInListingCurrencyValueOnly + "%26vc%3D" + bestListingForDislay.listingCurrencySymbol + "%26v%3D" + bestListingForDislay.bestPriceInPurchaseCurrencyValueOnly + "%26s%3D" + bestListingForDislay.purchaseCurrencySymbol;
    html += "<p><a href='" + currencyUrl + "' onclick='return openWindow(this.href, 0, 0, 0, 0, 1, 1, 400, 500, 100, 100);' title='" + this._properties.atb_link_convertcurrency + "'>" + this._properties.atb_link_convertcurrency + "</a></p>";

    html += "<div class='sidebar-input-separator2'>&nbsp;</div>";
    html += "<ul><li><a id='" + idprefix + "-link-saveforlater" + "' href='/servlet/ShopBasketPL?ac=a&il=S&ik=" + bestListingForDislay.bestListingid + paratrack2 + "' title='" + this._properties.atb_link_save + "'>" + this._properties.atb_link_save + "</a></li></ul>";
  }

  html += "</div><div class='sidebar-input-bottom2'>&nbsp;</div>";

  if(bestListingForDislay) {
    // There is a cheapest new or used price.

    html += "<div class='sidebar-input-top2'>&nbsp;</div><div class='sidebar-input-content2'>";
    html += "<ul>";

    if(response.newExists) {
      html += "<li><a id='" + idprefix + "-link-searchresults-new" + "' href='/servlet/SearchResults?isbn=" + container.getAttribute("isbn") + "&n=100121501" + paratrack2 + "' title=''>" + this._properties.atb_label_new + " " + response.pricingInfoForBestNew.bestPriceInSurferCurrencyWithCurrencySymbol + "</a></li>";
    }
    if(response.usedExists) {
      html += "<li><a id='" + idprefix + "-link-searchresults-used" + "' href='/servlet/SearchResults?isbn=" + container.getAttribute("isbn") + "&n=100121502%2B100121503" + paratrack2 + "' title=''>" + this._properties.atb_label_used + " " + response.pricingInfoForBestUsed.bestPriceInSurferCurrencyWithCurrencySymbol + "</a></li>";
    }
    html += "</ul>";

    html += "<form id='" + idprefix + "-form-searchresults-all" + "' method='post' action='/servlet/SearchResults?isbn=" + container.getAttribute("isbn") + paratrack2 + "'>";
    html += "<fieldset class='center' style='padding-top:10px'><input type='image' src='/images/servlets/AddToBasketServlet/view_all_listings_button.gif' alt='View all Listings for this Book'/></fieldset></form>";
    html += "<div class='sidebar-input-separator2'>&nbsp;</div></div>";
    html += "</div><div class='sidebar-input-bottom2'>&nbsp;</div>";
  }

  container.innerHTML += html;
};


