
function gotoPage(intGotoNumber,strUrl)
{
  document.location.href=strUrl+"&PageNumber="+intGotoNumber;
}
function writeBreakPageBar(intRowCount,intStart,intEnd,intPageCount,intPageNumber,strUrl,strSerial)
{
	if(intRowCount==0){
		intStart=-1;
		intEnd=-1;
		intPageNumber=0;
	}
	document.write("<table border='0' cellspacing='0' cellpadding='0' width='100%'><TR height='22' bgcolor='#D9D9D9'><TD>&nbsp;共 <B>"+intRowCount+"</B> 条，列出第 <B>"+(intStart+1)+"</B> 到第 <B>"+(intEnd+1)+"</B> 条</TD><TD align='center' width='150'>");
	if(intPageNumber>1){
		document.write("<A HREF='"+strUrl+"&PageNumber=1"+"'>首页</A>　<A HREF='"+strUrl+"&PageNumber="+(intPageNumber-1)+"'>上页</A>　");
	}
	else{
		document.write("首页　上页");
	}
	if(intPageNumber<intPageCount){
		document.write("<A HREF='"+strUrl+"&PageNumber="+(intPageNumber+1)+"'>下页</A>　<A HREF='"+strUrl+"&PageNumber="+intPageCount+"'>尾页</A>");
	}
	else{
		document.write("下页　尾页");
	}
	document.write("</TD><TD align='center' width='90'>第 <B>"+intPageNumber+"/"+intPageCount+"</B> 页</TD><TD align='center' width='130'>转到 <INPUT TYPE='text' id='txtGotoNumber"+strSerial+"' style='border-width:1pt;width:20;border-style:line;height:18'> 页 <B><span onclick=gotoPage(txtGotoNumber"+strSerial+".value,'"+strUrl+"') style='cursor:hand'>GO...</span></B></TD></TR></table>");
}
//输入空行
function writeTopSpace(){
	document.write("<TABLE border='0' cellspacing='0' cellpadding='0' width='100%'><TR><TD height='5'></TD></TR></TABLE>");
}

function writeSearchForm(strUrl){
	document.write("<TABLE border='0' cellspacing='0' cellpadding='0'>");
	document.write("<FORM METHOD='POST' NAME='frmWhere' ACTION='"+strUrl+"?IsFirstSearch=1'><INPUT TYPE='hidden' NAME='WhereSql'></FORM>");
	document.write("<TR><TD></TD></TR></TABLE>");
}

function onSearchData(strSearchUrl,lngHeight,lngWidth){
		var dte=new Date();
		var strResult=showModalDialog(strSearchUrl+"?dteasdfasiwe="+dte.getTime(),0,"dialogHeight:"+lngHeight+"px;dialogWidth:"+lngWidth+"px;status=no");
		if(strResult==null){
			return;
		}
		frmWhere.elements(0).value=strResult;
		frmWhere.submit();
}

function trim(strValue){
	var intStart=0;
	for(var i=0;i<strValue.length;i++)
	{
		if(strValue.substring(i,i+1)!=" "){
			intStart=i;
			break;
		}
	}
	var intEnd=strValue.length;
	for(var i=strValue.length;i>=0;i--)
	{
		if(strValue.substring(i-1,i)!=" "){
			intEnd=i;
			break;
		}
	}
	return strValue.substring(intStart,intEnd);
}

function getFindCount(strSource,strFind)
{
	var s=strSource.split(strFind);
	return s.length-1;
}

function getStringLength(strValue){
	var k=0;
	for(var i=0;i<strValue.length;i++){
		if(strValue.charCodeAt(i)>=0 && strValue.charCodeAt(i)<=255){
			k=k+1;
		}
		else{
			k=k+2;
		}
	}
	return k;
}

function isInt(strValue){
	if(strValue.substring(0,1)=="+" || strValue.substring(0,1)=="-"){
		strValue=strValue.substr(1);
	}
	if(strValue.length==0){
		return false;
	}
	for(var i=0;i<strValue.length;i++){
		if(strValue.charCodeAt(i)<48 || strValue.charCodeAt(i)>57){
			return false;
		}
	}
	return true;
}

function isEmail(intstr) { //v3.0
    if ((intstr.indexOf("@")<0)){ //是否在0-9之间
        return false;
      }
 return true;
	}
	

function isDouble(strValue){
	if(strValue.substring(0,1)=="+" || strValue.substring(0,1)=="-"){
		strValue=strValue.substr(1);
	}
	if(strValue.length==0){
		return false;
	}
	if(getFindCount(strValue,".")>1){
		return false;
	}
	if(strValue.substring(0,1)=="." || strValue.substring(strValue.length-1,strValue.length)=="."){
		return false;
	}
	for(var i=0;i<strValue.length;i++){
		var code=strValue.charCodeAt(i);
		if(code==46 || (code>=48 && code<=57)){}
		else{
			return false;
		}
	}
	return true;
}

function replace(strSource,strFind,strNew){
	while(strSource.indexOf(strFind,0)>=0){
		strSource=strSource.replace(strFind,strNew);
	}
	return strSource;
}

//,=44 '=39 "=34 >=62 <=60 & 38 ?
function replaceErrChar(strValue)
{
	strValue=replace(strValue,",","，");
	strValue=replace(strValue,"'","’");
	strValue=replace(strValue,"\"","”");
	strValue=replace(strValue,">","］");
	strValue=replace(strValue,"<","［");
	strValue=replace(strValue,"&","＋");
	strValue=replace(strValue,"?","？");
	return strValue;
}

//,=44 '=39 "=34 >=62 <=60 & 38 ?
function replaceHtmlErrChar(strValue)
{
	strValue=replace(strValue,"'","’");
	strValue=replace(strValue,"\"","”");
	strValue=replace(strValue,">","］");
	strValue=replace(strValue,"<","［");
	return strValue;
}

//yyyy-mm-dd
function isShortDate(strValue)
{
	if(strValue.length!=10){
		return false;
	}
	if(strValue.substring(4,5)!="-"){
		return false;
	}
	if(strValue.substring(7,8)!="-"){
		return false;
	}
	var strYear=strValue.substring(0,4);
	var strMonth=strValue.substring(5,7);
	var strDay=strValue.substring(8,10);
	if(isInt(strYear)==false){
		return false;
	}
	if(isInt(strMonth)==false){
		return false;
	}
	if(isInt(strDay)==false){
		return false;
	}
	if(strYear<1900 || strYear>2050){
		return false;
	}
	if(strMonth<1 || strMonth>12){
		return false;
	}
	if(strDay<1 || strDay>31){
		return false;
	}
	return true;
}
//是否是电话
function isTel(intstr) { //v3.0
 var theMark='0123456789-';
 for (var i=0;i<=intstr.length-1;i++)
   {
    var onechar;
    onechar=intstr.substring(i,i+1);
     if ((theMark.indexOf(onechar)==-1)){ //是否在0-9之间
        return false;
     }
   }
 return true;
}

//12:23:12
function isTime(strValue)
{
	if(strValue.length!=8){
		return false;
	}
	if(strValue.substring(2,3)!=":"){
		return false;
	}
	if(strValue.substring(5,6)!=":"){
		return false;
	}
	var strHour=strValue.substring(0,2);
	var strMin=strValue.substring(3,5);
	var strSen=strValue.substring(6,8);
	if(isInt(strHour)==false){
		return false;
	}
	if(isInt(strMin)==false){
		return false;
	}
	if(isInt(strSen)==false){
		return false;
	}
	if(strHour<0 || strHour>23){
		return false;
	}
	if(strMin<0 || strMin>59){
		return false;
	}
	if(strSen<0 || strSen>59){
		return false;
	}
	return true;
}

//yyyy-mm-dd hh:mm:ss
function isLongDate(strValue)
{
	if(strValue.length!=19){
		return false;
	}	
	if(isShortDate(strValue.substring(0,10))==false){
		return false;
	}
	if(isTime(strValue.substring(11,19))==false){
		return false;
	}
	return true;
}
//获得焦点
function focus(ctlText,strInfo)
{
	alert(strInfo);
	if(ctlText.disabled==true){
		return 
	}
	ctlText.focus();

}


function formOnSubmit(frmForm)
{
	for(var i=0;i<frmForm.elements.length;i++){
		var ctl=frmForm.elements[i];
		if(ctl.getAttribute("IsTime")!=null){
			if(isShortDate(ctl.value)==false && isLongDate(ctl.value)==false){
				alert("时间必须不能为空");
				return false;
			}
		}
		if(ctl.getAttribute("type").toUpperCase()=="TEXT" || ctl.tagName=="TEXTAREA" || ctl.getAttribute("type").toUpperCase()=="PASSWORD" || ctl.getAttribute("type").toUpperCase()=="FILE" ||ctl.getAttribute("type").toUpperCase()=="SELECT"){

			var strInfo=ctl.getAttribute("Info");
			ctl.value=trim(ctl.value);
			
			if(ctl.getAttribute("IsHtml")=="1"){
				ctl.value=replaceHtmlErrChar(ctl.value);
			}
			else{
				ctl.value=replaceErrChar(ctl.value);
			}

			if(ctl.getAttribute("NoEmpty")=="1"){
			
				if(ctl.value==""){
					focus(ctl,strInfo+"不能为空");
					return false;
				}
			}

			if(ctl.value!=""){
				if(ctl.getAttribute("isTel")=="1"){
					if(isTel(ctl.value)==false){
						focus(ctl,strInfo+"应符合电话号码格式");
						return false;
					}
				}				
				if(ctl.getAttribute("IsInt")=="1"){
				
					if(isInt(ctl.value)==false || ctl.value.replace(/\s/g,"")==""){
						focus(ctl,strInfo+"应是整数");
						return false;
					}
				}	
				if(ctl.getAttribute("isEmail")=="1"){
					if(isEmail(ctl.value)==false){
						focus(ctl,strInfo+"不是标准邮箱");
						return false;
					}
				}
				

				if(ctl.getAttribute("IsDouble")=="1"){
					if(isDouble(ctl.value)==false){
						focus(ctl,strInfo+"应是数字");
						ctl.select();
						return false;
					}
				}

				if(ctl.getAttribute("MaxValue")!=null){
					var dblValue=new Number(ctl.value);
					var dblMax=new Number(ctl.getAttribute("MaxValue"));
					if(dblValue>dblMax){
						focus(ctl,strInfo+"不能大于"+ctl.getAttribute("MaxValue"));
						return false;
					}
				}

				if(ctl.getAttribute("MinValue")!=null){
					var dblValue=new Number(ctl.value);
					var dblMin=new Number(ctl.getAttribute("MinValue"));
					if(dblValue<dblMin){
						focus(ctl,strInfo+"不能小于"+ctl.getAttribute("MinValue"));
						return false;
					}
				}

				if(ctl.getAttribute("MaxLen")!=null){
					var dblMaxLen=new Number(ctl.getAttribute("MaxLen"));
					if(getStringLength(ctl.value)>dblMaxLen){
						focus(ctl,strInfo+"字符长度不能超过"+ctl.getAttribute("MaxLen"));
						return false;
					}
				}

				if(ctl.getAttribute("IsShortDate")=="1"){
					if(isShortDate(ctl.value)==false){
						focus(ctl,strInfo+"应是日期型数据（如：2003-04-18）");
						return false;
					}
				}

				if(ctl.getAttribute("IsLongDate")=="1"){
					if(isLongDate(ctl.value)==false){
						focus(ctl,strInfo+"应是日期型数据（如：2003-04-18 12:23:00）");
						return false;
					}
				}
			}

		}
	}
	return true;
}
//关闭窗口
function CloseFrm(){
	self.close();
}
//清空文本框
function clearText(txtId,txtName){
	txtId.value="";
	txtName.value="";
}
//得到被单选按纽的值
function getRadioSelectId(optValue){
	for(var i=0;i<optValue.length;i++){
		if(optValue[i].checked==true){
			return i;
		}
	}
}
function KeyFilter(type){
	var berr=false;
	
	switch(type)
	{
		case 'date':
			if (!(event.keyCode == 45 || event.keyCode == 47 || (event.keyCode>=48 && event.keyCode<=57)))
				berr=true;
			break;
		case 'number':
			if (!(event.keyCode>=48 && event.keyCode<=57))
				berr=true;
			break;
		case 'cy':
			if (!(event.keyCode == 46 || (event.keyCode>=48 && event.keyCode<=57)))
				berr=true;
			break;
		case 'long':
			if (!(event.keyCode == 45 || (event.keyCode>=48 && event.keyCode<=57)))
				berr=true;
			break;
		case 'double':
			if (!(event.keyCode == 45 || event.keyCode == 46 || (event.keyCode>=48 && event.keyCode<=57)))
				berr=true;
			break;
		default:
			if (event.keyCode == 35 || event.keyCode == 37 || event.keyCode==38)
				berr=true;
	}
	return !berr;
}
//转换为数字
function val(strValue){
		return new Number(strValue);
}



///////////////////////////////////////// 得到一个对话框

function getKS(txtId,txtName,txtDeptName,txtGovName)
{
	var dte=new Date();
	var strResult=showModalDialog("../sys/SelectKS.jsp?Key="+dte.toString()+"&Id=",0,"dialogHeight:300px;dialogWidth:325px;status=no;resizable=yes");
	if(strResult==null){
		return "";
	}
	var s=strResult.split(",");
	txtId.value=s[0];
	txtGovName.value=s[1];
	txtDeptName.value=s[2];
	txtName.value=s[3];

}

function getKS1(txtId,txtDeptName,txtGovName)
{
	var dte=new Date();
	var strResult=showModalDialog("../sys/SelectKS1.jsp?Key="+dte.toString()+"&Id=",0,"dialogHeight:300px;dialogWidth:325px;status=no;resizable=yes");
	if(strResult==null){
		return "";
	}
	var s=strResult.split(",");
	txtId.value=s[0];
	txtGovName.value=s[1];
	txtDeptName.value=s[2];
}

document.write("<LINK href=\"../js/datecontrol/DatePicker.css\" type=text/css rel=stylesheet>");
document.write("<SCRIPT language=javascript src=\"../js/datecontrol/DateObject.js\"></SCRIPT>");
document.write("<SCRIPT language=javascript src=\"../js/datecontrol/DatePicker.js\"></SCRIPT>");
document.write("<SCRIPT language=javascript src=\"../js/datecontrol/editlib.js\"></SCRIPT>");

