//----------------------- 회원 가입/수정 ----------------------------
function Reg_send(theForm)
{
	if (typeof(theForm.type) != 'object')
	{
		if(!theForm.id.value){
			alert("아이디를 반드시 입력해야 합니다!");
			theForm.id.focus();
			return false;
		}
		if(theForm.id.value.length < 4){
			alert("아이디는 4자 이상 입력해야 합니다!");
			theForm.id.focus();
			return false;
		}
		if(!theForm.pwd.value){
			alert("비밀번호를  반드시 입력해야 합니다!");
			theForm.pwd.focus();
			return false;
		}else if(theForm.pwd.value.length <4){
			alert("비밀번호는 4자 이상 입력해야 합니다!");
			theForm.pwd.focus();
			return false;
		}
		if(!theForm.repwd.value){
			alert("비밀번호확인를  반드시 입력해야 합니다!");
			theForm.repwd.focus();
			return false;
		}
		if(theForm.pwd.value != theForm.repwd.value){
			alert("비밀번호가 일치하지 않습니다!");
			theForm.pwd.value="";
			theForm.repwd.value="";
			theForm.pwd.focus();
			return false;
		}
		if(!theForm.kname.value){
			alert("성명(한글)을 반드시 입력해야 합니다.");
			theForm.kname.focus();
			return false;
		}
		if(!theForm.user_type.value){
			alert("회원구분을 반드시 선택해야 합니다!");
			theForm.user_type.focus();
			return false;
		}else if(theForm.user_type.value == '기타' && !theForm.user_etc.value){
			alert("회원구분을 입력해야 합니다!");
			theForm.user_etc.focus();
			return false;
		}
		if(!theForm.jumin1.value){
			alert("주민등록번호를 반드시 입력해야 합니다.");
			theForm.jumin1.focus();
			return false;
		}
		if(!theForm.jumin2.value){
			alert("주민등록번호를 반드시 입력해야 합니다.");
			theForm.jumin2.focus();
			return false;
		}
		if(theForm.jumin1.value != "" && theForm.jumin2.value != ""){
			if(!JuminNoCheck()){
				theForm.jumin1.value = "";
				theForm.jumin2.value = "";
				theForm.jumin1.focus();
				return false;
			}
		}
	}
	else
	{
		if(theForm.pwd.value ==""){
			alert("비밀번호를  반드시 입력해야 합니다.");
			theForm.pwd.focus();
			return false;
		}                                                     
		if(theForm.new_pwd.value !=""){
			if(theForm.new_repwd.value ==""){
					alert("새 비밀번호확인를  반드시 입력해야 합니다.");
					theForm.new_repwd.focus();
					return false;
				}
				if(theForm.new_pwd.value != theForm.new_repwd.value){
					alert("새 비밀번호가 일치하지 않습니다.");
					theForm.new_pwd.value="";
					theForm.new_repwd.value="";
					theForm.new_pwd.focus();
					return false;
				}
		}
	}

/*
	if(!theForm.email.value){
		alert("이메일 주소를 입력해야 합니다!");
		theForm.email.focus();
		return false;
	}else{
		if (!isEmail(theForm.email.value)){
			alert("정확한 e-mail형식이 필요합니다, 확인후 다시 입력 바랍니다!");
			theForm.email.value="";
			theForm.email.focus();
			return false;
		}
	}
	*/
	if(!theForm.doc_num.value){
		alert("의사면허 번호를 반드시 입력해야 합니다!");
		theForm.doc_num.focus();
		return false;
	}else{
		if(!Check_Num(theForm.doc_num)) return false;
	}
	if(!theForm.doc_year.value || theForm.doc_year.value < 1900){
		alert("올바른 의사면허 취득년도를 입력해야 합니다!");
		theForm.doc_year.focus();
		return false;
	}else{
		if(!Check_Tel(theForm.doc_year,"4")) return false;
	}
	if(!theForm.univ.value){
		alert("출신의과대학을 반드시 선택해야 합니다.");
		theForm.univ.focus();
		return false;
	}else
	{
		if(theForm.univ.value == "직접입력" && !theForm.univ_etc.value){
			alert("출신의과대학을 반드시 입력해야 합니다.");
			theForm.univ_etc.focus();
			return false;
		}
	}
	if(!theForm.major.value){
		alert("전공(관심)분야를 입력해야 합니다.");
		theForm.major.focus();
		return false;
	}
	if(!radioCheck(theForm.office_type)){
		alert("근무처구분을 선택해야 합니다.");
		theForm.office_type[0].focus();
		return false;
	}
	if(!theForm.office.value){
		alert("근무처(직장명)을 반드시 입력해야 합니다!");
		theForm.office.focus();
		return false;
	}
	if(!theForm.of_zip1.value){
		alert("근무처우편번호를 우편번호찾기를 통해서 반드시 입력해야 합니다!");
		theForm.of_zip1.focus();
		return false;
	}
	if(!theForm.of_addr.value){
		alert("근무처주소를 반드시 입력해야 합니다!");
		theForm.of_addr.focus();
		return false;
	}
	if(!theForm.of_tel1.value){
		alert("근무처전화번호를 반드시 선택해야 합니다.");
		theForm.of_tel1.focus();
		return false;
	}
	if(!theForm.of_tel2.value || theForm.of_tel2.value == 0){
		alert("근무처전화번호를 반드시 입력해야 합니다.");
		theForm.of_tel2.focus();
		return false;
	}else{
		if(!Check_Tel(theForm.of_tel2,"3")) return false;
	}
	if(!theForm.of_tel3.value || theForm.of_tel3.value == 0){
		alert("근무처전화번호를 반드시 입력해야 합니다.");
		theForm.of_tel3.focus();
		return false;
	}else{
		if(!Check_Tel(theForm.of_tel3,"4")) return false;
	}
	if(theForm.of_fax2.value != ""){
		if(theForm.of_fax2.value == 0){
		alert("올바른 팩스번호를 입력해야 합니다.");
		theForm.of_fax2.focus();
		return false;
		}
		if(!Check_Tel(theForm.of_fax2,"3")) return false;
	}
	if(theForm.of_fax3.value != ""){
		if(theForm.of_fax3.value == 0){
		alert("올바른 팩스번호를 입력해야 합니다.");
		theForm.of_fax3.focus();
		return false;
		}
		if(!Check_Tel(theForm.of_fax3,"4")) return false;
	}
	if(!theForm.zip1.value){
		alert("자택우편번호를 우편번호찾기를 통해서 반드시 입력해야 합니다!");
		theForm.zip1.focus();
		return false;
	}
	if(!theForm.addr.value){
		alert("자택주소를 반드시 입력해야 합니다!");
		theForm.addr.focus();
		return false;
	}
	if(!theForm.tel1.value){
		alert("자택 전화번호를 반드시 선택해야 합니다.");
		theForm.tel1.focus();
		return false;
	}
	if(!theForm.tel2.value || theForm.tel2.value == 0){
		alert("자택전화번호를 반드시 입력해야 합니다.");
		theForm.tel2.focus();
		return false;
	}else{
		if(!Check_Tel(theForm.tel2,"3")) return false;
	}
	if(!theForm.tel3.value || theForm.tel3.value == 0){
		alert("자택전화번호를 반드시 입력해야 합니다.");
		theForm.tel3.focus();
		return false;
	}else{
		if(!Check_Tel(theForm.tel3,"4")) return false;
	}
	if(!theForm.pcs1.value){
		alert("휴대폰번호를 반드시 선택해야 합니다.");
		theForm.pcs1.focus();
		return false;
	}
	if(!theForm.pcs2.value || theForm.pcs2.value == 0){
		alert("휴대폰번호를 반드시 입력해야 합니다.");
		theForm.pcs2.focus();
		return false;
	}else{
		if(!Check_Tel(theForm.pcs2,"3")) return false;
	}
	if(!theForm.pcs3.value || theForm.pcs3.value == 0){
		alert("휴대폰번호를 반드시 입력해야 합니다.");
		theForm.pcs3.focus();
		return false;
	}else{
		if(!Check_Tel(theForm.pcs3,"4")) return false;
	}

	if(!radioCheck(theForm.receipt)){
		alert("우편물 수령지를 반드시 선택해야 합니다.");
		theForm.receipt[0].focus();
		return false;
	}
}
//----------------------- 회원 가입/수정 ----------------------------
function ChangeId(theForm)
{
	if(!theForm.id.value){
		alert("아이디를 반드시 입력해야 합니다!");
		theForm.id.focus();
		return false;
	}
	if(theForm.id.value.length < 4){
		alert("아이디는 4자 이상 입력해야 합니다!");
		theForm.id.focus();
		return false;
	}
	if(!theForm.pwd.value){
		alert("비밀번호를  반드시 입력해야 합니다!");
		theForm.pwd.focus();
		return false;
	}else if(theForm.pwd.value.length <4){
		alert("비밀번호는 4자 이상 입력해야 합니다!");
		theForm.pwd.focus();
		return false;
	}
	if(!theForm.repwd.value){
		alert("비밀번호확인를  반드시 입력해야 합니다!");
		theForm.repwd.focus();
		return false;
	}
	if(theForm.pwd.value != theForm.repwd.value){
		alert("비밀번호가 일치하지 않습니다!");
		theForm.pwd.value="";
		theForm.repwd.value="";
		theForm.pwd.focus();
		return false;
	}
}


//----------------------- 주민등록번호 체크 ----------------------------
//function JuminNoCheck() {
//	var a = new Array(),i=0, j=0, k=0;
//	var jRR1 = document.regist_frm.jumin1;
//	var jRR2 = document.regist_frm.jumin2;
//
//	if(jRR1.value.length != 6 || jRR2.value.length != 7)
//	    return alert ("주민등록번호 길이가 맞지 않으므로, 확인후 다시 입력 바랍니다.\n\n"),
//	    jRR1.value="",jRR2.value="",jRR1.focus(), false;
//
//	if(jRR1.value =="111111" || jRR2.value =="1111118"){
//		alert("주민등록 번호를 다시 확인 하세요.");
//		jRR1.value="";
//		jRR2.value="";
//		jRR1.focus();
//		return false;
//	}else{	
//		ser = jRR1.value+"0"+jRR2.value;
//		for(i=0; i < 14; i++)
//		{	a[i] = parseFloat(ser.substring(i,i+1));	}
//		// 자릿수 합산 
//		j = a[0]*2+a[1]*3+a[2]*4+a[3]*5+a[4]*6+a[5]*7+a[7]*8+a[8]*9+a[9]*2+a[10]*3+a[11]*4+a[12]*5;
//		j = j % 11;
//		k = 11 - j;
//		if(k > 9) k = k % 10;
//		j = a[13];
//		if(j == k){
//			if(a[7] == 1) sex =  "남자";
//			else if(a[7] == 2) sex =  "여자";              
//			else if(a[7] == 3) sex =  "남자";              
//			else if(a[7] == 4) sex =  "여자";
//			else {
//				return alert("주민등록번호가 정규상(성별)에 맞지 않으므로, 확인후 다시 입력 바랍니다.\n\n"),
//				jRR1.value="",jRR2.value="",jRR1.focus(), false;
//			}
//		  // 생년월일 확인 및 체크 
//		}else{ 
//			return alert ("올바르지 않는 주민등록번호입니다.\n\n 확인후 다시 입력 바랍니다."),
//			jRR1.value="",jRR2.value="",jRR1.focus(), false;
//		}
//		return true;
//	}
//}


//----------------------- 주민등록번호 체크 외국인포함 ----------------------------
function JuminNoCheck() {
	var f = document.regist_frm;

	var a = new Array(),i=0, j=0, k=0;
	var jRR1 = f.jumin1;
	var jRR2 = f.jumin2;
	var Key2 = jRR2.value;
	var jNO2 = Key2.substring(0,1);
	var reg_no = jRR1.value + jRR2.value;

	if(jNO2 == 5 || jNO2 == 6 || jNO2 == 7 || jNO2 == 8) {

	//"5761890", "6760295" , "5181290" , "6180496"
		var sum = 0;
		var odd = 0;
		
		buf = new Array(13);
		for (i = 0; i < 13; i++) buf[i] = parseInt(reg_no.charAt(i));

		odd = buf[7]*10 + buf[8];
		
		if (odd%2 != 0) {
			return alert ("올바르지 않는 외국인 주민등록번호입니다.\n\n 확인후 다시 입력 바랍니다."),
			jRR1.value="",jRR2.value="",jRR1.focus(), false;
		}

		if ((buf[11] != 6)&&(buf[11] != 7)&&(buf[11] != 8)&&(buf[11] != 9)) {
			return alert ("올바르지 않는 외국인 주민등록번호입니다.\n\n 확인후 다시 입력 바랍니다."),
			jRR1.value="",jRR2.value="",jRR1.focus(), false;
		}
		 
		multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
		for (i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]);

		sum=11-(sum%11);
		if (sum>=10) sum-=10;
		sum += 2;
		if (sum>=10) sum-=10;

		if ( sum != buf[12]) { 
			return alert ("올바르지 않는 외국인 주민등록번호입니다.\n\n 확인후 다시 입력 바랍니다."),
			jRR1.value="",jRR2.value="",jRR1.focus(), false;
		}

		if(typeof(f.fminChk) == 'object') {
			f.fminChk.value = "Y";
		}
		return true;

	}else{

		if (chkBlank_msg(jRR1,"주민번호 앞자리를 입력하세요.")) return false;
		if (chkBlank_msg(jRR2,"주민번호 뒷자리를 입력하세요.")) return false;

		if (jRR1.value.length != 6 || jRR2.value.length != 7) { 
			alert ("주민등록번호 길이가 맞지 않으므로, 확인후 다시 입력 바랍니다.");
			jRR1.value = "";
			jRR2.value = "";
			jRR1.focus();
			return false;
		}

		if (jRR1.value =="111111" || jRR2.value =="1111118") {
			alert("주민등록 번호를 다시 확인 하세요.");
			jRR1.value=""; jRR2.value=""; jRR1.focus(); return false;
		} else {	
			ser = jRR1.value + "0" + jRR2.value;
			for (i=0; i < 14; i++) { a[i] = parseFloat(ser.substring(i,i+1)); }
			// 자릿수 합산 
			j = a[0]*2+a[1]*3+a[2]*4+a[3]*5+a[4]*6+a[5]*7+a[7]*8+a[8]*9+a[9]*2+a[10]*3+a[11]*4+a[12]*5;
			j = j%11; k = 11 - j; if(k>9) k = k%10; j = a[13];
			if (j==k) {
				if (a[7]==1) sex = "남자"; 
				else if (a[7]==2) sex = "여자"; 
				else if (a[7]==3) sex = "남자"; 
				else if (a[7]==4) sex = "여자";
				else return alert("주민등록번호가 정규상(성별)에 맞지 않으므로, 확인후 다시 입력 바랍니다.\n\n"), jRR1.value="",jRR2.value="",jRR1.focus(), false;
				// 생년월일 확인 및 체크 
			} else {
				return alert ("올바르지 않는 주민등록번호입니다.\n\n 확인후 다시 입력 바랍니다."), jRR1.value="",jRR2.value="",jRR1.focus(), false;
			}

			if(typeof(f.fminChk) == 'object') {
				f.fminChk.value = "N";
			}
			return true;
		}
	}
	return true;
}



//----------------------- 근무처 우편번호/주소 입력 ----------------------------
function put_post1(zip1,zip2,kjuso,ejuso)
{
	theForm = document.rform;
	theForm.of_zip1.value = zip1 ;
	theForm.of_zip2.value = zip2 ;
	theForm.of_addr.focus();
	theForm.of_addr.value = kjuso ;
	//theForm.of_eaddr.value = ejuso ;
	return;
}

//----------------------- 자택 우편번호/주소 입력 ----------------------------
function put_post2(zip1,zip2,kjuso,ejuso)
{
	theForm = document.rform;
	theForm.zip1.value = zip1 ;
	theForm.zip2.value = zip2 ;
	theForm.addr.focus();
	theForm.addr.value = kjuso ;
	//theForm.eaddr.value = ejuso ;
	return;
}
//----------------------- 두개로 나뉜 자택 우편번호/주소 입력 ----------------------------
function put_post3(zip1,zip2,kjuso,ejuso)
{
	theForm = document.rform;
	theForm.zip1.value = zip1 ;
	theForm.zip2.value = zip2 ;
	theForm.addr_sub.focus();
	theForm.addr.value = kjuso ;
	//theForm.eaddr.value = ejuso ;
	return;
}


//----------------------- 직장명 입력 ----------------------------
function put_hospital(ha,hb,hc,hd,he)
{
	theForm = document.regist_frm;
	if(ha == 'office'){
		theForm = document.regist_frm;
		theForm.office.value = hb ;
		theForm.of_zip1.value = hc ;
		theForm.of_zip2.value = hd ;
		theForm.of_addr.value = he ;
		//theForm.of_sosok.focus() ;
		return;
	}else{
		var input_obj = eval("document.regist_frm." + ha + "");
		input_obj.value = hb ;
	}
}
//----------------------- 직장명 입력 ----------------------------
function put_hosp(ha,hb)
{
	var input_obj = eval("document.regist_frm." + ha + "");
	input_obj.value = hb ;
}

//----------------------- 회원구분 체크 ----------------------------
function User_chk()
{
	theForm = document.regist_frm;
	var user_type = theForm.user_type.value;
	if(user_type == "기타")
	{
		theForm.user_etc.style.backgroundColor='white';
		theForm.user_etc.readOnly = 0;
		theForm.user_etc.focus();
	}
	else
	{
		theForm.user_etc.value = "";
		theForm.user_etc.style.backgroundColor='#EEF9FF';
		theForm.user_etc.readOnly = 1;
	}
}

//----------------------- 출신의과대학 직접입력 ----------------------------
function Univ_chk()
{
	theForm = document.regist_frm;
	var uinv = theForm.univ.value;
	if(uinv == "직접입력")
	{
		theForm.univ_etc.style.backgroundColor='white';
		theForm.univ_etc.readOnly = 0;
		theForm.univ_etc.focus();
	}
	else
	{
		theForm.univ_etc.value = "";
		theForm.univ_etc.style.backgroundColor='#EEF9FF';
		theForm.univ_etc.readOnly = 1;
	}
}

//----------------------- 아이디 중복확인 ----------------------------
function IDCheck()
{
	var comp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
	var string=document.regist_frm.id.value;
	var len=string.length;
	for(i=0;i<len;i++) {
			
		if(comp.indexOf(string.substring(i,i+1))<0) {
			alert("허용된 문자가 아닙니다. 다시 입력해 주십시오");
			document.regist_frm.id.value="";
			document.regist_frm.id.focus();
			return false;
		}
	}
	if(len <4) {
		alert("\n아이디는 4자이상입니다.");
		document.regist_frm.id.value="";
		document.regist_frm.id.focus();
		return false;
	}
	jID = document.regist_frm.id.value;
	if (jID == "") 
	{
		alert("사용자 아이디를 정확하게 입력하십시오");
	}else{
		var window_left = (screen.width-640)/2;
		var window_top = (screen.height-480)/2;
		vName = "/id_check.html?k_key="+document.regist_frm.id.value;
		subwin=window.open(vName,null,'width=340,height=140,top=' + window_top + ',left=' + window_left + '')
	}
}

//----------------------- 아이디 중복확인 ----------------------------
function checkId() {
	var comp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
	var string=document.regist_frm.id.value;
	var len=string.length;
	if(len > 0) {
	    for(i=0;i<len;i++) {
	        if(comp.indexOf(string.substring(i,i+1))<0) {
	                alert("허용된 문자가 아닙니다. 다시 입력해 주십시오");
					document.regist_frm.id.value="";
					document.regist_frm.id.focus();
	                return;
	        }
	    }
	    if(len <4) {
            alert("\n아이디는 4자이상입니다.");
			document.regist_frm.id.value="";
            document.regist_frm.id.focus();
            return;
	    }
	}
}

//-------------------------- 실명인증 ----------------------------------
function msgBlank(box, msg) {
	if (box.value.replace(/ /g,"")=="") {
		if (msg != "") alert(msg);
		else alert("빈 값입니다. 값을 입력하세요.");
		box.focus();
		return true;
	} else {
		return false;
	}
}
function checkNum(box) { // 숫자 형식 검사 (앞에 오는 0 제거 / 특수문자 제거)
	var valid = "0123456789";
	for (var i=0; i<box.value.length; i++) {
		if (valid.indexOf(box.value.charAt(i)) == -1) {
			alert("숫자만 입력하세요");
			box.value = box.value.substring(0, i); box.focus();
		}
	}
}
function resno_check(theForm) {
	if (msgBlank(theForm.name,"이름을 입력하세요")) return false;
	if (msgBlank(theForm.jumin1,"주민번호 앞자리를 입력하세요")) return false;
	if (msgBlank(theForm.jumin2,"주민번호 뒷자리를 입력하세요")) return false;

	if (!JuminNoCheck()) {
		return false;
	}else{
		return true;
	}
	return false;
}
