var lie = !+'\v1'; //判断浏览器
var _$ = function(id,pareid){return typeof pareid == "undefined" ? (typeof id == "string" ? document.getElementById(id) : id) : (typeof pareid == "string" ? (typeof id == "string" ? eval("document.getElementById('"+pareid+"')."+id) : id) : (typeof id == "string" ? eval(pareid+"."+id) : id))} //Firefox必须有id值
var _$name = function(id,pareid){return typeof pareid == "undefined" ? document.getElementsByName(id) : (typeof pareid == "string" ? _$(pareid).getElementsByName(id) : pareid.getElementsByName(id))} //获取Name对象
var _$tag = function(id,pareid){return typeof pareid == "undefined" ? document.getElementsByTagName(id) : _$(pareid).getElementsByTagName(id)} //通过Tag获取对象
var _$inhtml = function(id,value){typeof id == "string" ? _$(id).innerHTML = value : id.innerHTML = value}
var _$intext = function(id,value){typeof id == "string" ? _$(id).innerText = value : id.innerText = value}
var _$value = function(id,value){typeof id == "string" ? _$(id).value = value : id.value = value}
var _$db = function(id,pareid){typeof pareid == "undefined" ? _$(id).disabled = true : eval("_$('"+id+"','"+pareid+"').disabled = true")} //锁定按钮
String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g,"")} //清除前后空格
Number.prototype.toFixed = function(d){
var s=this+"";if(!d)d=0;
if(s.indexOf(".")==-1)s+=".";s+=new Array(d+1).join("0");
if(new RegExp("^(-|\\+)?(\\d+(\\.\\d{0,"+ (d+1) +"})?)\\d*$").test(s)){
	var s="0"+ RegExp.$2, pm=RegExp.$1, a=RegExp.$3.length, b=true;
	if(a==d+2){a=s.match(/\d/g); if(parseInt(a[a.length-1])>4){
		for(var i=a.length-2; i>=0; i--){a[i] = parseInt(a[i])+1;
		if(a[i]==10){a[i]=0; b=i!=1;} else break;}
	}
	s=a.join("").replace(new RegExp("(\\d+)(\\d{"+d+"})\\d$"),"$1.$2");
}if(b)s=s.substr(1);return (pm+s).replace(/\.$/, "");} return this+"";
/*保留小数, 四舍五入, 0.499.toFixed(0)
Math.floor() //取整数部分
Math.ceil() //小数进一
Math.round() //四舍五入*/
}

var _$class = function(name){return document.getElementsByClassName(name)} //取得指定className的对像
document.getElementsByClassName = function(name){
var getEleClass = [];
var myre = new RegExp("(^| )"+name+"( |$)");
var elems = document.getElementsByTagName("*");
for(var h=0; h<elems.length; h++){
	if(myre.test(elems[h].className)) getEleClass.push(elems[h]);
}
return getEleClass;
}

function XHR(){ //创建XMLHttpRequest
if(window.XMLHttpRequest) //除IE外的其它浏览器
	return new XMLHttpRequest();
else if(window.ActiveXObject) //IE 
	return new ActiveXObject("MsXml2.XmlHttp");
}

function doValue(url,state){ //AJAX返回数据,doValue("Index.html",1);
if(url==""){
alert("网址错误");
return false;
}
if(url.indexOf("?")==-1){url += "?rndnum="+escape(Math.random())}
else{url += "&rndnum="+escape(Math.random())}
var xmlHttp = new XHR();
xmlHttp.open("GET", url, false);
xmlHttp.send(null);
if(xmlHttp.status==200){ //服务端完成处理并返回数据
	var ResponseText = unescape(xmlHttp.responseText);
	if(state)return document.write(ResponseText);
	else return ResponseText;
}else{ //服务器出现异常
	if(state)return document.write("-2");
	else return "-2";
}
}

function request(name){ //获取URL参数
var strHref = this.location.href;
var intPos = strHref.indexOf("#");
if(intPos!=-1){
	var strRight = strHref.substr(intPos + 1);
	if(strRight.indexOf("&")!=-1){
	var arrTmp = strRight.split("&");
		for(var i=0; i<arrTmp.length; i++){
			var arrTemp = arrTmp[i].split("=");
			if(arrTemp[0].toUpperCase() == name.toUpperCase()) return unescape(arrTemp[1]);
		}
	}
}
return null;
}

// 获取参数 (格式如 ?Param1=Value1&Param2=Value2)
var URLParams = new Object();
var aParams = document.location.search.substr(1).split("&");
for(var i=0; i<aParams.length; i++){
	var aParam = aParams[i].split("=");
	URLParams[aParam[0]] = aParam[1];
}

function ImgDiv(obj){ //产品图片垂直居中
if(obj.style.display=="none"){
	if(obj.parentNode.tagName.toLowerCase()=="a"){
	obj.parentNode.previousSibling.previousSibling.style.display="none";
	obj.style.display="block";
	obj.style.marginLeft = obj.parentNode.parentNode.offsetWidth>obj.offsetWidth?(obj.parentNode.parentNode.offsetWidth-obj.offsetWidth)/2:-(obj.offsetWidth-obj.parentNode.parentNode.offsetWidth)/2;
	obj.style.marginTop = (obj.parentNode.parentNode.offsetHeight-obj.offsetHeight)/2;
	}else if(obj.parentNode.tagName.toLowerCase()!="a" && obj.className!="loadpic"){
	obj.previousSibling.previousSibling.style.display="none";
	obj.style.display="block";
	obj.style.marginLeft = obj.parentNode.offsetWidth>obj.offsetWidth?(obj.parentNode.offsetWidth-obj.offsetWidth)/2:-(obj.offsetWidth-obj.parentNode.offsetWidth)/2;
	obj.style.marginTop = (obj.parentNode.offsetHeight-obj.offsetHeight)/2;
	}
}else{
	if(obj.parentNode.tagName.toLowerCase()=="a"){
	obj.style.marginLeft = obj.parentNode.parentNode.offsetWidth>obj.offsetWidth?(obj.parentNode.parentNode.offsetWidth-obj.offsetWidth)/2:-(obj.offsetWidth-obj.parentNode.parentNode.offsetWidth)/2;
	obj.style.marginTop = (obj.parentNode.parentNode.offsetHeight-obj.offsetHeight)/2;
	}else{
	obj.style.marginLeft = obj.parentNode.offsetWidth>obj.offsetWidth?(obj.parentNode.offsetWidth-obj.offsetWidth)/2:-(obj.offsetWidth-obj.parentNode.offsetWidth)/2;
	obj.style.marginTop = (obj.parentNode.offsetHeight-obj.offsetHeight)/2;
	}
}
}

function getPosX(obj){ //获取绝对坐标
	var posLeft = 0;
	while (obj.offsetParent){posLeft += obj.offsetLeft; obj = obj.offsetParent;}
	return posLeft;
}
function getPosY(obj){
	var posTop = 0;
	while (obj.offsetParent){posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}

function getStyle(obj,name){ //获取obj的CSS属性,getStyle("obj","backgroundColor");
	var elem = _$(obj);
	var style = elem.currentStyle ? elem.currentStyle : document.defaultView.getComputedStyle(elem,null);
	return style[name];
}
function setStyle(obj,styles){ //修改obj的CSS属性,setStyle("obj",{width:"200px",backgroundColor:"#000"});
	var elem = _$(obj);
	for(var p in styles){
		elem.style[p] = styles[p];
	}
	return elem;
}

function selectBoxes(state,oclass){ //显示隐藏SELECT,oclass为指定某些特定className的SELECT,空时代表全部,selectBoxes("visible"),selectBoxes("hidden")
var selects = document.getElementsByTagName("SELECT");
if(typeof oclass!="undefined" && oclass!="") var re = new RegExp("(^| )"+oclass+"( |$)");
for(var i=0; i<selects.length; i++){
	if(typeof oclass!="undefined" && oclass!=""){
	if(re.test(selects[i].className)) selects[i].style.visibility = state;
	}else{selects[i].style.visibility = state;}
}
}

function doAtt(stype,oid,otype,ovalue){ //自定义属性操作,doAtt(类型,控件ID,属性名称,属性值[设置用])
	var obj = _$(oid);
	if(obj.tagName.toLowerCase()=="select") obj = obj.options[obj.selectedIndex];
	stype = stype.toString().toLowerCase();
	switch(stype){
		case "set":
		case "2": //设置自定义属性
			return obj.setAttribute(otype,ovalue);
			break;
		case "remove":
		case "3": //删除自定义属性
			return obj.removeAttribute(otype);
			break;
		default: //获取自定义属性，stype为自定义属性名称
			return obj.getAttribute(otype);
			break;
			//obj.attributes["value"].nodeName; //返回第一个属性的名称
			//obj.attributes[0].nodeValue; //返回第一个属性的值
	}
}

function fontLen(oStr){ //检测字符长度
var iCount,sStr,strTemp;
iCount = 0;
if(oStr=="") return iCount;
sStr = oStr.split("");
for(var i=0; i<sStr.length; i++){
	strTemp = escape(sStr[i]);
	if(strTemp.indexOf("%u",0) == -1){iCount = iCount + 1;}
	else{iCount = iCount + 2;} //表示是汉字
}
return iCount;
}

function bindSize(oStr,oNum){ //截取字符
var x = 0;
var str = oStr.replace(/[\s\S]/g, function(d,i,s){
	if(d.charCodeAt(0)>127) x++;
	if(x+i>=oNum) return "";
	return d;
});
return str;
}

function left(mainStr,lngLen){ //获取左边部分
	if(lngLen>0){return mainStr.substring(0,lngLen)}
	else{return null}
}
function right(mainStr,lngLen){ //获取右边部分
	if(mainStr.length>=0 && mainStr.length-lngLen>=0 && mainStr.length-lngLen<=mainStr.length){
		return mainStr.substring(mainStr.length-lngLen,mainStr.length)}
	else{return null}
}
function mid(mainStr,starnum,endnum){ //获取中间部分
	if(mainStr.length>=0){
		return mainStr.substr(starnum,endnum)
	}else{return null}
}

function gfirstChild(obj){ //为Firefox兼容firstChild
var node = _$(obj).firstChild;
while(node.nodeType!=1) node = node.nextSibling;
return node;
}
function glastChild(obj){ //为Firefox兼容lastChild
var node = _$(obj).lastChild;
while(node.nodeType!=1) node = node.previousSibling;
return node;
}

function LoadImages(arrSrc,callBack){
//预载入图片，调用：
//new LoadImages(["http://www.baidu.com/img/baidu_logo.gif","http://www.baidu.com/img/baidu_logo.gif","http://www.baidu.com/img/baidu_logo.gif"]);
var IE = navigator.appName=="Microsoft Internet Explorer";
var Opera = navigator.appName.toLowerCase()=="opera";
var FF = !IE && !Opera;
this.Length = arrSrc.length;
this.LoadedLen = 0; //已经被加载的图片个数
var _this = this;
if(_this.Length<1){
callBack(arrSrc);
return;
}
if(Opera){ //经测试,OPERA与别的浏览器加载方式不同,所以特别独立开来
for(var i=0; i<_this.Length; i++){
var tmpImg = new Image();
tmpImg.src = arrSrc[i];
tmpImg.onload = function(){
_this.LoadedLen++;
if(_this.LoadedLen==_this.Length && callBack) callBack(arrSrc);
}
}
return;
}
this.Load = function(){
_this.LoadedLen++;
if(_this.LoadedLen<_this.Length) _this.DownImg();
else if(callBack) callBack(arrSrc);
}
this.DownImg = function(){
var tmpImg = new Image();
tmpImg.src = arrSrc[_this.LoadedLen];
if(IE){
if(tmpImg.readyState=="complete") _this.Load();
else tmpImg.onreadystatechange = function(){
if(this.readyState=="complete") _this.Load();
}
}
else tmpImg.onload = _this.Load;
}
this.DownImg();
}

function addload(func){ //add a onload function
window.attachEvent ? window.attachEvent("onload", func) : window.addEventListener("load", func, false) //window.addEventListener("DOMContentLoaded", func, false)
}
function addclick(func){ //add a onclick function
window.attachEvent ? document.attachEvent("onclick", func) : document.addEventListener("click", func, false)
}

if(!lie){ /*For Firefox and Other*/
function __firefox(){ //兼容Firefox的event对象,可以直接用 my=event.pageX, my=event.pageY
HTMLElement.prototype.__defineGetter__("runtimeStyle", __element_style);
window.constructor.prototype.__defineGetter__("event", __window_event);
Event.prototype.__defineGetter__("srcElement", __event_srcElement);
}
function __element_style(){return this.style;}
function __window_event(){return __window_event_constructor();}
function __event_srcElement(){return this.target;}
function __window_event_constructor(){
if(document.all){return window.event;}
var _caller = __window_event_constructor.caller;
while(_caller!=null){
var _argument = _caller.arguments[0];
if(_argument){
var _temp = _argument.constructor;
if(_temp.toString().indexOf("Event")!=-1){return _argument;}
}
_caller = _caller.caller;
}
return null;
}
if(window.addEventListener){__firefox();}

if(typeof(HTMLElement)!="undefined" && !window.opera){ //兼容Firefox的outerHTML,可以直接用 obj.outerHTML
HTMLElement.prototype.__defineGetter__("outerHTML",function(){
var a=this.attributes, str="<"+this.tagName, i=0;
for(;i<a.length;i++)if(a[i].specified)str+=" "+a[i].name+'="'+a[i].value+'"';
if(!this.canHaveChildren)return str+" />";
return str+">"+this.innerHTML+"</"+this.tagName+">";
});
HTMLElement.prototype.__defineSetter__("outerHTML",function(s){
var r=this.ownerDocument.createRange();
r.setStartBefore(this);
var df=r.createContextualFragment(s);
this.parentNode.replaceChild(df, this);
return s;
});
HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
});
}

HTMLElement.prototype.__defineGetter__("children",function(){ //兼容Firefox的children,可以直接用 obj.children
var returnValue = new Object();
var number = 0;
for(var i=0; i<this.childNodes.length; i++){
if (this.childNodes[i].nodeType == 1){returnValue[number] = this.childNodes[i];number++;}
}
returnValue.length = number;
return returnValue;
});
}/*End Firefox*/

addload(function(){
var tag = _$tag("A");
for(var i=0; i<tag.length; i++) tag[i].onfocus = function(){this.blur();}
var tagA = _$tag("AREA");
for(var i=0; i<tagA.length; i++) tagA[i].onfocus = function(){this.blur();}
var tagI = _$tag("INPUT");
for(var i=0; i<tagI.length; i++){
var btype = doAtt(1,tagI[i],"type","").toLowerCase();
if(btype!="radio" && btype!="checkbox"){
if(doAtt(1,tagI[i],"id","")==null||doAtt(1,tagI[i],"id","")==""){if(doAtt(1,tagI[i],"name","")!=null) doAtt(2,tagI[i],"id",doAtt(1,tagI[i],"name",""));}
}
if(btype=="submit" || btype=="button" || btype=="reset" || btype=="image" || btype=="radio" || btype=="checkbox")
tagI[i].onfocus = function(){this.blur()}
}
});