var AuctionManager=Class.create();AuctionManager.prototype={LOCAL_CYCLE:1000,REMOTE_CYCLE:1500,localTimeout:0,remoteTimeout:0,time:0,auctions:{},ids:[],ut:null,initialize:function(A){this._setOpt(A);var F=A.auctions;if(F!=null){var C;var D=[1,3,3];for(var B=0;B<F.length;B++){if(B>D[1]){C=2}else{if(B>=D[0]){C=1}else{C=0}}F[B].parent=$(A.containers[C]);F[B].manager=this;F[B].i18n=this.i18n;F[B].containerIndex=C;F[B].img_dir=A.img_dir+(B?"prod_img_thumb/":"prod_img_thumb_front/");if(this.detail){F[B].img_dir=A.img_dir}this.ids.push(F[B]["id"]);this.auctions[F[B]["id"]]=new Auction(F[B])}}this.setTimeRemote(A.currentTime);var E=new Date();E.setTime(A.currentTime);setTimeout(this.remoteCycle.bind(this),this.REMOTE_CYCLE);if(F!=null){this.setData(A.auctiondata);this.addToDisplayList()}},_setOpt:function(B){var A=$w("dataurl indexurl logged_in userid username i18n detail smsnumber url_pfx cache_id");A.each(function(C){this.manager[C]=this.opt[C]}.bind({opt:B,manager:this}))},remoteCycle:function(){var G="ids="+(this.ids.join(","))+"&cache_id="+this.cache_id;if(this.logged_in&&parseInt(this.userid)){G+="&u_id="+this.userid}if(this.ut==null||(new Date()).getTime()>this.ut){var C=$("loginbar").down(".num_credit");var A="0";if(C){A=C.innerHTML}G+="&ic="+A;if(this.ut==null){var D=new Date();var B=D.getTime();var F=B%60000;var E=Math.floor(B/300000)*300000;this.ut=E+F}this.ut+=300000}this.remotestartdate=new Date();if(this.detail){G+="&detail=1"}new Ajax.Request(this.dataurl,{method:"get",parameters:G,onFailure:this.remoteCycleFailure.bind(this),onSuccess:this.remoteCycleSuccess.bind(this)})},remoteCycleSuccess:function(D){this.remoteTimeout=setTimeout(this.remoteCycle.bind(this),this.REMOTE_CYCLE);var G=D.responseText.evalJSON();var B=parseInt(G.t);var A=new Date();var C=0;if(this.remotestartdate){C=A.getTime()-this.remotestartdate.getTime()}if(G.c){var E=$("loginbar").down(".num_credit");if(E){var F=E.innerHTML;if(F!=G.c){Element.setText(E,G.c);new Effect.Pulsate(E,{queue:{position:"end",scope:"creditq",limit:1}})}}}this.setTimeRemote(B);if(G.cache_id){this.cache_id=G.cache_id;this.setData(G.auctiondata)}},remoteCycleFailure:function(A){this.remoteTimeout=setTimeout(this.remoteCycle.bind(this),this.REMOTE_CYCLE)},setTimeRemote:function(C){var B=new Date();B.setTime(C);this.time=B;var A=C%1000;this.updateAuctionTime();this.resetLocalCycle(1000-A);this.updateTimeContainer()},updateTimeContainer:function(){Element.setText($("time"),d2(this.time.getHours())+":"+d2(this.time.getMinutes())+":"+d2(this.time.getSeconds()))},resetLocalCycle:function(A){clearTimeout(this.localTimeout);this.localTimeout=setTimeout(this.localSuccess.bind(this),A)},resetRemoteCycle:function(){clearTimeout(this.remoteTimeout);this.remoteCycle()},localSuccess:function(){this.time.setTime(this.time.getTime()+this.LOCAL_CYCLE);this.updateAuctionTime();this.localTimeout=setTimeout(this.localSuccess.bind(this),this.LOCAL_CYCLE);this.updateTimeContainer()},updateAuctionTime:function(){var B=this.time.getTime();for(var A in this.auctions){this.auctions[A].setTime(B)}},addToDisplayList:function(){for(var A in this.auctions){Element.insert(this.auctions[A].dparent.lastChild,{before:this.auctions[A].el})}},setData:function(B){for(var A=0;A<B.length;A++){if(this.auctions[B[A].jd.prod_id]){this.auctions[B[A].jd.prod_id].setData(B[A])}}}};var Auction=Class.create();Auction.prototype={PENDING:2,ACTIVE:3,HALTED:4,CLOSED:5,CHECKING:10,TYPE_LIMITED:1,TYPE_24:2,initialize:function(H){Object.extend(this,H);this.detail=this.manager.detail&&!this.itemindex;this.imgs=H.prod_img.split(";");this.time_to_end=parseInt(H.bid_interval);this.bid_interval=parseInt(H.bid_interval);this.dclock=$span(this.sec2time(this.time_to_end));this.dclockcont=$div({"class":"clockcont"},[$span({"class":"clock"},this.dclock),$span({"class":"label"},this.i18n.time_to_end)]);this.dstartclock=$span({"class":"clock"});this.dstartclockcont=$div({"class":"clockcont"},[this.dstartclock,$span({"class":"label"},this.i18n.time_to_start)]);if(!this.containerIndex){this.dclockcont=$div({"class":"clockcont"},[$span({"class":"label"},this.i18n.time_to_end),$span({"class":"clock"},this.dclock)]);this.dstartclockcont=$div({"class":"clockcont"},[$span({"class":"label"},this.i18n.time_to_start),this.dstartclock])}this.dprice=$span({"class":"price"});this.dprice2=$span({"class":"price2"});this.iautobid=$img({src:APP_URL+"site/tmpl/img/icon_autobid.png",border:1,width:10,height:10});Element.hide(this.iautobid);this.dlastbidder=$span({"class":"lastbidder"});this.dlastbiddercont=$div({"class":"lastbiddercont"},this.i18n.best_bidder+": ",this.dlastbidder," ",this.iautobid);var G=$a({href:"javascript:;"},this.i18n.make_bid);Element.observe(G,"click",this.makebid.bind(this));var F=$a({href:"javascript:;"},this.i18n.more_info);Element.observe(F,"click",this.moreinfo.bind(this));this.dmoreinfo=$div({"class":"moreinfo"},F);this.dactive=$div({"class":"active"},[G]);this.dpending=$div({"class":"pending"},this.i18n.open_soon);this.dchecking=$div({"class":"pending"},this.i18n.checking_data);this.dhalted=$div({"class":"pending"},this.i18n.auction_halted);this.dstopped=$div({"class":"stopped"},this.i18n.congrads);this.dleading=$div({"class":"stopped"},this.i18n.you_lead);Element.hide(this.dactive);Element.hide(this.dpending);Element.hide(this.dchecking);Element.hide(this.dhalted);Element.hide(this.dstopped);Element.hide(this.dleading);this.d24=$div({"class":"d24"});if(this.type==this.TYPE_LIMITED){Element.hide(this.d24)}this.dabicon=$div({"class":"dabicon"});if(this.is_autobid!=1){Element.hide(this.dabicon)}this.dcashback=$div({"class":"dcashback"});if(this.cashback!=1){Element.hide(this.dcashback)}this.dcashbackinfo=$div({"class":"dcashbackinfo"},this.cashbackinfo?this.cashbackinfo:"");if(!this.cashbackinfo){Element.hide(this.dcashbackinfo)}this.ddescr=$div({"class":"ddescr"});this.ddescr.innerHTML=this.descr;this.dimg=$div({"class":"img"});if(this.imgs[0]&&this.imgs[0].length){if(!this.manager.detail){var B=$img({src:this.img_dir+this.imgs[0]});this.dimg.appendChild(B);Event.observe(this.dimg,"click",this.moreinfo.bind(this))}else{if(this.manager.detail){for(var D=0;D<this.imgs.length;D++){var B=$div($table({height:"100%",width:"100%"},$tbody($tr($td($img({src:this.img_dir+"prod_img_thumb_detail/"+this.imgs[D]}))))));var A={index:D,auction:this};this.dimg.appendChild(B);Event.observe(B,"click",function(){myLightWindow.activateWindow({href:this.auction.img_dir+"prod_img_large/"+this.auction.imgs[this.index],type:"image",title:this.auction.name})}.bind(A))}}}}this.dopen_date=$span();this.dopen_time=$span();this.dto_be_opened=$div({"class":"to_be_opened"},this.i18n.to_be_opened,$br(),this.dopen_date," ",this.i18n.at," ",this.dopen_time);this.dsmsinstr=$div({"class":"smsinstr"},$div({"class":"title"},this.i18n.smstitle),this.i18n.smsdescr2," ",$span(H.smscode),this.containerIndex?$br():" ",this.i18n.to_number," ",$span(this.manager.smsnumber),$br(),this.i18n.smsprice);this.dummylink=$a({href:"javascript:;"},"dummylink");Element.observe(this.dummylink,"click",this.dummylinkClick.bind(this));this.dname=$div({"class":"name"},H.name);Event.observe(this.dname,"click",this.moreinfo.bind(this));this.dbidders=$div();this.dbidderscont=$div({"class":"bidderscont"},$div({"class":"label"},this.i18n.last_bids),this.dbidders);Element.hide(this.dbidderscont);this.dlinkslist=$div({"class":"dlinkslist"});if(this.linkslist&&this.linkslist.length&&this.linkslist[0].name!=""){for(var C=0;C<this.linkslist.length;C++){var G=$a({href:this.linkslist[C].url,target:"_blank"},this.linkslist[C].name);this.dlinkslist.appendChild(G)}}else{Element.hide(this.dlinkslist)}this.ab=$div();if(this.detail&&this.manager.logged_in&&$("autobid_cont")){this.ab.innerHTML=$("autobid_cont").innerHTML;$("autobid_cont").innerHTML=""}var E;if(!this.containerIndex){if(this.manager.detail){var E=$div({"class":"itemc"},$div({"class":"itemc2"},$div({"class":"item detailitem"},$table($tbody($tr($td({valign:"top","class":"leftpane"},$div(this.dimg)),$td({"class":"rightpane",valign:"top"},[this.dname,this.dabicon,this.d24,this.dcashback,$div({"class":"price_store"},this.i18n.price_store+": "+parseFloat(H.price_store).toFixed(0)+" "+this.i18n.currency),this.dcashbackinfo,this.ab,this.dactive,this.dpending,this.dchecking,this.dhalted,this.dstopped,this.dleading,this.dclockcont,this.dstartclockcont,$div({"class":"pricecont"},this.dprice,this.dprice2," ",$span({"class":"currency"},this.i18n.currency),$span({"class":"label"},this.i18n.price)),this.dlastbiddercont,this.dsmsinstr,this.dto_be_opened,this.ddescr,this.dlinkslist,this.dbidderscont]))))),$div({"class":"clear"})))}else{var E=$div({"class":"itemc"},$div({"class":"itemc2"},$div({"class":"item"},$table($tbody($tr($td({valign:"top","class":"leftpane"},$div(this.dimg)),$td({"class":"rightpane"},[this.dname,this.dabicon,this.d24,this.dcashback,$div({"class":"price_store"},this.i18n.price_store+": "+parseFloat(H.price_store).toFixed(0)+" "+this.i18n.currency),this.dactive,this.dpending,this.dchecking,this.dhalted,this.dstopped,this.dleading,this.dclockcont,this.dstartclockcont,$div({"class":"pricecont"},$span({"class":"label"},this.i18n.price),this.dprice,this.dprice2," ",$span({"class":"currency"},this.i18n.currency)),this.dlastbiddercont,this.dsmsinstr,this.dto_be_opened]))))),$div({"class":"clear"})))}}else{var E=$div({"class":"itemc"},$div({"class":"itemc2"},$div({"class":"item"},this.dname,this.dimg,$div({"class":"price_clock"},this.dclockcont,this.dstartclockcont,$div({"class":"pricecont"},$div({"class":"priceval"},this.dprice,this.dprice2),$div({"class":"label"},this.i18n.price,", ",this.i18n.currency))),this.dlastbiddercont,this.dactive,this.dpending,this.dchecking,this.dhalted,this.dstopped,this.dleading,this.d24,this.dcashback,this.dabicon,this.dsmsinstr,this.dto_be_opened),$div({"class":"clear"})))}this.el=E;this.id=H.id;this.dparent=H.parent},baseElement:function(A){switch(A){case"detail":return false;case"front_big":return false;case"front_small":return false}},moreinfo:function(){var A=this.manager.url_pfx+"/"+this.id;window.location=A},dummylinkClick:function(){},sec2time:function(C){var A=[];var B=C%60;A.unshift(d2(B));C-=B;B=C%(60*60);A.unshift(d2(B/60));C-=B;if(C!=0){B=C%(60*60*24);A.unshift(d2(B/(60*60)));C-=B;if(C!=0){B=C%(60*60*24*365);A.unshift(d2(B/(60*60*24)));C-=B}}return A.join(":")},setData:function(A){if(A.dt){this.dt=A.dt;if(this.dbidders){this.dbidders.innerHTML='<table class="dbidders" cellspacing=0>'+this.dt+"</table>"}Element.show(this.dbidderscont)}A=A.jd;this.status=A.status;this.to_open=null;if(A.to_open){this.to_open=A.to_open;var G=new Date();G.setTime(this.to_open*1000);Element.setText(this.dopen_date,d2(G.getDate())+"."+d2(G.getMonth()+1)+"."+d2(G.getFullYear()));Element.setText(this.dopen_time,d2(G.getHours())+":"+d2(G.getMinutes()))}this.to_close=null;if(A.to_close){this.to_close=A.to_close}var D=this.lbp;var E=this.lbn;this.autobid=parseInt(A.autobid);if(this.autobid){Element.show(this.iautobid)}else{Element.hide(this.iautobid)}this.lbt=A.lbt;this.lbn=A.lbn==null?"":A.lbn;this.lbp=A.lbp==null?0:parseFloat(A.lbp);if(!this.lbn.length){Element.hide(this.dlastbiddercont)}else{Element.show(this.dlastbiddercont)}Element.setText(this.dlastbidder,this.lbn);if(this.lbn==this.manager.username&&this.autobid&&this.detail){var I=$("autobid_credit");if(I){var C=parseInt(I.innerHTML);var B=C-1;I.innerHTML=B}}if(this.notfirstrun){if(this.lbn!=E){new Effect.Highlight(this.dlastbiddercont,{queue:{position:"end",scope:"lastbidderq",limit:1}})}if(this.lbp!=D){new Effect.Highlight(this.dprice,{queue:{position:"end",scope:"priceq",limit:1}})}}var H=(Math.floor(this.lbp*100))/100;Element.setText(this.dprice,d2(H.toFixed(2)).replace(".",","));var F=(this.lbp*1000).toString();F=F.substring(F.length-1);Element.setText(this.dprice2,F);this.notfirstrun=1;this.setTime(this.manager.time.getTime())},render:function(){if(this.status==this.PENDING){this.showButton(this.dpending);if(this.to_open){Element.show(this.dstartclockcont);Element.hide(this.dclockcont);Element.show(this.dto_be_opened);Element.setText(this.dstartclock,this.sec2time(this.time_to_open));Element.addClassName(this.d24,"d24_active");Element.addClassName(this.dabicon,"dabicon_active");Element.addClassName(this.dcashback,"dcashback_active");Element.show(this.dsmsinstr);Element.removeClassName(this.dprice,"lightgray");Element.removeClassName(this.dprice2,"lightgray");if(this.manager.logged_in&&this.manager.username==this.lbn){this.showButton(this.dleading)}else{this.showButton(this.dactive)}if(this.time_to_end<=15){this.dclock.className="ultrared"}else{if(this.time_to_end<=30){this.dclock.className="red"}else{if(this.time_to_end<=60){this.dclock.className="orange"}else{this.dclock.className="blue"}}}Element.setText(this.dclock,this.sec2time(this.time_to_end))}else{Element.hide(this.dstartclockcont);Element.show(this.dclockcont);Element.hide(this.dto_be_opened);Element.removeClassName(this.d24,"d24_active");Element.removeClassName(this.dabicon,"dabicon_active");Element.removeClassName(this.dcashback,"dcashback_active");Element.hide(this.dsmsinstr);this.dclock.className="";Element.addClassName(this.dprice,"lightgray");Element.addClassName(this.dprice2,"lightgray")}}else{Element.hide(this.dstartclockcont);Element.show(this.dclockcont);Element.hide(this.dto_be_opened)}if(this.status==this.HALTED){this.showButton(this.dhalted);if(this.to_open){Element.show(this.dstartclockcont);Element.hide(this.dclockcont);Element.show(this.dto_be_opened);Element.setText(this.dstartclock,this.sec2time(this.time_to_open))}else{Element.hide(this.dstartclockcont);Element.show(this.dclockcont);Element.hide(this.dto_be_opened)}}else{}if(this.status==this.CHECKING){this.showButton(this.dchecking)}else{}if(this.status==this.ACTIVE){Element.addClassName(this.d24,"d24_active");Element.addClassName(this.dabicon,"dabicon_active");Element.addClassName(this.dcashback,"dcashback_active");Element.show(this.dsmsinstr);Element.removeClassName(this.dprice,"lightgray");Element.removeClassName(this.dprice2,"lightgray");if(this.manager.logged_in&&this.manager.username==this.lbn){this.showButton(this.dleading)}else{this.showButton(this.dactive)}if(this.time_to_end<=15){this.dclock.className="ultrared"}else{if(this.time_to_end<=30){this.dclock.className="red"}else{if(this.time_to_end<=60){this.dclock.className="orange"}else{this.dclock.className="blue"}}}Element.setText(this.dclock,this.sec2time(this.time_to_end))}else{Element.removeClassName(this.d24,"d24_active");Element.removeClassName(this.dabicon,"dabicon_active");Element.removeClassName(this.dcashback,"dcashback_active");Element.hide(this.dsmsinstr);this.dclock.className="";Element.addClassName(this.dprice,"lightgray");Element.addClassName(this.dprice2,"lightgray")}if(this.status==this.CLOSED){this.showButton(this.dstopped);Element.setText(this.dclock,this.sec2time(0));Element.hide(this.ab)}else{Element.show(this.ab)}},showButton:function(B){var A=[this.dactive,this.dpending,this.dchecking,this.dhalted,this.dstopped,this.dleading];for(var C=0;C<A.length;C++){if(A[C]==B){Element.show(A[C])}else{Element.hide(A[C])}}},setTime:function(A){if(this.status==this.PENDING||this.status==this.HALTED){if(this.to_open){this.time_to_open=Math.floor((this.to_open*1000-A)/1000)+1;if(this.time_to_open<=0){this.status=this.ACTIVE;this.lbt=this.time_to_open}}}if(this.status==this.ACTIVE){if(this.lbt>0){var B=this.lbt+this.bid_interval;B*=1000;B-=A;B/=1000;this.time_to_end=Math.floor(B)+1}if(this.time_to_end<0){this.status=this.CHECKING}}if(this.status==this.CHECKING){if(this.lbt>0){var B=this.lbt+this.bid_interval;B*=1000;B-=A;B/=1000;this.time_to_end=Math.floor(B)+1}if(this.time_to_end>0){this.status=this.ACTIVE}}this.render()},makebid:function(){if(!this.manager.logged_in){myLightWindow.activateWindow({href:"#bid_no_login_container",type:"inline",width:430,height:340,title:""});Element.hide("credit_descr");var A=Element.down("bid_descr",".prodname");Element.setText(A,this.name);var B=Element.down("bid_no_login",".smscode");Element.setText(B,this.smscode);return }new Ajax.Request(this.manager.indexurl,{parameters:{tmpl:"mod_makebid",prod_id:this.id,t:this.manager.time.getTime(),l:this.time_to_end},onSuccess:this.makebidResponse.bind(this)})},makebidResponse:function(A){var B=A.responseText.evalJSON();if(B.code=="400"){alert(B.msg)}else{if(B.code=="401"){myLightWindow.activateWindow({href:"#bid_no_credit_container",type:"inline",width:550,height:510,title:""});Element.hide("just_buy")}else{this.manager.resetRemoteCycle()}}}};function d2(A){return(A<10)?"0"+A:A}function buy_credit(){if(!this.manager.logged_in){myLightWindow.activateWindow({href:"#bid_no_login_container",type:"inline",width:430,height:340,title:""});Element.hide("bid_descr");Element.remove("login_no_bid")}else{myLightWindow.activateWindow({href:"#bid_no_credit_container",type:"inline",width:550,height:380,title:""});Element.hide("buy_for_bid");Element.hide("buy_for_bid2")}}function onEnter(B,A){B=B||window.event;if(B.keyCode==13){A()}}function start_autobid(){var C=document.autobid_form;var B=parseFloat(C.sum_start.value);var D=parseFloat(C.sum_end.value);var A=parseInt(C.num_bids.value);if(!B||!D||!A){alert(manager.i18n.all_fields_required);return }C.submit()}Element.extendBuilderWithTagsnames("div a span br img table tr td tbody");