function toggleTabs(id)
{
	var menus = $(id).find("li").find("a");
	var tabs = $(id).find(".goods_list_rec");
	for(var i=0;i<menus.length;i++)
	{
		if(i>0)
		{
			tabs[i].style.display = "none";
		}
		else
		{
			tabs[i].style.display = "block";
			menus[i].className = "act";
		}
		
		menus[i].onmouseover = function(){ 
			for(var i=0;i<menus.length;i++)
			{
				if(menus[i]==this)
				{
					$(tabs[i]).fadeIn();
					menus[i].className = "act";
				}
				else
				{
					$(tabs[i]).hide();
					menus[i].className = "";
				}
			}
		}
	}
}

function init_gallery()
{
	var big_imgs = $("#big_img").find("div");
	var small_imgs = $("#small_img").find("li a");
	for(var i=0;i<small_imgs.length;i++)
	{
		small_imgs[i].onmouseover = function()
		{
			for(var j=0;j<small_imgs.length;j++)
			{
				if(small_imgs[j]==this)
				{
					small_imgs[j].className = "act";
					if(big_imgs[j].style.display != "block")
						big_imgs[j].style.display = "block"
				}
				else
				{
					small_imgs[j].className = "";
					big_imgs[j].style.display="none";
				}
			}
		}
	}
}


/* 会员区用到的JS */
function sw_detail(obj)
{
	if(obj.checked)
		$("#detail_table").slideDown();
	else
		$("#detail_table").slideUp();
}
function show_check_rs(obj, rs, tipid)
{
	if(!rs.state)
		{
			if(document.getElementById(tipid))
			{
				$("#"+tipid).html(rs.msg);	 				
			}
			else
			{
				$(obj.parentNode).append("<span id='"+tipid+"'>"+rs.msg+"</span>");
			}			
			return false;
		}
		else
		{
			if(document.getElementById(tipid))
			{
				$("#"+tipid).html("");
			}
			return true;
		}	
}
function check_field(obj,is_ajax)
{
	switch(obj.name)
	{
		case "user_name":
			rs = new Object();
			rs.state=true;
			if(obj.value.length < 6)
			{
				rs.state = false;
				rs.msg = USER_TOO_SHORT;
			}
			if(!show_check_rs(obj,rs,'name_tip'))return;
			if(is_ajax)
			$.ajax({
				  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=User&"+VAR_ACTION+"=checkField&fieldName=user_name&value="+obj.value,
				  cache: false,
				  success:function (html){
				 		var rs = $.evalJSON(html);
				 		show_check_rs(obj,rs,'name_tip');
					}
				});
			break;
		case "user_pwd":
			rs = new Object();
			rs.state=true;
			if(obj.value.length < 6)
			{
				rs.state = false;
				rs.msg = PWD_TOO_SHORT;
			}
			
			show_check_rs(obj,rs,'pwd_tip');
			break;
		case "user_pwd_confirm":
			rs = new Object();
			rs.state=true;
			if(document.getElementById("passwordbox").value!=document.getElementById("confirm_passwordbox").value)
			{				
				rs.state = false;
				rs.msg = PWD_CONFIRM_FAILED;
			}			
			show_check_rs(obj,rs,'cfpwd_tip');
			break;
		case "email":			
			//非ajax验证
			email_reg = /^\w+[\@]{1}\w+[\.]{1}\w{2,3}$/;
			rs = new Object();
			rs.state=true;
			if(!email_reg.test(obj.value))
			{				
				rs.state = false;
				rs.msg = EMAIL_FORMAT_ERROR;
			}			
			if(!show_check_rs(obj,rs,'email_tip'))return;
			if(is_ajax)
			$.ajax({
				  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=User&"+VAR_ACTION+"=checkField&fieldName=email&value="+obj.value,
				  cache: false,
				  success:function (html){
				 		var rs = $.evalJSON(html);
				 		show_check_rs(obj,rs,'email_tip');
					}
				});
			break;
		default:
			break;
	}
}
/* 会员区JS结束 */

function showAttrSearch(obj)
{
	$.ajax({
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Goods&"+VAR_ACTION+"=getTypeAttrList&type_id="+obj.value,
		  cache: false,
		  success:function (html){
		 		var rs = $.evalJSON(html);
		 		var res_html = "";
		 		if(rs)
		 		for(var i=0;i<rs.length;i++)
		 		{
		 			res_html+=rs[i].name+"：<input type='text' name='attr_value_"+rs[i].id+"' />";
		 			res_html+="<div class='blank5'></div>";
		 		}
		 		$("#attr_item").html(res_html);
			}
		});
}

function checkKeywords()
{
	var k = $("#head_keywords").val();
	if(k=='')
	{
		alert(KEYWORDS_EMPTY);
		document.getElementById("head_keywords").focus();
		return false;
	}
	else
	{
		return true;
	}
}

function reply_message(obj)
{
	var reply_id = $(obj.parentNode).find("input").val();
	var reply_title = $(obj.parentNode).find("span").html();

	if(reply_id&&reply_id!=0)
	{
		document.getElementById("message_title").value = "["+REPLY+"] "+reply_title;
		document.getElementById("message_title_span").innerHTML = "["+REPLY+"] "+reply_title;
		document.getElementById("message_title").style.display = "none";
		document.getElementById("pid").value = reply_id;
	}
}
function reset_reply()
{
	document.getElementById("message_title").value = "";
	document.getElementById("message_content").value = "";
	document.getElementById("message_title_span").innerHTML = "";
	document.getElementById("message_title").style.display = "";
	document.getElementById("pid").value = "0";	
}

/*加入购物车*/
// 购买规格（商品）
function addGoodsToCart(goods_id)
{
	spec_item_id = $("#spec_item").val();

		var number = 1;
		if(document.getElementById("number"))
		{
			var num = document.getElementById("number").value;
			if(isNaN(num)) {alert(IS_NAN);return;}			
			number = parseInt(num)<0?0:num;
		}
		$.ajax({
			  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=addGoodsToCart&is_ajax=1&rec_module=GoodsSpecItem&rec_id="+spec_item_id+"&number="+number+"&goods_id="+goods_id,
			  cache: false,
			  success:function (html){
					//alert(html);return;
			 		var rs = $.evalJSON(html);
			 		if(rs.status==0)
			 		{
			 			alert(rs.info);
			 		}
			 		else
			 		{
			 			location.href= ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=listCart";
			 		}			 		
				}
			});	
}

function modify_cart(id)
{
	number = document.getElementById("number_"+id).value;
	if(isNaN(number))
	{
		alert(IS_NAN);
		return;
	}
	
	$.ajax({
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=modifyCart&is_ajax=1&cart_id="+id+"&number="+number,
		  cache: false,
		  success:function (html){
		 		var rs = $.evalJSON(html);
		 		if(rs.status==0)
		 		{
		 			alert(rs.info);
		 		}
		 		else
		 		{
		 			location.href= location.href;
		 		}			 		
			}
		});
	
}

function del_cart(id)
{
	
	$.ajax({
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=delCart&is_ajax=1&cart_id="+id,
		  cache: false,
		  success:function (html){
		 		var rs = $.evalJSON(html);
		 		if(rs.status==0)
		 		{
		 			alert(rs.info);
		 		}
		 		else
		 		{

		 			if(rs.count!=0)
		 			{
		 				location.href= ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=listCart";
		 			}
		 			else
		 			{		 				
		 				location.href= ROOT_PATH;
		 			}
		 		}			 		
			}
		});
}


/*加入购物车*/
function addScoreCart(id)
{
	spec_item_id = $("#spec_item").val();
	
	if(id)
	{	
		var attr_str = "";
		if(document.getElementById("attr_table"))
		{
			var attrs = $("#attr_table").find("input");
			var attrs_select = $("#attr_table").find("option");
			if(attrs.length>0)
			{
				for(var i=0;i<attrs.length;i++)
				{
					if(attrs[i].checked)
					{
						attr_str += attrs[i].value+",";
					}
				}
				attr_str = attr_str.substr(0,attr_str.length-1);
			}
			else if(attrs_select.length>0)
			{
				for(var i=0;i<attrs_select.length;i++)
				{
					if(attrs_select[i].selected)
					{
						attr_str += attrs_select[i].value+",";
					}
				}
				attr_str = attr_str.substr(0,attr_str.length-1);				
			}
		}
		var number = 1;
		if(document.getElementById("number"))
		{
			var num = document.getElementById("number").value;
			if(isNaN(num)) {alert(IS_NAN);return;}			
			number = parseInt(num)<0?0:num;
		}
		$.ajax({
			  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=addGoodsToCart&is_ajax=1&rec_module=ScoreGoods&rec_id="+spec_item_id+"&attr_str="+attr_str+"&number="+number+"&goods_id="+id,
			  cache: false,
			  success:function (html){

			 		var rs = $.evalJSON(html);
			 		if(rs.status==0)
			 		{
			 			alert(rs.info);
			 		}
			 		else
			 		{
			 			location.href= ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=listCart";
			 		}			 		
				}
			});
	}
}

//地区切换
function selectRegion(obj,region_id,lvl)
{
	var id=obj.value;
	$.ajax({
		  url: APP+"?"+VAR_MODULE+"=Ajax&"+VAR_ACTION+"=getChildRegion&is_ajax=1&pid="+id,
		  success:function(data)
		  {
			data = $.evalJSON(data); 
			var origin_html = "<option value='0'>"+NO_SELECT+"</option>";
			switch(lvl)
			{				
				case 1:	
					html = origin_html;
					if(data)
					for(var i=0;i<data.length;i++)
					{
						html+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
					}
					if(id==0) html = origin_html;  //当未作选择时清空
					$("#region_lv2_"+region_id).html(html);
					$("#region_lv3_"+region_id).html(origin_html);
					$("#region_lv4_"+region_id).html(origin_html);
					break;
				case 2:
					html = origin_html;
					if(data)
					for(var i=0;i<data.length;i++)
					{
						html+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
					}
					if(id==0) html = origin_html;  //当未作选择时清空
					$("#region_lv3_"+region_id).html(html);
					$("#region_lv4_"+region_id).html(origin_html);
					break;
				case 3:
					html = origin_html;
					if(data)
					for(var i=0;i<data.length;i++)
					{
						html+="<option value='"+data[i].id+"'>"+data[i].name+"</option>";
					}
					if(id==0) html = origin_html;  //当未作选择时清空
					$("#region_lv4_"+region_id).html(html);
					break;
			}
		  }
		}); 
}



function selectRegionDelivery(obj,region_id,lvl)
{
	var id=obj.value;
	var origin_html = "<option value='0'>"+NO_SELECT+"</option>";
	html = origin_html;
	switch(lvl)
	{				
		case 1:	
			if(id > 0)
			{
				var evalStr="regionConf.r"+id+".c";
				var regionConfs=eval(evalStr);
				evalStr+=".";
				for(var key in regionConfs)
				{
					html+="<option value='"+eval(evalStr+key+".i")+"'>"+eval(evalStr+key+".n")+"</option>";
				}
			}

			$("#region_lv2_"+region_id).html(html);
			$("#region_lv3_"+region_id).html(origin_html);
			$("#region_lv4_"+region_id).html(origin_html);
			break;
		case 2:
			if(id > 0)
			{
				var evalStr="regionConf.r"+$("#region_lv1_"+region_id).val()+".c.r"+id+".c";
				var regionConfs=eval(evalStr);
				evalStr+=".";
				for(var key in regionConfs)
				{
					html+="<option value='"+eval(evalStr+key+".i")+"'>"+eval(evalStr+key+".n")+"</option>";
				}
			}
			
			$("#region_lv3_"+region_id).html(html);
			$("#region_lv4_"+region_id).html(origin_html);
			break;
		case 3:
			if(id > 0)
			{
				var evalStr="regionConf.r"+$("#region_lv1_"+region_id).val()+".c.r"+$("#region_lv2_"+region_id).val()+".c.r"+id+".c";
				var regionConfs=eval(evalStr);
				evalStr+=".";
				for(var key in regionConfs)
				{
					html+="<option value='"+eval(evalStr+key+".i")+"'>"+eval(evalStr+key+".n")+"</option>";
				}
			}
			
			$("#region_lv4_"+region_id).html(html);
			break;
	}
	
	loadDelivery();
}

//读取配送方式
function loadDelivery()
{
	var id = 0;
	if(parseInt($("#region_lv4_0").val())>0)
	{
		id = parseInt($("#region_lv4_0").val());
	}
	else if(parseInt($("#region_lv3_0").val())>0)
	{
		id = parseInt($("#region_lv3_0").val());
	}
	else if(parseInt($("#region_lv2_0").val())>0)
	{
		id = parseInt($("#region_lv2_0").val());
	}
	else if(parseInt($("#region_lv1_0").val())>0)
	{
		id = parseInt($("#region_lv1_0").val());
	}

	$.ajax({
		  url: APP+"?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=loadDelivery&id="+id,
		  cache: false,
		  success:function(data)
		  {
		  	$("#cart_delivery").html(data);
			$("#cart_total_box").html("");
		  }
		});
	
}

//切换配送方式
function sw_input(obj)
{
	$("#delivery_list").find(".protect").attr("disabled",true);
	$("#delivery_list").find(".protect").attr("checked",false);
	if(obj.checked)
       $(obj.parentNode.parentNode).find("input").attr("disabled",false);
	
	//开始获取货到付款是否允许
	var id = 0;  //地区ID
	if(parseInt($("#region_lv4_0").val())>0)
	{
		id = parseInt($("#region_lv4_0").val());
	}
	else if(parseInt($("#region_lv3_0").val())>0)
	{
		id = parseInt($("#region_lv3_0").val());
	}
	else if(parseInt($("#region_lv2_0").val())>0)
	{
		id = parseInt($("#region_lv2_0").val());
	}
	else if(parseInt($("#region_lv1_0").val())>0)
	{
		id = parseInt($("#region_lv1_0").val());
	}

	if(id>0)
	$.ajax({
		  url: APP+"?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=checkCod&region_id="+id+"&delivery_id="+obj.value,
		  cache: false,
		  success:function(data)
		  {
			 if(data==1)
			 {
			 	$("#payment_Cod").show();
			 }
			 else
			 {
			 	$("#payment_Cod").hide();
			 }
			 countCartTotal();	
		  }
		}); 
	
}

function del_consignee(id)
{
	if(confirm(CONFIRM_DELETE))
	location.href = APP+"?"+VAR_MODULE+"=UcConsignee&"+VAR_ACTION+"=delete&id="+id;
}

function cal_price()
{
	
	var spec_type_specs = $(".spec_type_input");
	
	var str = '';
	
	for(var i=0;i<spec_type_specs.length;i++)
	{
		var btns = $(spec_type_specs[i].parentNode).find("a");
		for(var j=0;j<btns.length;j++)
		{
			
			if(btns[j].id == "spec_item_"+spec_type_specs[i].value)
			{
				$(btns[j]).addClass("act");
			}
			else
			{
				$(btns[j]).removeClass("act");
			}

		}
		
		type_id_arr = (spec_type_specs[i].id).split("_");
		type_id = type_id_arr[1];
		str = str + type_id+"_" + spec_type_specs[i].value + ",";
	}
	str = str.substr(0,str.length-1);
	var goods_id = $("#goods_id").val();
	var num = $("#number").val();
	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Goods&"+VAR_ACTION+"=getSpecItem&goods_id="+goods_id+"&str="+str+"&num="+num,
		  cache: false,
		  success: function(html){
								 		var rs = $.evalJSON(html);
										if(rs.sn!='')
								 		$("#sn").html(rs.sn);
								 		$("#weight").html(rs.weight_format);								 		
								 		$("#shop_price").html(rs.shop_price_format);
								 		$("#member_price").html(rs.member_price_format);
								 		$("#total_price").html(rs.total_price_format);
								 		$("#stock").html(rs.stock);	 	
										$("#spec_item").val(rs.spec_item_id);
								 		$("#spec_choose").html(rs.choose_msg);
										
								 		if(rs.status)
										{
											$("#buy_button").attr("disabled",false);
											$("#buy_button").attr("class","btn_buy");
											$("#total_price").html(rs.total_price_format);
										}
										else
										{
											$("#buy_button").attr("disabled",true);
											$("#buy_button").attr("class","btn_buy_disable");
											$("#total_price").html("");
										}
								
		  
		  }
		});
	
	
}

function cal_score()
{
	
	var spec_type_specs = $(".spec_type_input");
	
	var str = '';
	
	for(var i=0;i<spec_type_specs.length;i++)
	{
		var btns = $(spec_type_specs[i].parentNode).find("a");
		for(var j=0;j<btns.length;j++)
		{
			
			if(btns[j].id == "spec_item_"+spec_type_specs[i].value)
			{
				$(btns[j]).addClass("act");
			}
			else
			{
				$(btns[j]).removeClass("act");
			}

		}
		
		type_id_arr = (spec_type_specs[i].id).split("_");
		type_id = type_id_arr[1];
		str = str + type_id+"_" + spec_type_specs[i].value + ",";
	}
	str = str.substr(0,str.length-1);
	var goods_id = $("#goods_id").val();
	var num = $("#number").val();
	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=ScoreGoods&"+VAR_ACTION+"=getSpecItem&goods_id="+goods_id+"&str="+str+"&num="+num,
		  cache: false,
		  success:function (html){
				var rs = $.evalJSON(html);
				if(rs.sn!='')
				$("#sn").html(rs.sn);
				$("#weight").html(rs.weight_format);
				$("#stock").html(rs.stock);	
				$("#total_score").html(rs.total_score_format);		
				$("#spec_item").val(rs.spec_item_id);
				$("#spec_choose").html(rs.choose_msg);	
				if(rs.status)
				{
					$("#buy_button").attr("disabled",false);
					$("#buy_button").attr("class","btn_buy");
					$("#total_score").html(rs.total_price_format);
				}
				else
				{
					$("#buy_button").attr("disabled",true);
					$("#buy_button").attr("class","btn_buy_disable");
					$("#total_score").html("");
				}
			}
		});
	
	
}

// 开始规格的相关脚本
function setSpec(spec_id,obj)
{
	if (obj.className == 'act') {
		$(obj.parentNode).find(".spec_type_input").val(0);
	}
	else {
		$(obj.parentNode).find(".spec_type_input").val(spec_id);
	}
	cal_price();
}

//开始规格的相关脚本
function setSpecScore(spec_id,obj)
{
	if (obj.className == 'act') {
		$(obj.parentNode).find(".spec_type_input").val(0);
	}
	else {
		$(obj.parentNode).find(".spec_type_input").val(spec_id);
	}
	cal_score();
}
function getPwdQuestion()
{
	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=User&"+VAR_ACTION+"=getPwdQuestion&username="+$("#user_name").val(),
		  cache: false,
		  success:function (html){
				$("#pwd_question").html(html);				
			}
		});
}

//礼品选取
function choose_gift(goods_id,obj)
{
	var spec_item_id = $(obj.parentNode).find(".spec_item").val();
	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Goods&"+VAR_ACTION+"=getGiftSpec&goods_id="+goods_id+"&spec_item_id="+spec_item_id,
		  cache: false,
		  success:function (html){	
		  			if (html != '') 
					{
						$(obj.parentNode).find(".spec_box").fadeIn();
						$(obj.parentNode).find(".spec_box").html(html);
					}
					else
					{
						$.ajax({
						  type: "POST", 	
						  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Goods&"+VAR_ACTION+"=getGiftSpecItem&goods_id="+goods_id+"&str=",
						  cache: false,
						  success:function (html){	
								var res = $.evalJSON(html);
								if(res.status)
								{
									$(obj.parentNode).find(".spec_item").val(res['id']);
									$(obj.parentNode).find(".spec_item").attr('checked',true);
								}
								else
								{
									alert(res['info']);
								}
							}	  
						});
					}
				}	  
		});
}
function setGiftSpec(spec_id,obj)
{
	$(obj.parentNode).find(".spec_type_input").val(spec_id);
	var spec_type_specs = $(".spec_type_input");

	for(var i=0;i<spec_type_specs.length;i++)
	{
		var btns = $(spec_type_specs[i].parentNode).find("a");
		for(var j=0;j<btns.length;j++)
		{
			
			if(btns[j].id == "spec_item_"+spec_type_specs[i].value)
			{
				$(btns[j]).addClass("act");
			}
			else
			{
				$(btns[j]).removeClass("act");
			}

		}
	}
}
function confirmGiftSpec(goods_id,obj)
{
	var spec_type_input = $(obj.parentNode.parentNode).find(".spec_type_row").find(".spec_type_input");
	var spec_conf_str = '';
	for(var i=0;i<spec_type_input.length;i++)
	{
		var spec_type_id = spec_type_input[i].id;
		spec_type_id = spec_type_id.split("_");
		spec_type_id = spec_type_id[1];
		spec_conf_str+=spec_type_id+"_"+spec_type_input[i].value+",";
	}
	spec_conf_str = spec_conf_str.substr(0,spec_conf_str.length-1);

	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Goods&"+VAR_ACTION+"=getGiftSpecItem&goods_id="+goods_id+"&str="+spec_conf_str,
		  cache: false,
		  success:function (html){	
				var res = $.evalJSON(html);
				if(res.status)
				{
					$(obj.parentNode.parentNode.parentNode).find(".spec_item").val(res['id']);
					$(obj.parentNode.parentNode.parentNode).find(".spec_item").attr('checked',true);
					$(obj.parentNode.parentNode).hide();
				}
				else
				{
					alert(res['info']);
				}
			}	  
		});

}
function cancelGiftSpec(obj)
{
	$(obj.parentNode.parentNode).fadeOut();
}
function cancel_gift(goods_id,obj)
{
	$(obj.parentNode).find(".spec_box").html("");
	$(obj.parentNode).find(".spec_item").val(0);
	$(obj.parentNode).find(".spec_item").attr('checked',false);
}

/**
 * 
 * 添加赠品
 */
function addGift(obj,promote_id)
{
	var cbos = $.find(".spec_item_"+promote_id);

	var spec_item_id = "";
	for(var i=0;i<cbos.length;i++)
	{
		if(cbos[i].checked)
		{
			spec_item_id+=cbos[i].value+",";
		}
	}
	if(spec_item_id.length>0)
	spec_item_id = spec_item_id.substr(0,spec_item_id.length-1);
	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=addGift&spec_item_ids="+spec_item_id+"&promote_id="+promote_id,
		  cache: false,
		  success:function (html){	
				if(html!='')
				{
					$("#cart_promote_goods_list").html(html);
				}
			}	  
		});
}
//使用优惠券
function useCard(obj)
{
	var card_code = $("#promote_card").val();
	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=useCard&card_code="+card_code,
		  cache: false,
		  success:function (html){	
				if(html!='')
				{
					var rs = $.evalJSON(html);
					if(rs.status==0)
					{
						alert(rs.info);
					}
					else
					{
						location.href = location.href;
					}
				}
				
			}	  
		});
}

//计算订单中所有费用
function countCartTotal()
{
	var delivery_id = 0;  //配送方式
	var payment_id =  0;   //支付方式
	var is_protect =  0;    //是否保价
	var region_lv1 = $("#region_lv1_0").val();   //一级地区
	var region_lv2 = $("#region_lv2_0").val();   //二级地区
	var region_lv3 = $("#region_lv3_0").val();   //三级地区
	var region_lv4 = $("#region_lv4_0").val();   //四级地区
	
	var tax = $("#tax").attr("checked")?1:0;
	
	//读取配送ID
	var delivery_cbos = $.find(".delivery_cbo");  
	for(var i=0;i<delivery_cbos.length;i++)
	{
		if(delivery_cbos[i].checked)
		{
			delivery_id = delivery_cbos[i].value;
			break;
		}
	}	
	
	//读取支付ID
	var payment_cbos = $.find(".payment_cbo");  
	for(var i=0;i<payment_cbos.length;i++)
	{
		if(payment_cbos[i].checked)
		{
			payment_id = payment_cbos[i].value;
			break;
		}
	}
	
	//读取保价
	var protect_cbo = $.find(".protect");  
	for(var i=0;i<protect_cbo.length;i++)
	{
		if(protect_cbo[i].checked)
		{
			is_protect = 1;
			break;
		}
	}
	
	
	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Cart&"+VAR_ACTION+"=getCartTotal&delivery_id="+delivery_id+"&payment_id="+payment_id+"&is_protect="+is_protect+"&region_lv1="+region_lv1+"&region_lv2="+region_lv2+"&region_lv3="+region_lv3+"&region_lv4="+region_lv4+"&tax="+tax,
		  cache: false,
		  success:function (html){	
				$("#cart_total_box").html(html);
				
			}	  
		});
}

//是否开票
function checkTax(obj)
{
	if(obj.checked)
	{
		
		$("#tax_content").attr("disabled",false);		
	}
	else
	{
		$("#tax_content").attr("disabled",true);
		$("#tax_content").val("");
	}
	countCartTotal();
}

function exchangeCard(card_id,msg)
{
	if(confirm(msg))
	{
		$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=UcPromoteCard&"+VAR_ACTION+"=exchange&card_id="+card_id,
		  cache: false,
		  success:function (html){	
			   var data = $.evalJSON(html);
			   if(data.status)
			   {
			   		alert(data.info);
			   }
			   else
			   {
			   		alert(data.info);
			   }
				
			}	  
		});
	}
}

function initAjaxLoader()
{
	 $("#ajax_loader").ajaxStart(function(){
	 		$(this).show();
	 }); 
	 $("#ajax_loader").ajaxStop(function(){
			$(this).hide();
	 });
}

//判断s是否为数字
function isdigit(s)
{
	//alert(typeof(s))
	if (typeof(s)=='string'){
		var r,re;
		re = /\d*/i;    //\d表示数字,*表示匹配多个数字
		r = s.match(re);
		
		return (r==s)?1:0;
	}else{
		return 0;
	}

}

//将字符串转化为数字，不是数字字符串的则返回为：0
function strToFloat(s){
	var r = parseFloat(s);
	if (isNaN(r)){
		return 0;
	}else{
		return r;
		//return round(r, precision);
	}	
}

function round(thisNumber,n){//四舍五入
	thisNumber = strToFloat(thisNumber);
	return Math.round(thisNumber*Math.pow(10,n))/Math.pow(10,n); 
}


function list_type(type)
{
	$.ajax({
		  type: "POST", 	
		  url: ROOT_PATH+"/index.php?"+VAR_MODULE+"=Ajax&"+VAR_ACTION+"=changeListType&type="+type,
		  cache: false,
		  success:function (html){	
			  location.href = location.href;				
			}	  
		});
}
