//dom-drag
zIndex=5
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;
		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
		o.root.style.zIndex= ++zIndex;

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;
		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
		
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		o.root.style.zIndex= ++zIndex;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},
	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};


$(document).ready(function(){ 

	$('img[name="log"]').click(function() {
   	     //
		 if(confirm("您需要登录后才能购买！点击“确定”跳转到登陆页面。点击“取消”继续浏览。")){
		 	open("logon.asp");
		 };
	}); 
});

function gms_err(huohao)
{
	$("#"+huohao+"").html("请填写正确的商品数量");
	setTimeout(function(){$("#"+huohao+"").html("");},2000);
}

function gms_err2(huohao)
{
	$("#"+huohao+"").html("不能大于库存数量");
	setTimeout(function(){$("#"+huohao+"").html("");},2000);
}


function jihuo(huohao)  //数量框获得焦点
{
	$("#dq_kc_"+huohao+"").html("<input style='height:20px;' type='button' value='提交'>");
}




/*  设置点击切换行样式 list需要*/
$(document).ready(function(){
	$("input[name='gms'],span[name='ljhz']").click(function(){  //阻止点击input和获知商家也切换class
	return false;});
});

function edi_sl(user_id,huohao,sl,cp_id,cp_jg,biaoqs)  //实时修改数量  用户ID，货号，购买数量，产品ID，产品价格
{
	$("#dq_kc_"+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)+"枚中文标签已经放进了购物车。");
		$("#dq_kc_"+huohao+"").html("<img src='img/gg.gif'>");
	});
}

//选购中文标签
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);
}


//立即查看批发价
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';} 

