/**
 *	常用的JS方法
 *
 *	Author: HUSONG  2007年11月19日 16:49:30 @ Shanghai eMap info&tech CO,LTD
 *
 *	husongmm@hotmail.com	QQ:7082928
 */

<!--
	//提示并拷贝信息
	function alertAndCopyMsg(sender){
		window.clipboardData.setData('text', sender); 
		alert(sender + "\n\n信息已经复制到剪切板！\n\n粘贴快捷键：[Ctrl] + V 或者单击鼠标右键选择“粘贴”");
	}

	function zoomtofull(url){
		var paramAttri = 'menubar=0,toolbar=0,directories=0,location=0,width='+screen.availWidth+',height='+(screen.availHeight-50)+',top=0,left=0,status=1,resizable=0,scrollbars=1';
		window.open(url, 'GIS', paramAttri);
	}
	
	 //根据ID获取对象
	function _G(id){
		return document.getElementById(id);
	}
	
	//根据ID获取对象的值
	function _V(id){
		return _G(id).value;
	}
	
	 //根据名称获取对象集合
	function _N(name){
		return document.getElementsByName(name);
	}

	//根据名称判断一组checkbox是否有被选中
	function testChecked(name){
		var obj = _N(name);
		var len = obj.length;
		for(var i=0; i<len; i++){
			if (obj[i].checked) return true;
		}
		return false;
	}

	//全选。 eg: onclick=selectAll(this, "name")
	function selectAll(id, name){
		var obj = _N(name);
		var len = obj.length;
		for(var i=0; i<len; i++){
			if(id.checked && !obj[i].disabled){
				obj[i].checked=true;
			}else{
				obj[i].checked=false;
			}
		}
	}

	//判断INPUT是否为空
	function inputEmpty(id){
		var obj=_G(id);
		if(obj!=null && (obj.value==null || obj.value=="" || obj.value.length<1)) {
			obj.focus();
			return true;
		}
		return false;
	}
	
	//打开网页对话框
	function OpenDialog(url, windowName, width, height, help, status){
		return window.showModalDialog(url, windowName, "DialogWidth:" + width + "px;DialogHeight: " + height + "px;help: " + help + ";status: " + status);
	}

	//打开弹出窗口
	function OpenWindow(url, windowName, top, left, width, height, scrollbars){
		return window.open(url, windowName, "top=" + top + ",left=" + left + ",width=" + width + ",height=" + height + ",scrollbars=" + scrollbars);
	}

	//获取元素上边距
	function getTop(e){
		var offset = e.offsetTop;
		if(e.offsetParent!=null) offset += getTop(e.offsetParent);
		return offset;
	}
	
	//获取元素左边距
	function getLeft(e){
		var offset = e.offsetLeft;
		if(e.offsetParent!=null) offset += getLeft(e.offsetParent);
		return offset;
	}

	//获取注册表键值（需要设置信任的站点） eg: readRegedit("HKLM\\SOFTWARE\\eMapSM\\emapsm_dir")
	function readRegedit(path){
		var oShell = new ActiveXObject("WScript.Shell");
		try
		{
			return oShell.RegRead(path).replace("\\","\\\\");
		}
		catch(e)
		{
			alert("Error Exec Notepad");
			return null;
		}
	}

	//调用可执行EXE文件（需要设置信任的站点）
	function runExe(sPath)
	{
		var oShell = new ActiveXObject("WScript.Shell");
		try
		{
			oShell.Run(sPath);
		}
		catch(e)
		{
			alert("Error Exec Notepad");
		}
	}

	//获取以当前时间(北京时间)的掩码字符串
	function getTimeMaskCode(){
		var now = new Date();
		var yy = now.getYear();
		var MM = (now.getMonth()+1)<10 ? ("0" + (now.getMonth()+1)) : (now.getMonth()+1);
		var dd = (now.getDate())<10 ? ("0" + now.getDate()) : (now.getDate());
		var hh = (now.getHours())<10 ? ("0" + now.getHours()) : (now.getHours());
		var min = (now.getMinutes())<10 ? ("0" + now.getMinutes()) : (now.getMinutes());
		var ss = now.getTime() % 60000;  
	    ss = (ss - (ss % 1000)) / 1000;
	    ss = ss<10 ? ("0" + ss) : ss;
	    
		return yy + "" + MM + "" + dd + "" + hh + "" + min + "" + ss;
	}

	//返回当前日期
	function getDate(){
		var now = new Date();
		var yy = now.getYear();
		var MM = (now.getMonth()+1)<10 ? ("0" + (now.getMonth()+1)) : (now.getMonth()+1);
		var dd = (now.getDate())<10 ? ("0" + now.getDate()) : (now.getDate());
	    
		return yy + "-" + MM + "-" + dd;
	}

	//获取某个时区当前时间
	//zone为时区
	function getCurrentTime(zone){
		var now = new Date();
			now.setHours(now.getHours() - 8);		//转换为标准时区时间。

		zone = parseFloat(zone);
		now.setHours(now.getHours() + zone)

		var minTemp = parseFloat(zone) - parseInt(zone);
		if(minTemp!=0){
			now.setMinutes(now.getMinutes() + 60*minTemp);
		}

		var yy = now.getYear();
		var MM = (now.getMonth()+1)<10 ? ("0" + (now.getMonth()+1)) : (now.getMonth()+1);
		var dd = (now.getDate())<10 ? ("0" + now.getDate()) : (now.getDate());

		var hh = (now.getHours())<10 ? ("0" + now.getHours()) : (now.getHours());
		var min = (now.getMinutes())<10 ? ("0" + now.getMinutes()) : (now.getMinutes());
		var ss = now.getTime() % 60000;  
	    ss = (ss - (ss % 1000)) / 1000;
	    ss = ss<10 ? ("0" + ss) : ss;
	    
		return yy + "-" + MM + "-" + dd + "  " + hh + ":" + min + ":" + ss;
	}

	//全局替换
	function  stringReplaceAll(AFindText,ARepText){
		raRegExp = new RegExp(AFindText,"gm");
		return this.replace(raRegExp,ARepText);
	}

	//更改样式
	function resetClass(obj, className){obj.className = className;}
	
	//获取客户端IP
	function GetLocalIPAddress(){
	    var resultIp = "";
	    try
	    {
	        var ipObj = new ActiveXObject("rcbdyctl.Setting");
	        resultIp = ipObj.GetIPAddress;
	    }
	    catch(err){alert("请先确保你已经信任了本机。" + err.message);}
	    return resultIp;
	}

	function validateIpAccess(accessIpArr){
		var ip = GetLocalIPAddress();
		var isAccess = false;
		if(ip!=null && ip!=""){
			try{
				var ipArr = accessIpArr.split("|");
				for(var i=0; i<ipArr.length; i++){
					if(ip==ipArr[i]) isAccess = true;
				}
			}catch(err){alert(err.message);}
		}
		if(!isAccess){alert("你的IP未被允许使用本机访问本系统(ip：" + ip + ")。请联系管理员"); window.top.location.href="error/404.jsp";}
	}

	//实现TRIM方法
	String.prototype.Trim = function()
	{
	    return this.replace(/(^\s*)|(\s*$)/g, "");
	}
	String.prototype.LTrim = function()
	{
	    return this.replace(/(^\s*)/g, "");
	}
	String.prototype.Rtrim = function()
	{
	    return this.replace(/(\s*$)/g, "");
	}

	//实现MAP类
	function Map() {
		var struct = function(key, value) {
			this.key = key;
			this.value = value;
		}
 
		var put = function(key, value){
			for (var i = 0; i < this.arr.length; i++) {
				if ( this.arr[i].key === key ) {
					this.arr[i].value = value;
					return;
				}
			}
			this.arr[this.arr.length] = new struct(key, value);
		}
	 
		var get = function(key) {
			for (var i = 0; i < this.arr.length; i++) {
				if ( this.arr[i].key === key ) {
					return this.arr[i].value;
				}
			}
			return null;
		}
	 
		var remove = function(key) {
			var v;
			for (var i = 0; i < this.arr.length; i++) {
				v = this.arr.pop();
					if ( v.key === key ) {
						continue;
					}
				this.arr.unshift(v);
			}
		}
	 
		var size = function() {
			return this.arr.length;
		}
	 
		var isEmpty = function() {
			return this.arr.length <= 0;
		}
	
		 this.arr = new Array();
		 this.get = get;
		 this.put = put;
		 this.remove = remove;
		 this.size = size;
		 this.isEmpty = isEmpty;
	}
	
	//下面几个为实现EQUALS方法
	function Object.prototype.equals(obj){
		if(this == obj)return true;
		if(typeof(obj)=="undefined"||obj==null||typeof(obj)!="object")return false;
		var length = 0; var length1=0;
		for(var ele in this) length++;for(var ele in obj) length1++;
		if(length!=length1) return false;
		if(obj.constructor==this.constructor){
			for(var ele in this){
				if(typeof(this[ele])=="object") {if(!this[ele].equals(obj[ele]))return false;}
				else if(typeof(this[ele])=="function"){if(!this[ele].toString().equals(obj[ele].toString())) return false;}
				else if(this[ele]!=obj[ele]) return false;
			}
			return true;
		}
		return false;
	}
	function String.prototype.equals(str){
		if(this==str)return true;
		return false;
	}
	function Function.prototype.equals(func){
		if(this.toString().equals(func.toString()))return true;
		return false;
	}
	function Boolean.prototype.equals(bool){
		if(this==bool)return true;
		if (bool instanceof Boolean){
		    return this.toString().equals(bool.toString());
		} 
		return false;
	}
	
	//将10进制转换为16进制
	function ToHex(n)
	{	var h, l;
		var hexch = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
		n = Math.round(n);
		l = n % 16;
		h = Math.floor((n / 16)) % 16;
		return (hexch[h] + hexch[l]);
	}
	
	//禁用按钮
	function disableButtons(formName){
		var form = document.forms[formName];	   
	    for(var i=0;i<form.elements.length;i++)
	    {
	        if(form.elements[i].type=="button" )
	        {
	            form.elements[i].disabled = true;
	        }    
	    }
	}
	
	//启用按钮
	function enableButtons(formName){
		var form = document.forms[formName];	   
	    for(var i=0;i<form.elements.length;i++)
	    {
	        if(form.elements[i].type=="button" )
	        {
	            form.elements[i].disabled = false;
	        }    
	    }
	}
	
	function callback(res)
	{
		 var str="";
		 if(res != "")
		 {
		  var xmlDoc = new ActiveXObject("Microsoft.xmldom"); 
		  xmlDoc.async = "false";
		  xmlDoc.loadXML(res);
		  var mtitles=xmlDoc.getElementsByTagName("HouseInfo//BID");
		  var arraylength=mtitles.length;
		  var contentArray = new Array();
	
		  for(i=0;i<arraylength;i++)
		  {
		   contentArray[i] = mtitles(i).text;
		  }
		  for(j=0;j<arraylength && j<3;j++)
		  {
		   if (j<arraylength-1 && j<3-1){
		   	str += contentArray[j].toString() + ",";
		   }else{
		    str += contentArray[j].toString();
		   }
		  }
		  str += "...";
		 }
		 return str;
	}
	
	
	function replaceTextExpressChar(formName){
		var form = document.forms[formName];	   
	    for(var i=0;i<form.elements.length;i++)
	    {
	        if(form.elements[i].type=="text" )
	        {
	            form.elements[i].value = replaceAll(form.elements[i].value,'\\','/');;
	        }    
	    }
	}
	
	function replaceTextAreaExpressChar(formName){
		var form = document.forms[formName];	   
	    for(var i=0;i<form.elements.length;i++)
	    {
	        if(form.elements[i].type=="textarea" )
	        {
	            form.elements[i].value = replaceAll(form.elements[i].value,'\\','/');;
	        }    
	    }
	}
	
	function moveStart(event, oObj) {
		oObj.onmousemove = mousemove;
		oObj.onmouseup = mouseup;
		oObj.setCapture ? oObj.setCapture() : function () {};
		oEvent = window.event ? window.event : event;
		var dragData = {x:oEvent.clientX, y:oEvent.clientY};
		var backData = {x:parseInt(oObj.style.top), y:parseInt(oObj.style.left)};
		function mousemove() {
			var oEvent = window.event ? window.event : event;
			var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
			var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
			oObj.style.left = iLeft;
			oObj.style.top = iTop;
			dragData = {x:oEvent.clientX, y:oEvent.clientY};
		}
		function mouseup() {
			var oEvent = window.event ? window.event : event;
			oObj.onmousemove = null;
			oObj.onmouseup = null;
			if (oEvent.clientX < 1 || oEvent.clientY < 1 || oEvent.clientX > document.body.clientWidth || oEvent.clientY > document.body.clientHeight) {
				oObj.style.left = backData.y;
				oObj.style.top = backData.x;
			}
			oObj.releaseCapture ? oObj.releaseCapture() : function () {
			};
		}
	}
//-->