// 
// [function.js] Copyright (C) 2009-2010 DDM
//

var $GET_P_S_COUNT = 0;var $O_P_INTERVAL = ["","","","",""];var $P_GETING = [false,false,false,false,false];var $1O_P_INTERVAL = "";var $1P_GETING = false;var $TOTAL_SEND = 0;var $LOST_SEND = 0;var $BIDBTNIMG = "";function productstatus(ids,trytimes,prefix){if(!prefix)prefix = "";$O_P_INTERVAL[$GET_P_S_COUNT] = window.setInterval("__productstatus('"+ids+"',"+trytimes+",'"+prefix+"',"+$GET_P_S_COUNT+")",1000);$GET_P_S_COUNT++;}function product1status(id,trytimes){$1O_P_INTERVAL = window.setInterval("__product1status("+id+","+trytimes+")",1000);}function __productstatus(ids,trytimes,prefix,count){$TOTAL_SEND++;if($P_GETING[count])$LOST_SEND++;get_speed();if(ids=="" || $P_GETING[count])return;var id_list = ids;var o_setTimeout = 0;$P_GETING[count] = true;$.ajax({url:AJAXREQUESTPATH+"productstatus.php?id="+ids, type:"GET", success:function(result,textStatus){$P_GETING[count] = false;if(result){var len = result.length;id_list = "";for(var i=0; i<len; i++){if(result[i].bt>result[i].nt && $id(prefix+'time'+result[i].id).className!=""){$id(prefix+'time'+result[i].id).innerHTML = "竞拍未开始";$id(prefix+'time'+result[i].id).className = "";if($id(prefix+'bidbtn'+result[i].id)){$id(prefix+'bidbtn'+result[i].id).innerHTML = '<img src="'+TPL_PATH+'images/bid_disable.gif" width="87" height="28" border="0" />';}}else if(result[i].et>=result[i].nt){if(result[i].hr)robotbid(result[i].hr.product,result[i].hr.rid);var et_nt = result[i].et-result[i].nt;var price = format_currency(result[i].np+result[i].bp,2,true);$id(prefix+'time'+result[i].id).innerHTML = et_nt<=10 ? '<span class="red">'+time(et_nt)+'</span>' : time(et_nt);if($id(prefix+'price'+result[i].id).innerHTML.substr(1)!=price){$id(prefix+'price'+result[i].id).innerHTML = '￥'+price;$id(prefix+'bieter'+result[i].id).innerHTML = result[i].nu ? cutstr(result[i].nu,8) : "--";color_f2("#"+prefix+"price"+result[i].id,"red","white");}id_list += ","+result[i].id;}else{$id(prefix+'time'+result[i].id).innerHTML = "Ended";if($id(prefix+'bidbtn'+result[i].id)){$id(prefix+'bidbtn'+result[i].id).innerHTML = '<img src="'+TPL_PATH+'images/btn_bieten_be.gif" width="87" height="28" border="0" />';}}}if(id_list!="")id_list = id_list.substr(1);}else{trytimes++;}if(trytimes>5){window.clearInterval($O_P_INTERVAL[count]);}else if(ids!=id_list){window.clearInterval($O_P_INTERVAL[count]);$O_P_INTERVAL[count] = window.setInterval("__productstatus('"+id_list+"',"+trytimes+",'"+prefix+"',"+count+")",1000);}}, error:function(XMLHttpRequest,textStatus,errorThrown){$P_GETING[count] = false;$LOST_SEND++;trytimes++;window.clearInterval($O_P_INTERVAL[count]);if(trytimes<=5){$O_P_INTERVAL[count] = window.setInterval("__productstatus('"+id_list+"',"+trytimes+",'"+prefix+"',"+count+")",1000);}}, dataType:"json", async:true, timeout:10000});}function get_speed(){var percentage = $TOTAL_SEND - $LOST_SEND;percentage = Math.floor(percentage/$TOTAL_SEND*100);if($id("progressbar2num").innerHTML!=percentage+"%"){$id("progressbar").style.width = percentage+"%";$id("progressbar2num").innerHTML = percentage+"%";if(percentage<100 && $id("speedpercentage").style.display=="none"){$id("speedpercentage").style.display = "";}}}function bid(vars,element){vars.r_r = "1";if($BIDBTNIMG=="")$BIDBTNIMG = $id('bidbtn'+vars.id).getElementsByTagName('a')[0].innerHTML;if(BID_ID==vars.id)return;BID_ID = vars.id;$id('bidbtn'+vars.id).getElementsByTagName('a')[0].innerHTML = '<img src="'+TPL_PATH+'images/loading.gif" border="0" />';$.post(AJAXREQUESTPATH+"bidproduct.php", vars, function(result,textStatus){if(result){switch(result.status){case 0:show_tips('您需要登录后才能进行此操作 &nbsp; [<a href="'+START_PATH+'user/?ac=login">登录</a>] [<a href="'+START_PATH+'user/?ac=reg">注册</a>]',false,{highlight:true,dom:element?element:false});if($id('form_login'))color_f2($("#form_login").parent(),"red","white");break;case 3:robotbid(result.product, result.rid);break;case 5:show_tips('对不起，您没有足够的点竞拍该商品，请充值点数后再来出价<br /><a href="'+START_PATH+'user/?ac=buybid">现在去充值</a>',false,{highlight:true,dom:element?element:false});break;case 6:show_tips('对不起，您所在的会员组下不能参考该商品的竞拍',false,{highlight:true,autohide:true,dom:element?element:false});break;case 7:show_tips('对不起，本商品还没有开始竞拍',false,{highlight:true,autohide:true,dom:element?element:false});break;case 8:show_tips('对不起，您的注册账户还没有通过我们审核',false,{highlight:true,autohide:true,dom:element?element:false});break;case 9:BID_ID = 0;bid(vars,element?element:false);break;case 10:show_tips('您的注册账户已被管理员禁用，请联系客服',false,{highlight:true,autohide:true,dom:element?element:false});break;}}$id('bidbtn'+vars.id).getElementsByTagName('a')[0].innerHTML = $BIDBTNIMG;$BIDBTNIMG = "";BID_ID = 0;}, 'json');}function robotbid(product,rlist,rep){if(!rep)rep = 0;if(rep<5 && rlist.length){var now_price = product.np+product.bp;if(rlist[0].uid!=product.nuid && rlist[0].bidtimes>0 && now_price>=rlist[0].minprice && now_price<=rlist[0].maxprice){$.post(AJAXREQUESTPATH+"bidproduct.php", {'id':product.id,'rid':rlist[0].id,'uid':rlist[0].uid,'ac':'robot','r_r':(rlist.length==1?'1':'0'),'robotkey':rlist[0].robotkey}, function(result,textStatus){if(result && result.status==3){robotbid(result.product, result.rid);}else{if(typeof(parseInt(result.status))=="number" && result.status!=9){rep = 0;rlist.shift();}else{rep++;}robotbid(product,rlist,rep);}}, 'json');}else{if(rlist.length==1){$.post(AJAXREQUESTPATH+"robot.php", {'pid':product.id,'ab':'1','ac':'get'}, function(result,textStatus){if(result)robotbid(product,result,++rep);}, 'json');}else{rlist.shift();robotbid(product,rlist,rep);}}}}function time(second){var return_value = "00:00:00";if(second>0){var hours = Math.floor(second/3600);var minutes = Math.floor(second%3600/60);var seconds = second%3600%60;hours<10 && (hours = "0"+hours);minutes<10 && (minutes = "0"+minutes);seconds<10 && (seconds = "0"+seconds);return_value = hours+":"+minutes+":"+seconds;}return return_value;}function format_currency(expression,precision,ILD){var return_value = round(expression,precision)+"";var num_arr = return_value.split(".");var temp = "";if(!num_arr[1])num_arr[1] = "";var n=num_arr[0].length-3;for(var n=num_arr[0].length-3; n>=0; n-=3){temp = ","+num_arr[0].substr(n,3)+temp;}if(n==-3 && temp!="")temp = temp.substr(1);num_arr[0] = num_arr[0].substring(0,n+3)+temp;if(ILD){for(var i=num_arr[1].length; i<precision; i++)num_arr[1] += "0";return_value = num_arr[0]+"."+num_arr[1];}return num_arr[1]=="" ? num_arr[0] : num_arr[0]+"."+num_arr[1];}function color_f2(dom,from,to){$(dom).css("backgroundColor",from);$(dom).animate({"backgroundColor":to},900);}function show_tips(msg,title,options){if(!title)title = "系统提示";if(!options)options = {};$id('msg_window').style.width = options.width ? options.width : '320px';if(options.height)$id('msg_window').style.height = options.height;$("#msg_window").html('<div class="box2" style="margin-bottom:0px;"><div class="subject" id="msg_window_title"><div class="left"><div class="label_nobg">'+title+'</div></div><div class="right">&nbsp;</div></div><div class="body"><div class="content"><div id="msgtext" style="padding:10px; line-height:130%; font-size:12px; color:#333; background-color:#FFF;">'+msg+'</div></div></div><div class="bot"><div class="right"></div><div class="left"></div></div></div>');if(options.dom){var _x = moveXbySlicePos(0,options.dom);var _y = moveYbySlicePos(element_height(options.dom,2),options.dom);if(_x+$("#msg_window").width()>$("body").width()){$id('msg_window').style.left = "auto";$id('msg_window').style.right = "0px";}else{$id('msg_window').style.right = "auto";$id('msg_window').style.left = _x+"px";}if(_y+$("#msg_window").height()>document.documentElement.clientHeight+(document.documentElement.scrollTop || document.body.scrollTop)){$id('msg_window').style.top = "auto";$id('msg_window').style.bottom = "0px";}else{$id('msg_window').style.bottom = "auto";$id('msg_window').style.top = _y+"px";}}else{$id('msg_window').style.right = "auto";$id('msg_window').style.bottom = "auto";$id('msg_window').style.top = ((document.documentElement.clientHeight-$("#msg_window").height())/2+(document.documentElement.scrollTop || document.body.scrollTop))+"px";$id('msg_window').style.left = ((document.documentElement.clientWidth-$("#msg_window").width())/2)+"px";}if(options.bgiframe){$("#msg_window_bgiframe").show();$("#msg_window_bgiframe").css({width:$('body').width(),height:$('body').height()});$("#msg_window_bgiframe").bgiframe();}$("#msg_window").fadeIn("slow",function(){$("#msg_window").bgiframe();if(options.highlight)color_f2("#msgtext","red","white");});if(options.btns){var msg_buttons = $id('msg_buttons');if(msg_buttons){try{msg_buttons.removeNode(true);}catch(e){msg_buttons.parentNode.removeChild(msg_buttons);}}msg_buttons = document.createElement('div');msg_buttons.id = "msg_buttons";msg_buttons.className = "buttons";$id('msgtext').appendChild(msg_buttons);for(var btnlen=0; btnlen<options.btns.length; btnlen++){var _button = document.createElement('input');_button.className = "msgbtn";_button.type = "button";_button.name = "msgbtn__"+btnlen;for(var key in options.btns[btnlen]){_button.onclick = options.btns[btnlen][key];_button.value = key;break;}msg_buttons.appendChild(_button);_button.focus();}$id("msg_window").onclick = null;if(window.__o_timeout){window.clearTimeout(window.__o_timeout);window.__o_timeout = null;}}else{if($id('msg_buttons')){try{$id('msg_buttons').removeNode(true);}catch(e){$id('msg_buttons').parentNode.removeChild($id('msg_buttons'));}}if(options.autohide){if(window.__o_timeout){window.clearTimeout(window.__o_timeout);}window.__o_timeout = window.setTimeout("if("+(options.bgiframe?'1':'0')+"){$('#msg_window').hide();$('#msg_window_bgiframe').hide();"+(typeof(options.onclose)=='function'?"("+options.onclose.toString()+")();":"")+"}else{$('#msg_window').slideUp('normal'"+(typeof(options.onclose)=='function'?","+options.onclose.toString():"")+");}",3000);}else{if(window.__o_timeout){window.clearTimeout(window.__o_timeout);window.__o_timeout = null;}}$id("msg_window").onclick = function(){if(window.__o_timeout){window.clearTimeout(window.__o_timeout);window.__o_timeout = null;}if(options.bgiframe){$("#msg_window").hide();$("#msg_window_bgiframe").hide();if(typeof(options.onclose)=="function"){options.onclose("msg_window");}}else{$("#msg_window").slideUp("normal",function(){if(typeof(options.onclose)=="function")options.onclose("msg_window");});}};}if(options.drag){$("#msg_window").draggable({cancel:"div.body"});$("#msg_window_title").css('cursor','move');}else{try{$("#msg_window").draggable('destroy');}catch(e){}}}