
var finderByID=function(it){return it.id==this;}
Page=WL.Class(Object,function()
{this.auctionID=0;this.auctionInfo=null;this.showWinner=false;var expires=new Date();expires.addMonths(1);this.soundCookie=new WL.Objects.Cookie("sound",expires.toString(CultureInfo.Date.formatPatterns.rfc1123));},function(type)
{type.main=function()
{if(this.auctionID!=0)
{WL.mask_attach(WL.Utils.$("in_autoBid"),"money");WL.mask_attach(WL.Utils.$("in_bid"),"money");this.showWinner=this.auctionInfo!=null&&this.auctionInfo.state==AUCTION_STATE.Started;this.updateRemainCookie=window.setInterval(updateRemain,1000);updateRemain();doUpdateInfo();WL.attachListener(WL.Utils.$("in_bid"),"focus",stopChanging);WL.attachListener(WL.Utils.$("in_bid"),"blur",releaseChanging);}}
var stopChanging=function(e){WL.getEvent(e).target.__stopChanging=true;}
var releaseChanging=function(e){WL.getEvent(e).target.__stopChanging=false;}
type.emailOutbid=function()
{if(window.userID==0)
{WL.Utils.$('emailOutbid').checked=false;WL.Utils.$("auctionid").value=this.auctionID;WL.Utils.$("setemailoutbid").value=true;WL.popup_show(WL.Utils.$("cont_login"));}
else
window.auctionManagerAPI.emailOutbid(this.auctionID,WL.Utils.$('emailOutbid').checked,null);}
type.makeBid=function()
{if(this.auctionID!=0&&this.auctionInfo!=null&&this.auctionInfo.state==AUCTION_STATE.Started)
{var bidValue=Number.fromMoney(WL.Utils.$('in_bid').value);if(bidValue>this.auctionInfo.retailPrice&&bidValue!=this.auctionInfo.nextBidValue)
{WL.alert(WL.S(389));return;}
if(window.userID==0)
{WL.Utils.$("auctionid").value=this.auctionID;WL.Utils.$("bidvalue").value=bidValue;WL.popup_show(WL.Utils.$("cont_login"));}
else if(this.auctionInfo.winnerID!=window.userID)
window.auctionManagerAPI.makeBid(this.auctionID,bidValue,on_makeBid.bind(this));}}
var on_makeBid=function(result)
{if(result.error)
{WL.alert(result.errorInfo?result.errorInfo.toString():"Making bid failed");return;}
this.auctionInfo=result.info;this.updateAuctionInfo();}
type.addToWatchlist=function()
{if(this.auctionID!=0&&this.auctionInfo!=null)
{if(window.userID==0)WL.login();else
window.watchlistManagerAPI.addToWatchlist(this.auctionID,on_addToWatchlist.bind(this));}}
var on_addToWatchlist=function(result)
{if(result.error)
{WL.alert(result.errorInfo?result.errorInfo.toString():"Adding to watchlist failed");return;}
WL.navigate("myg4b.aspx?manage=watchlist");}
type.showAutoBid=function()
{if(this.auctionID!=0&&this.auctionInfo!=null&&this.auctionInfo.state==AUCTION_STATE.Started)
{if(window.userID==0)WL.login();else
{WL.Utils.$("in_autoBid").value=this.auctionInfo.nextBidValue.toMoney();WL.popup_show(WL.Utils.$("cont_autoBid"));}}}
type.autoBid=function()
{if(this.auctionID!=0&&this.auctionInfo!=null&&this.auctionInfo.state==AUCTION_STATE.Started)
{if(window.userID==0)WL.login();else
window.auctionManagerAPI.setAutoBid(this.auctionID,Number.fromMoney(WL.Utils.$('in_autoBid').value),on_setAutoBid.bind(this));}}
var on_setAutoBid=function(result)
{WL.popup_hide();if(result.error)
{WL.alert(result.errorInfo?result.errorInfo.toString():"Set auto bid failed");return;}
this.auctionInfo=result.info;this.updateAuctionInfo();}
type.showBidHistory=function()
{if(this.auctionID!=0&&this.auctionInfo!=null&&this.auctionInfo.bidsCount!=0)
{window.auctionManagerAPI.queryBidHistory(this.auctionID,on_queryBidHistory.bind(this));var tbody=WL.Utils.$("table_bidHistory").tBodies[0];while(tbody.rows.length>1)tbody.removeChild(tbody.lastChild);}}
var on_queryBidHistory=function(result)
{if(result.error)
{WL.alert(result.errorInfo?result.errorInfo.toString():"Loading bid history failed");return;}
var tbody=WL.Utils.$("table_bidHistory").tBodies[0];while(tbody.rows.length>1)tbody.removeChild(tbody.lastChild);for(var i=0;i<result.list.length;++i)
{var bid=result.list[i];var user=result.users.find(finderByID.bind(bid.userID));var className=i&1?"base_table-cell":"base_table-cell2";var tr=WL.Utils.$e("tr");var td=WL.Utils.$e("td");td.className=className;td.innerHTML=user?user.name:"&nbsp;";tr.appendChild(td);td=WL.Utils.$e("td");td.className=className;td.innerHTML=bid.value.toMoney();tr.appendChild(td);td=WL.Utils.$e("td");td.className=className;td.innerHTML=bid.date.toString(CultureInfo.Date.formatPatterns.fullDateTime);tr.appendChild(td);td=WL.Utils.$e("td");td.className=className+(i==0?" auction-history-winning":" auction-history-loosing");td.innerHTML=WL.SHTML(i==0?135:136);tr.appendChild(td);tbody.appendChild(tr);}
WL.popup_show(WL.Utils.$("cont_bidHistory"));}
type.showSuggestions=function()
{WL.popup_show(WL.Utils.$("cont_suggestions"));}
type.sendSuggestions=function()
{if(this.auctionID!=0)
{WL.Utils.$("in_Suggestions").disabled=true;WL.Utils.$$("btn_sendSuggestions").disable(true);WL.Utils.$$("btn_cancelSuggestions").disable(true);window.auctionManagerAPI.sendSuggestion(this.auctionID,WL.Utils.$('in_Suggestions').value,on_sendSuggestions.bind(this));}}
var on_sendSuggestions=function(result)
{WL.popup_hide();WL.Utils.$$("btn_sendSuggestions").disable(false);WL.Utils.$$("btn_cancelSuggestions").disable(false);WL.Utils.$("in_Suggestions").disabled=false;WL.Utils.$("in_Suggestions").value="";if(result.error)
{WL.alert(result.errorInfo?result.errorInfo.toString():"Sending suggestions failed");return;}
WL.alert(WL.S(148));}
var playSound=function()
{var sound=WL.Utils.$("in_sounds").value;if(sound!='off'){WL.Utils.$("divSound").innerHTML="<embed autoplay='true' height='0' width='0' id='sound' src='Files/"+sound+"' >";}}
type.onSoundChanged=function()
{var sound=WL.Utils.$("in_sounds").value;this.soundCookie.remove("sound");this.soundCookie.set("",sound);}
var previousPrice;type.updateAuctionInfo=function()
{if(this.auctionInfo==null)return;var bidInput=WL.Utils.$('in_bid');WL.Utils.$('in_current').innerHTML=this.auctionInfo.currentPrice.toMoney();if(!bidInput.__stopChanging&&Number.fromMoney(bidInput.value)<=this.auctionInfo.currentPrice)
bidInput.value=this.auctionInfo.nextBidValue.toMoney();bidInput.disabled=this.auctionInfo.nextBidValue>=this.auctionInfo.retailPrice;WL.Utils.$('in_winner').innerHTML=this.auctionInfo.winner;WL.Utils.$('in_bidsCount').innerHTML=this.auctionInfo.bidsCount;WL.Utils.$('in_stop').innerHTML=this.auctionInfo.dateStop.toString(CultureInfo.Date.formatPatterns.fullDateTime);try
{if(previousPrice==null)
previousPrice=this.auctionInfo.currentPrice;if(previousPrice!=this.auctionInfo.currentPrice)
{previousPrice=this.auctionInfo.currentPrice;playSound();}}
catch(e){}
var btn=WL.Utils.$$("btn_makeBid");if(window.userID==0||this.auctionInfo.winnerID!=window.userID)
{var time=new WL.Objects.Time(Math.floor((this.auctionInfo.dateStop.valueOf()-WL.Utils.getServerTime().valueOf())/1000));if(time.getTotalSeconds()>12)btn.setCssClass("button");btn.setRID(111);}
else
{btn.setCssClass("winning_button");btn.setRID(112);}
switch(this.auctionInfo.state)
{case AUCTION_STATE.Created:WL.Utils.$("in_state").innerHTML=WL.SHTML(140);break;case AUCTION_STATE.Started:WL.Utils.$("in_state").innerHTML=WL.SHTML(141);break;case AUCTION_STATE.Closed:WL.Utils.$("in_state").innerHTML=WL.SHTML(142);break;case AUCTION_STATE.Sold:WL.Utils.$("in_state").innerHTML=WL.SHTML(143);break;}
if(this.auctionInfo.bidsCount>0)
WL.Utils.setNew(WL.Utils.$("cont_viewBids").style,"visibility","visible");if(this.auctionInfo.state==AUCTION_STATE.Sold)
{if(window.userID!=0&&this.auctionInfo.winnerID==window.userID){WL.Utils.setNew(WL.Utils.$("cont_pay").style,"visibility","visible");}}
WL.Utils.setNew(WL.Utils.$("bidMoreRetail").style,"visibility",bidInput.disabled?"visible":"hidden");var autobidLabel=WL.Utils.$("autobidOn");if(autobidLabel!=null)
{if(this.auctionInfo.autoBidValue!=0&&this.auctionInfo.autoBidValue>this.auctionInfo.currentPrice)
{WL.Utils.setNew(autobidLabel.style,"visibility","visible");autobidLabel.innerHTML=WL.SHTML(139)+" <b>"+this.auctionInfo.autoBidValue.toMoney()+"</b>.";}
else
WL.Utils.setNew(autobidLabel.style,"visibility","hidden");}}
var doUpdateInfo=function()
{window.auctionManagerAPI.getAuctionInfo([window.page.auctionID],on_getAuctionInfo.bind(window.page),true);}
var on_getAuctionInfo=function(result)
{if(!result.error)
{this.auctionInfo=result.list[0];this.updateAuctionInfo();if(this.auctionInfo.state<=AUCTION_STATE.Started)
window.setTimeout(doUpdateInfo,3000);else
{window.clearInterval(this.updateRemainCookie);WL.Utils.$("in_remain").innerHTML=WL.SHTML(144);if(this.auctionInfo.state==AUCTION_STATE.Sold&&this.auctionInfo.winnerID==window.userID)
{showWinner();}}}}
var showWinner=function()
{if(window.page.showWinner)
{if(WL.popup_show(WL.Utils.$("cont_winner")))
window.page.showWinner=false;else window.setTimeout(showWinner,1000);}}
var updateRemain=function()
{if(window.page.auctionInfo.state==AUCTION_STATE.Started)
{var time=new WL.Objects.Time(Math.floor((window.page.auctionInfo.dateStop.valueOf()-WL.Utils.getServerTime().valueOf())/1000));if(time.getTotalSeconds()<=0)
WL.Utils.$("in_remain").innerHTML=WL.SHTML(289);else
WL.Utils.$("in_remain").innerHTML=time.toString();if(time.getTotalSeconds()<=12)
{if(window.userID==0||window.page.auctionInfo.winnerID!=window.userID)
{var btn=WL.Utils.$$("btn_makeBid");btn.setCssClass((new Date().getSeconds()%2)!=0?"button":"default_button");}}}}});
