/*  设置点击切换行样式*/
$(document).ready(function(){ 
	$("div[@name='item']").click(function(){ //在点击后切换div_bs_的class
   	$(this).toggleClass("div_bs__");});
	$("input[@name='gms'],span[@name='ljhz']").click(function(){  //阻止点击input和获知商家也切换class
	return false;});
	
	//$('div[@name="lsj"]').prepend("零售价￥：");
	//$('.lings').prepend(":");
	//$('div[@name="pfj"]').prepend("批发价：");
	//$('span[@name="ljhz"]').prepend("查看");
	
	$('img[@name="log"]').click(function() {
   	     //
		 if(confirm("您需要登录后才能购买！点击“确定”跳转到登陆页面。点击“取消”继续浏览。")){
		 	open("logon.asp");
		 };
	}); 


//////////////--------------------------------------开始 浏览历史------------------------/////

	$(window).scroll(function(){ //滚动浏览历史框
		if($.cookie('lljl') != null){  //如果有浏览记录
		   var ttt = document.documentElement.scrollTop;
		   $("#llls").animate({ top : ttt+196 }, 5);
			var xx = document.getElementById("container").offsetLeft;  //浏览历史框
		   $("#llls").css('left',xx+796);  //显示
		 }
	})
	
	$(".llls").click(function(){ //点击某个商品后
		var link_hh = $(this).attr("id"); //获得连接货号
		var link_title = $(this).attr("title").replace(/\s/g, ''); //获得品名.replace(/\s/g,   '')
		var link_a = "<div><a target=_blank title="+link_title+" href=list.asp?hh="+link_hh+"><img src=bookpic/smallpic/"+link_hh+".jpg>"+link_title+"</a></div>"; //组合a
   	     //判断是否有重复
		 if($.cookie('lljl') == null){ //如果是第一次记录cookie
		 	$.cookie('lljl', link_a, { expires: 365 }); // 添加浏览记录到cookie
		 }else{
		 	var ys_cookie = $.cookie('lljl');  //获得原有cookie
			var arr = ys_cookie.split(",");// 分解成数组
		 
			var index = $.inArray(link_a,arr); //如果历史浏览包含当前浏览，会返回正数，否则返回-1
			if(index<0){  //如果是新记录才进行进一步操作
				
				var arr_xb = arr.length; //获得当前记录总数
				if(arr_xb >= 10){ //如果记录总数大于10
					var arr1 = arr.slice(0,9); //就保留前9记录，删掉后面的
					var arr2 = arr1.join(",");//重新组合a
					$.cookie('lljl', link_a + "," + arr2, { expires: 365 }); // 添加浏览记录到cookie
				}else{
					$.cookie('lljl', link_a + "," + ys_cookie, { expires: 365 }); // 添加浏览记录到cookie
				}
			}
					
		 }

		var lljl_html = $.cookie('lljl').replace(/,/g,''); //去掉逗号
		$("#llls_2").html(lljl_html+"<br style='clear:both;' />");  //显示
		//alert(lljl_html);
		//return false  //暂时阻止a
	});	
	if($.cookie('lljl') != null){  //如果有浏览记录
		var lljl_html = $.cookie('lljl').replace(/,/g,''); //去掉逗号
		$("#llls_2").html(lljl_html+"<br style='clear:both;' />");  //页面打开时就显示出浏览记录
	   var ttt = document.documentElement.scrollTop;
	   $("#llls").animate({ top : ttt+196 }, 5);
		var xx = document.getElementById("container").offsetLeft;  //浏览历史框
	   $("#llls").css('left',xx+796);  //显示
	}
	$("#llls_3 span").click(function(){
		$.cookie('lljl', '', { expires: -1 }); // 删除cookie//清空浏览记录
		$("#llls_2").html("已清空");
	});	
//////////////--------------------------------------结束 浏览历史------------------------/////

});

function gms_err(huohao)
{
	$("#err_"+huohao+"").html("请填写正确的商品数量");
	setTimeout(function(){$("#err_"+huohao+"").html("");},2000);
}
function gms_err2(huohao)
{
	$("#err_"+huohao+"").html("不能大于库存数量");
	setTimeout(function(){$("#err_"+huohao+"").html("");},2000);
}


function edi_sl(user_id,huohao,sl,cp_id,cp_jg,biaoqs)  //实时修改数量  用户ID，货号，购买数量，产品ID，产品价格
{
	$("#g_"+huohao+"").html("<img src='img/g.gif'>");
	//alert(user_id+huohao+sl)
	if(sl == "" || sl == 0){
		sl = 0;
		$("input[@name='xg_biaoqian_"+huohao+"']").attr('checked',0); //如果数量变成0，就取消标签的勾勾
	}
	var biaoqians = $("#biaoqian_num_"+huohao+"").html();
	$.post('edi_sl.asp',{
		user_id: user_id,
		huohao: huohao,
		sl: sl,
		cp_id: cp_id,
		cp_jg: cp_jg,
		biaoqians: biaoqians},
		function(data){
		//alert(data);//返回echo $_POST['a']+$_POST['b'];
		$(".lay2").html(""+data+"");
		$("#g_"+huohao+"").html("<img src='img/gg.gif'>");
		//根据返回的数量来修改标签选购数
		$("#biaoqian_num_"+huohao+"").html(""+parseInt(biaoqs)*parseInt(sl)+"");
		$("#biaoqian_"+huohao+"").attr("class","biaoqian_ts2").html("恭喜！您选购的"+parseInt(biaoqs)*parseInt(sl)+"枚中文标签已经放进了购物车。");
	});
}


//选购中文标签
function biaoqian_xg(user_id,huohao){
	//先查看此人购物车里是否已经至少已经有一盒了
	if($("input[@name='xg_biaoqian_"+huohao+"']").attr('checked')) //如果是勾上选购框
	{
		if($("input[@name='gms_"+huohao+"']").val() == "" || $("input[@name='gms_"+huohao+"']").val() < 1)  //如果当前还没有买
		{
			$("input[@name='xg_biaoqian_"+huohao+"']").attr("checked",0);
			$("#biaoqian_"+huohao+"").attr("class","biaoqian_ts3").html("抱歉！须先购买本品后，才能订购中文标签。").show();
		}else{
			var biaoqians = $("#biaoqian_num_"+huohao+"").html();
			$.post('biaoqian_xg.asp',{user_id: user_id,huohao: huohao,xg: "1",biaoqians: biaoqians},function(data){
				$("#biaoqian_"+huohao+"").show();
			});
		}
	}else{  //如果是取消选购框
		var biaoqians = $("#biaoqian_num_"+huohao+"").html();
		$.post('biaoqian_xg.asp',{user_id: user_id,huohao: huohao,xg: "0",biaoqians: biaoqians},function(data){
			//$("#biaoqian_"+huohao+"").show();
		});

		$("#biaoqian_qx_"+huohao+"").show();
		setTimeout(function(){$("#biaoqian_qx_"+huohao+"").fadeOut("slow");},2000);
	}
	setTimeout(function(){$("#biaoqian_"+huohao+"").fadeOut("slow");},3000);
}

function huiche(huohao)  //截获回车键并模拟Tab键
{
	if (window.event.keyCode==13) window.event.keyCode=9;
}

function jihuo(huohao)  //数量框获得焦点
{
	$("#g_"+huohao+"").html("<input style='height:20px;width:33px;' type='button' value='提交'>");
}

//立即查看批发价
document.onclick = eVclick;
function eVclick(event)
{  
	event = (event == null)?window.event:event;  
	var srcelement= event.target?event.target:event.srcElement;  
	if(srcelement.getAttribute("Author")==null){closeFloatobj(document.getElementById("floatObj"));}
}
function openFloatobj(obj,thi)
{
    var x = thi.offsetLeft;    
    var y = thi.offsetTop;    
    while(thi = thi.offsetParent)
	{
        x += thi.offsetLeft;    
        y += thi.offsetTop;    
    }
	obj.style.display = 'block';
	obj.style.left=(x+65)+"px";
	obj.style.top=(y-45)+"px";
}
function closeFloatobj(obj){obj.style.display = 'none';} 
