var user={logined:function(){var cookie=readCookie();var same=0;for(var i=0;i<cookie.length;i++){var list=cookie[i].split('=');if((isSameStr(list[0].toLowerCase(), 'zxcheck')||isSameStr(list[0].toLowerCase(), 'zxuser'))&&list[1]){same++;}}return(same>=2);}};var cart={productForm:false,suitForm:false,amount:{'product':0, 'suit':0},buyID:false,suitID:false,show:{'product':false, 'suit':false},info:{'product':false, 'suit':false},logined:false,init:function(obj, suit){var po=obj||new Object();var so=suit||new Object();cart.logined=user.logined();cart.display();},display:function(){if(cart.show['product']){cart.show['product'].innerHTML=cart.amount['product'];}if(cart.show['suit']){cart.show['suit'].innerHTML=cart.amount['suit'];}},buyProduct:function(info, root, amount, attrib, field, id, tmp){var product=info||'';var tmp=tmp||0;var productAmount=amount||1;var presentAttrib=attrib||'';var field=field||'';var customID=id||'';var root=root||'';if(product){var list=product.split(',');if(tmp<=0){var fm=document.createElement('form');fm.target='_blank';fm.method='post';fm.action=root+'shop.php';document.body.appendChild(fm);var hd=document.createElement('input');fm.appendChild(hd);hd.name="order_buy[]";hd.style.display='none';hd.value=list[0].substr(24);fm.submit();}else{if(!field){cart.cookieProduct();var buy=cart.product();var index=0;while(buy[index]){index++;}field='p['+index+']';}bindCookie(field, encodeURI(product+','+productAmount+','+presentAttrib+','+customID));if(cart.show['product']){cart.cookieProduct();cart.display();if(confirm('购买商品成功，您是否要查看购物车？')){windowOpen(root+'shop.php', 'yes', 600, 800);}}}}else{if(cart.show['product']){cart.message('购买失败', '请先选择要购买的产品');}}},updateProduct:function(index, amount){var index=index||0;var amount=amount||1;var buy=cart.product();if(buy[index]){if(buy[index].product_modify){cart.amount['product']=cart.amount['product'] - buy[index].product_amount*buy[index].buy_amount+buy[index].product_amount*amount;bindCookie('p['+index+']', encodeURI(buy[index].serialize+','+amount));if(cart.show['product']){cart.cookieProduct();cart.display();cart.message('更新成功', '您购物车中的商品['+buy[index].product_name+']已经更新成功');}}else{if(cart.show['product']){cart.display();cart.message('更新失败', '您购物车中的商品['+buy[index].product_name+']不能被修改');}}}else{if(cart.show['product']){cart.display();cart.message('更新失败', '您购物车没有要更新的商品');}}return(true);},deleteProduct:function(index, root){var index=index||0;var root=root||'';var buy=cart.product();if(buy[index]){cart.amount['product']=cart.amount['product'] - buy[index].product_amount*buy[index].buy_amount;dropCookie('p['+index+']');}if(cart.show['product']){cart.cookieProduct();cart.display();cart.message('删除成功', '删除购物车中的商品成功');}if(cart.logined){window.location=root+'shop.php?a=delete&t=cart&id='+index;}return(true);},message:function(title, content){if(typeof(zxmessage)=='object'){zxmessage.alert(title, content, 300, 50);}else{alert(content);}},product:function(){if(!cart.info['product']){cart.cookieProduct();}return(cart.info['product']);},cookieProduct:function(){var cookie=readCookie();cart.info['product']=new Object();if(cookie){var info=new Array();for(var i=0;i<cookie.length;i++){info=cookie[i].split('=');if(isSameStr(info[0].substr(0, 2), 'p[')){var s=decodeURI(info[1]);if(s){var index=info[0].substr(2, info[0].length - 3);cart.info['product'][index]=cart.cookieProductRecord(s);}}}}return(true);},cookieProductRecord:function(s){var code=s.substr(0, 32);var list=s.substr(32).split(',');var len=list.length - 1;var serialize='';for(var i=0;i<len;i++){serialize+=','+list[i];}return({'serialize':code+serialize.substr(1), 'product_id':list[0], 'product_amount':list[1], 'product_money':list[2], 'product_present':list[4], 'product_modify':list[5], 'buy_amount':list[6]});},buySuit:function(info, root, total, field){var suit=info||'';var total=total||1;var field=field||'';var root=root||'';if(suit){var list=info.split(',');cart.amount['suit']+=list[2]*total;if(!field){var buy=cart.suit();var index=0;while(buy[index]){index++;}field='s['+index+']';}var ser=suit+','+total;bindCookie(field, encodeURI(ser));if(cart.show['suit']){cart.info['suit'][index]=cart.cookieSuitRecord(ser);cart.display();if(confirm('购买套装成功，您是否要查看购物车？')){window.location=root+'shop.php';}}}else{if(cart.show['suit']){cart.display();cart.message('购买失败', '请先选择要购买的套装');}}},updateSuit:function(index, amount){var index=index||0;var amount=amount||1;var buy=cart.suit();if(buy[index]){if(buy[index].product_suit_modify){cart.amount['suit']=cart.amount['suit'] - buy[index].product_suit_amount*buy[index].buy_amount+buy[index].product_suit_amount*amount;bindCookie('s['+index+']', encodeURI(buy[index].serialize+','+amount));if(cart.show['suit']){cart.cookieSuit();cart.display();cart.message('更新成功', '您购物车中的套装['+buy[index].product_suit_name+']已经更新成功');}}else{if(cart.show['suit']){cart.display();cart.message('更新失败', '您购物车中的套装['+buy[index].product_suit_name+']不能被修改');}}}else{if(cart.show['suit']){cart.display();cart.message('更新失败', '您购物车中没有要更新的套装');}}return(true);},deleteSuit:function(index, root){var index=index||0;var root=root||'';var buy=cart.suit();if(buy[index]){cart.amount['suit']=cart.amount['suit'] - buy[index].product_suit_amount*buy[index].buy_amount;dropCookie('s['+index+']');}if(cart.show['suit']){cart.cookieProduct();cart.display();cart.message('删除成功', '删除购物车中的套装成功');}if(cart.logined){window.location=root+'shop.php?a=delete&t=cart&id='+index;}return(true);},suit:function(){if(!cart.info['suit']){cart.cookieSuit();}return(cart.info['suit']);},cookieSuit:function(){var cookie=readCookie();cart.info['suit']=new Object();if(cookie){var info=new Array();for(var i=0;i<cookie.length;i++){info=cookie[i].split('=');if(isSameStr(info[0].substr(0, 2), 's[')){var s=decodeURI(info[1]);if(s){var index=info[0].substr(2, info[0].length - 3);cart.info['suit'][index]=cart.cookieSuitRecord(s);}}}}return(true);},cookieSuitRecord:function(s){var code=s.substr(0, 32);var list=s.substr(32).split(',');var len=list.length - 1;var serialize='';for(var i=0;i<len;i++){serialize+=','+list[i];}return({'serialize':code+serialize.substr(1), 'product_suit_id':list[0], 'product_suit_amount':list[2], 'product_suit_money':list[3], 'product_suit_modify':list[4], 'buy_amount':list[5]});},clear:function(root){var root=root||'';if(!cart.logined){var product=cart.product();var suit=cart.suit();for(var index in product){dropCookie('p['+index+']');}for(var index in suit){dropCookie('s['+index+']');}if(cart.show['suit']||cart.show['product']){cart.cookieProduct();cart.cookieSuit();cart.display();cart.message('清空成功', '清空购物车成功');}}else{window.location=root+'shop.php?a=clean';}}};var favorite={add:function(id, name, root){var productID=id||false;if(productID){var productName=name||'';var root=root||'';favorite.addFavorite(productID, root);}},addFavorite:function(id, root){zxajax.create('favorite', 2);zxajax.setAsynchronous('favorite', true);zxajax.setMethod('favorite', 'post');zxajax.setParameters('favorite', 'id='+id);zxajax.setHandle('favorite', 'favorite.linked');zxajax.getTransResult(root+'product.php?a=modify', 'favorite');},linked:function(){if(zxajax.isReady('favorite')){if(zxajax.isComplate('favorite')){favorite.complate(zxajax.response('favorite'));}else{message('收藏商品失败', zxajax.getResponse('favorite').status);}}},complate:function(response){message('收藏商品反馈', response);}};var compare={ui:false,handle:false,targetX:0,targetY:0,left:0,top:0,timeHD:false,init:function(ui, handle){this.ui=ui||false;this.handle=handle||false;if(this.ui){browser.scrollPosition();this.left=this.ui.offsetLeft;this.top=this.ui.offsetTop;}this.hide();},add:function(id, name, path){var productID=id||false;if(productID){var productName=name||'';var productPath=path||'';bindCookie('3['+productID+']', encodeURI(productName)+'&'+encodeURI(productPath));this.list();}},display:function(){if(this.ui){this.ui.style.display='block';}},hide:function(){if(this.ui){this.ui.style.display='none';}},drop:function(id){var productID=id||false;if(productID){dropCookie('3['+productID+']');this.list();}},list:function(){var cookie=readCookie();var list=new Array();if(cookie){var info=new Array();for(var i=0;i<cookie.length;i++){info=cookie[i].split('=');if(isSameStr(info[0].substr(0, 2), '3[')){if(info[1]){var child=info[1].split('&');child[0]=decodeURI(child[0]);child[1]=decodeURI(child[1]);child[2]=parseInt(info[0].substr(2, info[0].indexOf(']')- 2));list.push(child);}}}}if(this.handle){eval(this.handle+'(list)');}},move:function(e){var e=e||event;if(this.ui){this.targetX=this.left+browser.pageX;this.targetY=this.top+browser.pageY;this.ui.style.left=this.targetX+'px';this.ui.style.top=this.targetY+'px';}}};var login={user:'',session:'',check:'',init:function(){var cookie=readCookie();if(cookie){var info=new Array();var user='';for(var i=0;i<cookie.length;i++){info=cookie[i].split('=');if(isSameStr(info[0].substr(0, 6), 'zxuser')){this.user=info[1];}else if(isSameStr(info[0].substr(0, 7), 'zxcheck')){this.check=info[1];}else if(isSameStr(info[0].substr(0, 9).toLowerCase(), 'zxsession')){this.session=info[1];}}}return(true);},isLogin:function(){return(this.check&&this.user&&this.session);},name:function(){return(this.user);}};login.init();var hc={length:0,width:244,current:0,moveTime:0,addProduct:function(category, name, href, money, photo){var category=category||'';var name=name||'';var href=href||'';var money=money||'';var dl=document.createElement('dl');$('head_commend_product').appendChild(dl);var dt=document.createElement('dt');dl.appendChild(dt);var div=document.createElement('div');dt.appendChild(div);classChange(div, 'product_category');div.innerHTML='<a href="'+href+'">'+category+'</a>';var div=document.createElement('div');dt.appendChild(div);classChange(div, 'product_name');div.innerHTML='<a href="'+href+'">'+name+'</a>';var div=document.createElement('div');dt.appendChild(div);classChange(div, 'product_money');div.innerHTML='<a href="'+href+'">'+money+'</a>';var dd=document.createElement('dd');dl.appendChild(dd);dd.innerHTML='<img src="'+photo+'" border="0" height="50" width="50" />';hc.length++;},display:function(){var listWidth=hc.length>0?hc.length*hc.width:hc.width;$('head_commend_product').style.width=listWidth+'px';},prev:function(){var next=hc.current;if(hc.current>0){hc.current--;}hc.movePrev(next*hc.width);},movePrev:function(current){var current=current||0;var maxs=hc.current*hc.width;current -=10;if(current<=maxs){$('head_commend_product').style.left='-'+maxs+'px';window.clearTimeout(hc.moveTime);}else{$('head_commend_product').style.left='-'+current+'px';hc.moveTime=window.setTimeout('hc.movePrev('+current+')', 10);}},next:function(){prev=hc.current;if(hc.current<hc.length - 1){hc.current++;}hc.moveNext(prev*hc.width);},moveNext:function(start){var start=start||0;var maxs=hc.current*hc.width;start+=10;if(start>=maxs){$('head_commend_product').style.left='-'+maxs+'px';window.clearTimeout(hc.moveTime);}else{$('head_commend_product').style.left='-'+start+'px';hc.moveTime=window.setTimeout('hc.moveNext('+start+')', 10);}}};documentEvent.regEvent('compare.move', 'onscroll');var productVisited={product:new Array(),maxLength:6,add:function(id, name, photo){this.fetch();if(this.product.length>=this.maxLength){var i=this.product.length - 1;bindCookie('v['+i+']', id+','+encodeURI(name).replace(',', '&z|x&').replace(';', '&$&')+','+photo);i--;for(;i>=0;i--){k=i+1;bindCookie('v['+i+']', this.product[k][0]+','+encodeURI(this.product[k][1]).replace(',', '&z|x&').replace(';', '&$&')+','+this.product[k][2]);}}},fetch:function(){var cookie=readCookie();var list=new Array();if(cookie){for(var i=0;i<cookie.length;i++){info=cookie[i].split('=');if(isSameStr(info[0].substr(0, 2), 'v[')){if(info[1]){var record=info[1].split(',');record[1]=decodeURI(record[1]).replace('&z|x&', ',').replace('&$&', ';');this.product.push(record);}}}}return(this.product);}};