function Auction(){this.id=0;this.name='';this.startTime=0;this.closeTime=0;this.type=1;this.isPublic=1;this.status='';this.price=0;this.startPrice=0;this.guaranteePrice=0;this.bidoPrice='hidden';this.bidoPriceMetText='';this.minPrice=0;this.lastPrice=0;this.lastTime=0;this.updatePriceTimerId;this.nextBid=0;this.bids=new BidsCollection(this);this.bidsCount=0;this.chat;this.userNick='';this.userId=0;this.userBid=0;this.userProxy=0;this.userWinning=false;this.userScheduledBid=0;this.userScheduledBidTime=0;this.userTriggerBid=0;this.userTriggerNeedBid=0;this.highBidder='';this.highBidderId=0;this.changes={};this.pauseReason='';this.messageBody;this.messageTimerId;this.messageDelay=7000;this.scales=[];this.defPercent=10;this.offerMode=0;this.offerTimer=0;this.buyItNowPrice=0;this.binOfferShowed=false;this.binBidPlaced=false;this.locationHome=true;this.priceFormat=0;this.videoStartTime=0;this.videoEndTime=0;this.chatStatus=0;this.init=function(opt){for(var i in opt){this[i]=opt[i];}
this.messageBody=$('#bidStatus');}
this.closeAuction=function(){this.status='closed';if(this.userWinning&&$('#sound_off')[0]&&$('#sound_off')[0].className=="sound-active"){playSound('win');}
var left=$('.main_auction_block .ablock_header .left img')[0];if(left){if(this.bids.length()>0&&this.bidoPrice!='hidden'&&this.price>=this.bidoPrice){left.src=imagePath+'/images/soldAuction.png';$('#sold_image').show();}else{left.src=imagePath+'/images/closedAuction.png';}
left.alt='Closed Auction';left.title='Closed Auction';}
$('#auctionTitle').html('Closed auction: ');$('.main_auction_block .ablock_header').css('background-image','url('+imagePath+'/images/blue_h.gif)');$('#orange_title a').css('color','#097EC3');$('.main_auction_block .ablock_header .right').css('background-image','url('+imagePath+'/images/blue_hright.gif)');$('#guarantee_price').hide();var children=$('.main_auction_block .bid-block').children();for(var i=0;i<children.length;i++){var child=children[i];if(child.className!='bid_status_text'&&child.className!='ablock_header'&&child.id!='ablock_info'&&child.id!='ablock_history'&&child.className!='visitor_link'){$(children[i]).remove();}}
$('#ablockInitBid').html('Closing price:');if(this.price==0){$('#currentBid').html('No bids');}
if($('#ablockStartBid').length>0)$('#ablockStartBid').remove();if($('#ablockCurrentBid').length>0)$('#ablockCurrentBid').remove();if($('#currentBidAd').length>0)$('#currentBidAd').remove();$('#userProxy').html('US $'+formatBidPrice(this.userProxy,this.priceFormat));if(this.bids.length()>0&&this.bidoPrice!='hidden'&&this.price>this.bidoPrice){var bid=this.bids.getLastNonRetracted();$('#ablock_info').append('<tr><td style="width: 100px;"><span style="font-size:12px;">Winner:</span></td><td>'+
(this.userNick=='visitor'?'<strong>'+bid.nick+'</strong>':'<a href="'+httpUrl+'/ViewProfile/'+bid.nick+'">'+bid.nick+'</a>')
+'</td></tr>');}
var startTime=new Date(this.startTime*1000);var closeTime=new Date(this.closeTime*1000);$("#ablock_info").append('<tr><td style="width: 100px;"><span style="margin-top: 7px;">Start date:</span></td>'+'<td nowrap><span>'+startTime.format("mmm dd yyyy, hh:MM tt")+'</span></td></tr>'+
(this.closeTime?'<tr><td style="width: 100px;"><span style="margin-top: 7px;">Close date:</span></td>'+'<td nowrap><span>'+closeTime.format("mmm dd yyyy, hh:MM tt")+'</span></td></tr>':''));if(this.userNick=='visitor'){$('.main_auction_block .live_visitor_link').remove();$('#bidHistoryLink').show();}
if(this.chat){this.chat.toggleSound(false);}
if($('#chat_sound_on').length>0)$('#chat_sound_on').remove();if($('#chat_sound_off').length>0)$('#chat_sound_off').remove();$('#tab-content-desc-table-status').html('CLOSED');if(this.buyItNowPrice){$('#buyNow').hide();}
if($('#timerTitle').length){document.location.reload();}else{closeWindow('dynamicOfferWindow');}}
this.openAuction=function(timer){if(this.status=='not started'){this.status='opened';var left=$('.main_auction_block .ablock_header .left img')[0];if(left){left.src=imagePath+'/images/atAuction.png';left.alt='At Auction';left.title='At Auction';}
$('#ablockInitBid').html('Current bid:');$('#auctionTitle').html('Live auction: ');$('.main_auction_block .ablock_header').css('background-image','url('+imagePath+'/images/orange_h.gif)');$('#orange_title a').css('color','#000000');$('.main_auction_block .ablock_header .right').css('background-image','url('+imagePath+'/images/orange_hright.gif)');$('#ablockStartBid').show();$('#ablockCurrentBid').show();$('#ablockReserve').show();$('#ablockTimerDate').hide();$('#ablockTimerTitle').html('Estimated time for Auction to end:');$('#pauseAuction').show();$('#guarantee_price').show();$('#bblockSound').show();$('#bblockMsg').hide();$('#userProxyHelp').html('(<a href="javascript:void(0)">?</a>)')
$('#userProxyHelp a').unbind().mouseover(function(){showHelpProcess(helpTexts.maxBid,this)}).click(function(){showHelpProcess(helpTexts.maxBid,this)});$('#userProxyHelp').show();if(this.userNick!='visitor'){$('#bidHistoryLink').show();}
$('#no-comments-text').text("No comments from our Expert Members.").css({"padding":"0px","vertical-align":"middle","text-align":"center"});if($('#comment_0')[0])$($('#comment_0')[0]).remove();if($('#biddingWindow')[0])$($('#biddingWindow')[0]).remove();$('.addCommentButton').remove();$('#commentariesClosed').show();if(this.type==2){$('#bidButtonContainer').show();this.lastPrice=this.startPrice;this.lastTimer=timer;this.updatePrice();}
if($('#timerTitle').length){$('#timerTitle').html('closes in ');}
if($('#casheback').length){$('#casheback').remove();}
$('#bidButton').show();}
if(this.status=='paused'){this.status='opened';this.pause(false);}}
this.setStatus=function(status,timer){if(status=='closed'&&(this.status=='opened'||this.status=='extended'||this.status=='not started')){this.closeAuction();}
if(status=='deleted'&&this.status!='deleted'){document.location.reload();}
if(status=='opened'){this.openAuction(timer);}
if(status=='paused'){this.status=status;this.pause(true);}
this.checkVideoTimer();}
this.setChatStatus=function(status){if(this.chatStatus!=status){this.chatStatus=status;if(this.id==$('.chatSelect').val()){if(this.chatStatus=='opened'){$('.chatConnectionStatus').css('text-align','center');$('.chatMessageBox, .chatSendButton').attr('disabled',!chatAvailable);$('.chatConnectionStatus').html(auctionTexts.chatOpened);}else{$('.chatMessageBox, .chatSendButton').attr('disabled',!chatAvailable);app.mainChat.clearUsers();}
app.mainChat.showLoginLink();}}}
this.setStartPrice=function(response){this.startPrice=response.start_price;if(this.type==2&&this.status=='opened'&&this.minPrice){this.lastPrice=response.current_price;this.lastTimer=response.timer;this.updatePrice();}}
this.updatePrice=callback(this,function(){this.price=this.getNextBid();this.nextBid=this.price;$('#bid').attr('value',this.nextBid);$('#currentBid').html('US $'+formatBidPrice(this.price,this.priceFormat));window.clearTimeout(this.updatePriceTimerId);this.updatePriceTimerId=window.setTimeout(this.updatePrice,1000);})
this.showUpcomingBuyItNow=function(bid){if(bid>=this.buyItNowPrice){showBinWindow(this.id,this.buyItNowPrice,this.name,'AuctionBIN');if(app.main_auction.id==this.id){$('#bidButtonLoad').hide();$('#bidButton').fadeIn();}
$('#auction_block_'+this.id).find('.bidButtonLoad').hide();$('#auction_block_'+this.id).find('.bidButton').fadeIn();$('#bidButtonLoad_'+this.id).hide();$('.bidButton_'+this.id).fadeIn();if($('#bidWindowAuctionId').val()==this.id){$('#bid_block_'+this.id+' .button-popup').fadeIn();}
return true;}
return false;}
this.placeBid=function(bid,isOffer,callback){if(this.buyItNowPrice&&this.status=='not started'&&this.showUpcomingBuyItNow(bid)){return false;}
var query={"auction":this.id,"bid":bid,"is offer":isOffer};sendMessage(JSJaCJSON.toString(query),callback);return true;}
this.scheduleBid=function(bid,time,callback){var query={"auction":this.id,"schedule bid":bid,"time":time};sendMessage(JSJaCJSON.toString(query),callback);}
this.triggerBid=function(bid,need_bid,callback){var query={"auction":this.id,"trigger bid":bid,"need bid":need_bid};sendMessage(JSJaCJSON.toString(query),callback);}
this.cancelBid=function(type,callback){var query={"auction":this.id,"cancel bid":type};sendMessage(JSJaCJSON.toString(query),callback);}
this.setProxy=function(response){if(response.price){this.price=response.price;}
if(response.high_bidder){this.highBidderId=response.high_bidder;}
this.binBidPlaced=response.bin?true:false;this.userProxy=response.proxy?response.proxy:0;this.showMessage(response);}
this.setScheduledBid=function(response){this.showMessage(response);if(response.result>=0){this.userScheduledBid=response.scheduled_bid?response.scheduled_bid:0;this.userScheduledBidTime=response.scheduled_bid_time?response.scheduled_bid_time:0;}}
this.setTriggerBid=function(response){this.showMessage(response);if(response.result>=0){this.userTriggerBid=response.trigger_bid?response.trigger_bid:0;this.userTriggerNeedBid=response.trigger_need_bid?response.trigger_need_bid:0;}}
this.getMessageColor=function(response){var color=(response.result==0||response.result==2||response.result==5)?'#009900':'#990000';if(this.status=='not started'){color='#000000';}
if(response.result==-2){color='#990000';}
if((response.result==4)||(response.result==6)||(response.result==7)){color='#990000';}
return color;}
this.showMessage=function(response){if(response.message&&typeof(response.result)!='undefined'){if(response.result==3&&typeof(showBidWindow)=='function'){showBidWindow(true,true);}
this.messageBody.css('color',this.getMessageColor(response));this.messageBody.html(response.message);window.clearTimeout(this.messageTimerId);this.messageTimerId=window.setTimeout('$("#bidStatus").text("")',this.messageDelay);}}
this.addBids=function(bids){var bid;for(var i=0;i<bids.length;i++){bid=bids[i];if(this.bidoPrice&&bid.amount>=this.bidoPrice){this.bids.add({'id':'BidoPriceMet','text':helpTexts['bidoPriceMetRow'].replace('{$bido_price}',formatBidPrice(this.bidoPrice))});}
if(this.bids.add(bid)){if(!bid.retracted){if(this.userId==bid.user){this.userBid=bid.amount;if(this.userProxy<bid.amount){this.userProxy=bid.amount;}}
if(this.price<=bid.amount&&!bid.retract_in_history){this.price=bid.amount;this.highBidder=bid.nick;this.highBidderId=bid.user;}}}}
this.bidsCount=this.bids.length();}
this.getPriceColor=function(){if(this.userWinning&&(this.userBid>=this.bidoPrice||this.userProxy>=this.bidoPrice||this.bidoPrice=='hidden')){return'#00AA00';}
if((this.userBid||this.userProxy)&&this.status!='not started'){return'#AA0000';}else{return'#000000';}}
this.update=function(eff){if(this.status=='closed'){return false;}
$('#userProxyHelp').show();var userProxyValue='US $'+formatBidPrice(this.userProxy,this.priceFormat);if(this.type==1){if(this.status=='opened'||this.status=='paused'||this.status=='extended'){if(this.price<this.userProxy){$('#userProxyTitle').html('Your max bid:');}else{$('#userProxyTitle').html('Your bid:');}}
if(this.userProxy<=0){userProxyValue='You have not bid yet';$('#userProxyHelp').hide();}}
$('#userProxy').html(userProxyValue);$('#startBid').html('US $'+formatBidPrice(this.startPrice,this.priceFormat));if(this.userBid>0){$('#userBid').html('US $'+formatBidPrice(this.userBid,this.priceFormat));}
var priceToCompare=(this.status=='not started'?this.userProxy:this.price);var needToCompare=(this.status=='not started'&&!(this.userProxy)?false:true);if(this.bidoPrice=='hidden'){$('#bidoPriceMet').html('Not met');}else if((this.bidoPrice>priceToCompare)&&needToCompare){$('#bidoPriceMet').html('US $'+formatBidPrice(this.bidoPrice)+' not met');}else if((this.bidoPrice<=priceToCompare)&&needToCompare){$('.bidoPrice').text('$'+formatBidPrice(this.bidoPrice));$('#bidoPriceMet').html(this.bidoPriceMetText.replace('{$bido_price}',formatBidPrice(this.bidoPrice)));}else{$('.bidoPrice').text('$'+formatBidPrice(this.bidoPrice));$('#bidoPriceMet').html('US $'+formatBidPrice(this.bidoPrice));}
this.nextBid=this.getNextBid();if($('#bidWindow').css('display')=='none'){$('#bid').attr('value',this.nextBid);}
if(this.price){var bin='';if(this.bids.length()>0&&this.bids.getLastNonRetracted().buy_it_now){bin=' (<span class="help-initiator" onmouseover="showHelpProcess(helpTexts.binBid, this);" onmouseout="cancelHelpShow();" onclick="showHelp(helpTexts.binBid, this);">bin</span>)';}
$('#currentBid').html('US $'+formatBidPrice(this.price,this.priceFormat));if($('#currentBid ~ span').attr('class')!='help-initiator'){$('#currentBid').after(bin);}
$('#currentBidAd').hide();}else{$('#currentBidAd').show();}
if(this.buyItNowPrice>0&&this.price>=Math.ceil(this.buyItNowPrice*app.config.binOfferPercent)){$('#buyNow').remove();var binWindowOpened=$('.main_auction_block .buyItNowWindow').css('display')!='none';$('.main_auction_block .buyItNowWindow').remove();if(binWindowOpened){$('#bidButtonContainer').show();}}
if(this.userId&&this.highBidderId==this.userId){if(!this.userWinning){this.userWinning=true;if(eff){playColor('high',5000,$('span.currentPrice'));}}}else{if(this.userWinning){this.userWinning=false;if(eff){playColor('out',5000,$('span.currentPrice'));if($('#sound_off')[0]&&$('#sound_off')[0].className=="sound-active"){playSound('outbid');}}}}
$('span.currentPrice').css('color',this.getPriceColor());var len=this.bids.length();if(len>0){$('#bidsCount').html('('+len+')');$('#bidHistoryLink').show();}
if(this.price>Math.ceil(this.buyItNowPrice*app.config.binOfferPercent)){$('#buyNow').hide();}
if(bidHistory.auction.id==this.id&&bidHistory.isVisible()){bidHistory.update();}
if(typeof(app.live_auctions[this.id])!='undefined'){app.live_auctions[this.id].userProxy=this.userProxy;app.live_auctions[this.id].update();}}
this.updateOffer=function(){var offerBid=getOfferPrice();if(this.nextBid>offerBid||this.userProxy>=offerBid||(this.status!='opened'&&this.status!='extended')){closeWindow('dynamicOfferWindow');return;}
$('#offer-price').html(offerBid);$('#acceptOfferButton').show();if(this.offerMode){setCountdownTimer('offer-timer',this.offerTimer);}else{this.offerMode=1;startCountdown('offer-timer',this.offerTimer,function(){this.offerTimer=0;this.offerMode=0;closeWindow('dynamicOfferWindow');},5);var wnd=$('#dynamicOfferWindow');$('body').append(wnd);displayWindow(wnd,250,0,true);}}
this.increasePriceInScale=function(price){var percent=this.defPercent;for(var i=0;i<this.scales.length;i++){if(price>=Number(this.scales[i].scale)){percent=Number(this.scales[i].percent);}else{break;}}
return Math.ceil(price+price*percent/100);}
this.getNextBid=function(){var nextBid=0;switch(this.type){case 1:if(this.status=='not started'){nextBid=Math.max(this.userProxy+1,this.startPrice);}else{if(this.price<this.startPrice){nextBid=this.startPrice;}else{if(this.highBidderId==this.userId&&this.bidoPrice!='hidden'&&this.price>=this.bidoPrice){nextBid=this.userProxy+1;}else{nextBid=this.increasePriceInScale(this.price);if(this.guaranteePrice>0&&this.price<=this.guaranteePrice&&nextBid>this.guaranteePrice){nextBid=this.guaranteePrice+1;}}}}
break;case 2:var currentTime=_timer.timer.time;nextBid=Math.ceil(currentTime*(this.lastPrice-this.minPrice)/this.lastTimer+this.minPrice);break;case 3:case 4:nextBid=Math.max(this.userProxy+1,2);break;}
return nextBid;}
this.pause=function(pause){if(pause){pauseCountdown('timer',true);$('#bidWindow').hide();$('#bidButtonContainer').hide();$('#pauseReason').html(this.pauseReason);$('#pauseWindow').show();}else{pauseCountdown('timer',false);$('#pauseWindow').hide();$('#bidButtonContainer').show();}}
this.recalculate=function(){this.price=0;this.userBid=0;this.highBidder='';this.highBidderId=0;this.userWinning=false;this.bids.forEach(function(item){if(!item.retracted){if(this.price<=item.amount){this.price=item.amount;this.highBidder=item.nick;this.highBidderId=item.user;}
if(this.userId==item.user){this.userBid=item.amount;}}},this);if(this.highBidderId==this.userId){var query={"auction":this.id,"info":2};sendMessage(JSJaCJSON.toString(query));}else{this.userProxy=this.userBid;}}
this.setRetracted=function(bids){this.bids.setRetracted(bids);this.recalculate();this.update();if(bidHistory.auction.id==this.id){bidHistory.clear();bidHistory.update();}}
this.checkStatus=callback(this,function(){if(_timer.timer&&_timer.timer.time<=0&&(this.status=='not started'||this.status=='opened'||this.status=='extended')){if(connected){getAuctionInfo();}}
window.setTimeout(this.checkTimer,15000);})
this.checkTimer=callback(this,function(){if(_timer.timer&&_timer.timer.time<=0&&this.status!='closed'&&this.status!='deleted'&&this.status!='frozen'){this.messageBody.css('color','red');this.messageBody.text('Please refresh your browser');}})
this.checkVideoTimer=callback(this,function(){switch(this.status){case'not started':if(this.videoStartTime!="now"){if(!_timer['video_start_timer']){startCountdown('video_start_timer',this.videoStartTime,this.checkVideoTimer);}else if(_timer['video_start_timer'].time<=0){$('#auction_video').show();}}else{$('#auction_video').show();}
break;case'opened':case'paused':case'extended':$('#auction_video').show();break;case'closed':if(!_timer['video_stop_timer']){if(this.videoEndTime!="never"){startCountdown('video_stop_timer',this.videoEndTime,this.checkVideoTimer);}
$('#auction_video').show();}else if(_timer['video_stop_timer'].time<=0){$('#auction_video').html(defaultVideoCode);}
break;case'deleted':$('#auction_video').html(defaultVideoCode);break;}})
this.needShowBidoPriceNotMetHelp=function(){return(this.bidoPrice=='hidden'||(this.bidoPrice>0&&this.bidoPrice>this.price))}}
function BidsCollection(auction){this.items=[];this.lines=[];this.auction=auction;this.add=function(item){if(!this.getLine(item.id)){for(var i in this.lines){if(this.lines[i].content.id=='BidoPriceNotMet'){this.lines.splice(i,1);break;}}
if(item.id=='BidoPriceMet'){this.lines.push({'type':'info','content':item});}else{var lastNonRetracted=this.getLastNonRetracted();if(lastNonRetracted&&lastNonRetracted.amount==item.amount&&!item.retracted){item.highest=true;lastNonRetracted.highest=false;}
if(item.buy_it_now){this.auction.binBidPlaced=true;}
item.nick=cutText(item.nick,35);this.items.push(item);this.lines.push({'type':'bid','content':item});}
if(this.auction.needShowBidoPriceNotMetHelp()){this.lines.push({'type':'info','content':{'id':'BidoPriceNotMet','text':helpTexts['bidoPriceNotMetRow']}});}
return true;}
return false;}
this.setRetracted=function(bids){for(var i=0;i<bids.length;i++){var bid=this.getItem(bids[i].id);if(bid){bid.retracted=true;if(bids[i].hold){bid.hold=true;}}}}
this.getItem=function(id){for(var i=0;i<this.length();i++){if(this.items[i].id==id){return this.items[i];}}
return false;}
this.getLine=function(id){for(var i=0;i<this.linesCount();i++){if(this.lines[i].content.id==id){return this.lines[i];}}
return false;}
this.getLastNonRetracted=function(){for(var i=this.length()-1;i>=0;i--){if(!this.items[i].retracted){return this.items[i];}}
return false;}
this.length=function(){return this.items.length;}
this.linesCount=function(){return this.lines.length;}
this.getBidsForPage=function(number,rowsPerPage){var bids=[];var pagesCount=Math.ceil(this.linesCount()/rowsPerPage);var rest=pagesCount*rowsPerPage-this.linesCount();var start=Math.max(rowsPerPage*(pagesCount-number)-rest,0);var end=rowsPerPage*(pagesCount-number+1)-rest;for(var i=start;i<end;i++){bids.push(this.lines[i]);}
return bids;}
this.getBids=function(number,rowsPerPage){var bids=[];for(var i=0;i<this.linesCount();i++){bids.push(this.lines[i]);}
return bids;}
this.forEach=function(handler,thisObj){for(var i in this.items){handler.call(thisObj,this.items[i]);}}}
function BidHistory(){this.auction={};this.body;this.table=[];this.page=1;this.rowsPerPage=10;this.emptyLabel;this.visible=false;this.auctionNameTruncate=36;this.init=function(){this.body=$('#bidHistory');$('body').append(this.body);this.emptyLabel=$('#bidHistoryEmptyLabel')[0];if(this.auctionNameTruncate&&this.auctionNameTruncate<this.auction.name.length){$('#bidHistoryAuctionName').text(this.auction.name.substring(0,this.auctionNameTruncate)+'...');}else{$('#bidHistoryAuctionName').text(this.auction.name);}
this.initTable();}
this.initTable=function(){this.addColumn('Name','',true,function(bid){return bid.nick;});this.addColumn('Date','style="white-space: nowrap; width: 125px;"',true,function(bid){return bid.time;});this.addColumn('Bid amount, US $','style="text-align: right; width: 125px;//padding-right: 20px"',true,function(bid,auction){var isBin='';var highest='';var retracted='';var isGuarantee='';var isAbsolute='';var originalAmount='';if(bid.is_proxy){highest='(<span class="help-initiator" onmouseover="showHelpProcess(helpTexts.proxyBid, this);" onmouseout="cancelHelpShow();" onclick="showHelp(helpTexts.proxyBid, this);">p</span>) ';}else if(bid.highest){highest='(<span class="help-initiator" onmouseover="showHelpProcess(helpTexts.sameBids, this);" onmouseout="cancelHelpShow();" onclick="showHelp(helpTexts.sameBids, this);">?</span>) ';}
if(bid.retracted||bid.retract_in_history){if(bid.hold){retracted='(<span class="help-initiator" onmouseover="showHelpProcess(helpTexts.retractedHoldBid, this);" onmouseout="cancelHelpShow();" onclick="showHelp(helpTexts.retractedHoldBid, this);">h</span>) ';}else{retracted='(<span class="help-initiator" onmouseover="showHelpProcess(helpTexts.retractedBid, this);" onmouseout="cancelHelpShow();" onclick="showHelp(helpTexts.retractedBid, this);">r</span>) ';}}
if(bid.buy_it_now){isBin=' (<span class="help-initiator" onmouseover="showHelpProcess(helpTexts.binBid, this);" onmouseout="cancelHelpShow();" onclick="showHelp(helpTexts.binBid, this);">bin</span>)';}
if(bid.guarantee){isGuarantee='(<span class="help-initiator" onmouseover="showHelpProcess(helpTexts.guaranteeBid, this);" onmouseout="cancelHelpShow();" onclick="showHelp(helpTexts.guaranteeBid, this);">g</span>) ';}
if(bid.absolute&&auction.isPublic){isAbsolute='(<span class="help-initiator" onmouseover="showHelpProcess(helpTexts.absoluteBid, this);" onmouseout="cancelHelpShow();" onclick="showHelp(helpTexts.absoluteBid, this);">a</span>) ';}
if(bid.overbid){originalAmount='<span style="text-decoration: line-through;">'+formatBidPrice(bid.amount)+'</span> ';var amount=bid.overbid;}else{var amount=bid.amount;}
return retracted+highest+isGuarantee+isAbsolute+originalAmount+formatBidPrice(amount)+isBin;});}
this.setAuction=function(auction){this.auction=auction;this.table=[];this.page=1;$('#bidHistoryHead th, #bidHistoryHead td').remove();}
this.toggleHeadColumn=function(column,visible){var display=visible?'table-cell':'none';if($.browser.msie&&visible){display='block';}
$(column).css('display',display);}
this.addColumn=function(name,attr,enabled,get){this.table.push({'name':name,'attr':attr,'enabled':enabled,'get':get});this.toggleHeadColumn($('<th '+attr+'>'+name+'</th>').appendTo(this.body.find('#bidHistoryHead')[0]),enabled);}
this.enableColumn=function(name,enabled){for(var i=0;i<this.table.length;i++){if(this.table[i].name==name){this.table[i].enabled=enabled;this.toggleHeadColumn(this.body.find('#bidHistoryHead th')[i],enabled);break;}}
this.clear();this.update();}
this.isVisible=function(){return this.visible;}
this.setVisible=function(visible){this.visible=visible;if(visible){this.body.css('display','');}else{this.body.css('display','none');}}
this.show=function(){this.update();this.center();this.body.draggable({handle:'.ui-drag-bar',cancel:'td'});this.body.bgiframe();this.setVisible(true);}
this.hide=function(){this.setVisible(false);}
this.center=function(){var pos=centerPos(this.body.width(),this.body.height());this.body.css('left',pos.x-100+'px');this.body.css('top',pos.y+'px');}
this.update=function(){try{var bids=this.auction.bids.getBids();if(bids.length==0){this.emptyLabel='<tr id="bidHistoryEmptyLabel"><td colspan="3">No bids.</td></tr>';this.body.find('.list').append(this.emptyLabel);return false;}
this.updateRows(bids);$('#bid_bottom_help').toggle(this.auction.needShowBidoPriceNotMetHelp());}catch(ex){}}
this.updatePager=function(){var bidsCount=this.auction.bids.length();if(bidsCount>this.rowsPerPage){var pager='<p class="pager">Page: ';var pagesCount=Math.ceil(bidsCount/this.rowsPerPage);var range=Math.ceil(this.page/10);if(range>1){var num=Number(this.page)-10;pager+='<a onclick="bidHistory.switchPage('+num+')" href="javascript:void(0);">Prev 10</a> ';}
for(var i=(range-1)*10+1;i<=Math.min(range*10,pagesCount);i++){if(i==this.page){pager+='<b>'+i+'</b> ';}else{pager+='<a onclick="bidHistory.switchPage('+i+')" href="javascript:void(0);">'+i+'</a> ';}}
if(range*10<pagesCount){var num=Math.min(Number(this.page)+10,pagesCount);pager+='<a onclick="bidHistory.switchPage('+num+')" href="javascript:void(0);">Next 10</a> ';}
pager+='</p>';var oldPager=this.body.find('.pager');if(oldPager.length==0){$(this.body.find('.list')).before(pager);}else{oldPager.replaceWith(pager);}}else{$('#bidHistory').find('.pager').hide();}}
this.updateRows=function(bids){if(this.emptyLabel){$(this.emptyLabel).remove();this.emptyLabel=null;}
$('#bid_BidoPriceNotMet').remove();var newRows=[];for(var i=0;i<bids.length;i++){if(!document.getElementById('bid_'+bids[i].content.id)){newRows.push(bids[i]);}}
for(var i=0;i<newRows.length;i++){if(newRows[i].type=='bid'){var newRow=this.getRow(newRows[i].content);}else{var newRow=this.getInfoRow(newRows[i].content);}
$(this.body.find('tr')[0]).after(newRow);}}
this.getRow=function(bid){var className='';if(bid.user==this.auction.userId){className=' class="past"';}
if(bid.retracted){className=' class="deleted"';}else if(bid.retract_in_history){className=' class="retract-in-history"';}
var row='<tr'+className+' id="bid_'+bid.id+'">';for(var i=0;i<this.table.length;i++){if(this.table[i].enabled){row+='<td '+this.table[i].attr+'>'+this.table[i].get(bid,this.auction)+'</td>';}}
return row+'</tr>';}
this.getInfoRow=function(info){var count=0;for(var i=0;i<this.table.length;i++){if(this.table[i].enabled){count++;}}
var row='<tr class="info" id="bid_'+info.id+'">';row+='<td colspan="'+count+'">'+info.text+'</td>';return row+'</tr>';}
this.switchPage=function(page){this.page=page;this.clear();this.update();}
this.clear=function(){var rows=this.body.find('tr');for(var i=1;i<rows.length;i++){if(rows[i]){$(rows[i]).remove();}}}}
function callback(obj,method){return function(){return method.apply(obj,arguments);}}
