	function DoPostBack(frm, targ) {
		frm.action = targ;
		frm.submit();
	}
	
	function SetSrc(frm) {
		var imgObj = document.getElementById("img_photo");
		var selectedPath = frm.file_photo.value;
		imgObj.src = selectedPath;
		imgObj.width = 120;
		imgObj.height = 150;
	}

	function SetPrefix(frm, obj) {
		var targObj = frm.txt_prefix;
		if (obj.selectedIndex == 3) {
			targObj.style.display = "";
		}
		else {
			targObj.style.display = "none";
		}
	}

	function ChkValidRegister(frm) {
		var msg = "";
		var idNo = frm.txt_id1.value + frm.txt_id2.value + frm.txt_id3.value + frm.txt_id4.value + frm.txt_id5.value;
		
		if (frm.lst_prefix.value == "4" && frm.txt_prefix.value == "") {
			msg += "- คำนำหน้านาม\n";
		}

		if (frm.txt_fname.value == "") {
			msg += "- ชื่อ\n";
		}
		if (frm.txt_lname.value == "") {
			msg += "- สกุล\n";
		}
		if (frm.lst_bdate_day.value == "" || frm.lst_bdate_month.value == "" || frm.lst_bdate_year.value == "") {
			msg += "- วันเดือนปีเกิด\n";
		}
		if (frm.txt_bplace.value == "") {
			msg += "- สถานที่เกิด\n";
		}
		if (frm.txt_race.value == "") {
			msg += "- เชื้อชาติ\n";
		}
		if (frm.opt_id_type[0].checked) {
			if (idNo == "" || idNo.length != 13) {
				msg += "- เลขบัตรประจำตัวประชาชน\n";
			}
			else if (idNo.length == 13) {
				if (!VerifyIDCardNo(idNo)) {
					msg += "- เลขบัตรประจำตัวประชาชนไม่ถูกต้อง";
				}
			}
		}
		else {
			if (frm.txt_passport.value == "") {
				msg += "- เลขที่หนังสือเดินทาง\n";
			}
			if (frm.lst_passport_country.value == "0") {
				msg += "- ประเทศ (ที่ออกหนังสือเดินทาง)\n";
			}
		}
		if (frm.txt_nation.value == "") {
			msg += "- สัญชาติ\n";
		}

		if (frm.opt_edu[0].checked) {
			if (frm.lst_faculty.value == "0") {
				msg += "- คณะแพทย์ศาสตร์\n";
			}
		}
		else if (frm.opt_edu[1].checked) {
			if (frm.lst_college.value == "0") {
				msg += "- วิทยาลัยแพทย์ศาสตร์\n";
			}
		}
		else if (frm.opt_edu[2].checked) {
			if (frm.lst_clinic.value == "0") {
				msg += "- ศูนย์แพทยศาสตร์ศึกษาชั้นคลินิค\n";
			}
		}
		else if (frm.opt_edu[3].checked) {
			if (frm.lst_institute_country.value == "0") {
				msg += "- ประเทศ (ที่สำเร็จการศึกษา)\n";
			}
			else {
				if (frm.lst_institute.value == "0") {
					msg += "- สถาบันที่สำเร็จการศึกษา\n";
				}			
			}
		}
		if (frm.opt_edu_status[0].checked) {
			if (frm.lst_degree.value == "0" && (frm.opt_edu[0].checked || frm.opt_edu[1].checked)) {
				msg += "- ชั้นปีที่กำลังศึกษา\n";
			}
		}

		if (frm.txt_addr_no.value == "") {
			msg += "- เลขที่\n";
		}
		if (frm.txt_grp_no.value == "") {
		//	msg += "- หมู่ที่\n";
		}
		if (frm.txt_street.value == "") {
		//	msg += "- ตรอก/ซอย\n";
		}
		if (frm.txt_road.value == "") {
		//	msg += "- ถนน\n";
		}
		if (frm.txt_sub_district.value == "") {
			msg += "- แขวง/ตำบล\n";
		}
		if (frm.txt_district.value == "") {
			msg += "- เขต/อำเภอ\n";
		}
		if (frm.lst_province.value == "0") {
			msg += "- จังหวัด\n";
		}
		if (frm.txt_postal.value == "") {
			msg += "- รหัสไปรษณีย์\n";
		}
		if (frm.txt_phone.value == "") {
			msg += "- โทรศัพท์\n";
		}
		if (frm.txt_mobile.value == "") {
			//msg += "- โทรศัพท์มือถือ\n";
		}
		if (frm.txt_email.value == "") {
			msg += "- อีเมล์\n";
		}
		else {
			if (!ChkValidEmail(frm.txt_email.value)) {
				msg += "- รูปแบบอีเมล์ไม่ถูกต้อง";
			}
		}


		if (msg != "") {
			msg = "กรุณากรอกข้อมูลต่อไปนี้ให้ครบถ้วน\n" + msg;
			alert(msg);
			return false;
		}

		return true;
	}


	function ChkValidEmail(sEmail){
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid        
		if (!reg1.test(sEmail) && reg2.test(sEmail)) { // if syntax is valid
			return true;
		}
		else{
			return false;
		}
	}

	function ChkValidID(frm) {
		var idNo = frm.txt_id1.value + frm.txt_id2.value + frm.txt_id3.value + frm.txt_id4.value + frm.txt_id5.value;
		if (!VerifyIDCardNo(idNo)) {
			alert("เลขบัตรประจำตัวประชาชนไม่ถูกต้อง");
		}
		else {
			alert("เลขบัตรประจำตัวประชาชนถูกต้อง");
		}
	}

function PrintApplication(reg_id, ref_no,test_id) {
		window.open('print_application.php?reg_id=' + reg_id + '&ref_no=' + ref_no+ '&test_id=' + test_id, 'print_application', "width=750, height=780, left=0, top=0, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=no");
	}
	function PrintPayin(reg_id, ref_no,test_id) {
		window.open('print_payin.php?reg_id=' + reg_id + '&ref_no=' + ref_no+ '&test_id=' + test_id, 'print_application', "width=750, height=780, left=0, top=0, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=no");
	}
	function score_exam_all(id_no) {
		window.open('check_score_exam_all.php?id_no=' + id_no, 'print_application', "width=750, height=780, left=0, top=0, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=no");
	}		
		function PrintApplicationStatus(reg_id, ref_no,test_id) {
		window.open('print_application_status.php?reg_id=' + reg_id + '&ref_no=' + ref_no+ '&test_id=' + test_id, 'print_application', "width=450, height=250, left=0, top=0, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=no");
	}
		
		


	function VerifyIDCardNo(id_card) {
	var multi_num = 13;
	var str_digit = 0;
	var result = 0;
		if(id_card.length != 13) {
			return false;
		} 

		while(multi_num != 1) {
			if(id_card.charAt(str_digit) == Number.NaN) {
				return false;
			}
			result = result + id_card.charAt(str_digit)*multi_num;
			multi_num = multi_num - 1;
			str_digit = str_digit + 1; 
		}// end while

		result = result % 11;
		if(result == 0) result = 10;

		result = 11 - result;

		if(result == 10) result = 0;

		if(result == id_card.charAt(12)) {
			return true;
		} 
		else {
			return false;
		}//end if
	} 

	function SetStatus(frm, enableObjStr, disableObjStr) {
		var objArr;
		var tmpObj
		var i;
		if (enableObjStr != "") {
			if (enableObjStr.indexOf(',') >= 0) {
				objArr = enableObjStr.split(',');
				for (i = 0; i < objArr.length; i++) {
					tmpObj = eval("frm." + objArr[i]);
					if (typeof tmpObj != "undefined") {
						tmpObj.disabled = false;
					}
				}
			}
			else {
				tmpObj = eval("frm." + enableObjStr);
				tmpObj.disabled = false;
			}
		}
		
		if (disableObjStr != "") {
			objArr = disableObjStr.split(',');
			for (i = 0; i < objArr.length; i++) {
				tmpObj = eval("frm." + objArr[i]);
				if (typeof tmpObj != "undefined") {
					tmpObj.disabled = true;
				}
			}
		}
	}

	//AJAX
	function LoadInstitute(frm, obj, selectedID) {
		var parentID = obj.value;
		var objGroup = document.getElementById("lb_institute");

		if (typeof selectedID == "undefined") {
			objGroup.innerHTML = GetInfo("/get_institute.php?parent_id=" + parentID);
		}
		else {
			objGroup.innerHTML = GetInfo("/get_institute.php?parent_id=" + parentID + "&selected_id=" + selectedID);
		}

		if (parentID != "0") {
			frm.opt_edu[3].focus();
		}
		else {
			frm.lst_institute.focus();
		}
	}

	function LoadInstituteStep1(frm, obj, selectedID) {
		var parentID = obj.value;
		var objGroup = document.getElementById("lb_institute");

		if (typeof selectedID == "undefined") {
			objGroup.innerHTML = GetInfo("/get_institute_step1.php?parent_id=" + parentID);
		}
		else {
			objGroup.innerHTML = GetInfo("/get_institute_step1.php?parent_id=" + parentID + "&selected_id=" + selectedID);
		}


		if (parentID != "0") {
			frm.opt_edu[3].focus();
		}
		else {
			frm.lst_institute.focus();
		}
	}


	function LoadChild(frm, obj) {
		var parentID = obj.value;
		var targObj = document.getElementById("lb_child");
		targObj.innerHTML = GetInfo("/get_faculty.php?parent_id=" + parentID);
	}

	function GetInfo(url) {
		var returnText = "";
		var http =  new ActiveXObject("Microsoft.XMLHTTP");
		http.open("get", url, false);
		http.send();
		returnText = http.responseText;
		return returnText;
	}

	//check does user press a number key in specified field
	function ChkNumKey() {
		e_k=event.keyCode
		if (e_k != 13 && ((e_k < 48) || (e_k > 57))) {
			event.returnValue = false;
			alert("Please enter number 0 - 9 only.");
		}
	}

	//check if specified field (variable: thisField) got all required value (assume maxlength is a length of value required
	function JumpNext(frm, thisField, nextField) {
		var thisObj = eval("frm." + thisField);
		var nextObj = eval("frm." + nextField);
		var maxLen = thisObj.maxLength;
		if (thisObj.value.length == maxLen) {
			nextObj.focus();
		}
	}

			function ToggleComment(sta) {
							
							var obj = document.getElementById("TbComment");
							
							if (sta == "1") {
								obj.style.display = "";
								document.frm_register.btn_submit.value="ตรวจสอบข้อมูล";
							}
							else {
								obj.style.display = "none";
								document.frm_register.btn_submit.value="สมัครสอบ";
							}
						}
						
						
	
	function Settest(frm,ObjStr,ObjStr2) 
	{
		
		var roundength = frm.r_round.length;
		if(ObjStr == '3') {
			for(var i = 0; i < roundength; i++) {
				if(frm.r_round[i].value==3){
					frm.r_round[i].disabled = true;
				}else{
					frm.r_round[i].disabled = false;
				}				
			}
		}else {
			for(var i = 0; i < roundength; i++) {
				if(frm.r_round[i].value!=3){frm.r_round[i].disabled = true;}else{frm.r_round[i].disabled = false;}
			}
		}
		
	}
	
	