/*****************************************************************
    jspublic.js
    2007-10-06
    封装了项目中所用到的js公共方法
    修改日志：
    	2008-04-07：解决验证类型中的死循环bug
    	2008-04-08：增加email的验证方法
    	
*****************************************************************/
//格式化日期方式
Date.prototype.format = function(format){
    	var o =
    	{
        	"M+" : this.getMonth()+1, //month
       	 	"d+" : this.getDate(),    //day
        	"h+" : this.getHours(),   //hour
        	"m+" : this.getMinutes(), //minute
        	"s+" : this.getSeconds(), //second
        	"q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        	"S" : this.getMilliseconds() //millisecond
    	}
    	if(/(y+)/.test(format))
    	format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
    	for(var k in o)
    	if(new RegExp("("+ k +")").test(format))
    	format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
    	return format;
}
//通过Servlet的通用打印2带WEB根
function printSetupByServlet2(title,root) {
	htmlurl = root+"/PublicListPrintServlet?TblName=" + title;
	var newwin = window.open(htmlurl, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" + (screen.availheight / 2 - 220) + " ,left=" + (screen.availwidth / 2 - 150) + ",width=300,height=440");
}
//打开一个窗口
function JsOpenWin(htmlurl,tmpWidth,tmpHeight){
   var  top = ((window.screen.availHeight-document.body.clientHeight)/2);  
   var  left = ((window.screen.availWidth-document.body.clientWidth)/2);  
	window.open(htmlurl, "printsetup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" 
		+ top
		+ " ,left=" 
		+ left
		+ ",width="+tmpWidth+"px,height=" + tmpHeight + "px");
}

/////////////////////////////////////////////////////处理页面标签中的查询部分脚本
function ListSearch(SearchNum) {
	var tmpstr = " and ";
	for (i = 1; i <= SearchNum; i++) {
		if (document.all("SValue" + i).value != "") {			
			tmpstr = tmpstr + document.all("Field" + i).value.split(":")[0] + " " + document.all("HH" + i).value;
			if (document.all("HH" + i).value == "like" || document.all("HH" + i).value == "not like") {
				tmpstr = tmpstr + " '%" + document.all("SValue" + i).value + "%' ";
			}else {
				tmpstr = tmpstr + " '" + document.all("SValue" + i).value + "' ";
			}
			if (i < SearchNum) {
				for (j = i + 1; j <= SearchNum; j++) {
					if (document.all("SValue" + j).value != "") {
						tmpstr = tmpstr + " " + document.all("AndOr" + i).value + " ";
						break;
					}
				}
			}
		}
	}
	if (tmpstr != " and ") {
		window.Form1.where1.value = " 1=1 " + tmpstr;
	}else {
		window.Form1.where1.value = " 1=1 ";
	}
	window.Form1.submit();
}

/////////////////////////////////////////////////////锁定表头脚本
function DrawTable(scrTable, newTable, iStart, iEnd, jEnd) {
	var i, j, k = 0, newTR, newTD, intWidth = 0, intHeight = 0;
	newTable.mergeAttributes(scrTable);
	for (i = iStart; i < iEnd; i++) {
		newTR = newTable.insertRow(k);
		newTR.mergeAttributes(scrTable.rows[i]);
		intHeight += scrTable.rows[i].offsetHeight;
		intWidth = 0;
		for (j = 0; j < (jEnd == -1 ? scrTable.rows[i].cells.length : jEnd); j++) {
			newTD = scrTable.rows[i].cells[j].cloneNode(true);
			intWidth += scrTable.rows[i].cells[j].offsetWidth;
			newTR.insertBefore(newTD);
			newTD.style.pixelWidth = scrTable.rows[i].cells[j].offsetWidth;
		}
		k++;
	}
	newTable.style.pixelWidth = intWidth;
	newTable.style.pixelHeight = intHeight;
}

function LockTable(arTable, ColNum, RowHead, RowFoot) {
	arTable.HeadRow = RowHead;
	var objDivMaster = arTable.parentElement;
	if (objDivMaster.tagName != "DIV") {
		return;
	}
	if ((arTable.offsetHeight > objDivMaster.offsetHeight) && (arTable.offsetWidth > objDivMaster.offsetWidth)) {
		if ((ColNum > 0) && (RowHead > 0)) {
			var objTableLH = document.createElement("TABLE");
			var newTBody = document.createElement("TBODY");
			objTableLH.insertBefore(newTBody);
			objTableLH.id = "objTableLH";
			objDivMaster.parentElement.insertBefore(objTableLH);
			DrawTable(arTable, objTableLH, 0, RowHead, ColNum);
			objTableLH.srcTable = arTable;
			with (objTableLH.style) {
				zIndex = 804;
				position = "absolute";
				pixelLeft = objDivMaster.offsetLeft;
				pixelTop = objDivMaster.offsetTop;
			}
		}
		if ((ColNum > 0) && (RowFoot > 0)) {
			var objTableLF = document.createElement("TABLE");
			var newTBody = document.createElement("TBODY");
			objTableLF.insertBefore(newTBody);
			objTableLF.id = "objTableLF";
			objDivMaster.parentElement.insertBefore(objTableLF);
			DrawTable(arTable, objTableLF, arTable.rows.length - RowFoot, arTable.rows.length, ColNum);
			objTableLF.srcTable = arTable;
			with (objTableLF.style) {
				zIndex = 803;
				position = "absolute";
				pixelLeft = objDivMaster.offsetLeft;
				pixelTop = objDivMaster.offsetTop + objDivMaster.offsetHeight - objTableLF.offsetHeight - 16;
			}
		}
	}
	if ((RowHead > 0) && (arTable.offsetHeight > objDivMaster.offsetHeight)) {
		var DivHead = document.createElement("DIV");
		objDivMaster.parentElement.insertBefore(DivHead);
		var objTableHead = document.createElement("TABLE");
		var newTBody = document.createElement("TBODY");
		objTableHead.id = "HeadTar";
		objTableHead.style.position = "relative";
		objTableHead.insertBefore(newTBody);
		DivHead.insertBefore(objTableHead);
		DrawTable(arTable, objTableHead, 0, RowHead, -1);
		HeadTar.srcTable = arTable;
		with (DivHead.style) {
			overflow = "hidden";
			zIndex = 802;
			pixelWidth = objDivMaster.offsetWidth - 16;
			position = "absolute";
			pixelLeft = objDivMaster.offsetLeft;
			pixelTop = objDivMaster.offsetTop;
		}
		objDivMaster.attachEvent("onscroll", divScroll1);
	}
	if ((RowFoot > 0) && (arTable.offsetHeight > objDivMaster.offsetHeight)) {
		var DivFoot = document.createElement("DIV");
		objDivMaster.parentElement.insertBefore(DivFoot);
		var objTableFoot = document.createElement("TABLE");
		var newTBody = document.createElement("TBODY");
		objTableFoot.insertBefore(newTBody);
		objTableFoot.id = "FootTar";
		objTableFoot.style.position = "relative";
		DivFoot.insertBefore(objTableFoot);
		DrawTable(arTable, objTableFoot, arTable.rows.length - RowFoot, arTable.rows.length, -1);
		objTableFoot.srcTable = arTable;
		with (DivFoot.style) {
			overflow = "hidden";
			zIndex = 801;
			pixelWidth = objDivMaster.offsetWidth - 16;
			position = "absolute";
			pixelLeft = objDivMaster.offsetLeft;
			pixelTop = objDivMaster.offsetTop + objDivMaster.offsetHeight - DivFoot.offsetHeight - 16;
		}
		objDivMaster.attachEvent("onscroll", divScroll2);
	}
	if ((ColNum > 0) && (arTable.offsetWidth > objDivMaster.offsetWidth)) {
		var DivLeft = document.createElement("DIV");
		objDivMaster.parentElement.insertBefore(DivLeft);
		var objTableLeft = document.createElement("TABLE");
		var newTBody = document.createElement("TBODY");
		objTableLeft.insertBefore(newTBody);
		objTableLeft.id = "LeftTar";
		objTableLeft.style.position = "relative";
		DivLeft.insertBefore(objTableLeft);
		DrawTable(arTable, objTableLeft, 0, arTable.rows.length, ColNum);
		LeftTar.srcTable = arTable;
		with (DivLeft.style) {
			overflow = "hidden";
			zIndex = 800;
			pixelWidth = objDivMaster.offsetWidth - 16;
			pixelHeight = objDivMaster.offsetHeight - 16;
			position = "absolute";
			pixelLeft = objDivMaster.offsetLeft;
			pixelTop = objDivMaster.offsetTop;
		}
		objDivMaster.attachEvent("onscroll", divScroll3);
	}
}
function divScroll1() {
	var tbl = document.all("HeadTar").srcTable, parDiv = tbl.parentElement;
	while (parDiv.tagName != "DIV") {
		parDiv = parDiv.parentElement;
	}
	window.status = -parDiv.scrollLeft;
	document.all("HeadTar").style.pixelLeft = -parDiv.scrollLeft;
}
function divScroll2() {
	var tbl = document.all("FootTar").srcTable, parDiv = tbl.parentElement;
	while (parDiv.tagName != "DIV") {
		parDiv = parDiv.parentElement;
	}
	window.status = -parDiv.scrollLeft;
	document.all("FootTar").style.pixelLeft = -parDiv.scrollLeft;
}
function divScroll3() {
	var tbl = document.all("LeftTar").srcTable, parDiv = tbl.parentElement;
	while (parDiv.tagName != "DIV") {
		parDiv = parDiv.parentElement;
	}
	window.status = -parDiv.scrollLeft;
	document.all("LeftTar").style.pixelTop = -parDiv.scrollTop;
}
/////////////////////////////////////////////////////锁定表头脚本结束

/////////////////////////////////////////////////////拖动列宽脚本
function MouseDownToResize(obj) {
	obj.mouseDownX = event.clientX;
	obj.pareneTdW = obj.parentElement.offsetWidth;
	obj.pareneTableW = mxh.offsetWidth;
	obj.setCapture();
}
function MouseMoveToResize(obj, clo) {
	if (!obj.mouseDownX) {
		return false;
	}
	var newWidth = obj.pareneTdW * 1 + event.clientX * 1 - obj.mouseDownX;
	if (newWidth > 0) {
		obj.parentElement.style.width = newWidth;
		document.getElementById("mxh").rows[0].cells[clo].style.width = newWidth;
		document.all("tblHeadDiv").style.pixelLeft = -document.all("mxhDiv").scrollLeft;
	}
}
function MouseUpToResize(obj) {
	obj.releaseCapture();
	obj.mouseDownX = 0;
}
/////////////////////////////////////////////////////拖动列宽脚本结束
function formSubmit(page) {
	document.forms[0].submit();
}
function gb_bgcolor(e, iRowID) {
	ioldSelectRow = document.getElementById("oldSelectRow").value;
	if (ioldSelectRow != "") {
		document.getElementById(ioldSelectRow).bgColor = "";
	}
	e.bgColor = "#cccccc";
	document.getElementById("oldSelectRow").value = iRowID;
}
//新的选择列表行的事件
//新的选择列表行的事件
function gb_bgcolor2(e, iRowID) {
	ioldSelectRow = document.getElementById("oldSelectRow").value;
	
	if (ioldSelectRow != "") {
	    	try{
			document.getElementById(ioldSelectRow).style.backgroundColor = "";
		}
		catch(eii){}
	}
	e.style.backgroundColor = "#cccccc";
	document.getElementById("oldSelectRow").value = iRowID;
}

function doWhereKey(e) {
	document.getElementById("key_where").value = document.getElementById("key_where_" + e.id).value;
	alert("key_where:" + document.getElementById("key_where").value);
}

function doAWhereKey(e) {
	document.getElementById("key_where").value = document.getElementById("key_where_" + e.id.toString().substr(1)).value;
	alert("key_where:" + document.getElementById("key_where").value);
}

/////////////////////////////////////////////////////全选脚本，在通用列表标记库中使用
function SelectAll() {
	if (document.all.C_Select == null)
		return;
	if (document.all.C_Select.length == null) {
		document.all.C_Select.checked = document.all.C_SelectALL.checked;
	} else {
		for (i = 0; i < document.all.C_Select.length; i++) {
			if(!document.all.C_Select.disabled)
				document.all.C_Select[i].checked = document.all.C_SelectALL.checked;
		}
	}
}

/////////////////////////////////////////////////////选择批量操作的内容
function ChangeSzValue() {
   if (document.all.ZdSzNr.value == ''){
      document.all.ZdSzValue.readOnly = true;
      document.all.cmdselect.style.visibility = "hidden";
   }
   else{
    		//代码:类型:下拉选择SQL
    var dmbz = document.all.ZdSzNr.value.split(":");
    		//字典的设置值
	document.all.ZdSzValue.value = "";
	//字典代码
	document.all.ZdSzCode.value = dmbz[0];
		//字典的显示内容
	document.all.ZdSzCodeValue.value = "";
		// 如果有字典内容显示字典内容
	if (dmbz.length > 2){
      document.all.ZdSzValue.readOnly = true;
      document.all.cmdselect.style.visibility = "visible";
		}else {// 不是字典			
	  document.all.ZdSzValue.readOnly = false;
      document.all.cmdselect.style.visibility = "hidden";
	}
  }
  document.getElementById('ZdSzCodeValue').value = "";
  document.getElementById('ZdSzValue').value = "";
  document.getElementById('ZDSXkeydm').value = "";
  document.getElementById("hiddenframe").style.display = "none";
}

function ZdSz() {
	if (document.all.ZdSzNr.value == "") {
		alert("请先指定要设置的内容!");
		document.all.ZdSzNr.focus();
		return false;
	}
	if (document.all.ZdSzValue.value == "") {
		alert("请先指定要设置的内容!");
		document.all.ZdSzValue.focus();
		return false;
	}

	var c_select=document.getElementsByName("C_Select");
	var val="",isSelect=false;	

	//判断是否选定记录
	for(var i=0;i<c_select.length;i++) {
		if(c_select[i].checked==true){// No selected 属性
			val+="'"+c_select[i].value+"',";
			isSelect=true;
		}
	}
	if(!isSelect) {
		alert('指定设置无效，没有选择记录！');
		return false;
	}else {
		if(document.all.ZdSzNr.value.split(":")[1]=="0"){
			var result=false;
			result=checkNumber(document.all.ZdSzValue);				
			if(result==true) {
				ZdZcing.style.visibility = "visible";
				if(document.all.ZdSzValueTemp.value=='')
					document.all.ZdSzValueTemp.value = document.all.ZdSzValue.value;					
				document.all.PlAction.value = "set";
				document.all.ZDSXkeydm.value = document.all.ZdSzNr.value;
				document.all.ZdSzCodeValue.value = document.all.ZdSzValue.value;				
				document.Form1.submit();
				ZdZcing.style.visibility = "hidden";
			}else{
				ZdZcing.style.visibility = "hidden";
				return false;
			}
		}
		if (!CheckCanDelete("设置<" + document.all.ZdSzNr.options[document.all.ZdSzNr.selectedIndex].text+">")) {
			return false;
		}
		//设置值		
		ZdZcing.style.visibility = "visible";
		if(document.all.ZdSzValueTemp.value=='')
			document.all.ZdSzValueTemp.value = document.all.ZdSzValue.value;
		if(document.all.ZdSzValueTemp.value=='可用')
			document.all.ZdSzValueTemp.value='1';
		if(document.all.ZdSzValueTemp.value=='不可用')
			document.all.ZdSzValueTemp.value='0';
		document.all.PlAction.value = "set";
		document.all.ZDSXkeydm.value = document.all.ZdSzNr.value;
		document.all.ZdSzCodeValue.value = document.all.ZdSzValue.value;		
		document.Form1.submit();
		ZdZcing.style.visibility = "hidden";
		document.all.PlAction.value = "";
		document.all.ZdSzValueTemp.value = "";
	}	
}

//批量设置事件
/**
function ZdSz() {
	if (document.all.ZdSzNr.value == "") {
		alert("请先指定要设置的内容!");
		document.all.ZdSzNr.focus();
		return false;
	}
	if (document.all.ZdSzValue.value == "") {
		alert("请先指定要设置的倄1 7!");
		document.all.ZdSzValue.focus();
		return false;
	}
	if (!CheckCanDelete("设置<" + document.all.ZdSzNr.options[document.all.ZdSzNr.selectedIndex].text+">")) {
		return false;
	}
	document.all.ZdSzValueTemp.value = document.all.ZdSzValue.value;
	document.all.PlAction.value = "set";
	ZdZcing.style.visibility = "visible";
	document.Form1.submit();
	ZdZcing.style.visibility = "hidden";
} 
*/
/*
//批量设置事件
function ZdSz() {
	if (document.all.ZdSzNr.value == "") {
		alert("请先指定要设置的内容!");
		document.all.ZdSzNr.focus();
		return false;
	}
	if (document.all.ZdSzValue.value == "") {
		alert("请先指定要设置的内容!");
		document.all.ZdSzValue.focus();
		return false;
	}

	var c_select=document.getElementsByName("C_Select");
	var val="",isSelect=false;	

	//判断是否选定记录
	for(var i=0;i<c_select.length;i++) {
		if(c_select[i].checked==true){// No selected 属性
			val+="'"+c_select[i].value+"',";
			isSelect=true;
		}
	}
	if(!isSelect) {
		alert('指定设置无效，没有选择记录！');
		return false;
	}else {
		if(document.all.ZdSzNr.value.split(":")[1]=="0"){
			var result=false;
			result=checkNumber(document.all.ZdSzValue);				
			if(result==true) {
				ZdZcing.style.visibility = "visible";
				document.all.ZdSzValueTemp.value = document.all.ZdSzValue.value;
				document.all.PlAction.value = "set";
				document.all.ZDSXkeydm.value = document.all.ZdSzNr.value;
				document.all.ZdSzCodeValue.value = document.all.ZdSzValue.value;				
				document.Form1.submit();
				ZdZcing.style.visibility = "hidden";
			}				
		}
		if (!CheckCanDelete("设置<" + document.all.ZdSzNr.options[document.all.ZdSzNr.selectedIndex].text+">")) {
			return false;
		}
		//设置值		
		ZdZcing.style.visibility = "visible";
		document.all.ZdSzValueTemp.value = document.all.ZdSzValue.value;
		document.all.PlAction.value = "set";
		document.all.ZDSXkeydm.value = document.all.ZdSzNr.value;
		document.all.ZdSzCodeValue.value = document.all.ZdSzValue.value;		
		document.Form1.submit();
		ZdZcing.style.visibility = "hidden";
	}	
}
*/

//选择查询操作的内容
function szSearchValue(i) {
	var searchF = document.all('Field'+i).value;
	document.all('SValue'+i).value = "";
	if (document.all('Field'+i).value == ''){
      		document.all('cmdselectS'+i).style.visibility = "hidden";
   	}else {
    		//代码:类型:下拉选择SQL
    		var dmbz = searchF.split(":");
		//字典代码
		document.all.ZdSzCode.value = dmbz[0];
		//字典的显示内容
		document.all.ZdSzCodeValue.value = "";
		// 如果有字典内容显示字典内容
		if (dmbz.length > 2){
      			document.all('cmdselectS'+i).style.visibility = "visible";
		}else {// 不是字典			
	  		document.all('cmdselectS'+i).style.visibility = "hidden";
			if (dmbz[1]=="10") {
				document.all('SValue'+i).value = "yyyy-MM-dd";
			}else if (dmbz[1]=="11") {
				document.all('SValue'+i).value = "yyyy-MM-dd hh:mm:ss";
			}else if (dmbz[1]=="12") {
				document.all('SValue'+i).value = "yyyyMM";
			}else if (dmbz[1]=="13") {
				document.all('SValue'+i).value = "yyyyMMdd";
			}else if (dmbz[1]=="14") {
				document.all('SValue'+i).value = "yyyyMMddhhmmss";
			}
		}
  	}
	document.getElementById('ZdSzCodeValue').value = "";  	
  	document.getElementById('ZDSXkeydm').value = "";
  	document.getElementById("hiddenframe").style.display = "none";
}

//查询操作选择弹出iframe
function ChooseHiddenframeS(i){
	var tmpUrl = "../../selectDictionary.do?method=execute&typeCode="+i+"&type=" + document.all('Field'+i).value;
	var abe=getLTWH(document.getElementById('SValue'+i));

	document.getElementById("hiddenframe").style.position = "absolute";
    	document.getElementById("hiddenframe").style.border = 0;
	document.getElementById("hiddenframe").width = 205;
	document.getElementById("hiddenframe").height = 225;
    	document.getElementById("hiddenframe").style.pixelLeft = abe.left;
	document.getElementById("hiddenframe").style.top = abe.top;
	document.getElementById("hiddenframe").style.display = "";
    	window.frames["hiddenframe"].location = tmpUrl;	
}

//检查数据类型事件
function CheckDataLx(obj, Lx) {
	s_array_objvalue = obj.value.toString().split("|");
	tmpstr = s_array_objvalue[0];
	if (trimstr(tmpstr) != "") {
		if (Lx == "number") {
			if (!checkNum(tmpstr)) {
				alert("必须输入数字！");
				obj.focus();
				obj.value = "";
				try {
					return false;
				}catch (exception) {
					return false;
				}
			}
		}else {
			if (Lx == "date") {
				if (!checkDate(tmpstr)) {
					alert("必须输入日期格式，例如：2007-01-01");
					obj.value = "";
					obj.focus();
					try {
						return false;
					}
					catch (exception) {
						return false;
					}
				}
			}
		}
	}
	return true;
}

//JS中的Trim方法，替换字符串中的空格
function trimstr(s){
  	return s.replace(/(^\s*)|(\s*$)/g, ""); 
}


//批量设置选择值事件
function SelectValueCode() {
	var batchSeter = document.all.batchSeter.value;
	var ZdSzCode = document.all.ZdSzCode.value;
	var zdBeanName = document.all.zdBeanName.value;
	var htmlurl = "public.do?method=ZdSearch&ZdSzCode=" + ZdSzCode + "&zdBeanName=" + zdBeanName + "&batchSeter=" + batchSeter;
	var newwin = window.open(htmlurl, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" + (screen.availheight / 2 - 147) + " ,left=" + (screen.availwidth / 2 - 110) + ",width=220,height=330");
}

//批量删除事件
function DeleteSelectedData(iPageNum) {
	if (!CheckCanDelete("删除")) {
		return false;
	}
	document.Form1.PlAction.value = "del";
	creating.style.visibility = "visible";
	document.Form1.submit();
	creating.style.visibility = "hidden";
}

//检查复选脚本
function CheckCanDelete(strOper) {
	var CanDelete = false;
	if (document.all.C_Select == null) {
		CanDelete = false;
	}else {
		if (document.all.C_Select.length == null) {
			CanDelete = document.all.C_Select.checked;
		}else {
			for (i = 0; i < document.all.C_Select.length; i++) {
				if (document.all.C_Select[i].checked) {
					CanDelete = true;
					break;
				}
			}
		}
	}
	if (!CanDelete) {
		alert("指定" + strOper + "无效,没有选择记录!");
		return false;
	}else if (!confirm("您所选择的记录将被指定" + strOper + ",继续？")) {
		return false;
	}
	return true;
}

//打开一个模态窗口
function JsMod(htmlurl,tmpWidth,tmpHeight){
	var newwin = window.showModalDialog(htmlurl,"","dialogWidth:"+tmpWidth+"px;status:no;dialogHeight:"+tmpHeight+"px");
	if (newwin != null && newwin == "ok"){
	    	creating.style.visibility='visible';
	    	window.Form1.submit();
	}
} 

//通过Servlet的通用设置个性化列表 url必须带路径,格式如/jiaowu/kkgl/listKktzd.jsp
function setPrivateShowByServlet(url,root) {
	htmlurl = root+"/PublicPrivateShowServlet?url=" + url;
	var newwin = window.open(htmlurl, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=" + (screen.availheight / 2 - 220) + " ,left=" + (screen.availwidth / 2 - 150) + ",width=300,height=440");
}

//通过Servlet的通用打印
function printSetupByServlet(title) {
	htmlurl = "../PublicListPrintServlet?TblName=" + title;
	var newwin = window.open(htmlurl, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" + (screen.availheight / 2 - 220) + " ,left=" + (screen.availwidth / 2 - 150) + ",width=300,height=440");
}
//通过Servlet的通用打印2带WEB根
function printSetupByServlet2(title,root) {
	htmlurl = root+"/PublicListPrintServlet?TblName=" + title;
	var newwin = window.open(htmlurl, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" + (screen.availheight / 2 - 220) + " ,left=" + (screen.availwidth / 2 - 150) + ",width=300,height=440");
}
//通过Servlet的sql通用打印
function printSetupByServlet3(title,root,isSql) {
	htmlurl = root+"/PublicListPrintServlet?TblName=" + title+"&isSql="+isSql;
	var newwin = window.open(htmlurl, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" + (screen.availheight / 2 - 220) + " ,left=" + (screen.availwidth / 2 - 150) + ",width=300,height=440");
}
//通过Servlet的通用打印4带WEB根
function printSetupByServlet4(title,root,url) {
	htmlurl = root+"/PublicListPrintServlet?TblName=" + title+"&url="+url;
	var newwin = window.open(htmlurl, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" + (screen.availheight / 2 - 220) + " ,left=" + (screen.availwidth / 2 - 150) + ",width=300,height=440");
}
//通过Servlet的通用打印5带WEB根
function printSetupByServlet5(title,root,isSql,url) {
	htmlurl = root+"/PublicListPrintServlet?TblName=" + title+"&url="+url+"&isSql="+isSql;
	var newwin = window.open(htmlurl, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" + (screen.availheight / 2 - 220) + " ,left=" + (screen.availwidth / 2 - 150) + ",width=300,height=440");
}
//打开一个窗口
function JsOpenWin(htmlurl,tmpWidth,tmpHeight){
   	var  top = ((window.screen.availHeight-document.body.clientHeight)/2);  
   	var  left = ((window.screen.availWidth-document.body.clientWidth)/2);  
	window.open(htmlurl, "printsetup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=" 
		+ top
		+ " ,left=" 
		+ left
		+ ",width="+tmpWidth+"px,height=" + tmpHeight + "px");
}

//检查输入是否是数字
function checkcapital(input, flag) {
	if (input.value == "") return false;
	str = input.value;
	var checkOK;
	var checkStr = str;
	var allValid = true;
	var allNum = "";
	if (flag == 0) {
		checkOK = "0123456789-, ";
	} else {
		checkOK = "0123456789";
	}
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i);
		for (j = 0; j < checkOK.length; j++) {
			if (ch == checkOK.charAt(j)) {
				break;
			}
		}
		if (j == checkOK.length) {
			allValid = false;
			break;
		}
		allNum += ch;
	}
	if (!allValid) {
		alert("输入的数据必须是数字!");
		input.value = "";
		input.focus();
		input.select();
		return (false);
	}
	return true;
}

//弹出一般窗口
function JsAdd(url, iWidth, iHeight, iTop, iLeft) {
	open(url, "Detail", "Scrollbars=no,Toolbar=no,Location=no,Direction=no,resizable=yes,Width=" + iWidth + " ,Height=" + iHeight + ",top=" + iTop + ",left=" + iLeft); 
}

//转入页事件
function submitpage(maxPageNum) {
	if (document.getElementById('txtpage').value == "") {
		alert("请输入要查看的页码！");
		document.getElementById('txtpage').focus();
		return false;
	} else {
		ipage = parseInt(document.getElementById('txtpage').value);
		if (isNaN(ipage)) {
			alert("请确认输入的是数字!");
			document.getElementById('txtpage').focus();
			return false;
		} else {
			if (ipage < 1) {
				document.Form1.PageNum.value = "1";
				ipage = 1;
			}
			if (ipage > maxPageNum) {
				document.Form1.PageNum.value = maxPageNum;
				ipage = maxPageNum;
			}
			document.Form1.PageNum.value = ipage;
			creating.style.visibility = "visible";
			document.Form1.submit();
			return true;
		}
	}
}

//子报表的打开关闭事件，第二个版本
function openclose2(rowIndex, subTableHeight, url, basePath) {
	var closeimg = basePath + "/framework/images/menu_close.gif";
	var openimg = basePath + "/framework/images/menu_open.gif";
	if (document.getElementById("img" + rowIndex).src.indexOf("close") > 0) {
		document.getElementById("img" + rowIndex).src = openimg;
		if (document.getElementById("subtd" + rowIndex).innerHTML.length <= 6){
		    	document.getElementById("subtd" + rowIndex).innerHTML = "<iframe scrolling=no id=\"subiframe" + rowIndex + "\" width=90% height=" + subTableHeight + " src=\"\"></iframe>";
		   	document.all("subiframe" + rowIndex).src = url;
		}
		document.all("subtr" + rowIndex).style.display = "block";
	} else {
		document.getElementById("img" + rowIndex).src = closeimg;
		document.all("subtr" + rowIndex).style.display = "none";
	}
}

//点击保存按钮--增加(增修删用)
function submitAdd(action1){
    	var notnul=document.Form1.notNull.value.split(/,/g);
    	for(var i=0;i<notnul.length;i++){
    		var temp=notnul[i].split(/:/g);
    		if(trimstr(document.getElementById(temp[1]).value)==""){
       			alert(temp[0]+'不能为空');
       			//temp[1].fouce();
       			//temp[1].select();
       			return false;
      		}
    	}
    	document.Form1.addButton1.disabled="true";
    	if(action1=="null"){
       		document.Form1.actionUrl.value="add";
       		window.Form1.submit();
    	}else{
       		window.Form1.action  = action1;
       		window.Form1.submit();
    	}
}
//点击保存按钮--修改(增修删用)
function submitEdit(action1){
 	var notnul=document.Form1.notNull.value.split(/,/g);
    	for(var i=0;i<notnul.length;i++){
    		var temp=notnul[i].split(/:/g);
    		if(trimstr(document.getElementById(temp[1]).value)==""){
       			alert(temp[0]+'不能为空');
     			//temp[1].fouce();
       			//temp[1].select();
       			return false;
      		}
    	}
    	document.Form1.addButton2.disabled="true";
    	document.Form1.loadTimes.value=1;
    	if(action1=="null"){
       		document.Form1.actionUrl.value="edit";
       		window.Form1.submit();
    	}else {
       		window.Form1.action = action1;
       		window.Form1.submit();
    	}
}
//点击删除按钮--删除(增修删用)
function submitDel(action1){
   	if(!confirm('数据将被删除,是否继续?')) {
		return false;
	}
    	document.Form1.delButton.disabled="true";
    	document.Form1.loadTimes.value=1;
    	if(action1=="null"){
       		document.Form1.actionUrl.value="del";
       		window.Form1.submit();
    	}else{
       		window.Form1.action= action1;
       		window.Form1.submit();
    	}
}

//查询事件
function JsFind(htmlurl,tmpWidth,tmpHeight){
	var newwin = window.showModalDialog(htmlurl,"","dialogWidth:"+tmpWidth+"px;status:no;dialogHeight:"+tmpHeight+"px");
	if (newwin != null) {
		if (newwin.type == "ok") {
			window.Form1.where1.value = newwin.wheresql;
			window.Form1.OrderBy.value = newwin.OrderBy;
			window.Form1.PageNum.value = "1";
			creating.style.visibility='visible';
			window.Form1.submit();
		}
	}
}
 
 //增加事件
function JsMAdd(htmlurl,tmpWidth,tmpHeight){
	var newwin = window.showModalDialog(htmlurl,"","dialogWidth:"+tmpWidth+"px;status:no;dialogHeight:"+tmpHeight+"px");
	if (newwin == null){
		creating.style.visibility='visible';
		window.Form1.submit();
	}else if (newwin == "ok") {
		if (confirm("是否再次增加纪录？")){
			JsMAdd(htmlurl,tmpWidth,tmpHeight);
		}else {
			creating.style.visibility='visible';
			window.Form1.submit();
		}
	}
}


//显示\隐藏表格
function showTable(imgId, divId) {
    	var tableDivObj = document.getElementById(divId);
    	tableDivObj.style.display = (tableDivObj.style.display == "none" ? "block" : "none");
} 

//判断身份证格式
function checkIdCard(obj) {
	if (obj.value == "") return false;
	var factorArr = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
	var error;
	var varArray = new Array();
	var intValue;
	var lngProduct = 0;
	var intCheckDigit;
	var idNumber = obj.value;
	var intStrLen = obj.value.length;
	if ((intStrLen != 15) && (intStrLen != 18)) {
		error = "输入身份证号码长度不正确！"; 
		alert(error);
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	for (i = 0; i < intStrLen; i++) {
		varArray[i] = idNumber.charAt(i);
		if ((varArray[i] < "0" || varArray[i] > "9") && (i != 17)) {
			error = "错误的身份证号码！"; 
			alert(error);
			obj.value = "";
			obj.focus();
			obj.select();
			return false;
		}else {
			if (i < 17) {
				varArray[i] = varArray[i] * factorArr[i];
			}
		}
	}
	if (intStrLen == 18) {
		var date8 = idNumber.substring(6, 14);
		if (checkDateId(date8) == false) {
			error = "身份证中日期信息不正确！"; 
			alert(error);
			obj.value = "";
			obj.focus();
			obj.select();
			return false;
		}
		for (i = 0; i < 17; i++) {
			lngProduct = lngProduct + varArray[i];
		}
		intCheckDigit = 12 - lngProduct % 11;
		switch (intCheckDigit) {
		  case 10:
			intCheckDigit = "X";
			break;
		  case 11:
			intCheckDigit = 0;
			break;
		  case 12:
			intCheckDigit = 1;
			break;
		}
		if (varArray[17].toUpperCase() != intCheckDigit) {
			error = "身份证效验位错误!...正确为： " + intCheckDigit + "";
			alert(error);
			obj.value = "";
			obj.focus();
			obj.select();
			return false;
		}
	}else {
		var date6 = idNumber.substring(6, 12);
		if (checkDateId(date6) == false) {
			alert("身份证日期信息有误！");
			obj.value = "";
			obj.focus();
			obj.select();
			return false;
		}
	}
	return true;
}

function checkDateId(date){    
	return true;
}

//判断日期格式
function CheckDate(obj) {
	var sDate = obj.value;
	var iaMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	var iaDate = new Array(3);
	var year, month, day;
	if (arguments.length != 1) {
		alert("程序里调用的参数有错，\n只能一个参数！");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	iaDate = sDate.toString().split("-");
	if (obj.value != "") {
		if (iaDate.length != 3) {
			alert("日期格式错误，正确格式：2000-01-01");
			obj.value = "";
			obj.focus();
			obj.select();
			return false;
		}
		if (iaDate[1].length > 2 || iaDate[2].length > 2) {
			alert("日期格式错误，正确格式：2000-01-01");
			obj.value = "";
			obj.focus();
			obj.select();
			return false;
		}
		year = parseFloat(iaDate[0]);
		month = parseFloat(iaDate[1]);
		day = parseFloat(iaDate[2]);
		if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
			iaMonthDays[1] = 29;
		}
		if (month < 1 || month > 12) {
			alert("月份错误，月份范围应在1-12之间!");
			obj.value = "";
			obj.focus();
			obj.select();
			return false;
		}
		if (day < 1 || day > iaMonthDays[month - 1]) {
			alert("日期错误，日期范围应在1-" + iaMonthDays[month - 1] + "之间");
			obj.value = "";
			obj.focus();
			obj.select();
			return false;
		}
		var reg = /^\d{4}-((0[1-9]{1})|([1-9]{1})|(1[0-2]{1}))-((0[1-9]{1})|([1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1}))$/;
		if (!reg.test(obj.value)) {
			alert("日期格式错误，正确格式：2000-01-01");
			obj.value = "";
			obj.focus();
			obj.select();
			return false;
		}
	}
}
//判断是否为数字
function checkNumber(input)
{
  str = input.value;
  var allValid = true;
  if(str==""){return false;}
  try
  {
	if(parseFloat(str)!=str) allValid = false;
  }
  catch(ex)
  {
	allValid = false;
  }
  if(!allValid){
	alert("输入的数据必须是数字");
	input.value="";
	input.focus();
	return false;
  }
  return true;
}

//判断是否为整数
function checkInteger(input){
	str = input.value;
  	var allValid = true;
  	if(str==""){return false;}
 	try{
		if(parseInt(str)!=str) allValid = false;
  	} catch(ex){
		allValid = false;
	}
	if(!allValid){
		alert("输入的数据必须是数字");
		input.value="";
		input.focus();
		return false;
  	}
  	return true;
}

//判断是否是字符或数字
function checkLetter(input){
	if (input.value == "") return false;
	if(/[^0-9a-zA-Z]/g.test(input.value)){
		alert("必须输入字符或数字");
		input.value="";
		input.focus();
		return false;
	}
	return true;
}
//去除字符串空格
function trim(input){
	return input.replace(/^\s+/g,"").replace(/\s+$/g,"");
}
//判断年月脚本函数yyyyMM
function checkYearMonth(input){
	if (input.value == "") return false;
	if(trim(input.value) != ""){
		var reg = /^\d{4}(0[1-9]{1})|(1[0-2]{1})$/;
		if(!reg.test(input.value) || input.value.length != 6){
			alert("格式错误,正确格式为200701");
			input.value = "";
			input.focus();
			return false;
		}
	}
	return true;
}

/////////////////////////////////////////////////////批量操作选择弹出iframe
function ChooseHiddenframe(basePath){
	var tmpWidth = 200;
	var tmpHeight = 200;
	var tmpUrl = basePath;
	var ChooseType = document.all.ZdSzNr.value.substring(document.all.ZdSzNr.value.lastIndexOf(":")+1);
	switch(ChooseType){
	  case "gymc":		//公寓信息
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "fjzfbz":		//资费标准
	    tmpWidth = "340";
	    tmpHeight = "300";
	    break;
	  case "xbmb":		//性别砄1�7
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "lxtjsm":		//离校条件
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "xn":		//学年
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "xq":   //学期
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "jllbmc":		//奖励类别
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "fxqmc":		//分校匄1�7
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "gyqmc":		//公寓匄1�7
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;  
	  case "lcbh":     //楼层
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "fjbh":    //房间
	  	tmpWidth = "450";
	    tmpHeight = "400";
	    break;
	  case "wpsm":   //物品
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "jgxm":   //军训教官
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "cdmc":   //军训场地
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "jxxmmc":   //军训项目
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "jxmc":   //军训名称
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "tzbzxmmc":   //体制健康标准项目
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	  case "zhcpxmmc":   //综合测评项目
	    tmpWidth = "320";
	    tmpHeight = "300";
	    break;
	}
    tmpUrl = tmpUrl + "/selectDictionary.do?type=" + ChooseType;
	var abe=getLTWH(document.getElementById('ZdSzValue'));
	document.getElementById("hiddenframe").style.position = "absolute";
    document.getElementById("hiddenframe").style.border = 0;
	document.getElementById("hiddenframe").width = tmpWidth;
	document.getElementById("hiddenframe").height = tmpHeight;
    document.getElementById("hiddenframe").style.pixelLeft = abe.left;
	document.getElementById("hiddenframe").style.top = abe.top - tmpHeight - 2;
	document.getElementById("hiddenframe").style.display = "";
	window.frames["hiddenframe"].location = tmpUrl;	
}

/// 找出元素在页面中的坐标和高度,宽度
///element  页面元素
/// <returns>返回元素的绝对Left,Top,Width,Heihgt</returns>
function getLTWH(element) { 
    if ( arguments.length != 1 || element == null )  { 
        return null; 
    } 
    var offsetTop = element.offsetTop; 
    var offsetLeft = element.offsetLeft; 
    var offsetWidth = element.offsetWidth; 
    var offsetHeight = element.offsetHeight; 
    while( element = element.offsetParent ) { 
        offsetTop += element.offsetTop; 
        offsetLeft += element.offsetLeft; 
    } 
    var Abe={
       left:offsetLeft,
       top:offsetTop,
       width:offsetWidth,
       height:offsetHeight
    }
    return Abe;
} 
///////////////选择按钮弹出iframe
function selectFrame(dmField,mcField,ChooseType)
{
	var tmpWidth = "";
	var tmpHeight = "";
	var tmpUrl = "";
	var tmpChooseType = ChooseType;
	var tmpRight = "";
	var strhql="";
	switch(tmpChooseType.toLowerCase())
	{
	   case "bzkzy":		     //选择部颁专业
			tmpWidth = "255";
			tmpHeight = "262";
			break;
	}
    tmpUrl = "../ggxx/selectFrame.do?method=select&type=" + tmpChooseType;
	var abe=getLTWH(document.getElementById(mcField));
	document.getElementById("hiddenframe").style.position = "absolute";
	document.getElementById("hiddenframe").style.border="0px ";
	document.getElementById("hiddenframe").width = tmpWidth;
	document.getElementById("hiddenframe").height = tmpHeight;
	document.getElementById("hiddenframe").style.pixelLeft = abe.left;
	document.getElementById("hiddenframe").style.top = abe.top+abe.height;
	document.getElementById("hiddenframe").style.display = "";
	window.frames["hiddenframe"].location = tmpUrl+"&dmField="+dmField+"&mcField="+mcField+"";	
}

//判断日期格式2 yyyyMMdd
function CheckDate2(obj) {
	if (obj.value == "") return false;
	var sDate = obj.value;
	var iaMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	var iaDate = new Array(3);
	if (sDate.length != 8) {
		alert("日期格式错误，正确格式：20080101");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	iaDate[0] = sDate.substring(0, 4);
	iaDate[1] = sDate.substring(4, 6);
	iaDate[2] = sDate.substring(6, 8);
	var year, month, day;
	if (arguments.length != 1) {
		alert("程序里调用的参数有错，\n只能传入1个参数！");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	if (iaDate[1].length > 2 || iaDate[2].length > 2) {
		alert("日期格式错误，正确格式：20080101");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	year = parseFloat(iaDate[0]);
	if (sDate.substring(4, 5) != "0") {
		month = parseFloat(iaDate[1]);
	} else {
		month = parseFloat(sDate.substring(5, 6));
	}
	if (sDate.substring(6, 7) != "0") {
		day = parseFloat(iaDate[2]);
	} else {
		day = parseFloat(sDate.substring(7, 8));
	}
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
		iaMonthDays[1] = 29;
	}
	if (month < 1 || month > 12) {
		alert("月份错误，月份范围应在1-12之间!");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	if (day < 1 || day > iaMonthDays[month - 1]) {
		alert("日期错误，日期范围应在" + iaMonthDays[month - 1] + "之间");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	var reg = /^\d{4}((0[1-9]{1})|([1-9]{1})|(1[0-2]{1}))((0[1-9]{1})|([1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1}))$/;
	if (!reg.test(obj.value)) {
		alert("日期格式错误，正确格式：20080101");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	return true;
}
//判断年份yyyy
function CheckYear(obj){
	if (arguments.length != 1) {
		alert("程序里调用的参数有错，\n只能传入1个参数！");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	if (obj.value == "") return false;
	if (obj.value.length != 4) {
		alert("日期格式错误，正确格式：2008");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	var reg=new RegExp("^\\d{4}$");
	if(!reg.test(obj.value)){
		alert("日期格式错误，正确格式：2008");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	var year = parseFloat(obj.value);
	if (year < 1970 || year > 2050){
		alert("年份输入错误!");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
}

//判断日期格式3 yyyyMM
function CheckDate3(obj) {
	if (arguments.length != 1) {
		alert("程序里调用的参数有错，\n只能传入1个参数！");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	if (obj.value == "") return false;
	var sDate = obj.value;
	var iaDate = new Array(2);
	if (sDate.length != 6) {
		alert("日期格式错误，正确格式：200801");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	var reg =  /^(\d{4})(\d{2})$/;
	if (!reg.test(obj.value)) {
		alert("日期格式错误，正确格式：200801");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	iaDate[0] = sDate.substring(0, 4);
	iaDate[1] = sDate.substring(4, 6);
	var year, month;
	year = parseFloat(iaDate[0]);
	if (year < 1970 || year > 2050){
		alert("年份输入错误!");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	if (sDate.substring(4, 5) != "0") {
		month = parseFloat(iaDate[1]);
	} else {
		month = parseFloat(sDate.substring(5, 6));
	}
	if (month < 1 || month > 12) {
		alert("月份错误，月份范围应在1-12之间!");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	return true;
}


//验证EMAIL格式
function ValidateEmail(obj){
	if (obj.value == "") return false;
    var emailReg=/^([a-zA-Z0-9_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (!emailReg.test(obj.value)) {
		alert("email格式错误！正确格式：admin@qzsoft.com");
		obj.value = "";
		obj.focus();
		obj.select();
		return false;
	}
	return true;
}
//设置cookie，默认保持30天
function setCookie(name, value) {
	var Days = 30;
	var exp = new Date(); 
	exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
//获取cookie
function getCookie(name) {
	var arr = document.cookie.match(new RegExp("(^|   )" + name + "=([^;]*)(;|$)"));
	if (arr != null) {
		return unescape(arr[2]);
	}
	return "";
}
//删除一个cookie
function delCookie(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = getCookie(name);
	if (cval != null) {
		document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
	}
}
//验证一个地址是否是IP地址
function isIPa(obj) { 
	if (obj.value == "") return false;
	var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g 
	if(re.test(obj.value)){ 
		if( RegExp.$1 <256 && RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256) return true; 
	}
	alert("IP地址格式错误，正确格式：192.168.1.1");
	obj.value = "";
	obj.focus();
	obj.select();
	return false; 
}
//日期时间检查  
//格式为：YYYY-MM-DD HH:MM:SS  
function CheckDateTime(obj){
	if (obj.value == "") return false;
    var reg = /^(\d+)-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/; 
    var reg1 = /^(\d+)-(\d{1,2})-(\d{1,2})$/; 
    var r = obj.value.match(reg); 
    var r1 = obj.value.match(reg1);
    if(r==null&&r1!=null){
    	obj.value = obj.value+" 00:00:00";
    }
    r = obj.value.match(reg); 
    if(r==null){
    	alert("日期时间格式错误，正确格式为：yyyy-MM-dd hh:mm:ss");
		obj.value = "";
		obj.focus();
		obj.select();
    	return false;
    }
    r[2]=r[2]-1;   
    var d= new Date(r[1],r[2],r[3],r[4],r[5],r[6]);
    if(d.getFullYear()!=r[1] || d.getMonth()!=r[2] 
    	|| d.getDate()!=r[3] || d.getHours()!=r[4] 
    	|| d.getMinutes()!=r[5] || d.getSeconds()!=r[6]){
    	alert("日期时间格式错误，正确格式为：yyyy-MM-dd hh:mm:ss");
		obj.value = "";
		obj.focus();
		obj.select();
    	return false;
    }
    return true;   
}

//跳转到你指定的PATH
function GoYourPath(path){
	window.location.href = path;
}

//判断是否为数字和正数 
function checkNumberIsTun(input)
{
  str = input.value;
  var allValid = true;
  
    if(str==""){return false;}
    
    if( str.substr(0,1) =="0" &&  str.substr(1,1)!=".")
	{
	  alert("输入格式错误！");
	  input.value="";
	  input.focus();
	  return false;
	}
	
	try
	 {
		if(parseFloat(str,10)!=str) allValid = false;
	 }
	 catch(ex)
	 {
		allValid = false;
	 }
  if(!allValid){
	alert("输入的数据必须是数字!");
	input.value="";
	input.focus();
	return false;
  }
  else if(eval(str) <= 0)
  {
  	alert("输入的数据必须大于零!");
  	input.value="";
	input.focus();
	return false;
  }
  else if(eval(str) > 9999999999.99)
  {
	alert("数据过大,必须小于百亿!");
	input.value="";
	input.focus();
	return false;
  }
    return true;
}

//判断是否为整数和正数
function checkIntegerIsTun(input)
{
	str = input.value;
  	var allValid = true;
  	if(str==""){return false;}
 	try{
		if(parseInt(str,10)!=str) allValid = false;
  	} 
  	catch(ex)
  	{
		allValid = false;
	}
	if(!allValid){
		alert("输入的数据必须是整数!");
		input.value="";
		input.focus();
		return false;
  	}
  	else if(str <= 0)
    {
      alert("输入的数据必须大于零!");
  	  input.value="";
	  input.focus();
	  return false;
    }
    else if(eval(str) > 99999999)
  	{
	  alert("数据过大,必须小于亿!");
	  input.value="";
	  input.focus();
	  return false;
  	}
  	return true;
}

//判断是否为数字和正数
function checkNumberIsMoney(input)
{
  str = input.value;
  var allValid = true;
  if(str==""){return false;}
  
    if( str.substr(0,1) =="0" &&  str.substr(1,1)!=".")
	{
	  alert("输入格式错误！");
	  input.value="";
	  input.focus();
	  return false;
	}
	try
	 {
		if(parseFloat(str,10)!=str) allValid = false;
	 }
	 catch(ex)
	 {
		allValid = false;
	 }
	 
  if(!allValid){
	alert("输入的数据必须是数字!");
	input.value="";
	input.focus();
	return false;
  }
  else if(eval(str) <= 0)
  {
  	alert("输入的数据必须大于零!");
  	input.value="";
	input.focus();
	return false;
  }
  else if(eval(str) > 999999989999999999.99)
  {
	alert("数据过大!");
	input.value="";
	input.focus();
	return false;
  }
    return true;
}
/****************************************************************************
* 谢平20080924增加一系列检查JS方法
****************************************************************************/
//通过id获得这个对象的值
function getValue(idOrName) {
	return document.getElementById(idOrName).value;
}
//通过id获得对象
function getObj(idOrName) {
	return document.getElementById(idOrName);
}

//检查输入对象是否为空
function isEmpty(s) {
	var bool = false;
	if (s == null || trimstr(s) == "")
		bool = true;
	return bool;
}

//检查用户输入字段是否超过指定长度
function checkInputValueLength(inStr, length) {
	if ((inStr == null) || (trimstr(inStr) == "")) {
		return true;
	}
	if (inStr.length > length) {
		return true;
	}
	return false;
}

//检查用户输入字段长度在两个数之间
function checkInputBetween(inStr, limitLen, maxLen) {
	if ((inStr == null) || (trimstr(inStr) == "")) {
		return false;
	}
	if ((inStr.length < limitLen) || (inStr.length > maxLen)) {
		return true;
	}
	return false;
}

//将查两个字符串是否相等
function checkTwoString(str1, str2) {
	return (str1 == str2);
}

//过滤掉字符串 sString 中的空格，返回过滤后的字符串
function tFilterSpace(sString) {
	var re;
	re = / /g;
	return sString.replace(re, "");
}

//检查字符串1(findval)在字符串2(val)中出现的次数
function stringAppearCount(findval, val) {
	var v1 = 0;
	var v2 = 0;
	while (v1 != -1 && v1 < val.length) {
		v1 = val.indexOf(findval, v1);
		if (v1 >= 0) {
			v1++;
			v2++;
		}
	}
	return v2;
}

//检查字符串1(findval)在字符串2(val)中出现第几次(val3)时的位置
function stringAppearPlace(findval, val, val3) {
	var v1 = 0;
	while (val3 > 0 && v1 != -1 && v1 < val.length) {
		v1 = val.indexOf(findval, v1);
		if (v1 >= 0) {
			v1 = v1 + findval.length;
			val3--;
		}
	}
	if (v1 > 0) {
		v1 = v1 - findval.length();
	}
	return v1;
}

