﻿window.onerror = function() {return true;};
//为STR添加函数trim
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
//request获取地址参数
function request(strName)
{
	var strHref = window.document.location.href;
	var intPos = strHref.indexOf("?");
	var strRight = strHref.substr(intPos + 1);
	var arrTmp = strRight.split("&");
	for(var i = 0; i < arrTmp.length; i++)
	{
		var arrTemp = arrTmp[i].split("=");
		if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
	}
	return "";
}
//添加事件
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 removeEvent(o,e,f)
{
	if (o.removeEventListener)
	{
		o.removeEventListener(e.replace("on"),f,false );
	}
	else if (o.detachEvent)
	{
		o.detachEvent(e,o["e"+e+f]);
		o["e"+e+f] = null;
	}
	else
	{
		var es=eval(o+"."+e);
		es=es.replace(f+";","");
		eval(o+"."+e+"=function(){"+es+";}");
	}
}
//空值判断
function IsNull(str)
{
  return (str.replace(/(^\s*)|(\s*$)/g, "")=="");
}
//邮件判断
function IsEmail(str)
{
	var reg_email =/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	return reg_email.test(str)
}
function winopen(url,n,w,h)
{
	var t=(screen.availHeight-h)/2;
	if (h==0) t=-1000;
	var l=(screen.availWidth-w)/2;
	if (w==0) w=-1000;
	var newwin=window.open(url,n,"top="+t+",left="+l+",width="+w+",height="+h+",toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no");
	if (h==0||w==0)
	{
		newwin.onload=function()
		{
			this.resizeTo(this.document.body.scrollWidth,this.document.body.scrollHeight+20);
			this.moveTo(parseInt((this.screen.availWidth-this.document.body.scrollWidth)/2),parseInt((this.screen.availHeight-this.document.body.scrollHeight)/2));
		}
	}
	newwin.focus();
	return newwin;
}
//IE PNG背景图片支持
function pngBg_load(node)//参数node是一个Node对象
{
//	if(node.nodeType != 1) return ;//检查node是否为Element对象
	if(node.nodeType == 1)
	{
		var bgImg="";
		if (node.currentStyle)
		{
			bgImg=node.currentStyle.backgroundImage;
		}
		else if (window.getComputedStyle)
		{
			bgImg=window.getComputedStyle(node,null).backgroundImage;
		}
		if (bgImg!="none" && bgImg!="")
		{
			bgImg=bgImg.substring(5,bgImg.length-2);
			if (bgImg.substring(bgImg.length-4,bgImg.length).toUpperCase()==".PNG")
			{
					//node.style.filter=
					with(node.style.filter)
					{
						src=bgImg;
						sizingMethod="crop";
						//"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\""+bgImg+"\",sizingMethod=crop);";
					}
					//node.style.filter+="progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\""+bgImg+"\",sizingMethod=crop);";
			}
		}
	}
	for(var i=0; i<node.childNodes.length; i++)//获取node的全部子节点
	{
		pngBg_load(node.childNodes[i]); //在每个子节点上进行递归操作
	}
}
//IE PNG图片支持
function png_load(img)
{
	var imgSrc = img.src.toUpperCase();
	if (imgSrc.substring(imgSrc.length-4, imgSrc.length) == ".PNG")
	{
	//方法一
	img.setAttribute("bg",img.src);
	img.style.cssText+="width:" + img.width + "px; height:" + img.height + "px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+img.getAttribute("bg")+"\',sizingMethod='scale');";
	img.src="images/null.gif";
	//方法二
//	var imgStyle=img.style.cssText ;
//	if (imgStyle.length!=0) imgStyle+=";";
//	imgStyle+=";width:" + img.width + "px; height:" + img.height + "px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+img.src+"\',sizingMethod='scale');";
//	img.src="images/null.gif";
//	img.style.cssText=imgStyle;
	}
}
//图片按比例缩放
function img_size(img)
{
	var w=img.getAttribute("w");
	var h=img.getAttribute("h");
	if (img.getAttribute("w")==null||img.getAttribute("h")==null)
	{
		w=img.width;
		h=img.height;
		img.setAttribute("w",w);
		img.setAttribute("h",h);
	}
	var image=new Image();
	image.src=img.src;
	if (img.complete)
	{
		var img_w=image.width;
		var img_h=image.height;
		if(img_w>0 && img_h>0)
		{
			if (img_w>w||img_h>h)
			{
				if(img_w/img_h>= w/h)
				{
					img.width=w;
					img.height=(img_h*w)/img_w;
				}
				else
				{
					img.height=h;
					img.width=(img_w*h)/img_h; 
				}
			}
			else
			{
				img.height=img_h;
				img.width=img_w; 
			}
		}
		else
		{
			img.src="images/null.gif";
			img.alt="this images address error";
			return false;
		}
	}
} 
//调用：<img src="图片" onload="img_size(this)">
//全部图片缩放
function img_load()
{
	var img_item=document.getElementsByTagName("img");
	var reloadPNG=false;
	if(window.ActiveXObject)		//IE 5.5<ver<7 PNG图片透明处理
	{
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])
		if ((version >= 5.5) && (version < 7) && (document.body.filters)) reloadPNG=true;
	}
	for (i=0;i<img_item.length; i++)
	{
		if (img_item[i].getAttribute("rel")=="img") img_size(img_item[i]);
		addEvent(img_item[i],"onload",function(){img_size(this)});
		if (reloadPNG)
		{
			png_load(img_item[i]);
			addEvent(img_item[i],"onload",function(){png_load(this)});
		}
	}
}
//全部input式样
function form_load()
{
	var t_obj=document.getElementsByTagName("input");
	for (var i=0; i<t_obj.length; i++)
	{
		t_obj[i].className=t_obj[i].getAttribute("type");
		addEvent(t_obj[i],"onfocus",function(){this.className=this.getAttribute("type")+"_focus"});
		addEvent(t_obj[i],"onblur",function(){this.className=this.getAttribute("type")});
		addEvent(t_obj[i],"onmouseover",function(){this.className=this.getAttribute("type")+"_focus";});
		addEvent(t_obj[i],"onmouseout",function(){if (this!=document.activeElement) this.className=this.getAttribute("type")});
	}
	t_obj=document.getElementsByTagName("textarea");
	for (var i=0; i<t_obj.length; i++)
	{
		addEvent(t_obj[i],"onfocus",function(){this.className="textarea_focus"});
		addEvent(t_obj[i],"onblur",function(){this.className=""});
		addEvent(t_obj[i],"onmouseover",function(){this.className="textarea_focus";});
		addEvent(t_obj[i],"onmouseout",function(){if (this!=document.activeElement) this.className=""});
	}
	t_obj=document.getElementsByTagName("select");
	for (var i=0; i<t_obj.length; i++)
	{
		addEvent(t_obj[i],"onfocus",function(){this.className="select_focus"});
		addEvent(t_obj[i],"onblur",function(){this.className=""});
		addEvent(t_obj[i],"onmouseover",function(){this.className="select_focus";});
		addEvent(t_obj[i],"onmouseout",function(){if (this!=document.activeElement) this.className=""});
	}
}
function a_load()
{
	var a=document.getElementsByTagName("a");
	var tempFunc;
	for (var i=0;i<a.length; i++)
	{
		tempFunc=a[i].onfocus;
		a[i].onfocus=function(){if (typeof (tempFunc) == "function"){
			try{
				tempFunc();
			} catch(e){}
		}
		this.blur();
		};
	}
}
//获取对象坐标
function Point(iX, iY){
	this.x = iX;
	this.y = iY;
}
//获取对象坐标
function GetXY(obj){
	var pt = new Point(0,0);
	var oTmp = obj;
	do {
		pt.x += oTmp.offsetLeft;
		pt.y += oTmp.offsetTop;
		oTmp = oTmp.offsetParent;
	}
	while(oTmp.tagName!="BODY");
	return pt;
}
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("a")[0].onclick=function(){
			return false;
			};
			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-35,dy=nav_y+parseInt(this.offsetHeight);
				var dx=nav_x,dy=nav_y+parseInt(this.offsetHeight);
				//计算绝对位置
				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 class_load()
{
	var menu=document.getElementById("class");
	if (!menu) return ;
	menu.style.height=menu.offsetHeight+"px";
//	if (menu_ul.length!=1) menu.style.height=menu.offsetHeight+"px";
	//FF 非IE层遮罩处理 只处理 ul内容
	if(!(window.ActiveXObject||navigator.userAgent.indexOf("Opera")!=-1))
	{
//		ulNew.replaceChild(menu_ul[0]);
		//COPY对象输出到BODY最后，设置坐标，在对象外创建父级元素div设置高度，div替换原对象
			var divNew=document.createElement("div");
			divNew.id="newClass";
		
			var menuNew=menu.cloneNode(true)
			menuNew.name="newClass";
			document.body.appendChild(menuNew);
			menu.style.position="absolute";
			//需要精确计算
			menuNew.style.left=menu.offsetLeft+"px";
			menuNew.style.top=menu.offsetTop+"px";
			menuNew.style.position="absolute";
			menuNew.style.zIndex="999";
			menuNew.style.width=menu.offsetWidth+"px";
			menuNew.style.height=menu.offsetHeight+"px";
			menuNew.style.overflow="visible";
			menu.style.position="";
			menu.style.visibility="hidden";
//			menu_ul[0].parentNode.removeChild(menu_ul[0]);
//			menu.replaceChild(divNew);
			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("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 menu=document.getElementById("class");
//	var divNew=document.getElementById("newClass");
//	alert(divNew);
//	divNew.style.left=menu.offsetLeft+"px";
//	divNew.style.top=menu.offsetTop+"px";
}
//搜索表单动作
function search_load()
{
	if (!document.forms["search"]) return false;
	var keywords=document.forms["search"].keywords;
	addEvent(keywords,"onmouseover",function(){this.focus();});
	addEvent(keywords,"onmouseout",function(){if (this!=document.activeElement) this.blur();});
	addEvent(keywords,"onfocus",function(){if (this.value==this.defaultValue) this.value="";});
	addEvent(keywords,"onblur",function(){if (this.value=="") this.value=this.defaultValue;});
	addEvent(keywords,"onchange",function(){if (this.value!=""&&this.value!=this.defaultValue) this.form.submit();});
}
//搜索表单验证
function chk_search()
{
	var keywords=document.forms["search"].keywords;
	if (!IsNull(keywords.value))
	{
		alert("请输入正确的E-mail地址！");
		keywords.focus();
		return false;
	}
}
//邮件表单动作
function mail_load()
{
	var getEmail=document.forms["getEmail"];
	if (!getEmail) return false;
	getEmail.onsubmit=function(){return chk_get();};
	var UserEmail=getEmail.UserEmail;
	addEvent(UserEmail,"onmouseover",function(){this.focus();});
	addEvent(UserEmail,"onmouseout",function(){if (this!=document.activeElement) this.blur();});
	addEvent(UserEmail,"onfocus",function(){if (this.value==this.defaultValue) this.value="";});
	addEvent(UserEmail,"onblur",function(){if (this.value=="") this.value=this.defaultValue;});
}
//邮件表单验证
function chk_get()
{
	var UserEmail=document.forms["getEmail"].UserEmail;
	if (!IsEmail(UserEmail.value))
	{
		alert("please input your E-mail");
		UserEmail.focus();
		return false;
	}
}
//登陆表单动作
function login_load()
{
	var login=document.forms["login"];
	if (login)
	{
		login.onsubmit=function(){return checkLogin();};
	}
	var SafeKey=document.getElementsByName("SafeKey");
	for (i=0; i<SafeKey.length; i++)
	{
		if (SafeKey[i].tagName=="IMG")
		{
			SafeKey[i].onclick=function()
			{
				this.style.cursor="pointer";
				this.src=this.src+"?t="+Math.random();
			};
		}
	}
}
//登陆表单验证
function checkLogin()
{
	var login=document.forms["login"];
	if(IsNull(login.userid.value))
	{
		login.userid.focus();
		alert("please input user ID!");
		return false;
	}
	if(IsNull(login.password.value))
	{
		login.password.focus();
		alert("please input password!");
		return false;
	}
	if(IsNull(login.safeKey.value))
	{
		login.safeKey.focus();
		alert("please input code");
		return false;
	}
}
//购物车，定单商品图片显示
function pShow()
{
	var as=document.getElementsByName("pShow");
//	alert(as.length);
	var pS=new imgShow(this.rel);
	for (i=0; i<as.length; i++)
	{
		if (as[i].tagName=="A"&&as[i].getAttribute("rel")!="")
		{
			//onmousemove事件发生在onmouseover之前
//			as[i].onmouseover=function()
//			{
//				pS.show(this.rel);
//			};
			as[i].style.display="block";
			as[i].onmousemove=function(e)
			{
				pS.show(this.rel);
				pS.move(e);
			}
			as[i].onmouseout=function()
			{
				pS.hidden();
			};
		}
	}
}
function imgShow(img)
{
	this.Div=document.createElement("div");
	document.body.appendChild(this.Div);
	this.Div.style.position="absolute";
	this.Div.style.left="0px";
	this.Div.style.top="0px";
	this.Div.style.zIndex="500";
	this.Div.style.backgroundColor="#FFFFFF";
	this.Div.style.border="1px solid #CCCCCC";
	this.Div.style.visibility="hidden";
	this.Img=document.createElement("img");
	this.Div.appendChild(this.Img);
	if(!document.all) document.captureEvents(Event.MOUSEMOVE);
	this.move=function(e)
	{
		e = e||window.event;
		var x,y;
		//方法一
//		if(!document.all)
//		{
//			x=event.pageX; 
//			y=event.pageY;
//		}
//		else
//		{
//			x=document.documentElement.scrollLeft+event.clientX;
//			y=document.documentElement.scrollTop+event.clientY; 
//		}
		//方法二
		x=document.documentElement.scrollLeft+e.clientX;
		y=document.documentElement.scrollTop+e.clientY; 
		this.Div.style.left=x+"px";
		this.Div.style.top=y+"px";
//		window.status="在整个页面中的X, Y坐标 : ("+x+", "+y+") ;"
	};
	this.show=function(img)
	{
		this.Img.src=img;
		this.Img.width="200";
		this.Img.height="200";
		this.Div.style.visibility="visible";
	}
	this.hidden=function()
	{
		this.Div.style.visibility="hidden";
//		document.body.removeChild(this.Div);
	}
}
function setPimg(v)
{
	var Pimg=document.getElementById("prodImage");
//	alert(Pimg.offsetWidth);
//	var PDisplay=(Pimg.offsetWidth!=0)?"block":"none";
//	Pimg.style.display="none";
	Pimg.src = v;
//	Pimg.style.display="block";
	return false;
}
//拉条式样
if(window.ActiveXObject)
{
	document.writeln("<style type=\"text/css\" />");
	document.writeln("html,body { ");
	document.writeln("	scrollbar-face-color:  #ffffff; ");			///立体滚动条的颜色
	document.writeln("	SCROLLBAR-HIGHLIGHT-COLOR: #acacac; ");	//滚动条空白部分的颜色
	document.writeln("	SCROLLBAR-SHADOW-COLOR: #acacac; ");		//立体滚动条阴影的颜色
	document.writeln("	SCROLLBAR-3DLIGHT-COLOR: #ffffff; ");		//立体滚动条亮边的颜色
	document.writeln("	SCROLLBAR-ARROW-COLOR: black; ");				//三角箭头的颜色
	document.writeln("	SCROLLBAR-TRACK-COLOR: #f8f8f8;");			//立体滚动条背景颜色
	document.writeln("	scrollbar-darkshadow-color: #666666;");	//立体滚动条强阴影的颜色
	document.writeln("	scrollbar-base-color: #acacac;");				//滚动条的基本颜色
	document.writeln("}");
	document.writeln("</style>");
}
addEvent(window,"onload",a_load);
//addEvent(window,"onload",png_load);
addEvent(window,"onload",img_load);
//addEvent(window,"onload",function(){pngBg_load(document);});
addEvent(window,"onload",form_load);
addEvent(window,"onload",mail_load);
addEvent(window,"onload",login_load);
addEvent(window,"onload",search_load);
addEvent(window,"onload",class_load);
addEvent(window,"onload",pShow);
//addEvent(window,"onload",nav_load);
