//初始化加载
$(document).ready(function(){
	//商品分类
	webLoadGoodsType();
	
	//加载销售排行商品
	//webLoadHotGoodsOrder();
	
	//加载商品区域分类
	//webLoadAreaTypeByYouNong();
	
	//加载商城公告
	//webLoadShopPost();
	
	//加载促销商品
	//webLoadHotGoodsList();
	
	//加载新品上市商品
	//webLoadNewGoodsList();
	
	//加载推荐商品
	//webLoadBestGoodsList();
	
	//加载休闲零嘴
	//webLoadXiuxianList();
	
	//加载农家土鸡
	//webLoadNongjiaList();
	
	//加载礼盒
	//webLoadBestGiftBag();
	
	//校验COOKIE
	checkCookie();
	//校验订单Cookie
	checkCartCookie();
});
//加载商品分类
function webLoadGoodsType(){
	$.ajax({
		url:'web.do?method=webLoadGoodsType', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
			alert("链接超时，请检查您的网络连接...");
			return;
		},
		success: function(obj){
			$('#index_goodsnavbox').html('');
			for(var i in obj){
				if(obj[i].pgoodsType == '0571buy'){
					$('#index_goodsnavbox').append('<div class="index_goodsnav_title index_nobdt"><a href="web.do?method=productList&cid=' + obj[i].goodsType + '">' + obj[i].typeName + '</a></div>');
					var div = document.createElement('div');
					var ul = document.createElement('ul');
					$(div).addClass('index_goods_txtdiv');
					for(var j in obj){
						if(obj[j].pgoodsType == obj[i].goodsType){
							var li = document.createElement('li');
							var a = document.createElement('a');
							$(a).attr('href', 'web.do?method=productList&check=true&cid=' + obj[j].goodsType);
							$(a).html(obj[j].typeName);
							$(a).attr('title', obj[j].typeName);
							$(li).append(a);
							$(ul).append(li);
						}
					}
					$(div).append(ul);
					$('#index_goodsnavbox').append(div);
				}
			}
			//分类加载完成后，再加载公告
			webLoadShopPost();
		}
	});
}

//加载销售排行商品
function webLoadHotGoodsOrder(){
	$.ajax({
		url:'web.do?method=webLoadHotGoodsOrder', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
		},
		success: function(obj){
			$('#goodsHotValue').html('');
			for(var i in obj){
				if(i == 0){
					if(obj[i].isPromote == 1){
						$('#goodsHotValue').append('<div class="index_hottop_goods"><div class="index_hottop_num"><img src="images/top_' + (parseInt(i)+1) + '.gif" border="0"/></div><div class="index_hottop_img"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '"><img src="'+ sysImagesUrl + obj[i].imagepathc + '" alt="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '" /></a></div><div class="index_hottop_intro"><a href="web.do?method=productInfo&cid='+obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice"><span class="index_ilvjian_priceValue">￥'+ FormatNumber(obj[i].promotePrice,2) +'</span></div></div></div>')
					}
					else {
						$('#goodsHotValue').append('<div class="index_hottop_goods"><div class="index_hottop_num"><img src="images/top_' + (parseInt(i)+1) + '.gif" border="0"/></div><div class="index_hottop_img"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '"><img src="'+ sysImagesUrl + obj[i].imagepathc + '" alt="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '" /></a></div><div class="index_hottop_intro"><a href="web.do?method=productInfo&cid='+obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice"><span class="index_ilvjian_priceValue">￥'+ FormatNumber(obj[i].shopPrice,2) +'</span></div></div></div>')
					}
				}
				else {
					if(obj[i].isPromote == 1){
						$('#goodsHotValue').append('<div class="index_hottop_goods"><div class="index_hottop_goodsl"><div class="index_hottop_num"><img src="images/top_' + (parseInt(i)+1) + '.gif" border="0"/></div><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsName.substring(0,7) + '</a></div><div class="index_hottop_goodsr onlyMemberPrice4 index_ilvjian_priceValue" style="padding-top:5px;">￥' + FormatNumber(obj[i].promotePrice,2) + '</div></div>');
					}
					else {
						$('#goodsHotValue').append('<div class="index_hottop_goods"><div class="index_hottop_goodsl"><div class="index_hottop_num"><img src="images/top_' + (parseInt(i)+1) + '.gif" border="0"/></div><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsName.substring(0,7) + '</a></div><div class="index_hottop_goodsr onlyMemberPrice4 index_ilvjian_priceValue" style="padding-top:5px;">￥' + FormatNumber(obj[i].shopPrice,2) + '</div></div>');
					}
				}
			}
		}
	});
}

function webLoadAreaTypeByYouNong(){
	$.ajax({
		url:'younong.do?method=webLoadAreaTypeByYouNong', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
			return;
		},
		success: function(obj){
			$('#index_goodsnavboxArea').html('');
			for(var i in obj){
				if(obj[i].pareaType == 'younong'){
					$('#index_goodsnavboxArea').append('<div class="index_goodsnav_title index_nobdt"><a href="web.do?method=productList&cid=0571buy&tid=' + obj[i].areaType + '">' + obj[i].typeName + '</a></div>');
					var div = document.createElement('div');
					var ul = document.createElement('ul');
					$(div).addClass('index_goods_txtdiv');
					for(var j in obj){
						if(obj[j].pareaType == obj[i].areaType){
							var li = document.createElement('li');
							var a = document.createElement('a');
							$(a).attr('href', 'web.do?method=productList&cid=0571buy&tid=' + obj[j].areaType);
							$(a).html(obj[j].typeName);
							$(a).attr('title', obj[j].typeName);
							$(li).append(a);
							$(ul).append(li);
						}
					}
					$(div).append(ul);
					$('#index_goodsnavboxArea').append(div);
				}
			}
			
			webLoadHotGoodsOrder();
		}
	});
}

//加载商城公告
function webLoadShopPost(){
	$.ajax({
		url:'web.do?method=webLoadShopPost', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
		},
		success: function(obj){
			$('#index_m1_noticeinfo').html('');
			for(var i in obj){
				var ul = document.createElement('ul');
				var li = document.createElement('li');
				var a = document.createElement('a');
				$(a).attr('href','web.do?method=lvjianbaInfo&cid=' + obj[i].articleguid);
				$(a).attr('title',obj[i].title);
				$(a).html(obj[i].title);
				$(li).append(a);
				$(ul).append(li);
				$(ul).addClass('index_m1_ul');
				$('#index_m1_noticeinfo').append(ul);
			}
			$('#index_m1_noticeinfo').append('<div id="index_m1_ad3"><a title="杭州龙网" href="http://www.hzagro.com" target="_blank"><img src="images/ynlogo.jpg" alt="杭州龙网" width="220" height="60" /></a></div>');
		
			//加载促销商品
			webLoadHotGoodsList();
		}
	});
}

//加载新品上市商品
function webLoadNewGoodsList(){
	$.ajax({
		url:'web.do?method=webLoadNewGoodsList', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
		},
		success: function(obj){
			$('#index_m4goods_new').html('');
			for(var i in obj){
				var div = document.createElement('div');
				$(div).addClass('index_m4tbox');
				$(div).mouseover(function (){
					$(this).attr('class','index_m4tboxbg');
				});
				$(div).mouseout(function (){
					$(this).attr('class','index_m4tbox');
				});
				if(obj[i].isPromote == 1){
					$(div).html('<div class="index_m4timg" style="position:relative;"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid +'"><img src="'+ sysImagesUrl + obj[i].imagepathb + '" border="0" alt="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"/></a><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" class="price_logo" style="background-image:url(images/priceImage.gif);"></a></div><div class="index_m4ttxt"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid + '">' + obj[i].goodsName + '<br/>' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>促销价</span> ￥' + FormatNumber(obj[i].promotePrice,2) + '</div></div></div>');
				}
				else {
					$(div).html('<div class="index_m4timg" style="position:relative;"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid +'"><img src="'+ sysImagesUrl + obj[i].imagepathb + '" border="0" alt="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"/></a></div><div class="index_m4ttxt"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid + '">' + obj[i].goodsName + '<br/>' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>本店价</span> ￥' + FormatNumber(obj[i].shopPrice,2) + '</div></div></div>');
				}
				$('#index_m4goods_new').append(div);
			}
			//加载推荐
			webLoadBestGoodsList();
		}
	});

}
//加载推荐商品
function webLoadBestGoodsList(){
	$.ajax({
		url:'web.do?method=webLoadBestGoodsList', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
		},
		success: function(obj){
			$('#index_m4goods_best').html('');
			for(var i in obj){
				var div = document.createElement('div');
				$(div).addClass('index_m4tbox');
				$(div).mouseover(function (){
					$(this).attr('class','index_m4tboxbg');
				});
				$(div).mouseout(function (){
					$(this).attr('class','index_m4tbox');
				});
				if(obj[i].isPromote == 1){
					$(div).html('<div class="index_m4timg" style="position:relative;"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid +'"><img src="'+ sysImagesUrl + obj[i].imagepathb + '" border="0" alt="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"/></a><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" class="price_logo" style="background-image:url(images/priceImage.gif);"></a></div><div class="index_m4ttxt"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid + '">' + obj[i].goodsName + '<br/>' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>促销价</span> ￥' + FormatNumber(obj[i].promotePrice,2) + '</div></div></div>');
				}
				else {
					$(div).html('<div class="index_m4timg" style="position:relative;"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid +'"><img src="'+ sysImagesUrl + obj[i].imagepathb + '" border="0" alt="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"/></a></div><div class="index_m4ttxt"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid + '">'  + obj[i].goodsName + '<br/>' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>本店价</span> ￥' + FormatNumber(obj[i].shopPrice,2) + '</div></div></div>');
				}
				$('#index_m4goods_best').append(div);
			}
			
			webLoadAreaTypeByYouNong();
			
		}
	});

}
//加载促销商品
function webLoadHotGoodsList(){
	$.ajax({
		url:'web.do?method=webLoadHotGoodsList', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
		},
		success: function(obj){
			$('#index_m4goods_hot').html('');
			for(var i in obj){
				var div = document.createElement('div');
				$(div).addClass('index_m4tbox');
				$(div).mouseover(function (){
					$(this).attr('class','index_m4tboxbg');
				});
				$(div).mouseout(function (){
					$(this).attr('class','index_m4tbox');
				});
				if(obj[i].isPromote == 1){
					$(div).html('<div class="index_m4timg" style="position:relative;"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid +'"><img src="'+ sysImagesUrl + obj[i].imagepathb + '" border="0" alt="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"/></a><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" class="price_logo" style="background-image:url(images/priceImage.gif);"></a></div><div class="index_m4ttxt"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid + '">' + obj[i].goodsName + '<br/>' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>促销价</span> ￥' + FormatNumber(obj[i].promotePrice,2) + '</div></div></div>');
				}
				else {
					$(div).html('<div class="index_m4timg" style="position:relative;"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid +'"><img src="'+ sysImagesUrl + obj[i].imagepathb + '" border="0" alt="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"/></a></div><div class="index_m4ttxt"><a href="web.do?method=productInfo&cid='+ obj[i].goodsguid + '">' + obj[i].goodsName + '<br/>' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>本店价</span> ￥' + FormatNumber(obj[i].shopPrice,2) + '</div></div></div>');
				}
				$('#index_m4goods_hot').append(div);
			}
			
			//加载新品
			webLoadNewGoodsList();
		}
	});

}

//加载休闲零嘴
function webLoadXiuxianList(){
	$.ajax({
		url:'web.do?method=webLoadGoodsByGoodsTypeList&cid=xiuxian', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
		},
		success: function(obj){
			$('#xiuxian_text1').html('');
			$('#xiuxian_text2').html('');
			$('#xiuxian_text3').html('');
			for(var i in obj){
				if(i < 4){
					var li = document.createElement('li');
					var a = document.createElement('a');
					$(a).attr('href','web.do?method=productInfo&cid=' + obj[i].goodsguid);
					$(a).attr('title', obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm);
					if(obj[i].isPromote == 1){
						$(a).html( obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].promotePrice,2) + '</span>）');
					}
					else {
						$(a).html( obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].shopPrice,2) + '</span>）');
					}
					$(li).append('&middot;');
					$(li).append(a);
					$('#xiuxian_text1').append(li);
				}
				else if(i < 8){
					if(obj[i].isPromote == 1){
						$('#xiuxian_text2').append('<div class="index_m6_probox"><div class="index_m3qimg" style="position:relative"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"><img src="' + sysImagesUrl + obj[i].imagepathb + '" alt="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '" style="width:100px;height:100px;"/></a><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" class="price_logo" style="background-image:url(images/priceImage.gif);"></a></div><div class="index_m3qtxt"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>促销价</span> ￥' + FormatNumber(obj[i].promotePrice,2) + '</div></div></div></div>')
					}
					else {
						$('#xiuxian_text2').append('<div class="index_m6_probox"><div class="index_m3qimg" style="position:relative"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"><img src="' + sysImagesUrl + obj[i].imagepathb + '" alt="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '" style="width:100px;height:100px;"/></a></div><div class="index_m3qtxt"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>本店价</span> ￥' + FormatNumber(obj[i].shopPrice,2) + '</div></div></div></div>')
					}
				}
				else {
					if(obj[i].isPromote == 1){
						$('#xiuxian_text3').append('<li>·<a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].promotePrice,2) + '</span>）</a></li>');
					}
					else {
						$('#xiuxian_text3').append('<li>·<a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].shopPrice,2) + '</span>）</a></li>');
					}
				}
			}
		}
	});
}
	
//加载农家
function webLoadNongjiaList(){
	$.ajax({
		url:'web.do?method=webLoadGoodsByGoodsTypeList&cid=nongjia', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
		},
		success: function(obj){
			$('#nongjia_text1').html('');
			$('#nongjia_text2').html('');
			$('#nongjia_text3').html('');
			for(var i in obj){
				if(i < 4){
					var li = document.createElement('li');
					var a = document.createElement('a');
					$(a).attr('href','web.do?method=productInfo&cid=' + obj[i].goodsguid);
					$(a).attr('title', obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm);
					if(obj[i].isPromote == 1){
						$(a).html(obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].promotePrice,2) + '</span>）');
					}
					else {
						$(a).html(obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].shopPrice,2) + '</span>）');
					}
					$(li).append('&middot;');
					$(li).append(a);
					$('#nongjia_text1').append(li);
				}
				else if(i < 8){
					if(obj[i].isPromote == 1){
						$('#nongjia_text2').append('<div class="index_m6_probox"><div class="index_m3qimg" style="position:relative"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" title="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"><img src="' + sysImagesUrl + obj[i].imagepathb + '" alt="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '" style="width:100px;height:100px;"/></a><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" class="price_logo" style="background-image:url(images/priceImage.gif);"></a></div><div class="index_m3qtxt"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>促销价</span> ￥' + FormatNumber(obj[i].promotePrice,2) + '</div></div></div></div>')
					}
					else {
						$('#nongjia_text2').append('<div class="index_m6_probox"><div class="index_m3qimg" style="position:relative"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" title="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"><img src="' + sysImagesUrl + obj[i].imagepathb + '" alt="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '" style="width:100px;height:100px;"/></a></div><div class="index_m3qtxt"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>本店价</span> ￥' + FormatNumber(obj[i].shopPrice,2) + '</div></div></div></div>')
					}
				}
				else {
					if(obj[i].isPromote == 1){
						$('#nongjia_text3').append('<li>·<a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].promotePrice,2) + '</span>）</a></li>');
					}
					else {
						$('#nongjia_text3').append('<li>·<a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].shopPrice,2) + '</span>）</a></li>');
					}
				}
			}
		}
	});
}
	
//加载礼盒
function webLoadBestGiftBag(){
	$.ajax({
		url:'web.do?method=webLoadGoodsByGoodsTypeList&cid=bestGiftBag', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
		},
		success: function(obj){
			$('#bestGiftBag_text1').html('');
			$('#bestGiftBag_text2').html('');
			$('#bestGiftBag_text3').html('');
			for(var i in obj){
				if(i < 4){
					var li = document.createElement('li');
					var a = document.createElement('a');
					$(a).attr('href','web.do?method=productInfo&cid=' + obj[i].goodsguid);
					$(a).attr('title', obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm);
					if(obj[i].isPromote == 1){
						$(a).html( obj[i].goodsName + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].promotePrice,2) + '</span>）');
					}
					else {
						$(a).html( obj[i].goodsName + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].shopPrice,2) + '</span>）');
					}
					$(li).append('&middot;');
					$(li).append(a);
					$('#bestGiftBag_text1').append(li);
				}
				else if(i < 8){
					if(obj[i].isPromote == 1){
						$('#bestGiftBag_text2').append('<div class="index_m6_probox"><div class="index_m3qimg" style="position:relative"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" title="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"><img src="' + sysImagesUrl + obj[i].imagepathb + '" alt="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '" style="width:100px;height:100px;"/></a><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" class="price_logo" style="background-image:url(images/priceImage.gif);"></a></div><div class="index_m3qtxt"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>促销价</span> ￥' + FormatNumber(obj[i].promotePrice,2) + '</div></div></div></div>')
					}
					else {
						$('#bestGiftBag_text2').append('<div class="index_m6_probox"><div class="index_m3qimg" style="position:relative"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid +'" title="'+ obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm +'"><img src="' + sysImagesUrl + obj[i].imagepathb + '" alt="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '" style="width:100px;height:100px;"/></a></div><div class="index_m3qtxt"><a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '</a><br /><div class="onlyMemberPrice2" style="text-align:center"><div class="index_ilvjian_priceValue"><span>本店价</span> ￥' + FormatNumber(obj[i].shopPrice,2) + '</div></div></div></div>')
					}
				}
				else {
					if(obj[i].isPromote == 1){
						$('#bestGiftBag_text3').append('<li>·<a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsName + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].promotePrice,2) + '</span>）</a></li>');
					}
					else {
						$('#bestGiftBag_text3').append('<li>·<a href="web.do?method=productInfo&cid=' + obj[i].goodsguid + '" title="' + obj[i].goodsBrand + ' ' + obj[i].goodsName + ' ' + obj[i].goodsNorm + '">' + obj[i].goodsName + '（<span class="index_ilvjian_priceValue">￥' + FormatNumber(obj[i].shopPrice,2) + '</span>）</a></li>');
					}
				}
			}
		}
	});
}


//是否可以使用COOKIE
function checkCookie(){
	$.cookie('ilvjian_web_url_info','http://www.ilvjian.com', { expires: 30 });
	if(!$.cookie('ilvjian_web_url_info')) {
		alert("您的浏览器不支持COOKIE，请先设置您的浏览器！谢谢合作！");
		return;
	}
}

//校验订单Cookie
function checkCartCookie(){
	if(!$.cookie('ilvjian_web_cart_info_order_orderguid')) {
		$.ajax({
			url:'web.do?method=getOrderInfoCheckOrderGuid', type: 'post',dataType:'json',cache: false,
			error: function(xhr){
			},
			success: function(obj){
				$.cookie('ilvjian_web_cart_info_order_orderguid', obj.guid,{expires: 30});
			}
		});
	}
	else {
		$.ajax({
			url:'web.do?method=getOrderGuidForWebCheck&cid=' + $.cookie('ilvjian_web_cart_info_order_orderguid'), type: 'post',dataType:'json',cache: false,
			error: function(xhr){
			},
			success: function(obj){
				if(!obj.flag){
					readInCookie();
				}
			}
		});
	}
}
//数据库中不存在,重新生成
function readInCookie(){
	$.ajax({
		url:'web.do?method=getOrderInfoCheckOrderGuid', type: 'post',dataType:'json',cache: false,
		error: function(xhr){
		},
		success: function(obj){
			$.cookie('ilvjian_web_cart_info_order_orderguid', obj.guid,{expires: 30});
		}
	});
}

//按价格区间
function doPriceSearchGoods(start,end){
	$('#startprice').val(start);
	$('#endprice').val(end);
	var saveOptions={
		target: '#priceForm',
		url:'web.do?method=doSearchGoods',type: 'post',dataType:'json',cache:false,
		error:function(xhr){
		},
		success: function(obj) {
			if(obj.flag){
				window.location.href = 'web.do?method=searchGoodsList';
			}
			else {
				alert(obj.returnMsg);
			}
		}
	}
	$('#priceForm').ajaxSubmit(saveOptions);
}


//--小数点格式化
/*function FormatNumber(srcStr,nAfterDot){     //nAfterDot小数位数
	var srcStr,nAfterDot;
	var resultStr,nTen;
	srcStr = ""+srcStr+"";
	strLen = srcStr.length;
	dotPos = srcStr.indexOf(".",0);
	if (dotPos == -1){
		resultStr = srcStr+".";
　　　　  for (i=0;i<nAfterDot;i++){
　　　　　	resultStr = resultStr+"0";
　　　　  }
　　　　  return resultStr;
　　  }
　　  else{
　　　	if ((strLen - dotPos - 1) >= nAfterDot){
　　　　　	nAfter = dotPos + nAfterDot + 1;
　　　　　　   nTen =1;
　　　　　　   for(j=0;j<nAfterDot;j++){
　　　　　　　　	nTen = nTen*10;
　　　　　　   }
　　　　　　   resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
　　　　　　   return resultStr;
　　　　    }
　　　　    else{
　　　　　　	resultStr = srcStr;
　　　　　　   for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
　　　　　　　		resultStr = resultStr+"0";
　　　　　　   }
　　　　　　   return resultStr;
　　　 	  }
　　	}
}
*/
function FormatNumber(s, n)
{
   n = n > 0 && n <= 20 ? n : 2;
   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
   var l = s.split(".")[0].split("").reverse(),
   r = s.split(".")[1];
   t = "";
   for(i = 0; i < l.length; i ++ )
   {
      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "" : "");
   }
   return t.split("").reverse().join("") + "." + r;
}
