$(function()
{
	 $(".shopminus").click(function(){
		if($(".shopnum").length<=0)
		{alert("系统错误");}
		else
		{
			var shopnum=$(".shopnum").attr("value");
			var r=/^\+?[1-9][0-9]*$/;
			if(!r.test(shopnum)){shopnum=1;}else{shopnum--;}
			if(shopnum<=0){shopnum=1;}
			$(".shopnum").attr("value",shopnum);
		}
	})
	//
	$(".shopadd").click(function(){
		if($(".shopnum").length<=0)
		{alert("系统错误");}
		else
		{
			var shopnum=$(".shopnum").attr("value");
			var old=shopnum;
			var id=$(".shopnum").attr("proid");
			var r=/^\+?[1-9][0-9]*$/;
			if(!r.test(shopnum)){shopnum=1;}else{shopnum++;}
			$.ajax(
			{
				type:"post",
				cache:false,
				url:webroot+"cart.asp?act=stock&id="+id+"&num="+shopnum+"",
				success:function(_)
				{
					$(".shopnum").attr("value",old);
					var act=_.substring(0,1);
					var info=_.substring(1);
					if(act==0){$.fn.tips({content:info,time:3000});}
					else
					{
						$(".shopnum").attr("value",shopnum);
					}
				}
			});
		}
	})
	//
	$(".shopnum").blur(function(){
		var shopnum=$(this).attr("value");
		var id=$(".shopnum").attr("proid");
		$.ajax(
			{
				type:"post",
				cache:false,
				url:webroot+"cart.asp?act=stock&id="+id+"&num="+shopnum+"",
				success:function(_)
				{
					$(".shopnum").attr("value","1");
					var act=_.substring(0,1);
					var info=_.substring(1);
					if(act==0){$.fn.tips({content:info,time:3000});}
					else
					{
						$(".shopnum").attr("value",shopnum);
					}
				}
			});
	})
	//
	$("#prolist").scrollable();
	$("#prolist ul li a").click(function(){
		$("#prolist ul > li a").each(function(){$(this).parent().removeClass("hover");})
		$(this).parent().addClass("hover");
		var imgurl=$(this).find("img").attr("src");
		$("#shop_big").attr("src",imgurl);
	})
	//
	$("#shop_big").click(function(){window.open($(this).attr("src"))})
	//添加到购物车
	$("#addcart").click(function(){
		if($(".shopnum").length<=0)
		{alert("系统错误");}
		else
		{
			var shopnum=$(".shopnum").attr("value");
			var r=/^\+?[1-9][0-9]*$/;
			if(!r.test(shopnum)){shopnum=1;}
			if(shopnum>=1000){shopnum=999;}
			var id=$(this).attr("config");
			$.ajax(
			{
				type:"post",
				cache:false,
				url:webroot+"cart.asp?act=addcart&id="+id+"&shopnum="+shopnum+"",
				success:function(_)
				{
					$(".shopnum").attr("value","1");
					var act=_.substring(0,1);
					var info=_.substring(1);
					if(act==0){$.fn.tips({content:info,time:3000});}
					else
					{
						var arr=info.split(":");
						var h=arr[0]+"<br><br>共计：<span style=\"color:#f30;\">"+arr[1]+"</span> 件商品";
						dialog({content:h,lock:true,opacity:0.3,icon:"succeed",fixed:true,okValue:"去结算",ok:function(){location.href=webroot+"cart.asp?act=order";},cancelValue:"继续购物",cancel:function(){},time:5}).showModal();
						get_cartnum();	
						loadtopcart();
					}
				}
			});
		}
	})
})

