document.onkeydown=keyDownNext;
window.onerror=killErrors;
document.onerror=killErrors;

function killErrors()
{
	return true;
}

function myOpen(pageName,width,height,win)
{
    top.myOpen(pageName,width,height,win);
}

//buttonName代表父窗体的按钮id,jb代表要调用的父窗体的级别,1代表第一个父窗体,2代表第二个父窗体,以此类推
function refOpener(buttonName,jb)
{
	top.refOpener(buttonName,jb);
}


//给父窗体的文本框赋值,txtList是文本框id列表(用|分隔),valueList是对应的值列表(用|分隔),jb代表要调用的父窗体的级别,1代表第一个父窗体,2代表第二个父窗体,以此类推
function setOpenTxtValue(txtList,valueList,jb)
{
	top.setOpenTxtValue(txtList,valueList,jb);
}

function myClose()
{
	top.myClose();
}

//清空所有文本框,取消选中所有CheckBox,isClearHidden是否清除隐藏文本框，是的话传true,否则传false
function Add(isClearHidden)
{
	var input=document.all.tags("input");
	for(i=0;i<input.length;i++)
	{	
		if(input[i].TabIndex==0)
			input[i].focus();
		if(input[i].type=="text" || input[i].type=="file")
		{
			if(!input[i].disabled)
				input[i].value="";
		
		}
		if(input[i].type=="checkbox")
		{
			if(!input[i].disabled)
				input[i].checked=false;
		}
		if(isClearHidden)
		{
		    if(input[i].type=="hidden")
		    {
			    input[i].value="";
		    }
		}
	}
	var textarea=document.all.tags("textarea");
	for(j=0;j<textarea.length;j++)
	{
		textarea[j].value="";
	}
}

//按回车切换焦点
function keyDownNext()
{
  if(event.keyCode==13 && event.srcElement.type!='button' && event.srcElement.type!='submit' && event.srcElement.type!='reset' && event.srcElement.type!='textarea' && event.srcElement.type!=''&& event.srcElement.type!='file')

     event.keyCode=9;
}

//全选/反选
function selectCBL()
{
	var cbl=document.all.tags("input");
	for(i=0;i<cbl.length;i++)
	{
		if(cbl[i].type=="checkbox")
			cbl[i].checked =! cbl[i].checked;
	}
}

//判断是否选中了一项或多项并提示是否要删除
function getCheck(Message)
{
	var cbl=document.all.tags("input");
	var Num=cbl.length;
	var IsOneCheck=false;
	var wconfirm=false;

	for(i=0;i<Num;i++)
	{
		if(cbl[i].type=="checkbox")
		{
			if(cbl[i].checked==true)
			{
				if(IsOneCheck==false)
					wconfirm=window.confirm(Message);
				IsOneCheck=true;
			}
		}
	}			
	if(IsOneCheck==false)
		window.alert("请选中一项或多项！");					
	return wconfirm;
}

//身份证验证
function checkIdcard(controlName){ 
idcard=document.getElementById(controlName).value;
if(idcard!="")
{
	var Errors=new Array( 
	"验证通过!", 
	"身份证号码位数不对!", 
	"身份证号码出生日期超出范围或含有非法字符!", 
	"身份证号码校验错误!", 
	"身份证地区非法!" 
	); 
	var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}  
	var idcard,Y,JYM; 
	var S,M; 
	var idcard_array = new Array(); 
	idcard_array = idcard.split(""); 
	//地区检验 
	if(area[parseInt(idcard.substr(0,2))]==null) 
	{
	alert(Errors[4]);
	document.getElementById(controlName).select();
	return false; 
	}
	//身份号码位数及格式检验 
	switch(idcard.length){ 
	case 15: 
	if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){ 
	ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性 
	} else { 
	ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性 
	} 
	if(ereg.test(idcard)) 
	{
	return true; 
	}
	else
	{
	alert(Errors[2]);
	document.getElementById(controlName).select();
	return false;
	}
	break; 
	case 18: 
	//18位身份号码检测 
	//出生日期的合法性检查  
	//闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9])) 
	//平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8])) 
	if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){ 
	ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式 
	} else { 
	ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式 
	} 
	if(ereg.test(idcard)){//测试出生日期的合法性 
	//计算校验位 
	S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7 
	+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9 
	+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10 
	+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5 
	+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8 
	+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4 
	+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2 
	+ parseInt(idcard_array[7]) * 1  
	+ parseInt(idcard_array[8]) * 6 
	+ parseInt(idcard_array[9]) * 3 ; 
	Y = S % 11; 
	M = "F"; 
	JYM = "10X98765432"; 
	M = JYM.substr(Y,1);//判断校验位 
	if(M == idcard_array[17])
	{
	return true;
	}//检测ID的校验位 
	else 
	{
	alert(Errors[3]);
	document.getElementById(controlName).select();
	return false;
	}
	} 
	else
	{
	alert(Errors[2]);
	document.getElementById(controlName).select();
	return false;
	} 
	break; 
	default: 
	alert(Errors[1]);
	document.getElementById(controlName).select();
	return false;
	break; 
	} 
}
else
{
	return true;
}
} 

String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}

//验证输入的信息,controlList是控件ID名列表，控件ID名之间用|分隔，
//验证输入的信息,controlNameList是控件名列表，控件名之间用|分隔，
//checkType是验证类型，验证类型这间用|分隔，
//0代表验证不能为空，
//1代表验证只能是大于0小于99999的整数，
//2代表只能输入不小于0的数字,且长度不能大于7位，
//3代表超过指定长度，
//4代表验证只能输入大于0的数字,且不能大于8位,
//5代表验证只能输入小数,,且不能大于8位
//6代表验证中间不能有空格,
//7代表验证EMAIL检测
//8验证下拉有没有选项
//控件列表和其要验证的类型要一一对应起来，如果验证类型是3，则传的时候应写成3*200，其中200代表限定的长度
function checkInfo(controlList,controlNameList,checkType)
{
	var isOK=true;
	var oList=controlList.split("|");
	var oNameList=controlNameList.split("|");
	var tList=checkType.split("|");
	for(i=0;i<oList.length-1;i++)
	{
		if(isOK)
		{
			switch(tList[i])
			{
                //不能为空			
				case "0":
					if(document.getElementById(oList[i]).value.trim()=="")
					{
						alert("【"+oNameList[i]+"】不能为空！");
						document.getElementById(oList[i]).select();
						isOK=false;
					}
					break;
                //只能是大于0小于99999的整数
				case "1":
					var info1=/^\d+$/;
					
					if(!info1.test(document.getElementById(oList[i]).value))
					{
						alert("【"+oNameList[i]+"】只能输入大于等于0的整数！");
						document.getElementById(oList[i]).select();
						isOK=false;
					}
					else
					{
						if(document.getElementById(oList[i]).value.length>5)
						{
							alert("【"+oNameList[i]+"】输入的数值过大！");
							document.getElementById(oList[i]).select();
							isOK=false;
						}
					}
					break;	
                //只能输入不小于0的数字,且长度不能大于7位				
				case "2":			
					var info2=/^\d+(\.\d+)?$/;
					if(document.getElementById(oList[i]).value!="")
					{
						if(!info2.test(document.getElementById(oList[i]).value))
						{
							alert("【"+oNameList[i]+"】只能输入不小于0的数字！");
							//document.getElementById(oList[i]).value="";
							document.getElementById(oList[i]).select();
							isOK=false;
						}
						else
						{
							var v=document.getElementById(oList[i]).value;
							var index=v.lastIndexOf(".");
							if(index!=-1)
								v=v.substring(0,index);
							if(v.length>7)
							{
								alert("【"+oNameList[i]+"】输入的数值过大！");
								document.getElementById(oList[i]).select();
								isOK=false;
							}
							
						}
					}
					break;
                //只能输入大于0的数字,且不能大于8位
				case "4":
					var info2=/^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
					if(document.getElementById(oList[i]).value!="")
					{
						if(!info2.test(document.getElementById(oList[i]).value))
						{
							alert("【"+oNameList[i]+"】只能输入大于0的数字！");
							document.getElementById(oList[i]).select();
							isOK=false;
						}
						else
						{
							var v=document.getElementById(oList[i]).value;
							var index=v.lastIndexOf(".");
							if(index!=-1)
								v=v.substring(0,index);
							if(v.length>8)
							{
								alert("【"+oNameList[i]+"】输入的数值过大！");
								document.getElementById(oList[i]).select();
								isOK=false;
							}
							
						}
					}
					break;
                //只能输入小数,,且不能大于8位
				case "5":
					var info2=/^(-?\d+)(\.\d+)?$/;
					if(document.getElementById(oList[i]).value!="")
					{
						if(!info2.test(document.getElementById(oList[i]).value))
						{
							alert("【"+oNameList[i]+"】只能输入小数！");
							document.getElementById(oList[i]).select();
							isOK=false;
						}
						else
						{
							var v=document.getElementById(oList[i]).value;
							var index=v.lastIndexOf(".");
							if(index!=-1)
								v=v.substring(0,index);
							if(v.length>8)
							{
								alert("【"+oNameList[i]+"】输入的数值过大！");
								document.getElementById(oList[i]).select();
								isOK=false;
							}
							
						}
					}
					else
					{
					    document.getElementById(oList[i]).value="0";
					}
					break;
                //中间不能有空格							
				case "6":
					var reg=/\S\s{1,}\S/;
					if(document.getElementById(oList[i]).value!="")
					{
						if(reg.test(document.getElementById(oList[i]).value))
						{
							alert("【"+oNameList[i]+"】中间不能有空格！");
							document.getElementById(oList[i]).select();
							isOK=false;
						}
					}	
					break;
                //EMAIL检测
				case "7":	
					var myReg =/^[-!#$%&*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i;
					if(document.getElementById(oList[i]).value.trim().length!=0)
					{
						if(!myReg.test(document.getElementById(oList[i]).value.trim()))
						{						
							alert("【"+oNameList[i]+"】格式不正确！");
							document.getElementById(oList[i]).select();
							isOK=false;
						}
					} 
					break;
				//验证下拉有没有选项
				case "8":
					if(document.getElementById(oList[i]).length==0)
					{
						alert("【"+oNameList[i]+"】不能为空！");
						document.getElementById(oList[i]).focus();
						isOK=false;
					}
					break;
				default:
					var t=tList[i].split("*");
					if(document.getElementById(oList[i]).value.length>parseInt(t[1]))
					{
						alert("【"+oNameList[i]+"】输入了过多的字符，最多只能输入"+t[1]+"字！");
						document.getElementById(oList[i]).select();
						isOK=false;
					}
					break;
			}
		}
		else
		{
			break;
		}
	}
	return isOK;
}