var setErr=true;    //是否关闭错误提示 true出错提示.false出错不提示
function TAG(tagname){
	return $(document.createElement(tagname));
}
function $(obj){
	if(typeof(obj)=="string"){var obj=document.getElementById(obj);}
	if(obj.style.mark==true){return obj;}
	obj.style.mark=true;
	if(!obj.style.opacity){ obj.style.opacity=1;}

	obj.html=function(value){
		return value == undefined ? (obj ? obj.innerHTML : null) : obj.innerHTML=value;
	}
	obj.txt=function(){return obj.innerText;}
	obj.del=function(){
		if(!obj.parentNode){return;}
		obj.parentNode.removeChild(obj);
	}
	obj.setend=function(domNode){
		if(!domNode){return;}
		var domNode2=domNode.nextSibling;
		if(!domNode2){
			domNode.parentNode.appendChild(obj);
		}else{
			domNode2.parentNode.insertBefore(obj,domNode2);
		}
	}
	obj.setstart=function(domNode){
		if(!domNode){return;}
		domNode.parentNode.insertBefore(obj,domNode);
	}
	obj.setstartin=function(parentNode){
		if(!parentNode){parentNode=document.body}
		parentNode.insertBefore(obj,parentNode.firstChild);
	}
	obj.setendin=function(parentNode){
		if(!parentNode){parentNode=document.body}
		parentNode.appendChild(obj);
	}
	obj.addcss=function(styles){
		for(styleitem in styles){
			obj.style[styleitem]=styles[styleitem];
		}
	}
	obj.setstyle=function(styles){
		if(!styles) return;
		var arr=styles.split(";")
		for(var i=0;i<=arr.length;i++){
			if(arr[i]){
				var item=arr[i].split(":")[0];
			obj.style[item]=arr[i].split(":")[1];}
		}
	}
	obj.addatt=function(atts){
		for(attitem in atts){
			obj[attitem]=atts[attitem];
		}
	}
	obj.getstyle=function(){
		return obj.currentStyle||document.defaultView.getComputedStyle(obj,null);
	}

	obj.hide=function(time,end,fun){
		if(!time&&!end&&!fun) {obj.style.display="none";return;}
		obj.style.display2=obj.getstyle().display;
		if(isNaN(time)){time=700;}
		if(isNaN(end)){end=0;}
		if(navigator.userAgent.indexOf("MSIE")>=0){
			var speed=1000/time;
			var opacity=obj.style.opacity*100;
			var number=setInterval(function(){
				opacity-=speed;
				obj.style.filter="progid\:DXImageTransform.Microsoft.Alpha\(style=0,opacity="+opacity+",finishOpacity=100\)";
				obj.style.opacity=opacity/100;
				if(opacity<=end){
					clearInterval(number);
					if(typeof(fun)=="function"){fun();}
				}
			},1)
		}else{
			var speed=10/time;
			var opacity=obj.style.opacity;
			var number=setInterval(function(){
				opacity-=speed;
				opacity=parseInt(opacity*10000)/10000;
				obj.style.opacity=opacity;
				if(opacity<=(end/100)){
					clearInterval(number);
					if(typeof(fun)=="function"){fun();}
					return;
				}
			},1)
		}
	}
	obj.show=function(time,end,fun){
		if(!time&&!end&&!fun) {obj.style.display="";return;}
		if(isNaN(time)||time==""||time==null){time=700;}
		if(isNaN(end)||end==""||end==null){end=100;}
		if(navigator.userAgent.indexOf("MSIE")>=0){
			var speed=1000/time;
			var opacity=obj.getop();
			var number=setInterval(function(){
				opacity+=speed;
				obj.style.filter="progid\:DXImageTransform.Microsoft.Alpha\(style=0,opacity="+opacity+",finishOpacity=100\)";
				obj.style.opacity=opacity/100;
				if(opacity>=end){
					clearInterval(number);
					if(typeof(fun)=="function"){fun();}
					return;
				}
			},1)
		}
		else{
			var speed=10/time;
			var opacity=obj.getop()/100;
			var number=setInterval(function(){
				opacity+=speed;
				opacity=parseInt(opacity*10000)/10000;
				obj.style.opacity=opacity;
				if(opacity>=(end/100)){
					clearInterval(number);
					if(typeof(fun)=="function"){fun();}
					return;
				}
			},1)
		}
	}
	obj.setop=function(number){
		if(isNaN(number)||number==""||number==null){number=50}
		if(number>100){number=100}
		if(number<0){number=0}
		if(navigator.userAgent.indexOf("MSIE")>=0){
			obj.style.filter="progid\:DXImageTransform.Microsoft.Alpha\(style=0,opacity="+number+",finishOpacity=100\)";
		}
		obj.style.opacity=number/100;
	}
	obj.getop=function(){
		return obj.style.opacity*100;
	}
	obj.addclass=function(classname){
		if(obj.className==""){obj.className=classname;return true;}
		var classnames=obj.className.split(" ");
		for(var i=0;i<classnames.length;i++){
			if(classnames[i]==classname){
				return true;
			}
		}
		obj.className+=" "+classname;
		return true;
	}
	obj.setclass=function(classname){if(classname){obj.className=classname;}}
	obj.delclass=function(classname){
		if(obj.className==classname){obj.className="";return true;}
		var classnames=obj.className.split(" ");
		for(var i=0;i<classnames.length;i++){
			if(classnames[i]==classname){
				classnames.splice(i,1)
			}
		}
		obj.className="";
		obj.className+=classnames.join(" ");
	}

	//Object end
	return obj;
}
function $IE(val){
	if(!val||val==''||val==null){
	if(window.navigator.userAgent.indexOf("MSIE")>=0) return 'IE';
	else if(window.navigator.userAgent.indexOf("Firefox")>=0) return 'FF';
	else if(window.navigator.userAgent.indexOf("Opera")>=0) return 'OP';
	else return "OT";
  }else{
  if(val=='IE8') if(navigator.userAgent.indexOf("MSIE 8")>=0){return true;}else{return false;}
  if(val=='IE7') if(navigator.userAgent.indexOf("MSIE 7")>=0){return true;}else{return false;}
  if(val=='IE6') if(navigator.userAgent.indexOf("MSIE 6")>=0){return true;}else{return false;}
  if(val=='IE5') if(navigator.userAgent.indexOf("MSIE 5")>=0){return true;}else{return false;}
  }
}
function win(url,width,height,title){
	if(width==""||width==null||isNaN(width)){width=500};
	if(height==""||height==null||isNaN(height)){height=400};
	if(!title) title='TxtCms'; else title=title+'-TxtCms';
	var styles={
		width:(document.documentElement.scrollWidth)+"px",
		height:(document.documentElement.scrollHeight)+"px",
		backgroundColor:"#000000",top:"0",left:"0",position:"absolute",zIndex:"9999"
	}
	var bg=new TAG("div");
	bg.addcss(styles);
	bg.setop(0);
	bg.show(100,60);
	bg.setendin();
	if($IE()=='IE'){
		bg.setstyle("width:"+(bg.style.width.split('px')[0]-20)+"px")
		var selects=document.getElementsByTagName("select");
		for(var i=0;i<selects.length;i++)	selects[i].style.visibility="hidden";
	}
	if($IE()=='FF'||$IE('IE5')){
		var scrollLeft=document.body.scrollLeft;
		var scrollTop=document.body.scrollTop;
	}else{
		var scrollLeft=document.documentElement.scrollLeft;
		var scrollTop=document.documentElement.scrollTop;
	}
	var styles={
		width:width+"px",height:height+"px",
		border:"#D4D0C8 solid 1px",
		backgroundColor:"#ffffff",
		top:"50%",left:"50%",
		marginLeft:(scrollLeft-width/2)+"px",
		marginTop:(scrollTop-height/2)+"px",
		position:"absolute",zIndex:"10000"
	}
	var iframe=new TAG("div");
	var istr='<iframe src="'+url+'" width='+width+' height='+(height-20)+' scrolling="yes" marginwidth="0" marginheight="0" frameborder="0" id="itxt"></iframe>';
	iframe.addcss(styles);
	iframe.innerHTML="<div id=itop style='width:"+width+"px;position:absolute;top:0;z-index:500000;background:#6C8CBD;color:#fff;line-height:20px'><span style='font-size:12px'>"+title+"</span></div>";
	iframe.innerHTML+="<div id=imain style='margin:0;padding:0;margin-top:20px'>"+istr+"<div>";
	iframe.setendin();
	this.iframe=iframe;
	this.obj=$('imain');
	this.html=$('itxt');
	this.bg=bg;
	bg.win=this;
	var closeNode=new TAG("b");
	closeNode.win=this;
	closeNode.innerHTML="×";
	closeNode.style.cssFloat="right";
  closeNode.style.styleFloat="right";
	closeNode.onclick=function(){this.win.close();}
	closeNode.setstartin($('itop'));
	closeNode.setstyle("font-size:18px;cursor:pointer;");
	//bg.onclick=function(){this.win.close();}
	win.prototype.close=function(){
		this.iframe.hide(20,0,ifrdel);
		this.bg.hide(20,0,bgdel);
		iframe=this.iframe;
		bg=this.bg;
		function ifrdel(){iframe.del();iframe=null;closeNode=null}
		function bgdel(){bg.del();bg=null;}
		if($IE()=='IE'){
			var selects=document.getElementsByTagName("select");
			for(var i=0;i<selects.length;i++) selects[i].style.visibility="visible";
		}
	}
}

//xmlhttp和xmldom对象
var TxtXHttp = null,TxtXDom = null,TxtDiv = null;
function $Ajax(Divid,strDown,strErr){
  if(!Divid){ alert("建立$Ajax失败！没有装载内容的容器。"); return;}
	if(!strErr) strErr="下载数据失败";
	if(!strDown) strDown="正在下载数据...";
	if(typeof(Divid)!="object") Divid=document.getElementById(Divid);
	TxtDiv = Divid;
	//post或get发送数据的键值对
	this.keys = Array();
	this.values = Array();
	this.keyCount = -1;
	//http请求头
	this.rkeys = Array();
	this.rvalues = Array();
	this.rkeyCount = -1;
	//请求头类型
	this.rtype = 'text';
	//初始化xmlhttp
	if(window.ActiveXObject){//IE6、IE5
		try { TxtXHttp = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) { }
		if (TxtXHttp == null) try { TxtXHttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { }
	}else{
		TxtXHttp = new XMLHttpRequest();
	}
	TxtXHttp.onreadystatechange = function(){
		if(TxtXHttp.readyState == 4){
			if(TxtXHttp.status == 200){
				TxtDiv.innerHTML = TxtXHttp.responseText;
				TxtXHttp = null;
			}
			else TxtDiv.innerHTML = strErr;
		}
		else TxtDiv.innerHTML = strDown;
	};

	//增加一个POST或GET键值对
	this.AddKey = function(skey,svalue){
		this.keyCount++;
		this.keys[this.keyCount] = skey;
		this.values[this.keyCount] = escape(svalue);
	};

	//增加一个Http请求头键值对
	this.AddHead = function(skey,svalue){
		this.rkeyCount++;
		this.rkeys[this.rkeyCount] = skey;
		this.rvalues[this.rkeyCount] = svalue;
	};

	//清除当前对象的哈希表参数
	this.ClearSet = function(){
		this.keyCount = -1;
		this.keys = Array();
		this.values = Array();
		this.rkeyCount = -1;
		this.rkeys = Array();
		this.rvalues = Array();
	};

	//发送http请求头
	this.SendHead = function(){
		if(this.rkeyCount!=-1){ //发送用户自行设定的请求头
			for(;i<=this.rkeyCount;i++){
				TxtXHttp.setRequestHeader(this.rkeys[i],this.rvalues[i]);
			}
		}
		　if(this.rtype=='binary'){
			TxtXHttp.setRequestHeader("Content-Type","multipart/form-data");
		}else{
			TxtXHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		}
	};

	//用Post方式发送数据
	this.post = function(purl){
		var pdata = "";
		var i=0;
		this.state = 0;
		TxtXHttp.open("POST", purl, true);
		this.SendHead();
		if(this.keyCount!=-1){ //post数据
			for(;i<=this.keyCount;i++){
				if(pdata=="") pdata = this.keys[i]+'='+this.values[i];
				else pdata += "&"+this.keys[i]+'='+this.values[i];
			}
		}
		TxtXHttp.send(pdata);
	};

	//用GET方式发送数据
	this.get = function(purl){
		var gkey = "";
		var i=0;
		this.state = 0;
		if(this.keyCount!=-1){ //get参数
			for(;i<=this.keyCount;i++){
				if(gkey=="") gkey = this.keys[i]+'='+this.values[i];
				else gkey += "&"+this.keys[i]+'='+this.values[i];
			}
			if(purl.indexOf('?')==-1) purl = purl + '?' + gkey;
			else  purl = purl + '&' + gkey;
		}
		TxtXHttp.open("GET", purl, true);
		this.SendHead();
		TxtXHttp.send(null);
	};

} // End Class Ajax

//初始化xmldom
function InitXDom(){
	if(TxtXDom!=null) return;
	var obj = null;
	if (typeof(DOMParser) != "undefined") { // Gecko、Mozilla、Firefox
		var parser = new DOMParser();
		obj = parser.parseFromString(xmlText, "text/xml");
	} else { // IE
		try { obj = new ActiveXObject("MSXML2.DOMDocument");} catch (e) { }
		if (obj == null) try { obj = new ActiveXObject("Microsoft.XMLDOM"); } catch (e) { }
	}
	TxtXDom = obj;
};
//自定函数
//读写cookie函数
function getcookie(c_name){
	if (document.cookie.length > 0){
		c_start = document.cookie.indexOf(c_name + "=")
		if (c_start != -1){
			c_start = c_start + c_name.length + 1;
			c_end   = document.cookie.indexOf(";",c_start);
			if (c_end == -1){
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return null
}
function setcookie(c_name,value,expiredays){
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); //使设置的有效时间正确。增加toGMTString()
}
function $url(){
	var url=document.location;
	url=url.toString();
	url=url.split("//");
	index=url[1].split("/");
	return url[0]+"//"+index[0]+"/";
}
function $goto(url){
	if(url.lastIndexOf('/.') > 0) url = url.replace(/\/(\.[a-zA-Z]+)([0-9]+)$/g, "/$2$1");
	//if(url.indexOf('://') == -1 && url.substr(0, 1) != '/' && url.substr(0, 1) != '?') url = $('base').attr('href')+url;
	location.href = url;
}
function $YN(text){ 
	var thistext=window.confirm(text);
  if(thistext){return true;}
  else { return false;}
}
function $loadjs(jsurl){
		var script=new TAG("script");
		script.src=jsurl;
		document.documentElement.appendChild(script);
}
function $loadcss(cssurl){
		var linknode=new TAG("link");
		linknode.rel="stylesheet";
		linknode.type="text/css";
		linknode.href=cssurl;
		document.documentElement.firstChild.appendChild(linknode);
}
function $loadflash(url,wmode,width,Height,param){ 
  document.write(
  '<embed src="' + url + '" FlashVars="'+param+'" wmode=' + wmode +
  ' quality="high" pluginsPage=http://www.macromedia.com/go/getflashplayer type="application/x-shockwave-flash" width="' + width + 
  '" height="' + Height + '"></embed>');   
}
function $imgsize(thispic,width,height){
	if(thispic.width>width){
		thispic.height=thispic.height*width/thispic.width;
	thispic.width=width;		}
	else if(thispic.height>height){
		thispic.width=thispic.width*height/thispic.height;
	thispic.height=height;	}
}
function $form(strUrl,iwidth,iheight,winobj){
	var strItem ;var thiswidth=700;var thisheight=500;
	if(iwidth){thiswidth=iwidth;}
	if(iheight){thisheight=iheight;}
	var strItem = window.showModalDialog(strUrl,winobj,"Help=no;status:no;dialogWidth="+thiswidth+"px;dialogHeight="+thisheight+"px;scroll=yes;");
    return strItem;
}
function $copy(copy){
	if (window.clipboardData){
	window.clipboardData.setData("Text", copy);}
	else if (window.netscape){
		try{ netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		}catch(e){
		alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");   }
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=copy;
		str.data=copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid=Components.interfaces.nsIClipboard;
		if (!clip) return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	return false;
}
function $r(html){document.write(html)}
//string扩展
String.prototype.cnlen=function(){
	return this.replace(/[^\x00-\xff]/g,"**").length;
}
// 默认过滤,'"空格html标记，reg正则表达式 替换成str
String.prototype.trim=function(reg,str) {
	if(!str) str="";
	if(reg)
	return this.replace(reg,str);
	else
	return this.replace(/[,'"]|[\s*]|<[^>]*>/g,str);
}
// 除去两边空白
String.prototype.ctrim = function() {
	return this.replace(/(^s+)|(s+$)/g,"");
}
// 从左截取指定长度字串 左边left个字符到n个字符中间的字符
String.prototype.mid = function(left,n) {
	if(!left) left=0;
	if(!n) return this;
	return this.slice(left,n);
}
//得到中间的字符串,从start到len
String.prototype.Mid = function(start,len){
	if(!start) start=0;
	if(!len) return this;
	return this.substr(start,len);
}
//从左边截取n个字符 ,如果包含汉字,则汉字按两个字符计算
String.prototype.left=function(n){
	if(n)
	return this.slice(0,n-this.slice(0,n).replace(/[\x00-\xff]/g,"").length)
	else
	return this;
}
//从右边截取n个字符 ,如果包含汉字,则汉字按两个字符计算
String.prototype.right=function(n){
	if(n)
	return this.slice(this.slice(-n).replace(/[\x00-\xff]/g,"").length-n)
	else
	return this;
}
String.prototype.isnum=function(flag) {
	if(isNaN(this)){return false;}
	switch(flag){
		case null:        //数字
		case "": return true;
		case "+": return /(^\+?|^\d?)\d*\.?\d+$/.test(this);//正数
		case "-": return /^-\d*\.?\d+$/.test(this);         //负数
		case "i": return /(^-?|^\+?|\d)\d+$/.test(this);    //整数
		case "+i": return /(^\d+$)|(^\+?\d+$)/.test(this);  //正整数
		case "-i": return /^[-]\d+$/.test(this);            //负整数
		case "f": return /(^-?|^\+?|^\d?)\d*\.\d+$/.test(this);//浮点数
		case "+f": return /(^\+?|^\d?)\d*\.\d+$/.test(this);  //正浮点数
		case "-f": return /^[-]\d*\.\d$/.test(this);         //负浮点数
		default: return true;   //缺省
	}
}
//是否是手机
String.prototype.ismobile = function(){
	return /^0{0,1}13[0-9]{9}$/.test(this);
}
//是否是有效的电话号码(中国)
String.prototype.isphone = function(){
	return /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/.test(this);
}
//是否是邮件
String.prototype.isemail = function(){
	return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(this);
}
//是否是有效链接
String.prototype.isurl = function(){
	return /^http[s]?:\/\/([\w-]+\.)+[\w-]+([\w-./?%&=]*)?$/i.test(this);
}
//是否是颜色(#FFFFFF形式)
String.prototype.iscolor = function(){
	var temp        = this;
	if (temp=="") return true;
	if (temp.length!=7) return false;
	return (temp.search(/\#[a-fA-F0-9]{6}/) != -1);
}
//检查某字符是否在 左开始 返回字符位置
String.prototype.instr=function(str) {
	if(!str){ str = "";}
	return this.indexOf(str);
}
//在字符串里反向查找另一字符串:位置0开始
String.prototype.instrr = function(str){
	if(!str){ str = "";}
	return this.lastIndexOf(str);
}
String.prototype.instrnum = function(str){
	if(!str){ str = "";}
	return this.split(str).length-1;
}
//对字符串进行Html编码
String.prototype.HtmlEncode = function(){
	var str = this;
	str=str.replace(/&/g,"&amp;");
	str=str.replace(/</g,"&lt;");
	str=str.replace(/>/g,"&gt;");
	str=str.replace(/\'/g,"&apos;");
	str=str.replace(/\"/g,"&quot;");
	str=str.replace(/\n/g,"<br>");
	str=str.replace(/\ /g,"&nbsp;");
	str=str.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
	return str;
}
//忽略错误
function killErr(){return true;}
if(setErr==false) window.onerror=killErr;
