var GAP=GAP||{};GAP.Module=GAP.Module||{},GAP.Module.Lot=GAP.Module.Lot||{},GAP.Module.Lot.Model=GAP.Module.Lot.Model||{},GAP.Module.Lot.Model.LotModel=GAP.Module.Lot.Model.LotModel||{},GAP.Module.Lot.Model.LotDetailsModel=GAP.Module.Lot.Model.LotModel.extend({initialize:function(){this.constructor.__super__.initialize.apply(this,arguments),this.set("Map",_.extend(this.get("Map"),{EventStartDateTimeUtc:"StartTimeUtc",BiddingOpensDateTimeInternationalText:"BiddingOpensMessage",LotExpiryDateTimeUtc:"EndTimeUtc",BiddingEndsDateTimeInternationalText:"BiddingEndsMessage",LeadBidderId:"WinningBidderId",TimezoneId:"TimeZone",WishListCount:"WatchListCount",TimedBidHistory:"BidHistory",MinimumBidAmount:"MinimumBid",Message:"DialogMessage",ButtonText:"DialogButton",BiddingType:"BiddingType"})),this.set({Type:"Details"}),_.bindAll(this,"generateTimer");Backbone.Events.on("GAP.Service.LotDetail.DataUpdated",this.bidHistoryAdd,this);Backbone.Events.on("GAP.Service.LotDetail.DataUpdated",this.panelLogic,this);Backbone.Events.on("Gap.Lot.BidderRegistrationStatus.Update",this.registrationStatusLogic,this);this.on("change:WinningBidderId",this.lotDetailsStateLogic,this);this.on("change:BidderId",this.lotDetailsStateLogic,this);this.on("change:BidderId",this.bidHistoryLogic,this);this.on("change:LotClosed",this.lotDetailsStateLogic,this);this.on("change:LotClosed",this.panelLogic,this);this.on("change:TotalBids",this.bidsLogic,this);this.on("change:ConfirmationAmount",this.confirmationCurrencyLogic,this);this.on("change:ConfirmationAmount",this.confirmationAmountLogic,this);this.on("change:IsPieceMeal",this.confirmationPieceMealLogic,this);this.on("change:Quantity",this.confirmationPieceMealLogic,this);this.on("change:LeadingBid",this.lotDetailsBidAmountLogic,this);this.on("change:LeadingBid",this.panelLogic,this);this.on("change:BidHistory",this.bidHistoryLogic,this);this.on("change:RegistrationStatus",this.panelLogic,this);this.on("change:EventStarted",this.panelLogic,this);this.on("change:CurrentMaximumBid",this.panelLogic,this);this.on("change:CurrentMaximumBid",this.currentMaximumBidLogic,this);this.on("change:CurrentMaximumBid",this.currentMaximumBidCurrencyLogic,this);this.on("change:NextMaximumBid",this.minimumBidLogic,this);this.on("change:MinimumBid",this.minimumBidLogic,this);this.on("change:BuyItNowConfirmationAmount",this.butItNowConfirmationAmountLogic,this);this.on("change:IsPieceMeal",this.buyItNowConfirmationPieceMealLogic,this);this.on("change:Quantity",this.buyItNowConfirmationPieceMealLogic,this);this.on("change:BuyItNowPrice",this.butItNowConfirmationAmountLogic,this);this.on("change:MinimumBid",this.butItNowConfirmationAmountLogic,this)},prepareUpdate:function(){var n={};this.executeUpdate(n)},saveValues:function(n){if(typeof n!="undefined")for(var t in n)this.get("Filter").indexOf(t)===-1&&(typeof this.get("Map")[t]!="undefined"?this.set(this.get("Map")[t],n[t]):this.set(t,n[t]))},parse:function(n){var i={},u=this.get("Map"),t,f,r;for(t in n){f=!1;for(r in u)t===r&&(i[u[r]]!==n[t]&&(i[u[r]]=n[t]),f=!0);f||i[t]!==n[t]&&(i[t]=n[t])}return i},lotDetailsStateLogic:function(){if(this.get("WinningBidderId")===this.get("BidderId")&&this.set({BidderHasBids:!0}),this.get("LotClosed"))this.set({LotDetailsStateMessage:portalScriptResources.TimerLotClosed}),this.set({LotDetailsStateClass:""});else{var n=this.get("BiddingType")&&this.get("BiddingType")==="Competitive"&&this.get("AuctionType")&&this.get("AuctionType")==="Live";this.get("WinningBidderId")&&this.get("BidderId")&&this.get("WinningBidderId")===this.get("BidderId")?(n?this.set({LotDetailsStateMessage:portalScriptResources.BidderStateCurrentlyLeading}):this.set({LotDetailsStateMessage:portalScriptResources.BidderStateInLead}),this.set({LotDetailsStateClass:"lead"})):this.get("WinningBidderId")&&this.get("BidderId")&&this.get("BidderHasBids")===!0?n&&this.get("IsPending")||(this.set({LotDetailsStateMessage:portalScriptResources.BidderStateOutBid}),this.set({LotDetailsStateClass:"outBid"})):(this.set({LotDetailsStateMessage:portalScriptResources.BidderStateBidToday}),this.set({LotDetailsStateClass:""}))}},bidsLogic:function(){typeof this.get("TotalBids")!="undefined"?this.get("TotalBids")===0?(this.set({BidsToolTipMessage:portalScriptResources.ToolTipNoBidsOnLot}),this.set({BidsLinkClass:""}),this.set({BidsPanelDisplay:"none"})):(this.set({BidsToolTipMessage:portalScriptResources.ViewAllBids}),this.set({BidsLinkClass:"link"}),this.set({BidsPanelDisplay:"block"})):(this.set({BidsToolTipMessage:""}),this.set({BidsLinkClass:""}),this.set({BidsPanelDisplay:"none"}))},minimumBidLogic:function(){var n=this.get("MinimumBid");this.get("NextMaximumBid")>n&&(n=this.get("NextMaximumBid")),n&&(this.get("LeadingBid")||this.get("CurrentMaximumBid")?(this.get("LeadingBid")<n||this.get("CurrentMaximumBid")<n)&&(this.set({MinimumBidTextBefore:portalScriptResources.MinimumBidBeforeOpened}),this.set({MinimumBidTextAfter:portalScriptResources.MinimumBidAfterOpened.format(this.get("Currency"))}),this.displayMinimumBid(n)):(this.set({MinimumBidTextBefore:portalScriptResources.MinimumBidBeforeOpening}),this.set({MinimumBidTextAfter:portalScriptResources.MinimumBidAfterOpening.format(this.get("Currency"))}),this.displayMinimumBid(n)))},lotDetailsBidAmountLogic:function(){this.get("ShowSaleResults")?this.get("LeadingBid")?this.set({LotDetailsPriceClass:"amount"}):this.set({LotDetailsPriceClass:"noBid"}):this.set({LotDetailsPriceClass:""})},confirmationAmountLogic:function(){this.get("ConfirmationAmount")?this.set({ConfirmationAmountDisplay:$.autoNumeric.FormatAmount(this.get("ConfirmationAmount"))}):this.set({ConfirmationAmountDisplay:""}),this.confirmationCurrencyLogic(),this.confirmationPieceMealLogic()},butItNowConfirmationAmountLogic:function(){this.showBuyItNow()?this.set({BuyItNowConfirmationAmountDisplay:$.autoNumeric.FormatAmount(this.get("BuyItNowPrice"))}):this.set({BuyItNowConfirmationAmountDisplay:""}),this.buyItNowConfirmationCurrencyLogic(),this.buyItNowConfirmationPieceMealLogic()},confirmationCurrencyLogic:function(){this.get("Currency")?this.get("ConfirmationAmount")&&this.get("ShowSaleResults")?this.set({ConfirmationCurrencyDisplay:this.get("Currency")}):this.set({ConfirmationCurrencyDisplay:""}):this.set({ConfirmationCurrencyDisplay:""})},buyItNowConfirmationCurrencyLogic:function(){this.get("Currency")?this.showBuyItNow()?this.set({BuyItNowConfirmationCurrencyDisplay:this.get("Currency")}):this.set({BuyItNowConfirmationCurrencyDisplay:""}):this.set({BuyItNowConfirmationCurrencyDisplay:""})},confirmationPieceMealLogic:function(){this.get("IsPieceMeal")&&this.get("Quantity")>1&&this.get("ConfirmationAmount")?this.set({PieceMealConfirmationMessage:"("+$.autoNumeric.FormatAmount(this.get("ConfirmationAmount"))+" x "+$.autoNumeric.FormatAmount(this.get("Quantity"))+" = "+$.autoNumeric.FormatAmount(this.get("Quantity")*this.get("ConfirmationAmount"))+" "+this.get("ConfirmationCurrencyDisplay")+")"}):this.set({PieceMealConfirmationMessage:""})},buyItNowConfirmationPieceMealLogic:function(){this.get("IsPieceMeal")&&this.get("Quantity")>1&&this.showBuyItNow()?this.set({BuyItNowPieceMealConfirmationMessage:"("+$.autoNumeric.FormatAmount(this.get("BuyItNowPrice"))+" x "+$.autoNumeric.FormatAmount(this.get("Quantity"))+" = "+$.autoNumeric.FormatAmount(this.get("Quantity")*this.get("BuyItNowPrice"))+" "+this.get("BuyItNowConfirmationCurrencyDisplay")+")"}):this.set({BuyItNowPieceMealConfirmationMessage:""})},bidHistoryAdd:function(n){if(typeof n.EventType!="undefined"&&n.EventType==="TimedBidAdded"){var t={BidderId:n.LeadBidderId,Amount:n.LeadingBid,DisplayTimeSinceBidPlaced:portalScriptResources.AFewSecondsAgo};this.get("BidHistory")&&_.isArray(this.get("BidHistory"))&&(this.get("BidHistory").unshift(t),this.trigger("change:BidHistory",this))}},bidHistoryLogic:function(){var n,t;if(this.get("BidHistory")){for(t=0;t<this.get("BidHistory").length;t++)n=this.get("BidHistory")[t],n.AmountDisplay=$.autoNumeric.FormatAmount(n.Amount),n.WhoBid=this.get("BidderId")&&n.BidderId?this.get("BidderId")===n.BidderId?portalScriptResources.WhoBidYou:portalScriptResources.WhoBidOther:"";this.totalBidsLogic()}},totalBidsLogic:function(){var t,n;if(this.get("AuctionType")==="Live"&&this.get("BiddingType")==="Competitive"){this.set({BidderHasBids:this.get("CurrentMaximumBid")>0,TotalBids:this.get("NumberOfBids")});return}for(t=!1,n=0;n<this.get("BidHistory").length;n++)this.get("BidHistory")[n].BidderId===this.get("BidderId")&&(t=!0);this.set({BidderHasBids:t,TotalBids:this.get("BidHistory").length})},currentMaximumBidLogic:function(){$(".customersMaxBid").val(this.get("CurrentMaximumBid")),this.get("CurrentMaximumBid")?(this.set({CurrentMaximumBidDisplay:$.autoNumeric.FormatAmount(this.get("CurrentMaximumBid"))}),this.set({CurrentMaximumBidDisplayClass:"amount"})):(this.set({CurrentMaximumBidDisplay:portalScriptResources.None}),this.set({CurrentMaximumBidDisplayClass:""}))},currentMaximumBidCurrencyLogic:function(){this.get("Currency")?this.get("CurrentMaximumBid")&&this.get("ShowSaleResults")?this.set({CurrentMaximumCurrencyDisplay:this.get("Currency")}):this.set({CurrentMaximumCurrencyDisplay:""}):this.set({CurrentMaximumCurrencyDisplay:""})},reserveLogic:function(){this.constructor.__super__.reserveLogic.apply(this,arguments),this.get("HasReserve")?$("#timedAuctionPanel").addClass("reserve"):$("#timedAuctionPanel").removeClass("reserve")},registrationStatusLogic:function(n){this.get("BidderId")&&typeof n.BidderId!="undefined"&&typeof n.RegistrationStatus!="undefined"&&this.get("BidderId")===n.BidderId&&this.set({RegistrationStatus:n.RegistrationStatus})},panelLogic:function(){this.get("BidderId")!==this.get("GuidEmpty")&&(this.get("RegistrationStatus")===this.get("RegistrationStatuses").Declined?($("#bidPanel").removeClass("pending").removeClass("approved").addClass("declined"),$("#notAllowed").addClass("declined")):this.get("RegistrationStatus")===this.get("RegistrationStatuses").Pending?($("#bidPanel").removeClass("approved").removeClass("declined").addClass("pending"),$("#notAllowed").removeClass("declined")):this.get("RegistrationStatus")===this.get("RegistrationStatuses").Approved&&($("#bidPanel").removeClass("pending").removeClass("declined").addClass("approved"),$("#notAllowed").removeClass("declined")),this.get("CurrentMaximumBid")&&(this.get("CurrentMaximumBid")>0?($("#bidPanel").addClass("bidPlaced"),$("#bidPanel").removeClass("confirm-your-bid"),this.get("RegistrationStatus")===this.get("RegistrationStatuses").Approved&&(this.get("WinningBidderId")===this.get("BidderId")?$("#bidPanel").addClass("inLead").removeClass("outBid").removeClass("noBids").removeClass("confirm-your-bid"):this.get("WinningBidderId")===null?$("#bidPanel").addClass("noBids").removeClass("outBid").removeClass("inLead").removeClass("confirm-your-bid"):this.get("AuctionType")&&this.get("AuctionType")==="Live"&&this.get("BiddingType")&&this.get("BiddingType")==="Competitive"||$("#bidPanel").addClass("outBid").removeClass("inLead").removeClass("noBids").removeClass("confirm-your-bid"))):$("#bidPanel").removeClass("bidPlaced"))),this.get("EventStarted")?$("#bidPanel").removeClass("notStarted"):$("#bidPanel").addClass("notStarted"),this.get("LotClosed")?$("#bidPanel").removeClass().addClass("lotExpired"):$("#bidPanel").removeClass("lotExpired"),this.showBuyItNow()?$("#bidPanel").addClass("buyItNow"):$("#bidPanel").removeClass("buyItNow"),this.minimumBidLogic(),this.reserveLogic()},generateTimer:function(n){var r=moment(),u=moment.unix(r.unix()+n),t,i;this.setTimeRemaining({SecondsRemaining:n}),t="",i=location.pathname.split("/")[1],this.get("TimeRemaining").Days>0?(this.get("TimerHeading")!==portalScriptResources.TimerHeadingBiddingEnds+":"&&this.set({TimerHeading:portalScriptResources.TimerHeadingBiddingEnds+":"}),this.get("BiddingEndsMessage")?this.set({Timer:this.get("BiddingEndsMessage")}):this.set({Timer:u.locale(i).format(this.get("TimerFormat"))})):(this.get("TimerHeading")!==portalScriptResources.TimerHeadingTimeRemaining&&this.set({TimerHeading:portalScriptResources.TimerHeadingTimeRemaining}),t+=this.displayCountdown(),(this.get("TimeRemaining").Seconds===300||this.get("TimeRemaining").Seconds===0)&&this.dataReload(),this.get("TimeRemaining").Minutes<10&&!this.get("TimerAlert")&&this.set({TimerAlert:!0}),this.get("TimeRemaining").Seconds>0&&this.set({Timer:t}))},biddingOpens:function(){var t=location.pathname.split("/")[1],n;this.get("BiddingOpensMessage")?(this.get("TimerHeading")!==portalScriptResources.TimerHeadingBiddingOpens+":"&&this.set({TimerHeading:portalScriptResources.TimerHeadingBiddingOpens+":"}),this.set({Timer:this.get("BiddingOpensMessage")})):this.get("StartDate")&&(n=this.get("StartDate"),this.get("StartDateOffset")&&(n+=this.get("StartDateOffset")),this.get("TimerHeading")!==portalScriptResources.TimerHeadingBiddingOpens+":"&&this.set({TimerHeading:portalScriptResources.TimerHeadingBiddingOpens+":"}),this.set({Timer:moment.unix(n/1e3).locale(t).format(this.get("TimerFormat"))}))},displayMinimumBid:function(n){if(this.get("AuctionType")==="Live"&&this.get("BiddingType")==="Competitive"&&this.get("WinningBidderId")===this.get("BidderId"))this.set({MinimumBidDisplay:""});else{var t='<span class="minBidAmount">'+$.autoNumeric.FormatAmount(n)+"</span>";this.set({MinimumBidDisplay:"("+this.get("MinimumBidTextBefore")+" "+t+" "+this.get("MinimumBidTextAfter")+")"})}},showBuyItNow:function(){return this.get("LotClosed")===!0||this.get("EventStarted")===!1?!1:this.get("MinimumBid")?this.get("BuyItNowPrice")>0&&this.get("BuyItNowPrice")>=this.get("MinimumBid"):this.get("BuyItNowPrice")>0},dataReload:function(){Backbone.Events.trigger("GAP.SingleLot.Update",null)}}),GAP=GAP||{},GAP.Module=GAP.Module||{},GAP.Module.Lot=GAP.Module.Lot||{},GAP.Module.Lot.Details=GAP.Module.Lot.Details||{},GAP.Module.Lot.Details.View=GAP.Module.Lot.Details.View||{},GAP.Module.Lot.Details.View.Bids=GAP.Module.Lot.View.LotView.extend({initialize:function(){this.constructor.__super__.initialize.apply(this,arguments);this.model.on("change:BidsToolTipMessage",this.changeToolTipMessage,this);this.model.on("change:BidsLinkClass",this.changeLinkClass,this);this.model.on("change:BidsPanelDisplay",this.changePanelDisplay,this);this.changeToolTipMessage(),this.changeLinkClass(),this.changePanelDisplay()},changeToolTipMessage:function(){document.getElementById("bidsToolTip")&&document.getElementById("bidsToolTip").setAttribute("title",this.model.get("BidsToolTipMessage"))},changeLinkClass:function(){document.getElementById("bidsLink")&&(document.getElementById("bidsLink").className=this.model.get("BidsLinkClass"))},changePanelDisplay:function(){document.getElementById("bidsPanel")&&$("#bidsPanel").css("display",this.model.get("BidsPanelDisplay"))}}),GAP=GAP||{},GAP.Module=GAP.Module||{},GAP.Module.Lot=GAP.Module.Lot||{},GAP.Module.Lot.Details=GAP.Module.Lot.Details||{},GAP.Module.Lot.Details.View=GAP.Module.Lot.Details.View||{},GAP.Module.Lot.Details.View.Price=GAP.Module.Lot.View.LotView.extend({initialize:function(){this.constructor.__super__.initialize.apply(this,arguments);this.model.on("change:"+this.options.ChangeClass,this.changeClass,this);this.changeClass()},changeClass:function(){this.el.className=this.model.get(this.options.ChangeClass)},render:function(){this.constructor.__super__.render.apply(this,arguments)}}),GAP=GAP||{},GAP.Module=GAP.Module||{},GAP.Module.Lot=GAP.Module.Lot||{},GAP.Module.Lot.Details=GAP.Module.Lot.Details||{},GAP.Module.Lot.Details.View=GAP.Module.Lot.Details.View||{},GAP.Module.Lot.Details.View.State=GAP.Module.Lot.View.LotView.extend({tagName:"span",initialize:function(){this.constructor.__super__.initialize.apply(this,arguments);this.model.on("change:LotDetailsStateClass",this.changeClass,this);this.changeClass()},changeClass:function(){this.el.className=this.model.get("LotDetailsStateClass")},render:function(){this.constructor.__super__.render.apply(this,arguments)}}),GAP=GAP||{},GAP.Module=GAP.Module||{},GAP.Module.Lot=GAP.Module.Lot||{},GAP.Module.Lot.Details=GAP.Module.Lot.Details||{},GAP.Module.Lot.Details.View=GAP.Module.Lot.Details.View||{},GAP.Module.Lot.Details.View.BidHistory=GAP.Module.Lot.View.LotView.extend({tagName:"div",className:"hide",id:"bidHistoryForm",initialize:function(){this.classOptions(),this.constructor.__super__.initialize.apply(this,arguments),this.clickable()},classOptions:function(){this.Classes={Amount:"amount",Currency:"currency",WhoBid:"whoBid",Time:"time"}},clickable:function(){context=this,$("#bidsLink").click(function(){return context.$el.slideToggle(function(){context.$el.hasClass("hide")?(context.$el.removeClass("hide").addClass("open"),$("#bidHistory").addClass("open"),typeof ga!="undefined"&&ga("send","event","LotDetails","Open","BidHistory")):(context.$el.removeClass("open").addClass("hide"),$("#bidHistory").removeClass("open"),typeof ga!="undefined"&&ga("send","event","LotDetails","Close","BidHistory"))}),!1})},render:function(){var n,t,r,u;if(this.model.get("BidHistory"))for(this.el.innerHTML='<table><thead><tr><th><span class="a11y">'+portalScriptResources.Amount+'</span></th><th><span class="a11y">'+portalScriptResources.Bidder+'</span></th><th><span class="a11y">'+portalScriptResources.Time+"</span></th></tr></thead ></table > ",i=0;i<this.model.get("BidHistory").length;i++)bid=this.model.get("BidHistory")[i],tableRow=document.createElement("tr"),n=document.createElement("td"),n.className=this.Classes.Amount,n.innerHTML=$.autoNumeric.FormatAmount(bid.Amount)+" ",t=document.createElement("span"),t.className=this.Classes.Currency,t.innerHTML=this.model.get("Currency"),n.appendChild(t),tableRow.appendChild(n),r=document.createElement("td"),r.className=this.Classes.WhoBid,r.innerHTML=bid.WhoBid,tableRow.appendChild(r),u=document.createElement("td"),u.className=this.Classes.Time,u.innerHTML=bid.DisplayTimeSinceBidPlaced,tableRow.appendChild(u),this.el.getElementsByTagName("table")[0].appendChild(tableRow)}})