function winopen(url,w,h)
{
	var t=(screen.availHeight-h)/2;
	var l=(screen.availWidth-w)/2;
	var newwin=window.open(url,"","top="+t+",left="+l+",width="+w+",height="+h+",toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no");
	newwin.focus();  
}
//分页连接处理脚本
function PageLink()
{
	var pForm=document.getElementsByName("page_form");
	for (i=0; i<pForm.length; i++)
	{
		var pa=pForm[i].getElementsByTagName("a");
		for (var ii=0; ii<pa.length; ii++)
		{
			if (pa[ii].href!="")
			{
				pa[ii].onclick=function()
				{
					var f=this.parentNode;
					while (f.tagName!="FORM")
					{
						f=f.parentNode;
					}
					f.action=this.href;
					f.submit();
//					void(0);
					event.returnValue=false;
				};
			}
		}
	}
}
//添加事件
function addEvent(o,e,f)
{
	if (o.addEventListener)
	{
		o.addEventListener(e.substr(2,e.length-2),f,false);
	}
	else if (o.attachEvent)
	{
		o["e"+e+f] = f;
		o.attachEvent(e,function(){o["e"+e+f]();});
	}
	else
	{
		var es=eval(o+"."+e);
		es=es+f+";";
		eval(o+"."+e+"=function(){"+es+";}");
	}
}
function chk_search(fm)
{
	if (fm.search_key.value=="")
	{
		alert("Please fill search keywords");
		fm.search_key.focus();
		return false;
	}
	else
	{
		fm.submit();
		return true;
	}
}
function ck_buy(w,h)
{
	var pnum  = document.getElementById("num").value;
	var psize = document.getElementById("size").options[document.getElementById("size").selectedIndex].value;
	var pcolor= document.getElementById("color").options[document.getElementById("color").selectedIndex].value;
	var id = document.getElementById("id").value;
	if (pnum==""||isNaN(pnum))
	{
		alert("QUANTITY ERROR!");
		document.getElementById("id").focus;
	}
	var t=(screen.availHeight-h)/2;
	var l=(screen.availWidth-w)/2;
	var newwin=window.open("shopcar.asp?id="+id+"&num="+pnum+"&size="+psize+"&color="+pcolor,"shopcart","top="+t+",left="+l+",width="+w+",height="+h+",toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no");
	newwin.focus();
}
function move()
{
	var speed=2; //速度数值越大速度越慢
	var d_0=document.getElementById("o_list");
	var d_ul=d_0.getElementsByTagName("ul")[0];
	while (d_0.offsetHeight<d_0.offsetHeight)
	{
		d_ul.innerHTML+=d_ul.innerHTML;
	}
	var MyMar=setInterval(dmove,speed);
	d_ul.onmouseover=function() {clearInterval(MyMar)}
	d_ul.onmouseout=function() {MyMar=setInterval(dmove,speed)}
}
function dmove()
{
	if(d_2.offsetHeight-d_0.scrollTop<=0)
	{	d_0.scrollTop-=d_1.offsetHeight;	}
	else
	{	d_0.scrollTop++;	}
}
//分类
function ClassLoad()
{
	var menu=document.getElementById("class");
	if (!menu) return ;
	menu.style.height=menu.offsetHeight+"px";
//非IE层遮罩处理
//	if(!(window.ActiveXObject||navigator.userAgent.indexOf("Opera")!=-1))
//	{
		//COPY对象输出到BODY最后，设置坐标，在对象外创建父级元素div设置高度，div替换原对象
			menu.setAttribute("name","class");		//FF不支持DIV的NAME设置
			var menuNew=menu.cloneNode(true)
			menuNew.setAttribute("name","class");
			if(window.ActiveXObject)
			{
				menu.name="class";
				menuNew.name="class";
			}
			document.body.appendChild(menuNew);
			//需要精确计算
			menuNew.style.position="absolute";
			menuNew.style.zIndex="999";
			menuNew.style.overflow="visible";
			menuNew.style.width=menu.offsetWidth+"px";
			menuNew.style.height=menu.offsetHeight+"px";
			menu.style.position="absolute";
			var h1=menuNew.getElementsByTagName("h1")[0];
			document.getElementById("search").getElementsByTagName("h1")[0].inerText=h1.inerText;
			h1.style.display="none";
//			h1.style.display="block";
			menuNew.style.left=menu.offsetLeft+"px";
			menuNew.style.top=menu.offsetTop-h1.offsetHeight+"px";
			menu.style.position="relative";
			menu.style.visibility="hidden";
			menu=menuNew;
			addEvent(window,"onresize",class_size);
//	}
	var menu_ul=menu.getElementsByTagName("ul");
	for (i=0; i<menu_ul.length; i++)
	{
		menu_ul[i].style.position="absolute";
		menu_ul[i].style.zIndex="999";
//	menu_ul[i].style.overflow="visible";
//	切记不能设置 ul overflow: hidden;
	}
	var menu_item=menu.getElementsByTagName("li");
	for (i=0; i<menu_item.length; i++)
	{
		if (menu_item[i].getElementsByTagName("ul").length!=0)
		{
			menu_item[i].onmouseover=function()
			{
				var nav_x=parseInt(this.offsetLeft)+parseInt(this.offsetWidth);
				var nav_y=parseInt(this.offsetTop);
				this.getElementsByTagName("li")[0].className="head";
				this.getElementsByTagName("a")[0].className="ed";
//				this.getElementsByTagName("ul")[0].style.visibility="hidden";
				this.getElementsByTagName("ul")[0].style.visibility="visible";
				this.getElementsByTagName("ul")[0].style.left=nav_x+"px";
				this.getElementsByTagName("ul")[0].style.top=nav_y+"px";
			};
			menu_item[i].onmouseout=function()
			{
				this.getElementsByTagName("a")[0].className="";
				this.getElementsByTagName("ul")[0].style.visibility="hidden";
			};
		}
	}
}
function class_size()
{
	var oldMenu=document.getElementsByName("class")[0];
	var newMenu=document.getElementsByName("class")[1];
	oldMenu.style.overflow="visible";
	oldMenu.style.position="absolute";
	var h1=newMenu.getElementsByTagName("h1")[0];
	document.getElementById("search").getElementsByTagName("h1")[0].inerText=h1.inerText;
	h1.style.display="none";
	h1.style.display="block";
	newMenu.style.top=oldMenu.offsetTop-h1.offsetHeight+"px";
	newMenu.style.left=oldMenu.offsetLeft+"px";
	oldMenu.style.visibility="hidden";
	oldMenu.style.position="relative";
}
function nav_load()
{
	var nav=document.getElementById("nav");
	var nav_ul=nav.getElementsByTagName("ul");
	var nav_li=nav.getElementsByTagName("li");
	var nav_x=parseInt(document.body.offsetLeft);
	var nav_y=parseInt(document.body.offsetTop);
	for (i=0; i<nav_li.length; i++)
	{
		if (nav_li[i].getElementsByTagName("ul").length!=0)
		{
			nav_li[i].getElementsByTagName("ul")[0].style.display="none";
			nav_li[i].getElementsByTagName("ul")[0].style.visibility="hidden";
			nav_li[i].onmouseover=function()
			{
				var dx=nav_x+parseInt(this.offsetWidth)-1,dy=nav_y-1;	//1/2为边框
				//计算绝对位置
				var oTmp=this;
				do
				{
					dx += parseInt(oTmp.offsetLeft);
					dy += parseInt(oTmp.offsetTop);
					oTmp = oTmp.offsetParent;
				}
				while(oTmp.tagName!="BODY"&&oTmp.tagName!="HTML");
				this.getElementsByTagName("li")[0].className="ed";
				this.getElementsByTagName("ul")[0].style.display="block";
				this.getElementsByTagName("ul")[0].style.position="absolute";
				this.getElementsByTagName("ul")[0].style.visibility="visible";
				this.getElementsByTagName("ul")[0].style.left=dx+"px";
				this.getElementsByTagName("ul")[0].style.top=dy+"px";
			};
			nav_li[i].onmouseout=function()
			{
				this.getElementsByTagName("ul")[0].style.visibility="hidden";
				this.getElementsByTagName("ul")[0].style.display="none";
			};
		}
	}
}
//清除绝对定位导致的左边高度问题
function leftHeight()
{
	var div=document.getElementById("class");
	if (!div) div=document.getElementById("left_nav");
	if (!div) return;
	var h1=div.getElementsByTagName("h1")[0];
	document.getElementById("search").getElementsByTagName("h1")[0].innerHTML=div.getElementsByTagName("h1")[0].innerText;
	div.getElementsByTagName("h1")[0].style.display="none";
}
function noSave()
{
	window.onbeforeprint=function(){window.document.body.style.display="none"}		//禁止打印
	document.onpaste=function(){window.event.returnValue=false};					//禁止粘贴
	document.oncopy=function(){document.selection.empty()};							//禁止复制
	document.oncut=function(){window.event.returnValue=false};						//禁止剪切
	//禁止点击非连接
	//document.ondblclick	//双击
/*	document.onclick=function()
	{
		event.returnValue=false;
		var tagname=event.srcElement.tagName.toLowerCase();
		if(tagname=="a"||tagname=="img"||tagname=="area"||tagname=="input")			//允许点击对象
		{
			event.returnValue=true;
		}
	} ;*/
	if (top.location != self.location){ top.location=self.location;}				//防止被frame
	window.ClearEvent=function()
	{
		event.cancelBubble=false;
		var tagname=event.srcElement.tagName.toLowerCase();
		return (tagname=="textarea" || tagname=="input" || tagname=="select");		//允许表单使用右键菜单/选择/鼠标拖动
	};
	window.ClearKey=function()	//78=n 禁止新建本页 8退格删除键 116=F5 82=r
	{
		event.cancelBubble=false;
		var iKeyCode=event.keyCode;
		var tagname=event.srcElement.tagName.toLowerCase();
		if (tagname!="textarea" && tagname!="input")
		{
			return !((iKeyCode==78 && event.ctrlKey)||(iKeyCode==8)||(iKeyCode==82 && event.ctrlKey));
		}
	};
	if (window.attachEvent)
	{
		document.attachEvent("oncontextmenu",window.ClearEvent);	//禁止右键
		document.attachEvent("onselectstart",window.ClearEvent);	//禁止选择
		document.attachEvent("ondragstart",window.ClearEvent);		//鼠标拖动
		document.attachEvent("onkeydown",window.ClearKey);			//禁止点击非连接
	}
	else
	{
		document.addEventListener("contextmenu",window.ClearEvent,false);
		document.addEventListener("selectstart",window.ClearEvent,false);
		document.addEventListener("dragstart",window.ClearEvent,false);
		document.addEventListener("keydown",window.ClearKey,false);
	}
}
addEvent(window,"onload",leftHeight);
//addEvent(window,"onload",ClassLoad);
addEvent(window,"onload",noSave);