// JavaScript Document

<!--
var aCity={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:"国外"}  

function cidInfo(sId){
	var iSum=0
	var info=""
	if(!/^\d{17}(\d|x)$/i.test(sId)) return false;
	sId=sId.replace(/x$/i,"a");
	if(aCity[parseInt(sId.substr(0,2))]==null) return false;
	sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
	var d=new Date(sBirthday.replace(/-/g,"/"))
	if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate())) return false;
	for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11)
	if(iSum%11!=1) return false;
	return true;
	//return aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女")
}


function CloseWindow(Value) {
	if (Value < 0) {
		parent.location.href = APP_MODULE + "/Login";	
	} else {
		window.returnValue = Value;
		window.close();
	}
}


function CheckInputValue(Objs, Messages) {
	var i;
	var Num = Objs.length;
	for (i = 0; i < Num; i++) {
		if (Objs[i].value == "" || Objs[i].value == 0) {
			window.alert(Messages[i]);
			//Objs[i].focus();
			event.returnValue = false;
			return false;
		}
	}
	return true;
}

function CheckValue() {
	if (CheckInputValue([
		document.getElementById("xs"),
		document.getElementById("bmlb"),
		document.getElementById("xm"),
		document.getElementById("mz"),
		document.getElementById("sfzh"),
		document.getElementById("xb"),
		document.getElementById("csny"),
		document.getElementById("xl"),
		document.getElementById("byyx1"),
		document.getElementById("byyx2"),
		document.getElementById("byyx3"),
		document.getElementById("byzh"),
		document.getElementById("lxdh"),
		document.getElementById("bz"),
		document.getElementById("kslb"),
		document.getElementById("bkxd"),
		document.getElementById("bkkm")],[
		"请选报名人员户口所在地！",
		"请选择报名人类别！",
		"请输入姓名！",
		"请选择族别！",
		"身份证号未经过验证！",
		"请选择性别！",
		"请选择出生年月！",
		"请选择学历！",
		"请输入毕业年份！",
		"请输入毕业学校！",
		"请输入所学专业！",
		"请输入毕业证编号！",
		"请输入联系电话！",
		"请输入通讯地址！",
		"请选择考生类别！",
		"请选择报考学段！",
		"请选择报考学科！"]))
	{
			
		var KSBM = "您提交的报名信息为：\n\n" +
			"报名人户口所在地：" + document.getElementById("xs").value + "\n" +
			"报名人类别：" + document.getElementById("bmlb").value + "\n" +
			"姓名：" + document.getElementById("xm").value + "\n" +
			"族别：" + document.getElementById("mz").value + "\n" +
			"身份证号：" + document.getElementById("sfzh").value + "\n" +
			"性别：" + document.getElementById("xb").value + "\n" +
			"出生年月：" + document.getElementById("csny").value + "\n" +
			"学历：" + document.getElementById("xl").value + "\n" +
			"毕业院校：" + document.getElementById("byyx1").value + ',' + document.getElementById("byyx2").value + "\n" +
			"所学专业：" + document.getElementById("byyx3").value + "\n" +
			"毕业证编号：" + document.getElementById("byzh").value + "\n" +
			"HSK等级：" + document.getElementById("HSK").value + "\n" +
			"联系电话：" + document.getElementById("lxdh").value + "\n" +
			"通讯地址：" + document.getElementById("bz").value + "\n" +
			"考生类别：" + document.getElementById("kslb").value + "\n" +
			"报考学段：" + document.getElementById("bkxd").value + "\n" +
			"报考学科：" + document.getElementById("bkkm").value + "\n\n" +
			"请确认以上信息是否正确？\n\n如果没有错误请单击[确定]，如果要返回修改请单击[取消]。";
		if(!window.confirm(KSBM)) {
			event.returnValue = false;
			return false;
		}	
	}
}

function CheckIDCard(number) {
	if (!cidInfo(number)) {
		window.alert("身份证号输入错误！");
		event.returnValue = false;
		return false;
	}
}

function detectBrowser() {
	var isIE = (navigator.appName == "Microsoft Internet Explorer"); 
	if (! isIE) {
		window.location.href="../HTML/NoIE.html";
	}
}

function IsIDCard(number) {
	var date, Ai;
	var verify = "10x98765432";
	var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
	var area = ['','','','','','','','','','','','北京','天津','河北','山西','内蒙古','','','','','','辽宁','吉林','黑龙江','','','','','','','','上海','江苏','浙江','安微','福建','江西','山东','','','','河南','湖北','湖南','广东','广西','海南','','','','重庆','四川','贵州','云南','西藏','','','','','','','陕西','甘肃','青海','宁夏','新疆','','','','','','台湾','','','','','','','','','','香港','澳门','','','','','','','','','国外'];
	var re = number.match(/^(\d{2})\d{4}(((\d{2})(\d{2})(\d{2})(\d{3}))|((\d{4})(\d{2})(\d{2})(\d{3}[x\d])))$/i);
	window.alert(re);
	if(re == null) return false;
	if(re[1] >= area.length || area[re[1]] == "") return false;
	if(re[2].length == 12){
		Ai = number.substr(0, 17);
		date = [re[9], re[10], re[11]].join("-");
	}
	else{
		Ai = number.substr(0, 6) + "19" + number.substr(6);
		date = ["19" + re[4], re[5], re[6]].join("-");
	}
	if(!this.IsDate(date, "ymd")) return false;
	var sum = 0;
	for(var i = 0;i<=16;i++){
		sum += Ai.charAt(i) * Wi[i];
	}
	Ai +=  verify.charAt(sum%11);
	
	return (number.length == 15 || number.length == 18 && number == Ai);
}

function SelectDate(DateFormat, TextFieldId) {
	var DateString = showModalDialog(VD_HTML + "/calendar.html", DateFormat, "dialogWidth:286px;dialogHeight:230px;status:no;help:no;");
	if ((TextFieldId) && (DateString != "") && (DateString != undefined)) {
		document.getElementById(TextFieldId).value = DateString;	
	}
	
	return DateString;
}

function AddNewSysUser() {
	var ReturnValue = window.showModalDialog(APP_MODULE + "/AddNewSysUser?N=" + Math.random(), "", "dialogHeight:130px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
	if (ReturnValue == 1) {
		window.location.href = APP_MODULE + "/SysUsers";	
	}
}

function ChangePassword(ID) {
	var ReturnValue = window.showModalDialog(APP_MODULE + "/ChangePassword?ID=" + ID + "&N=" + Math.random(), "", "dialogHeight:160px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
	if (ReturnValue == 1) {
		window.location.href = APP_MODULE + "/SysUsers";	
	}
}

function SetEnabled(ID,Enabled) {
	var Msg = (Enabled == 1) ? "启用" : "禁用";
	if (window.confirm("是否 " + Msg + " 用户帐号？")) {
		var ReturnValue = window.showModalDialog(APP_MODULE + "/DoSetEnabled?ID=" + ID + "&Enabled=" + Enabled + "&N=" + Math.random(), "", "dialogHeight:130px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
		if (ReturnValue == 1) {
			window.location.href = APP_MODULE + "/SysUsers";	
		}
	}
}

function SetIsAdmin(ID,IsAdmin) {
	var Msg = (IsAdmin == 1) ? "设为管理员" : "取消管理员";
	if (window.confirm("是否将选定用户 " + Msg + " ？")) {
		var ReturnValue = window.showModalDialog(APP_MODULE + "/DoSetIsAdmin?ID=" + ID + "&IsAdmin=" + IsAdmin + "&N=" + Math.random(), "", "dialogHeight:130px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
		if (ReturnValue == 1) {
			window.location.href = APP_MODULE + "/SysUsers";	
		}
	}
}

function DeleteSysUser(ID) {
	if (window.confirm("是否删除选定用户？")) {
		var ReturnValue = window.showModalDialog(APP_MODULE + "/DoDeleteSysUser?ID=" + ID + "&N=" + Math.random(), "", "dialogHeight:130px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
		if (ReturnValue == 1) {
			window.location.href = APP_MODULE + "/SysUsers";	
		}
	}
}

function AddNewBM() {
	var ReturnValue = window.showModalDialog(APP_MODULE + "/AddNewBM?N=" + Math.random(), "", "dialogHeight:160px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
	if (ReturnValue == 1) {
		window.location.href = APP_MODULE + "/SetupBM";	
	}
}

function EditBM(Year) {
	var ReturnValue = window.showModalDialog(APP_MODULE + "/EditBM?Year=" + Year + "&N=" + Math.random(), "", "dialogHeight:160px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
	if (ReturnValue == 1) {
		window.location.href = APP_MODULE + "/SetupBM";	
	}
}

function DeleteBM(Year) {
	if (window.confirm("是否删除报名时限？")) {
		var ReturnValue = window.showModalDialog(APP_MODULE + "/DoDeleteBM?Year=" + Year + "&N=" + Math.random(), "", "dialogHeight:130px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
		if (ReturnValue == 1) {
			window.location.href = APP_MODULE + "/SetupBM";	
		}
	}
}


function GotoPage(Page) {
	window.location.href = APP_MODULE + "/DownloadData?Page=" + Page;	
}

function Search() {
	var SearchField = document.getElementById("SearchField").value;
	var SearchValue = document.getElementById("SearchValue").value;
	if(SearchValue != "") {
		window.open(APP_MODULE + "/Search?Field=" + SearchField + "&Value=" + SearchValue);
	} else {
		window.alert("请输入查询字段的值！");	
		document.getElementById("SearchValue").focus();
	}	
}

function DeleteAllData() {
	if (window.confirm("是否清空报名数据？")) {
		var ReturnValue = window.showModalDialog(APP_MODULE + "/DoDeleteAllData", "", "dialogHeight:130px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
		if (ReturnValue == 1) {
			window.location.href = APP_MODULE + "/DownloadData";	
		}
	}
}

function DownloadData() {
	if (window.confirm("是否下载报名数据？")) {
		var ReturnValue = window.showModalDialog(APP_MODULE + "/DoDownloadData", "", "dialogHeight:130px;dialogWidth:430px;scroll:no;status:no;help=no;"); 
	}
}

function InsertScore() {
	if (window.confirm("是否导入考试成绩？")) {
		var ReturnValue = window.showModalDialog(APP_MODULE + "/InsertScore", "", "dialogHeight:450px;dialogWidth:600px;scroll:no;status:no;help=no;"); 
	}
}
-->