<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{echo: lp{m_u_center};/}</title>
<link rel="stylesheet" type="text/css" href="skin/{echo: $SYSINFO['templates'];/}/css/modules.css">
<link rel="stylesheet" type="text/css" href="skin/{echo: $SYSINFO['templates'];/}/css/layout.css">
<link rel="stylesheet" type="text/css" href="skin/{echo: $SYSINFO['templates'];/}/css/style.css">
<script type="text/javascript" src="skin/{echo: $SYSINFO['templates'];/}/js/changeStyle.js"></script>
<script type="text/javascript" src="skin/{echo: $SYSINFO['templates'];/}/js/userchangeStyle.js"></script>

<style type="text/css">
.edit span{background:#efefef;}
.search {margin:5px;}
.search input {color:#444;}
td.img img{cursor:pointer}
</style>
</head>
<body onload="menu_style_change('user_cart');changeMenu();">
{inc: require("shop/index_header.php");/}
	<div class="site_map">
	  {echo:lp{m_current_position};/}<A href="index.php">{echo:$SYSINFO['sys_name'];/}</A>/<a href="modules.php">{echo:lp{m_u_center};/}</a>/&nbsp;&nbsp;{echo:lp{m_my_cart};/}
	</div>
    <div class="clear"></div>
    {inc: require("modules/left_menu.php");/}
	<form action="do.php?act=user_cart_del" name="form" id="form1" method="get" onsubmit="return submitform();">
	    <div class="main_right">
			<div class="right_top"></div>
			<div class="cont">
				<div class="cont_title">
					<span class="tr_op">
					<a href="javascript:;" onclick="return go_to_buy()">{echo:lp{m_check_out};/}</a><a href="index.php" target="_blank">{echo:lp{m_go_buy};/}</a>
					</span>
					{echo:lp{m_my_cart};/}
				</div>
				<hr />
				<table class="commodityCart" width="100%" border="0" cellspacing="0">
				  <tr>
					<th width="40"></th>
					<th width="150">{echo: lp{m_goods_image};/}</th>
					<th>{echo: lp{m_goods_info};/}</th>
					<th width="80">{echo: lp{m_buy_num};/}</th>
					<th width="130">{echo: lp{m_manage};/}</th>
				  </tr>
				  {sta:if(!empty($result['result'])) {
					foreach($result['result'] as $k=> $v) {
					    foreach ($shoparray as $ke=>$va){
					    	if($v['shop_id']==$va){
					    		 unset($shoparray[$ke]);/}
					    	
					
    <tr class="shopInfo">
     	<td colspan="5">{echo: lp{m_order_shops};/}：<a href="{echo:shop_url($v['shop_id']);/}" target="_blank" >{echo: $v['shop_name'];/}</a></td>
     </tr>
     <?php }  }?>
				<tr class="commodity">
					<td align="center"><input type="checkbox" id="good_check" name="goods[]" onclick="add_buy({echo:$v['goods_id'];/},{echo:$v['shop_id'];/},{echo:$v['goods_number'];/},this,this.checked)" value="{echo: $v['cart_id'];/}" /></td>
						<td align="center"><a href="{echo: goods_url($v['goods_id']);/}" target="_blank"><img src="{echo: $v['goods_thumb'];/}" width="80" height="80" onerror="this.src='skin/default/images/nopic.gif'"/></a></td>
					<!--	<input type="hidden" name="gid[]" value="{echo:$v['goods_id'];/}" />-->
						<td class="name"><a href="{echo: goods_url($v['goods_id']);/}" target="_blank">{echo: $v['goods_name'];/}</a>
						<br /> {echo: lp{m_order_shops};/}：<a href="{echo: shop_url($v['shop_id'],'index');/}" target="_blank">{echo: $v['shop_name'];/}</a>
						<br />  {echo: lp{m_price};/}：{echo:lp{m_money_sign};/}<span>{echo: $v['goods_price'];/}</span>{echo: lp{m_yuan};/}
						<br /> {echo: lp{m_add_time};/}：{echo: substr($v['add_time'],0,16);/} &nbsp;&nbsp; <script src="imshow.php?u={echo: $v['user_id'];/}"></script>
						</td>
						<!--<input type="hidden" name="v[]" value="<?php //echo $v['goods_number']?>" />-->
						<td align="center" id="goodssortid_{echo: $v['cart_id'];/}">
							<span onclick="edit_sort(this,{echo: $v['cart_id'];/})">&nbsp;{echo: $v['goods_number'];/}&nbsp;</span></td>
						<td align="center">
						{sta:if($v['lock_flg']=='1') { ;/}
							<font color='red'>{echo: lp{m_other_shop_lock};/}</font>
						{sta:} else if($v['open_flg']=='1')[exc]}
							<font color='red'>{echo: lp{m_other_shop_close};/}</font>
						{sta:} else [exc]}
							<input type="hidden" id="shop_id_{echo: $v['goods_id'];/}" value="{echo: $v['shop_id'];/}" />
							<a href="javascript:addFavorite({echo: $v['goods_id'];/});">收藏</a>
							<br />
							<a id="num_{echo: $v['cart_id'];/}" href="modules.php?app=user_order_adress&gid={echo: $v['goods_id'];/}&v={echo: $v['goods_number'];/}">{echo: lp{m_ccbuy};/}</a>
						{end:if/}<br />
						<a href="do.php?act=user_cart_del&id={echo: $v['cart_id'];/}{sta:if($v['cart_id']==0)[exc]}&goods_id={echo:$v['goods_id'];/}{end:if/}" onclick="return confirm('{echo: lp{m_sure_delcartgoods};/}');">{echo: lp{m_del};/}</a>
						</td>
					</tr>
				
					{end:foreach/}
						{sta:if(!empty($row['sumvalue'])) [exc]}
							<tr><td colspan="5" style="border-bottom:0"><div>{echo: lp{m_car_sum};/}{echo: $row['sumvalue'];/}{echo: lp{m_yuan};/}</div></td></tr>
						{end:if/}
                    <tr><td colspan="5" style="border-bottom:0"><div class="page">{inc: require("modules/page.php");/}</div></td></tr>
					<!--<tr><th width="40"><input type="checkbox" onclick="checkall(this);" /></th><th align="left" colspan="4"><input class="submit" type="button" onclick="select_all()" value="全选"> <input class="submit" type="button" onclick="select_last()" value="反选"> <INPUT class="submit" type=submit value={echo:lp{m_pl_del};/} name=deletesubmit></th></tr>-->
					{sta: } else [exc]}
					<tr><th colspan="5" class="center">{echo: lp{m_nolist_record};/}</td></tr>
					{end:if/}
					<input type="hidden" name="app" value="user_order" />
					<input type="hidden" id="shop_user" value="{echo:$user_id;/}" />
					<input type="hidden" name="iscart" value="1" />
				</table>
			</div>
			<div class="clear"></div>
			<div class="right_bottom"></div>
			<div class="back_top"><a href="#"></a></div>

		</div>
	</form>
	<form action="modules.php?app=user_order_adress" method="post" id="form2">
		<div id="gid_box"></div>
		<div id="shop_box"><input type="hidden" name="sid" id="sid" value="0" /></div>
		<div id="gnum_box"></div>
		<input type="hidden" name="app" value="user_order_adress" />
	</form>
{inc: require("shop/index_footer.php");/}
<script language="JavaScript" src="servtools/ajax_client/ajax.js"></script>
<script>
	function addFavorite(id) {
			var shop_id = document.getElementById('shop_id_'+id).value;
			var user_id = document.getElementById('shop_user').value;
			if (shop_id == user_id){
				alert('{echo:lp{s_mygoods_error};/}');
			}else {
				ajax("do.php?act=goods_add_favorite","POST","id="+id,function(data){
					if(data == 1) {
						alert("{echo: lp{s_g_addedfavorite};/}");
					} else if(data == -1) {
						alert("{echo: lp{s_g_stayfavorite};/}");
					} else {
						alert("{echo: lp{s_g_addfailed};/}");
					}
				});
			}
		}
		
</script>
</body>
</html>

<script language="JavaScript">
<!--
function toggle_show(obj,id) {
	var re = /yes/i;
	var src = obj.src;
	var isshow = 1;
	var sss = src.search(re);
	if(sss > 0) {
		isshow = 0;
	}
	ajax("do.php?act=shop_isshow_toggle","POST","id="+id+"&s="+isshow,function(data){
		if(data) {
			obj.src = 'skin/default/images/'+data+'.gif';
		}
	});
}

var inputs = document.getElementsByTagName("input");
function submitform() {
	var status = document.getElementsByName("goods");
	var checknum = 0;
	for(var i=0; i<inputs.length; i++) {
		if(inputs[i].type=='checkbox') {
			if(inputs[i].checked) {
				checknum++;
			}
		}
	}
	if(checknum==0) {
		alert("{echo:lp{m_selceted_one};/}");
		return false;
	}else {
		var flg = confirm('{echo:lp{m_manage_sure_del};/}');
		if (flg){
			return true;
		}
	}
	return false;
}

function checkall(obj) {
	if(obj.checked) {
		for(var i=0; i<inputs.length; i++) {
			if(inputs[i].type=='checkbox') {
				inputs[i].checked = true;
			}
		}
	} else {
		for(var i=0; i<inputs.length; i++) {
			if(inputs[i].type=='checkbox') {
				inputs[i].checked = false;
			}
		}
	}
}

var sort_value,number_value,price_value;
function edit_sort(span,id) {
	obj = document.getElementById("goodssortid_"+id);
	sort_value = span.innerHTML;
	sort_value = sort_value.replace(/&nbsp;/ig,"");
	obj.innerHTML = '<input style="width:35px" type="text" id="input_goodssortid_' + id + '" value="' + sort_value + '" onblur="edit_sort_post(this,' + id + ')"  maxlength="2" />';
	document.getElementById("input_goodssortid_"+id).focus();
}

function edit_sort_post(input,id) {
	var obj = document.getElementById("goodssortid_"+id);
	var num = document.getElementById("num_"+id);
	var re = /v=[0-9]+/g;
	if(isNaN(input.value)) {
		alert("{echo:lp{m_input_numpl};/}");
		obj.innerHTML = '<span onclick="edit_sort(this,' + id + ')">&nbsp;' + sort_value + '&nbsp;</span>';
		return ;
	}
	if(sort_value==input.value) {
		obj.innerHTML = '<span onclick="edit_sort(this,' + id + ')">&nbsp;' + sort_value + '&nbsp;</span>';
	} else {
		ajax("do.php?act=goods_num_edit","POST","id="+id+"&v="+input.value,function(data){
			if(data==1) {
				num.href = num.href.replace(re, "v="+input.value);
				obj.innerHTML = '<span onclick="edit_sort(this,' + id + ')">&nbsp;' + input.value + '&nbsp;</span>';
			} else {
				obj.innerHTML = '<span onclick="edit_sort(this,' + id + ')">&nbsp;' + sort_value + '&nbsp;</span>';
			}
		});
	}
}

function select_all() {
	for(var i=0; i<inputs.length; i++) {
		if(inputs[i].type=='checkbox') {
			inputs[i].checked = true;
		}
	}
}

function select_last() {
	for(var i=0; i<inputs.length; i++) {
		if(inputs[i].type=='checkbox') {
			if (inputs[i].checked == true){
				inputs[i].checked = false;
			}else if (inputs[i].checked == false){
				inputs[i].checked = true;
			}
		}
	}
}
function go_to_buy(){
	var obj = document.getElementById('form2');
//	obj.action="modules.php?app=user_order";
	var gids = document.getElementsByName('gid[]');
	if(gids.length<=0){
		alert("{echo:lp{m_select_goods};/}");
	}else{
		obj.submit();
	}
	return false;
}
function add_buy(gid,shop_id,gnum,obj,bl){
	if(bl){
		if(document.getElementById("sid").value==0){
			document.getElementById("sid").value=shop_id;
		}
		if(document.getElementById('sid').value==shop_id){
			document.getElementById("gid_box").innerHTML+="<input type='hidden' name='gid[]'value='"+gid+"' />";
			document.getElementById("gnum_box").innerHTML+="<input type='hidden' name='v[]'value='"+gnum+"' />";
//			obj.checked=true;
		}else{
			alert("{echo:lp{m_select_goods_error};/}");
			obj.checked=false;
		}
	}else{
		var gids = document.getElementsByName('gid[]');
		var nums = document.getElementsByName("v[]");
		var temp_gid_box = "";
		var temp_gnum_box = "";
		for(i=0;i<gids.length;i++){
		    if(gid!=gids[i].value){
		        temp_gid_box+="<input type='hidden' name='gid[]' value='"+gids[i].value+"' />";
		        temp_gnum_box+="<input type='hidden' name='v[]' value='"+nums[i].value+"' />";
		    }
		}
		document.getElementById("gid_box").innerHTML=temp_gid_box;
		document.getElementById("gnum_box").innerHTML=temp_gnum_box;
		if(temp_gid_box.length<=0){
		    document.getElementById("sid").value=0;
		}
	}
}
//-->
</script>