//域
//document.domain = "jinti.com";

//String类型原型重载
String.prototype.len = function() {
		return this.replace(/[^\x00-\xff]/g, "aa").length;
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.isEmail = function() {
	var pattern = /^[^@\s]+@[A-Za-z0-9-\u4e00-\u9fa5]+(?:\.[A-Za-z0-9-\u4e00-\u9fa5]+)+$/;
	if (pattern.test(this)) return true;
	else return false;
}

String.prototype.isURL = function() {
	var pattern = /^(?:http:\/\/)?[A-Za-z0-9-\u4e00-\u9fa5]+(?:\.[A-Za-z0-9-\u4e00-\u9fa5]+)+(?:\/[^\s]*)?$/;
	if (pattern.test(this)) return true;
	else return false;
}

String.prototype.isMoney = function() {
	var pattern = /^(?:^\d+$)|(?:^\d+.\d(?:\d)?$)$/;
	if (pattern.test(this)) return true;
	else return false;
}

//Number类型原型重载
Number.prototype.fill = function(length) {
	var strNum = parseInt(this).toString();
	var space = length - strNum.length;
	if (space > 0) {
		var zero = "";
		for (var i=0; i<space ; i++) {
			zero += "0";
		}
		strNum =  zero + strNum;
	}
	return strNum;
}

var Tools = {
	compatMode:document.compatMode,
	isIE:navigator.appName=="Microsoft Internet Explorer"?true:false,
	isFF:navigator.appName=="Netscape"?true:false,
	isFixed:(/MSIE\s([\d\.]+?);/ig.test(navigator.appVersion))?((parseInt(navigator.appVersion.match(/MSIE\s([\d\.]+?);/ig)[0].replace("MSIE ","").replace(";",""))>6)?true:false):true,
	scrollWidth:function() {return document.documentElement.scrollWidth>document.documentElement.clientWidth?document.documentElement.scrollWidth:document.documentElement.clientWidth},
	scrollHeight:function() {return document.documentElement.scrollHeight>document.documentElement.clientHeight?document.documentElement.scrollHeight:document.documentElement.clientHeight},
	clientWidth:function() {return document.compatMode=="CSS1Compat"?document.documentElement.clientWidth:document.body.clientWidth},
	clientHeight:function() {return document.compatMode=="CSS1Compat"?document.documentElement.clientHeight:document.body.clientHeight},
		
	random:function(up, down) {
		if (up && down) {
			return parseInt(Math.random()*(up-down+1)+down);
		}
		else if (up) {
			return parseInt(Math.random()*parseInt(up)+1);
		}
		else {
			return Math.random();
		}
	},
		
	covering:{
		zindex:2008,
		obj:null,
		objTimer:null,
		objCount:0,
		hiddenObj:null,
		clientSize:null,
		open:function(opacity, backgroundColor) {
			var coveringDiv;
			if (Tools.covering.obj == null) coveringDiv = document.createElement("div");
			else coveringDiv = Tools.covering.obj;
			coveringDiv.id = "tools_covering_div";
			coveringDiv.style.position = "absolute";
			coveringDiv.style.zIndex = Tools.covering.zindex;
			coveringDiv.style.left = "0px"; coveringDiv.style.top = "0px";
			coveringDiv.style.width = Tools.scrollWidth() + "px"; coveringDiv.style.height = Tools.scrollHeight() + "px";
			Tools.covering.clientSize = {width:Tools.clientWidth(), height:Tools.clientHeight()};
			if (backgroundColor) coveringDiv.style.backgroundColor = backgroundColor;
			else coveringDiv.style.backgroundColor = "#000000";
			if (opacity) {
				if (opacity>1 && opacity<=100) {
					coveringDiv.style.filter = "alpha(opacity="+opacity.toString()+")";
					coveringDiv.style.opacity = (opacity*0.01).toString();
				}
				else if(opacity>=0 && opacity<=1) {
					coveringDiv.style.filter = "alpha(opacity="+(opacity*100).toString()+")";
					coveringDiv.style.opacity = opacity.toString();
				}
			}
			else {
				coveringDiv.style.filter = "alpha(opacity=50)";
				coveringDiv.style.opacity = "0.5";
			}
			if (Tools.covering.obj == null) {
				Tools.covering.obj = coveringDiv;
				Tools.covering.hiddenObj = new Array();
				this.hidden(document.getElementsByTagName("select"));
				this.hidden(document.getElementsByTagName("object"));
				document.body.appendChild(Tools.covering.obj);
				if (Tools.covering.objTimer == null) Tools.covering.objTimer = setInterval("Tools.covering._interval()", 1);
			}
			Tools.covering.objCount++;
		},
		_interval:function() {
			if (Tools.covering.obj != null) {
				if (Tools.covering.clientSize.width != Tools.clientWidth()) {
					Tools.covering.obj.style.width = Tools.scrollWidth() + "px";
				}
				if (Tools.covering.clientSize.height != Tools.clientHeight()) {
					Tools.covering.obj.style.height = Tools.scrollHeight() + "px";
				}
			}
		},
		hidden:function(hiddenElement) {
			for (var i=0; i<hiddenElement.length; i++) {
				Tools.covering.hiddenObj.push({obj:hiddenElement[i],value:hiddenElement[i].style.display});
				hiddenElement[i].style.display = "none";
			}
		},
		close:function() {
			if (Tools.covering.objCount > 1) {
				Tools.covering.objCount--;
			}
			else {
				if (Tools.covering.objTimer != null) {
					clearInterval(Tools.covering.objTimer);
					Tools.covering.objTimer = null;
				}
				if (Tools.covering.clientSize != null) {
					Tools.covering.clientSize = null;
				}
				if (Tools.covering.obj != null) {
					Tools.covering.obj.parentNode.removeChild(Tools.covering.obj);
					Tools.covering.obj=null;
				}
				if (Tools.covering.hiddenObj != null) {
					for (var i=0; i<Tools.covering.hiddenObj.length; i++) {
						Tools.covering.hiddenObj[i].obj.style.display = Tools.covering.hiddenObj[i].value;
					}
					Tools.covering.hiddenObj = null;
				}
			}
		}
	},

	Win:function(obj, title, content) {
		this.width = "250px";
		this.height;
		this.top;
		this.left;

		this.title = "JsWin"; //标题
		this.content = ""; //内容

		this.isDrag = true; //是否可以拖动
		this.isCovering = false; //是否需要遮罩
		this.isScroll = false; //是否需要随滚动条滚动
		this.isTitleDblclick = true; //双击标题栏是否会最大化

		this.isMaxBtn = true; //是否需要最大化按钮
		this.isCloseBtn = true; //是否需要关闭按钮
		this.isTitleBox = true;

		this.isAlign = true; //内容是否需要居中
		this.isVerticalAlign = true; //内容是否需要垂直居中

		this.picPath = ""; //图片路径
		this.border = "solid 1px #93B2CE"; //边框样式 solid 1px #C0D2DE";

		if (title != undefined && title != null) {this.title = title;}
		if (content != undefined && content != null) {this.content = content}

		this.mainTag = document.createElement("div");
		this.drag = {draging:false, e:null, x:0, y:0, top:0, left:0, dashedWin:null, overWin:null}
		this.maxSize = {isMax:false, btn:null, width:null, height:null, top:null, left:null}
		this.titleBtnWidth = 60;
		this.onmousemove; this.onmouseup;
		this.onscroll = {x:null, y:null, Timer:null}

		this.dragDown = function(e) {
			if (!this.maxSize.isMax) {
				this.drag.e = e;
				this.drag.x = e.clientX; this.drag.y = e.clientY;
				this.drag.top = parseInt(this.mainTag.style.top); this.drag.left = parseInt(this.mainTag.style.left);
				this.drag.draging = true;
				//拖动时的虚线框
				this.drag.dashedWin = document.createElement("div");
				this.drag.dashedWin.style.zIndex = Tools.covering.zindex + 2;
				this.drag.dashedWin.style.border = "dashed 1px black";
				this.drag.dashedWin.style.background = "url("+this.picPath+"ransparency.PNG)";
				this.drag.dashedWin.style.width = parseInt(this.mainTag.offsetWidth) + "px";
				this.drag.dashedWin.style.height = parseInt(this.mainTag.offsetHeight) + "px";
				this.drag.dashedWin.style.position = "absolute";
				this.drag.dashedWin.style.top = parseInt(this.mainTag.style.top) + "px";
				this.drag.dashedWin.style.left = parseInt(this.mainTag.style.left) + "px";
				this.drag.dashedWin.style.cursor = "default";
				//this.drag.dashedWin.innerHTML='<div style="width:' + parseInt(this.mainTag.offsetWidth) + 'px;height:' + parseInt(this.mainTag.offsetHeight) + 'px;" onmousemove="' + obj + '.dragMove(event)" onmouseup="' + obj + '.dragUp()" onmouseout="' + obj + '.dragUp()">&#160;</div>';
				this.drag.dashedWin.innerHTML='<div style="width:' + parseInt(this.mainTag.offsetWidth) + 'px;height:' + parseInt(this.mainTag.offsetHeight) + 'px;"></div>';
				this.onmousemove = document.onmousemove; this.onmouseup = document.onmouseup;
				document.onmousemove = this.dragMove; document.onmouseup = this.dragUp;
				document.body.appendChild(this.drag.dashedWin);
			}
		}

		this.dragMove = function(e) {
			if (eval(obj).drag.draging) {
				var tmp_y;
				var tmp_x;
				if (Tools.isIE) {
					tmp_y = eval(obj).drag.top+event.clientY - eval(obj).drag.y;
					tmp_x = eval(obj).drag.left+event.clientX - eval(obj).drag.x;
				}
				else {
					tmp_y = eval(obj).drag.top+e.clientY - eval(obj).drag.y;
					tmp_x = eval(obj).drag.left+e.clientX - eval(obj).drag.x;
				}
				eval(obj).movedashedWin(tmp_x, tmp_y);
			}
		}

		this.dragUp = function() {
			if (eval(obj).drag.draging) {
				eval(obj).drag.draging = false;
				eval(obj).move(parseInt(eval(obj).drag.dashedWin.style.left), parseInt(eval(obj).drag.dashedWin.style.top));
				eval(obj).drag.dashedWin.parentNode.removeChild(eval(obj).drag.dashedWin);
				eval(obj).drag.dashedWin = null;
				document.onmousemove = eval(obj).onmousemove;
				document.onmouseup = eval(obj).onmouseup;
			}
		}

		this.movedashedWin = function(x, y) {
			if (x>0 && (x + parseInt(this.mainTag.offsetWidth) < (parseInt(Tools.scrollWidth()) - 1))) { this.drag.dashedWin.style.left = x + "px"; }
			if (y>0 && (y + parseInt(this.mainTag.offsetHeight) < (parseInt(Tools.scrollHeight()) - 1))) { this.drag.dashedWin.style.top = y + "px"; }
		}

		this.move = function(x,y) {
			if (x>0 && (x + parseInt(this.mainTag.offsetWidth) < (parseInt(Tools.scrollWidth()) - 1))) {
				this.mainTag.style.left = x + "px";
				if (this.isScroll != null) { this.onscroll.x = x - parseInt(document.documentElement.scrollLeft); }
			}
			if (y>0 && (y + parseInt(this.mainTag.offsetHeight) < (parseInt(Tools.scrollHeight()) - 1))) {
				this.mainTag.style.top = y + "px";
				if (this.isScroll != null) { this.onscroll.y = y - parseInt(document.documentElement.scrollTop); }
			}
		}

		this.open = function() {
			if (this.isCovering) { Tools.covering.open(); }
			//主框
			this.mainTag.style.zIndex = Tools.covering.zindex + 1;
			this.mainTag.style.border = this.border;
			this.mainTag.style.background = "white"; //"#F4F7F9";
			this.mainTag.style.width = this.width;
			var reg_exp = /MSIE 7.0/ig;
			if (this.isScroll) {
				if ( (Tools.isIE && reg_exp.test(navigator.appVersion)) || !Tools.isIE) {
					this.mainTag.style.position = "fixed";
					this.isScroll = false;
				}
				else {
					this.mainTag.style.position = "absolute";
				}
			}
			else {
				this.mainTag.style.position = "absolute";
			}
			//标题栏
			var titleTitleDblclick = this.isTitleDblclick?'ondblclick=' + obj + '.max()':'';
			var maxBtn = this.isMaxBtn?'<font style="cursor:pointer;" onclick="' + obj + '.max()">大</font>':'';
			var closeBtn = this.isCloseBtn?'<font style="cursor:pointer;font-size:12px;color:#1F62A4;" onclick="' + obj + '.close()">关闭</font>':'';
			var dragClick = this.isDrag?'onmousedown="' + obj + '.dragDown(event)"':'';
			var TitleBoxDisplay = this.isTitleBox?"":"display:none;";
			var titleHTML = '<div style="'+TitleBoxDisplay+'position:absolute;width:' + parseInt(parseInt(this.width) - this.titleBtnWidth) + 'px;height:23px;background-images:url('+this.picPath+'transparency.PNG);" ' + titleTitleDblclick + ' ' + dragClick + '>'
							+'</div>'
							+'<table border="0" cellspacing="0" cellpadding="0" style="'+TitleBoxDisplay+'width:100%;height:24px;background-image:url('+this.picPath+'titleBG.jpg);border-bottom:'+this.border+'">'
								+'<tr style="width:100%;">'
									+'<td style="font-size:14px;font-weight:bold;color:#1F62A4;">'
										+'&#160;&#160;' + this.title
									+'</td>'
									+'<td style="width:' + this.titleBtnWidth + 'px;text-align:right;">'
										+maxBtn
										+closeBtn
										+'&#160;'
									+'</td>'
								+'</tr>'
							+'</table>';
			//内容区域
			var contentHTML = '';
			if (this.content != '') {
				contentHTML = '<table style="width:100%;" border="0" cellspacing="0" cellpadding="0">'
								+'<tr>'
									+'<td style="word-break:break-all;word-wrap:break-word;">'
										+ this.content 
									+'</td>'
								+'</tr>'
							+ '</table>';
			}

			this.mainTag.innerHTML = titleHTML + contentHTML;
			if (Tools.isIE) { this.maxSize.btn = this.mainTag.childNodes(1).firstChild.firstChild.childNodes(1).firstChild; }
			else { this.maxSize.btn = this.mainTag.childNodes[1].firstChild.firstChild.childNodes[1].firstChild; }
			document.body.appendChild(this.mainTag);

			//if (parseInt(this.mainTag.offsetHeight) < 48) { this.mainTag.style.height = "48px"; }
			if (this.top==undefined) { this.top = parseInt(document.documentElement.scrollTop)+(parseInt(Tools.clientHeight())-parseInt(this.mainTag.offsetHeight))/2; }
			if (this.left==undefined) { this.left = (parseInt(Tools.scrollWidth())-parseInt(this.mainTag.clientWidth))/2; }
			this.mainTag.style.top = this.top + "px"; this.mainTag.style.left = this.left + "px";
			if (this.isScroll) {
				this.onscroll.x = this.left - parseInt(document.documentElement.scrollLeft);
				this.onscroll.y = this.top - parseInt(document.documentElement.scrollTop);						
				this.onscroll.Timer = setInterval(obj + ".Scroll()", 500);
			}
		}

		this.close = function() {
			this.mainTag.parentNode.removeChild(this.mainTag);
			if (this.drag.overWin != null) {
				this.drag.overWin.parentNode.removeChild(this.drag.overWin);
				var select = document.getElementsByTagName("select");
				for (var i=0; i<selectObj.length; i++) {
					select[i].style.display = selectObj[i];
				}
			}
			if (this.isScroll) { clearInterval(this.onscroll.Timer); }
			if (this.isCovering) { Tools.covering.close(); }
			obj = null;
		}

		this.max = function() {
			if (this.maxSize.isMax) {
				this.mainTag.style.top = parseInt(this.maxSize.top) + parseInt(document.documentElement.scrollTop) + "px";
				this.mainTag.style.left = parseInt(this.maxSize.left) + parseInt(document.documentElement.scrollLeft) + "px";
				this.mainTag.style.border = "solid 1px #93B2CE";
				this.mainTag.style.width = parseInt(this.maxSize.width) + "px";
				this.mainTag.style.height = parseInt(this.maxSize.height) + "px";
				this.mainTag.firstChild.style.width = parseInt(parseInt(this.mainTag.style.width) - this.titleBtnWidth) + "px";
				if (this.isMaxBtn) this.maxSize.btn.innerHTML = '大';
				this.maxSize.isMax = false;
			}
			else {
				this.maxSize.width = parseInt(this.mainTag.offsetWidth);
				this.maxSize.height = parseInt(this.mainTag.offsetHeight);
				this.maxSize.top = parseInt(this.mainTag.style.top) - parseInt(document.documentElement.scrollTop);
				this.maxSize.left = parseInt(this.mainTag.style.left) - parseInt(document.documentElement.scrollLeft);
				this.mainTag.style.top = "0px";
				this.mainTag.style.left = "0px";
				this.mainTag.style.border = "0px";
				this.mainTag.style.width = parseInt(document.documentElement.scrollWidth) + "px";
				if (parseInt(document.documentElement.clientHeight) > parseInt(document.body.clientHeight)) {
					this.mainTag.style.height = parseInt(document.documentElement.clientHeight) + "px";
				}
				else {
					this.mainTag.style.height = parseInt(document.body.clientHeight) + "px";
				}
				this.mainTag.firstChild.style.width = parseInt(parseInt(this.mainTag.style.width) - this.titleBtnWidth) + "px";
				if (this.isMaxBtn) this.maxSize.btn.innerHTML = '小';
				document.documentElement.scrollTop = 0;
				document.documentElement.scrollLeft = 0;
				this.maxSize.isMax = true;
			}
		}

		this.Scroll = function() {
			this.mainTag.style.left = this.onscroll.x + parseInt(document.documentElement.scrollLeft) + "px";
			this.mainTag.style.top = this.onscroll.y + parseInt(document.documentElement.scrollTop) + "px";
		}

		this.refreshContent = function(contentHTML) {
			var objContent;
			if (isIE) { //内容标签
				objContent = this.mainTag.childNodes(2).firstChild.firstChild.firstChild;
			}
			else {
				objContent = this.mainTag.childNodes[2].firstChild.firstChild.firstChild;
			}
			if (contentHTML) {
				this.content = contentHTML;
			}
			objContent.innerHTML = this.content;
		}
	},

	Tip:{
		obj:null,
		open:function(content) {
			if (Tools.Tip.obj != null) {
				Tools.Tip.obj.close();
			}
			Tools.Tip.obj = new Tools.Win("Tools.Tip.obj", content, '');
			Tools.Tip.obj.isDrag = false;
			Tools.Tip.obj.isScroll = true;
			Tools.Tip.obj.isTitleDblclick = false;
			Tools.Tip.obj.isMaxBtn = false;
			Tools.Tip.obj.isCovering = true;
			Tools.Tip.obj.open();
		}
	},

	QQTip:{
		obj:null,
		time:1,
		width:316,
		height:198,
		open:function(innerHTML, width, height){
			if (width) Tools.QQTip.width = width;
			if (height) Tools.QQTip.height = height;
			var qqtip = document.createElement("div");
			qqtip.innerHTML = innerHTML;
			qqtip.id = "QQTip";
			qqtip.style.position = Tools.isFixed?"fixed":"absolute";
			qqtip.style.zIndex = 2010;
			qqtip.style.width = Tools.QQTip.width+"px";
			qqtip.style.height = "0px";
			qqtip.style.overflow = "hidden";
			qqtip.style.top = Tools.clientHeight()+"px";
			qqtip.style.left = (Tools.clientWidth()-parseInt(qqtip.style.width))+"px";
			document.body.appendChild(qqtip);
			Tools.QQTip.obj = qqtip;
			setTimeout("Tools.QQTip.rising()",Tools.QQTip.time);
		},
		rising:function() {
			if (Tools.QQTip.obj!=null) {
				if (parseInt(Tools.QQTip.obj.style.height)<Tools.QQTip.height) {
					if (Tools.isFixed) {
						Tools.QQTip.obj.style.top = (parseInt(Tools.QQTip.obj.style.top)-1)+"px";
						Tools.QQTip.obj.style.height = (parseInt(Tools.QQTip.obj.style.height)+1)+"px";
					}
					else {
						if (!Tools.isFixed) {
							Tools.QQTip.obj.style.left = Tools.clientWidth()+parseInt(document.documentElement.scrollLeft)-parseInt(Tools.QQTip.obj.style.width)+"px";
						}
						Tools.QQTip.obj.style.top = (Tools.clientHeight()+parseInt(document.documentElement.scrollTop)-parseInt(Tools.QQTip.obj.style.height)-1)+"px";
						Tools.QQTip.obj.style.height = (parseInt(Tools.QQTip.obj.style.height)+1)+"px";
					}
					setTimeout("Tools.QQTip.rising()",Tools.QQTip.time);
				}
				else if (!Tools.isFixed) {
					setTimeout("Tools.QQTip.keep()",100);
				}
			}
		},
		keep:function() {
			Tools.QQTip.obj.style.left = Tools.clientWidth()+parseInt(document.documentElement.scrollLeft)-parseInt(Tools.QQTip.obj.style.width)+"px";
			Tools.QQTip.obj.style.top = Tools.clientHeight()+parseInt(document.documentElement.scrollTop)-parseInt(Tools.QQTip.obj.style.height)+"px";
			setTimeout("Tools.QQTip.keep()",100);
		},
		close:function() {
			if (Tools.QQTip.obj!=null) {
				Tools.QQTip.obj.parentNode.removeChild(Tools.QQTip.obj);
				Tools.QQTip.obj=null;
			}
		}	
	}
}