
/**
 * 收藏友情商铺
 * @param shopId
 * @return
 */
function favorStoreAction(str,shopId){
	window.location.href="/b2cMemFavorList.htm";
}
function favorCommAction(commodityId){
	window.location.href="/adminB2cMemFavorList.htm";
}
/**
 * 加载商品详细信息
 * @param infoId
 * @return
 */
function loadCommodityDetail(commodityId){
	window.location.href="meConDetail.htm?commodityId="+commodityId;
}
/**
 * 根据商铺 Id和商铺所属货架 Id查询商品信息
 * @param shopid
 * @param shelfId
 * @return
 */
function searchOnlinestoreByShopIdAndshelfId(shopid,shelfId){
	window.location.href="shopDetail.htm?shopid="+shopid+"&shelfId="+shelfId;
}

$(function(){

	var timer;
	$('.float-box').draggable();
	$('.float-box .closebtn').click(function(){
		$(this).parents('.float-box').hide();
	});
	$('#shop_adr').mouseover(function(){
		clearTimeout(timer);
		$('.float-box').hide();
		floatPos = $(this).parents('.sidebar-column').offset();
		$('#shop_detail').show().css({left:floatPos.left+200,top:floatPos.top});
	}).mouseout(function(){
		timer = setTimeout(mOut,1000);
	});
	$('#shop_level').mouseover(function(){
		clearTimeout(timer);
		$('.float-box').hide();
		floatPos = $(this).parents('.sidebar-column').offset();
		$('#shop_credit').show().css({left:floatPos.left+200,top:floatPos.top});
	}).mouseout(function(){
		timer = setTimeout(mOut,1000);
	});
	$('.float-box').hover(function(){
		clearTimeout(timer);
	},function(){
		mOut();
	});
	function mOut(){
		$('.float-box').fadeOut();
	}

	$('#glideBox').find('.glide-each').each(function(){
		$this = $(this);
		pointThis = $this.find('span.point').text();
		numThis = parseFloat(pointThis);
		star = '<img src="../images/ico_star.gif" />';
		starNo = '<img src="../images/ico_star_no.gif" />';
		starHalf = '<img src="../images/ico_star_half.gif" />';
		$this.find('img').remove();
		for(i = 1; i <= 5; i++){
			if(i <= numThis){
				$this.find('span.level').before(star);
			}else if(i > numThis && i-1 < numThis){
				$this.find('span.level').before(starHalf);
			}else if(i > numThis){
				$this.find('span.level').before(starNo);
			}
		}
		marginThis = parseInt((parseFloat(pointThis)/5)*375);
		$this.find('p.number').empty().text(pointThis).css('margin-left',marginThis + 'px');
	});

	$('.float-box1 .closebtn').click(function(){
		$(this).parents('.float-box1').hide();
	});
	$('#ask').click(function(){
		$('.float-box1').hide();
		list_pos = $('#listData').offset();
		ask_left = list_pos.left;
		ask_top = list_pos.top;
		$('#ask_to_store').show().css({left:ask_left+300,top:ask_top+500});
	});
	$('#ask2').click(function(){
		$('.float-box1').hide();
		list_pos = $('#listData').offset();
		ask_left = list_pos.left;
		ask_top = list_pos.top;
		$('#ask_to_store').show().css({left:ask_left+300,top:ask_top+600});
	});

	// 点击“立刻购买”或“放入购物车”后，所执行的验证
	function cartValidate(num,max){
		var value = parseInt($.trim(num));
		var total = parseInt($.trim(max));
		if(value==''){
			$.alert("请填写购买数量");
			return false;
		}
		else if(/^\d+$/.test(value)==false){
			$.alert("请填写整数");
			return false;
		}
		else if(value<=0)
		{
			$.alert("购买数量必须大于0");
			return false;
		}
		else if(total==0)
		{
			$.alert("抱歉，该商品当前处于缺货状态");
			return false;
		}
		else if(value>total)
		{
			$.alert("购买数量不能大于该商品数量");
			return false;
		}
		else
		{
			return true;
		}
	}
	
	/*$('#addCart').click(function(){
		var commodityId = $("#commodityId").val();
		var buynumber = $("#buynumber").val();
		var totalnumber = $('#commcount').text();
		var valRlt = cartValidate(buynumber,totalnumber);
		if(valRlt == true){
		window.location="addCart.htm?commodityId="+commodityId+"&buynumber="+buynumber;
		}
	});*/                               
	                                   
	$('#addCart').click(function(){
		var commodityId = $("#commodityId").val();
		var buynumber = $("#buynumber").val();
		var totalnumber = $('#commcount').text();
		var valRlt = cartValidate(buynumber,totalnumber);
		if(valRlt == true){
			$.post(
				$('#contentPath').val()+"/view/addCart.htm",
				{commodityId:commodityId,buynumber:buynumber},
				function(data){
					if(data=='success'){
						$.alert('商品已经成功放入购物车');
					}else{
						$.alert(data);
					}
				}
			);
		}
		return false;
	});
	
	$('#direcbuy').click(function(){
		var commodityId = $("#commodityId").val();
		var buynumber = $("#buynumber").val();
		var totalnumber = $('#commcount').text();
		var valRlt = cartValidate(buynumber,totalnumber);
		if(valRlt == true){
		window.location="directBuy.htm?commodityId="+commodityId+"&buynumber="+buynumber;
		}
	});

	$photo = $('#goods_show>div.photo-list>div.photo');
	$thumb = $('#goods_show>ul.thumbs>li');
	$thumb.each(function(i){
		$($thumb[i]).hover(function(){
			$thumb.removeClass();
			$(this).addClass('current');
			$photo.hide();
			$($photo[i]).show();
		},function(){});
	});
	$(".jqzoom").jqueryzoom({
		xzoom:250,
		yzoom:250,
		position:"right",
		preload:1
	});
});
