﻿var no =1,$=function(id){return document.getElementById(id)},proPsss={},proshow={},proPsssPre={},proshowPre={},proshowMap={},proPsssMap={};
var path ="http://img.vaakav.com";
function updateProduct(cid,id,cid){
	if(!cid&&cid!=0){
		var	num=document.getElementById("td_"+id).value;
		if(num&&!/^\d+$/.test(num)){
			alert("购买数量必须为数字！");
			location.href="/my_cart.dhtml";
			return;
		}else{
			location.href="/update_cartItem.dhtml?updateIndex="+id+"&quantity="+num;
		}
	}else{
		var	num=document.getElementById("td_"+id+"_"+cid).value;
		if(num&&!/^\d+$/.test(num)){
			alert("购买数量必须为数字！");
			location.href="/my_cart.dhtml";
			return;
		}else{
			location.href="/update_cartItem.dhtml?updateIndex="+id+"&quantity="+num+"&attCommIndex="+cid;
		}
	}
	
}

var timers;
function deleteProductNum(t,id,cid){
	var numNode=(cid||cid==0)?document.getElementById("td_"+id+"_"+cid):document.getElementById("td_"+id),num = numNode.value;
		if(num>1){
			num--;
			numNode.value=num;
			clearTimeout(timers);
			timers = setTimeout(function(){
			 updateProduct('',id,cid);
			},1000)
		}
}
function addProductNum(t,id,cid){
	var numNode=(cid||cid==0)?document.getElementById("td_"+id+"_"+cid):document.getElementById("td_"+id),num = numNode.value;
			num++;
			numNode.value=num;
			clearTimeout(timers);
			timers = setTimeout(function(){
			 updateProduct('',id,cid);
			},1000)
}

function deleteProduct(id,cid){
	if(confirm("是否删除该商品？")){
		if(cid||cid==0){
			location.href="/delete_cartItem.dhtml?removeIndex="+id+"&attCommIndex="+cid;
		}else{
			location.href="/delete_cartItem.dhtml?removeIndex="+id;
		}
	}
}
function laypack(divid,name){
		//Lay.show({
		//	width:0.5,
		//	height:0.5,
		//	title:name,
		//	id:divid
		//})
}
var timer;
function layPackDiv(divid,name){
	var n = document.getElementById(divid).innerHTML;
	toolTip(n)
	//clearTimeout(timer);
	//timer = setTimeout(function(){
	//	laypack(divid,name);
	//},1000)
}
function disappearDiv(){
	//clearTimeout(timer);
	toolTip();
}

(function drow(){
	var drowprotr = function(pro,i,cid){
		var pros="";
		
		pros+='<tr>';
			  pros+='<td align="center">'+(no++)+'</td>';
        	  if('pck'==pro.sourceCat){
        	  	pros+='<td align="center"><div style="position:relative;cursor :pointer ;width:46px; height:46px; text-align: center" onclick=window.open("/pack_detail-'+pro.source+'.dhtml"); ><img src="'+path+pro.image+'" width="46" height="46" onload="util.drawImage(this, 46, 46)" alt="'+pro.name+'" title="'+pro.name+'"/></div></td>';
        	  	pros+='<td align="left" onmouseout="disappearDiv();"  onmouseover=layPackDiv(&quot;lay'+pro.source+i+'&quot;,&quot;'+pro.name+'&quot;)><a href="/pack_detail-'+pro.source+'.dhtml" target="_blank" class="blue">'+pro.name+(pro.errorMessage?"<br/><font style='color:red;'>("+pro.errorMessage+")</font>":"")+'</a><span class="integral">'+(pro.score?(pro.score>1?pro.score+"积分":pro.score+"倍积分"):"")+'</span></td>';
        	  }else if('pan'==pro.sourceCat){
        	  	pros+='<td align="center"><div style="cursor :pointer ;position:relative;width:46px; height:46px; text-align: center;" onclick=window.open("/detail-'+pro.productIds+'.dhtml");><img src="'+path+pro.image+'" width="46" height="46" alt="'+pro.name+'" title="'+pro.name+'"  onload="util.drawImage(this, 46, 46)"/></div></td>';
        	 	pros+='<td align="left"><a href="/detail-'+pro.productIds+'.dhtml" target="_blank" class="blue">'+pro.name+(pro.errorMessage?"<br/><font style='color:red;'>("+pro.errorMessage+")</font>":"")+'</a><span class="integral">'+(pro.score?(pro.score>1?pro.score+"积分":pro.score+"倍积分"):"")+'</span></td>';
        	  }else{
        	  	pros+='<td align="center"><div onclick=window.open("/detail-'+pro.productIds+'.dhtml") style="cursor :pointer ;position:relative;width:46px; height:46px; text-align: center;" ><img src="'+path+pro.image+'" width="46" height="46" alt="'+pro.name+'" title="'+pro.name+'"  onload="util.drawImage(this, 46, 46)"/></div></td>';
        	 	pros+='<td align="left"><a href="/detail-'+pro.productIds+'.dhtml" target="_blank" class="blue">'+pro.name+(pro.errorMessage?"<br/><font style='color:red;'>("+pro.errorMessage+")</font>":"")+'</a><span class="integral">'+(pro.score?(pro.score>1?pro.score+"积分":pro.score+"倍积分"):"")+'</span></td>';
        	  }
        	  pros+='<td align="center">'+(pro.cate?pro.cate.replace(/#[^、]+/g,''):'&nbsp;')+'</td>';
        	  if('pck'==pro.sourceCat){
        	  		pros+='<td align="center">'+pro.quantity+'</td>';
        	  }else if('att'==pro.sourceCat){
        	  		pros+='<td align="center"><img style="cursor: pointer;" src="'+path+'/themes/default/images/decrease.gif" width="9" height="9" onclick="deleteProductNum(this,'+i+','+cid+')"/>';
		        	pros+='  <input name="num" id="td_'+i+'_'+cid+'" type="text" style="width:25px; text-align:center; margin:0 3px" value="'+pro.quantity+'" onchange="updateProduct(this,'+i+','+cid+')"/>';
		        	pros+='  <img style="cursor: pointer;" src="'+path+'/themes/default/images/adding.gif" width="9" height="9"  onclick="addProductNum(this,'+i+','+cid+')"/></td>';
        	  }else{
		        	pros+='<td align="center"><img style="cursor: pointer;" src="'+path+'/themes/default/images/decrease.gif" width="9" height="9" onclick="deleteProductNum(this,'+i+')"/>';
		        	pros+='  <input name="num" id="td_'+i+'" type="text" style="width:25px; text-align:center; margin:0 3px" value="'+pro.quantity+'" onchange="updateProduct(this,'+i+')"/>';
		        	pros+='  <img style="cursor: pointer;" src="'+path+'/themes/default/images/adding.gif" width="9" height="9"  onclick="addProductNum(this,'+i+')"/></td>';
        	  }
        	  pros+='<td align="center"><span class="pic">￥'+(pro.price&&pro.price.toFixed(2))+'</span></td>';
        	  pros+='<td align="center"><span class="pic">￥'+(pro.money&&pro.money.toFixed(2))+'</span></td>';
        	  pros+='<td align="center"><a href="#" onclick="deleteProduct('+i+','+cid+')" class="blue">删除</a></td>';
        	
		pros+='</tr>';
		if('pck'==pro.sourceCat){
			var laydiv = drowLayPack(pro,i);
			var html = document.getElementById('laydiv').innerHTML+laydiv;
			document.getElementById('laydiv').innerHTML=html;
		}
		//配件
		if(pro.productsList&&!pro.sourceCat){
			var attp = pro.productsList;
			for(var ci =0;ci<attp.length;ci++){
				 pros+=drowprotr(attp[ci],i,ci);
			}
		}
		return pros;
		},
		//画礼包浮层
		drowLayPack=function(pro,i){
		var lay	="",packPro;
			if(pro){
				packPro = pro.productsList;
			}
			lay+='<div class="cart_lay" id="lay'+pro.source+i+'" ><ul>';
			if(packPro){
				for(var p in packPro){
					lay+='<li><span>'+packPro[p].name+'</span><span>'+(packPro[p].cate?packPro[p].cate:'')+'</span></li>'; 	
				}
			}
			lay+=' </ul></div>';
		return lay;		
		},
		//画积分换购
		drowexctr = function(pro,i){
		var excs=""; 
			excs+='<tr class="jfbj">';
        	  excs+='<td align="center">积分换购</td>'; 
        	  excs+='<td align="center"><div onclick=window.open("/detail-'+pro.productIds+'.dhtml?commId="'+pro.commIds+')  style="cursor :pointer ;position:relative;width:46px; height:36px; text-align: center" ><img src="'+pro.image+'" alt="'+pro.name+'" title="'+pro.name+'" width="46" height="46" onload="util.drawImage(this, 46, 46)"/></div></td>';
        	  excs+='<td align="left"><a href="/detail-'+pro.productIds+'.dhtml?commId='+pro.commIds+'" target="_blank" class="blue">'+pro.name+(pro.errorMessage?"<br/><font style='color:red;'>("+pro.errorMessage+")</font>":"")+'</a><span class="integral"></span></td>';
        	  excs+='<td align="center">'+(pro.cate?pro.cate:'&nbsp;')+'</td>';
        	  excs+='<td align="center">';
        	  excs+=pro.quantity;
        	  excs+='</td>';
        	  excs+='<td align="center">'+(pro.exchageMoney?(pro.exchageMoney/(pro.quantity?pro.quantity:1)+"元+"):"")+(pro.exchageIntegral?pro.exchageIntegral:0)/(pro.quantity?pro.quantity:1)+'积分</td>';
        	  excs+='<td align="center">'+(pro.exchageMoney?(pro.exchageMoney+"元+"):"")+(pro.exchageIntegral?pro.exchageIntegral:0)+'积分</td>';
        	  excs+='<td align="center"><a href="#" onclick="deleteProduct('+i+')" class="blue">删除</a></td>';
      	  excs+='</tr>';
      	  return excs;	
		},
		//画积分换购错误信息
		drowLayPanic=function(panic){
		var lay	="";
			lay+='<div class="cart_lay" id="layPanic" ><ul>';
			if(panic){
				for(var p in panic){
					lay+='<li><span style="color:red;">'+panic[p]+'</span></li>'; 	
				}
				lay+='<li><span>请确认</span></li>'
			}
			lay+=' </ul></div>';
		return lay;		
		},
		drowpretr = function(pro,i){
		var pres ="";
			pres +='<tr class="zp">';
	            pres +='<td align="center">赠品</td>';
	            pres +='<td width="50" align="center"><div onclick=window.open("/detail-'+pro.productIds+'.dhtml") style="cursor :pointer ;position:relative;width:46px; height:46px; text-align: center" ><img src="'+pro.image+'" alt="'+pro.name+'" title="'+pro.name+'" width="46" height="46" onload="util.drawImage(this, 46, 46)"/></div></td>';
	            pres +='<td align="left" width="338"><a href="/detail-'+pro.productIds+'.dhtml" target="_blank" class="blue">'+pro.name+'</a><span class="integral"></span></td>';
	            pres +='<td align="center">'+(pro.cate?pro.cate.replace(/#[^、]+/g,''):'&nbsp;')+'</td>';
	            pres +='<td align="center">'+pro.quantity+'</td>';
	            pres +='<td align="center"><span class="pic">￥'+(pro.price&&pro.price.toFixed(2))+'</span></td>';
	            pres +='<td align="center"><span class="pic">￥'+(pro.money&&pro.money.toFixed(2))+'</span></td>';
	            pres +='<td align="center"><a href="#"  onclick="deleteProduct('+i+')" class="blue">删除</a></td>';
            pres +='</tr>';
            return pres;
		},
		drowtitle=function(){
		var title = '<table cellpadding="0" cellspacing="0" border="0" width="928" class="shopping_list" >';
			title+='<tr class="bjcolor01">';
            title+='<td width="40" align="center">序号</td>';
            title+='<td width="388" colspan="2" align="center">商品名称</td>';
            title+='<td width="140" align="center">规格</td>';
            title+='<td width="80" align="center">数量</td>';
            title+='<td width="80" align="center">单价</td>';
            title+='<td width="80" align="center">小计</td>';
            title+='<td width="80" align="center">操作</td>';
            title+='</tr>';
            return title;
		},
		drowprttitle=function(){
		var title = ' <h2>您可以选择的赠品</h2><table cellpadding="0" cellspacing="0" border="0" width="928" class="shopping_list">';
			title+='<tr class="bjcolor01">';
            title+='<td width="180" align="center">促销活动</td>';
            title+='<td width="288" align="center">赠品</td>';
            title+='<td width="288" align="center">规格</td>';
            title+='<td align="center">数量</td>';
            title+='<td width="80" align="center">加购</td>';
            title+='<td width="80" align="center">小计</td>';
            title+='<td width="80" align="center">操作</td>';
            title+='</tr>';
            return title;
		},
		drowdtail=function(cart){
		var dtail="";
			dtail+='<tr>';
            dtail+='<td colspan="8" class="bjcolor02"><span>商品数量总计：'+(cart?(cart.num?cart.num:0):0)+'件</span>'
            	 +'<span>商品总金额：<strong class="pic">￥'+((cart&&cart.order&&cart.order.money)?cart.order.money.toFixed(2):0.00)+'</strong>元</span>'
                 +'<span>需使用积分:'+((cart&&cart.order&&cart.order.integral)?cart.order.integral:0)+'分</span>'
                 //+'<p style="font-size:12px; font-weight:normal"><span>市场价'+((cart&&cart.totalMarketPrice)?cart.totalMarketPrice.toFixed(2):0.00)+'元</span>'
                 //+'<span>节省了'+((cart&&cart.order&&cart.totalMarketPrice)?(cart.totalMarketPrice-cart.order.goodsMoney).toFixed(2):0.00)+'元</span></p></td>';
            dtail+='</tr>';	
            dtail+='</table>';
            return dtail;
		},
		//drowProPresents=function(prt,p){
		//	var pre="";
		////	pre+='<tr>';
        //    pre+='<td align="left">'+prt[7]+'</td>'
        //    	 +'<td align="left">'+prt[2]+'</td>'
        //         +'<td align="center">'
        //         + drowCateSelect(prt["cates"],'&quot;'+p+'&quot;')	
        //         +'</td>'
        //        +'<td align="center" id ="num_'+p+'">'
        //        + drowSelect(prt[14],prt[1],prt[5],'&quot;'+p+'&quot;')
        //         +'</td>'
        //         +'<td align="center"><span class="pic" id="pic_'+p+'">￥'+prt[5]+'</span></td>'
        //         +' <td align="center"><span class="pic" id="pict_'+p+'">￥'+prt[12]*prt[5]+'</span></td>'
        //         +'<td align="center"><a href="#" class="blue" onclick="choose(&quot;'+p+'&quot;,'+prt[1]+')">选择</a></td>'
        //    pre+='</tr>';	
        //    return pre;
		//},
		drowBinds=function(bind,p){
			
		var binds="";
			binds+='<tr>' 
            +'<td align="left" height="30px" width="300px">'+bind[2]+'</td>'
            +'<td align="left" width="130px">'
            + drowCateSelect(bind["cates"],p)
            +' </td>'
            +'<td align="center" width="70px" id ="num_'+p+'">'
            + drowSelect(bind[14],bind[1],bind[5],'&quot;'+p+'&quot;')
            +'</td>'
            +'<td align="left" width="300px"><span style="padding:0 10px">x</span>优惠价<span id="pic_'+p+'">￥'+bind[5].toFixed(2)+'</span>=<span style="color:#f00" id="pict_'+p+'">￥'+(bind[14]*bind[5]).toFixed(2)+'</span></td>'
            +'<td align="left"><a href="#" class="blue" onclick="choose(&quot;'+p+'&quot;,'+bind[1]+')">选择</a></td>'
       		+'</tr>'
        return binds;
       },
       drowProPresents=function(bind,p){
		var binds="";
			binds+='<tr>' 
            +'<td align="left" height="30px" width="300px">'+bind[2]+'</td>'
            +'<td align="left" width="130px">'
            + drowCateSelectPro(bind["cates"],p)
            +' </td>'
            +'<td align="center" width="70px" id ="num_'+p+'">'
            + drowSelect(bind[12],bind[1],bind[5],'&quot;'+p+'&quot;')
            +'</td>'
            +'<td align="left" width="300px"><span style="padding:0 10px">x</span>优惠价<span id="pic_'+p+'">￥'+bind[5].toFixed(2)+'</span>=<span style="color:#f00" id="pict_'+p+'">￥'+(bind[12]*bind[5]).toFixed(2)+'</span></td>'
            +'<td align="left"><a href="#" class="blue" onclick="choose(&quot;'+p+'&quot;,'+bind[1]+')">选择</a></td>'
       		+'</tr>'
        return binds;
       },
		//drowBinds=function(bind,p){
		//	var binds="";
		//	binds+='<tr>'; 
        //    binds+='<td align="left">'+bind[7]+'</td>'
        //    	 +'<td align="left">'+bind[2]+'</td>'
        //         +'<td align="center">'
        //         + drowCateSelect(bind["cates"],p)	
        //         +'</td>'
         //        +'<td align="center" id ="num_'+p+'" >'
         //        + drowSelect(bind[14],bind[1],bind[5],'&quot;'+p+'&quot;')	
         //        +'</td>'
         //        +'<td align="center"><span class="pic" id="pic_'+p+'">￥'+bind[5]+'</span></td>'
        //         +'<td align="center"><span class="pic" id="pict_'+p+'">￥'+bind[14]*bind[5]+'</span></td>'
        //         +'<td align="center"><a href="#" class="blue" onclick="choose(&quot;'+p+'&quot;,'+bind[1]+')">选择</a></td>'
        //    binds+='</tr>';	
        //    return binds;
		//},
		drowSelect=function(n,num,pic,p){
			var options='数量<select name="num" id="num'+num+'" onchange="selectnum(this,'+pic+','+p+')">';
			for(var i = n; i >0;i--){
				options+='<option value="'+i+'">'+i+'</option>'
			}
			options+='</select>';
			return options;
		},
		drowCateSelect=function(cates,p){
			if(cates){
				var options='<select style="width:100px"  id="cate_'+p+'" onchange="selectcate(this,&quot;'+p+'&quot;)" >';
				for(var i = 0; i <cates.length;i++){
					options+='<option value="'+cates[i][1]+'">'+cates[i][0]+'</option>';
				}
				options+='</select>';
			}else{
				return '';
			}
			return options;
		},
		drowCateSelectPro=function(cates,p){
			if(cates){
				var options='<select style="width:100px"  id="cate_'+p+'" onchange="selectcatepro(this,&quot;'+p+'&quot;)" >';
				for(var i = 0; i <cates.length;i++){
					options+='<option value="'+cates[i][1]+'">'+cates[i][0]+'</option>';
				}
				options+='</select>';
			}else{
				return '';
			}
			return options;
		},
		drowdefault=function(){
			var defaulttr="";
			defaulttr+='<tr><td align="center" colspan="8" style="text-align: center;">购物车中没有商品</td></tr>';
			return defaulttr;	
		}
	util.ajax('/show_cart.dhtml?time='+(+new Date),function(d){
				var n = d.cartItems,titles=drowtitle(),dtail = drowdtail(d),tablehtml,protr="",excstr="",prestr="",proPresents=d.proPresents,proBinds=d.proBinds,proPs='',panicMessage = d.panicBuyErrorMessage,promotionMap=d.promotionMap ;
		if(n){
			
			for(var i =0;i<n.length;i++){
			    if(n[i]&&n[i].sourceCat=="exc"){
					excstr+=drowexctr(n[i],i);
				}else if(n[i]&&n[i].sourceCat=="prt"){
					prestr+=drowpretr(n[i],i);
				}else{
					protr += drowprotr(n[i],i);
				}
			}
		}
		if(promotionMap){
			var promotion ="",spread = promotionMap.spread,fullCapacity=promotionMap.fullCapacity,proBindsstr = promotionMap.proBinds;
			if(spread){
				promotion=promotion+"您再消费 "+spread+" 元 的商品，即可免运费。<br/>";
			}
			if(fullCapacity){
				promotion=promotion+"您已购物满"+fullCapacity+"元，可享受免15元运费。<br/>";
			}
			if(proBindsstr){
				promotion=promotion+"恭喜您，您已购买亲肤无痕系列的产品，只需49元即可选择第二件。<a href='#prttbale'>马上选择>></a><br/>";
			}
			document.getElementById('promotiondiv').innerHTML=promotion;
		}
		protr+=excstr+=prestr
		if(!protr){
			protr=drowdefault();
			dtail+=' <div class="bt"><a href="#" onclick="alertnopro(&quot;您还没有购买商品！&quot;);return false;"><img src="'+path+'/themes/2010/images/cart_bt01.gif"style="float:right;"/></a><a href=/ ><img src="'+path+'/themes/default/images/cart_bt.gif"  /></a></div>';
		}else if(d.errorMessage.proError){
			dtail+=' <div class="bt"><a href="#" onclick="alertnopro(&quot;请核对购物车中商品是否有误！&quot;);return false;"><img src="'+path+'/themes/2010/images/cart_bt01.gif" style="float:right;"/></a><a href=/ ><img src="'+path+'/themes/2010/images/cart_bt.gif"/></a></div>';
		}else{
			dtail+=' <div class="bt"><div  style="float:right;"><span style="color:#f00; padding-right:10px">购物满200元免运费，满300元送收纳盒！</span><a href="/input_shopping_info.dhtml"><img src="'+path+'/themes/2010/images/cart_bt01.jpg" align="absmiddle"/></a></div><a href=/ ><img src="'+path+'/themes/2010/images/cart_bt.gif"  /></a></div>';
		}
		//限时抢购活动错误信息
		if(panicMessage){
		var laydiv = drowLayPanic(panicMessage);
			var html = document.getElementById('laydiv').innerHTML+laydiv;
			document.getElementById('laydiv').innerHTML=html;
			Lay.show({
				width:0.5,
				height:0.5,
				title:name,
				id:'layPanic'
			})
		}
		tablehtml=titles+protr+dtail;
		
		document.getElementById('carttab').innerHTML=tablehtml;
		
		//proPs+=drowprttitle();
		proPs+='<table cellpadding="0" cellspacing="0" border="0" width="868">';
		var proPss='';
		if(proPresents){
			var cate = new Array();
			var pid_cid_old = "";
			for(var i =0;i<proPresents.length;i++){
				proPsssPre[proPresents[i][6]+"_"+proPresents[i][0]+"_"+proPresents[i][1]] = proPresents[i];
				var pid_cid = proPresents[i][6]+"_"+proPresents[i][0];
				if(i==0){
					pid_cid_old=pid_cid;
					proshowPre[pid_cid_old] = proPresents[i];
				}
				if(proPresents[i][3]){
					if(pid_cid&&pid_cid_old&&pid_cid==pid_cid_old){
						cate[cate.length]=new Array(proPresents[i][3].replace(/#[^、]+/g,''),pid_cid_old+"_"+proPresents[i][1]);
						if(i==proPresents.length-1){
							proshowPre[pid_cid_old]["cates"] = cate;
						}
					}else{
						proshowPre[pid_cid_old]["cates"] = cate;
						pid_cid_old=proPresents[i][6]+"_"+proPresents[i][0];
						cate = new Array();
						cate[cate.length]=new Array(proPresents[i][3].replace(/#[^、]+/g,''),pid_cid_old+"_"+proPresents[i][1]);
						proshowPre[pid_cid_old] = proPresents[i];
					}
				}
				
				//proPss+=drowBinds(proPresents[i]);
			}
			//for(var p in proshow){
			//	proPss+=drowBinds(proshow[p],p);
			//}
		if(proshowPre){
			for(var p in proshowPre){
				var proshowl = proPsssMap[proshowPre[p][6]];
				if(!proshowl){
					proPsssMap[proshowPre[p][6]]={};
				}
				proPsssMap[proshowPre[p][6]][p]=proshowPre[p];
			}
		}
		if(proPsssMap){ 
			for(var prog in proPsssMap){
				var pros = proPsssMap[prog];
				var s='';
				for(var p in pros){
					s=pros[p][7];
					break;
				}
				proPss+='<tr>'
        					+'<td style="border-bottom:1px solid #ccc; color:#f00; padding-bottom:10px" colspan="5">'+s+'</td>'
        				+'</tr>'
				for(var p in pros){
					proPss+=drowProPresents(proshowPre[p],p);
				}
			}
		}
			//for(var i =0;i<proPresents.length;i++){
			//	 proPss+=drowProPresents(proPresents[i]);
			//}
		}
		if(proBinds){
			var cate = new Array();
			var pid_cid_old = "";
			for(var i =0;i<proBinds.length;i++){
				proPsss[proBinds[i][6]+"_"+proBinds[i][0]+"_"+proBinds[i][1]] = proBinds[i];
				var pid_cid = proBinds[i][6]+"_"+proBinds[i][0];
				if(i==0){
					pid_cid_old=pid_cid;
					proshow[pid_cid_old] = proBinds[i];
				}
				if(proBinds[i][3]){
					if(pid_cid&&pid_cid_old&&pid_cid==pid_cid_old){
						cate[cate.length]=new Array(proBinds[i][3].replace(/#[^、]+/g,''),pid_cid_old+"_"+proBinds[i][1]);
						if(i==proBinds.length-1){
							proshow[pid_cid_old]["cates"] = cate;
						}
					}else{
						proshow[pid_cid_old]["cates"] = cate;
						pid_cid_old=proBinds[i][6]+"_"+proBinds[i][0];
						cate = new Array();
						cate[cate.length]=new Array(proBinds[i][3].replace(/#[^、]+/g,''),pid_cid_old+"_"+proBinds[i][1]);
						proshow[pid_cid_old] = proBinds[i];
					}
				}
				
				//proPss+=drowBinds(proBinds[i]);
			}
			//for(var p in proshow){
			//	proPss+=drowBinds(proshow[p],p);
			//}
		}
		if(proshow){
			for(var p in proshow){
				var proshowl = proshowMap[proshow[p][6]];
				if(!proshowl){
					proshowMap[proshow[p][6]]={};
				}
				proshowMap[proshow[p][6]][p]=proshow[p];
			}
		}
		if(proshowMap){
			for(var prog in proshowMap){
				var pros = proshowMap[prog];
				var s='';
				for(var p in pros){
					s=pros[p][7];
					break;
				}
				proPss+='<tr>'
        					+'<td style="border-bottom:1px solid #ccc; color:#f00; padding-bottom:10px" colspan="5">'+s+'</td>'
        				+'</tr>'
				for(var p in pros){
					proPss+=drowBinds(proshow[p],p);
				}
			}
		}
		proPs+=proPss;
		proPs+='</table>';
		if(!proPss){
			proPs='';
		}else{
			document.getElementById('prttbalediv').style.display='block';
		}
		document.getElementById('prttbale').innerHTML=proPs;
	},{});
})()
function selectnum(t,price,p){
	var v=t.value;
	$("pict_"+p).innerHTML='￥'+(v*price).toFixed(2);
	//$("picn_"+p).innerHTML='￥'+v.toFixed(2);
}
function drowSelect(n,num,pic,p){
			var options='<select name="num" id="num'+num+'" onchange="selectnum(this,'+pic+','+p+')">';
			for(var i = n; i >0;i--){
				options+='<option value="'+i+'">'+i+'</option>'
			}
			options+='</select>';
			return options;
		}
function selectcate(t,p){
	var v =t.value,
	o = proPsss[v],
	numSelect=drowSelect(o[14],o[1],o[5],'&quot;'+p+'&quot;'),
	pic=o[5],tp=o[14]*o[5];
	$("num_"+p).innerHTML="数量"+numSelect;
	$("pic_"+p).innerHTML = '￥'+pic.toFixed(2);
	$("pict_"+p).innerHTML = '￥'+tp.toFixed(2);
	//var v=t.value,n = t.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.innerHTML;
	//t.parentNode.nextSibling.nextSibling.nextSibling.innerHTML='<span class="pic">￥'+v*price+'</span>';
}
function selectcatepro(t,p){
	var v =t.value,
	o = proPsssPre[v],
	numSelect=drowSelect(o[12],o[1],o[5],'&quot;'+p+'&quot;'),
	pic=o[5],tp=o[12]*o[5];
	$("num_"+p).innerHTML="数量"+numSelect;
	$("pic_"+p).innerHTML ='￥'+ pic.toFixed(2);
	$("pict_"+p).innerHTML ='￥'+ tp.toFixed(2);
	//var v=t.value,n = t.parentNode.nextSibling.nextSibling.nextSibling.nextSibling.innerHTML;
	//t.parentNode.nextSibling.nextSibling.nextSibling.innerHTML='<span class="pic">￥'+v*price+'</span>';
}
function choose(p,cid){
	var aid_cid_pid_select = document.getElementById('cate_'+p),pid,cid,aid,aid_cid_pid,ids;
	if(aid_cid_pid_select){
		var aid_cid_pid =document.getElementById('cate_'+p).value,
		ids = aid_cid_pid.split("_"),
		pid=ids[1],cid=ids[2],aid=ids[0];
	}else{
		ids = p.split("_");
		aid = ids[0];pid=ids[1];
	}

	var n = document.getElementById('num'+cid).value;
	location.href='add_cartItem.dhtml?productIds='+pid+'&commIds='+cid+'&quantity='+n+'&sourceCat=prt&source='+aid;
}
function alertnopro(msg){
	alert(msg);
}