// ¼º¸í ÇÑ±ÛÀÎÁö Ã¼Å©ÇÏ´Â ÇÔ¼ö
function AlphaCheck(target, cmt)
{
	var i
	var Alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
	var Digit = '1234567890'
	astr = Alpha + Digit
	var t=target.value
	if (astr.length > 1) {
		for(i=0;i<t.length;i++){
		    if(astr.indexOf(t.substring(i,i+1))>=0) {
				alert(cmt + 'Àº ÇÑ±Û·Î¸¸ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.');
				//openmsg(cmt + 'Àº+ÇÑ±Û·Î¸¸+ÀÔ·ÂÇØ+ÁÖ½Ê½Ã¿À.','txt_Name');
				target.value = ""
				target.focus();
				return;
				}
		}		
	}
	var name_num = target.value.length;

   for (var k = 0; k <= (name_num - 1); k++)
      {
         if (target.value.indexOf(" ") >= 0 ) 
           {
                alert('¼º¸í(ÇÑ±Û)À» ºóÄ­¾øÀÌ ºÙ¿©½á ÁÖ½Ê½Ã¿À.\n\n °ø¹éÀº »ç¿ëÇÏ½Ç¼ö°¡ ¾ø½À´Ï´Ù.');
				//openmsg('¼º¸í(ÇÑ±Û)À»+ºóÄ­¾øÀÌ+ºÙ¿©½á+ÁÖ½Ê½Ã¿À.\n°ø¹éÀº+»ç¿ëÇÏ½Ç¼ö°¡+¾ø½À´Ï´Ù.','txt_Name');
				target.value = ""
				target.focus();
                return (false);
           } 
       }

	var strValue = target.value
	var retCode = 0

	for (i = 0; i < strValue.length; i++) {

		var retCode = strValue.charCodeAt(i)
		var retChar = strValue.substr(i,1).toUpperCase()

		retCode = parseInt(retCode)

		if ((retChar < "0" || retChar > "9") && (retChar < "A" || retChar > "Z") && ((retCode > 255) || (retCode < 0))) {
			return;
		}
		else{
			alert(cmt + 'Àº ÇÑ±Û·Î¸¸ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.');
			//openmsg(cmt + 'Àº+ÇÑ±Û·Î¸¸+ÀÔ·ÂÇØ+ÁÖ½Ê½Ã¿À.','txt_Name');
			target.value = ""
			target.focus();
			return;
		}
	}
}

// ¾ÆÀÌµð Áßº¹°Ë»ç ÆË¾÷Ã¢ ¶ç¿öÁÖ±â
function openIDCheck(){
	wnd = window.open("check_id.asp","","width=410, height=200, status=no, scrollbars=no");
	//wnd.focus();
}

// ºñ¹Ð¹øÈ£°¡ Á¤È®ÇÑÁö È®ÀÎÇÏ±â
function f_PwdConfirm(form){
    if (form.pw.value != form.pw_confirm.value) {
		alert('ºñ¹Ð¹øÈ£¿Í ºñ¹Ð¹øÈ£È®ÀÎÀÌ ¼­·Î ´Ù¸¨´Ï´Ù')
		//openmsg('ºñ¹Ð¹øÈ£¿Í+ºñ¹Ð¹øÈ£+È®ÀÎÀÌ+¼­·Î+´Ù¸¨´Ï´Ù.','pw_confirm');
		form.pw.value = ""
		form.pw_confirm.value = ""
		form.pw.focus();
    return true;
		}
}

//ÁÖ¼Ò°Ë»öÃ¢ ¶ç¿öÁÖ±â
function f_OpenWindow(t)
{
	var s_Url
	if (t==1){s_Url = 'post_search.asp?gubun=1';}

    if (navigator.appName == 'Netscape') {
			wnd = window.open(s_Url, 'view', "status=no,scrollbars=yes,width=410,height=400")
            wnd.focus();
    } else {
			wnd = window.open(s_Url, 'view', "status=no,scrollbars=yes,width=410,height=400")
    }
}

// ÀüÈ­¹øÈ£¿Í µ¿ÀÏ °ü·Ã
function sameNumber(){
	if (document.user_reg.same_number.checked){	

		if (document.user_reg.telephone_category[2].checked){
			
			document.user_reg.handphone1.selectedIndex = document.user_reg.telephone1.selectedIndex;			
			document.user_reg.handphone2.value = document.user_reg.telephone2.value;
			document.user_reg.handphone3.value = document.user_reg.telephone3.value;
		}else{
			alert("ÀüÈ­¹øÈ£ÀÇ ±¸ºÐÀÌ ÈÞ´ëÀüÈ­·Î ¼±ÅÃµÇ¾î¾ß ÇÕ´Ï´Ù.");
		}	

	}else{
		document.user_reg.handphone1.selectedIndex = 0;
		document.user_reg.handphone2.value = "";
		document.user_reg.handphone3.value = "";

	}
}

// ÇÐ±³°Ë»öÃ¢ ¶ç¿öÁÖ±â
function openSchoolSearch(gubun){
	wnd = window.open("search_school.asp?gubun=" + gubun,"","width=410, height=400, status=no, scrollbars=yes");
}

// ÀçÇÐ, ÈÞÇÐ°ü·Ã
function changeEnrollment(enrollment){
	if (enrollment == "1"){
		document.user_reg.school_year.disabled = false;
		document.user_reg.graduation_year.disabled = true;
	}else{
		document.user_reg.school_year.disabled = true;
		document.user_reg.graduation_year.disabled = false;
	}
}

// ÇÐ±³°ü·Ã º¹»ç
function sameDesiredSchool(){
	if (document.user_reg.same_desired_school.checked){	

		document.user_reg.desired_school2.value = document.user_reg.desired_school1.value;			
		document.user_reg.desired_school2_code.value = document.user_reg.desired_school1_code.value;
		document.user_reg.desired_department2.value = document.user_reg.desired_department1.value;
		

	}else{
		document.user_reg.desired_school2.value = "";			
		document.user_reg.desired_school2_code.value = "";
		document.user_reg.desired_department2.value = "";

	}
}

// Æû submit
function sendForm(form){
	form.action = "member_modify_ok.asp";
	 
	if(f_Submit(form)) form.submit();
}

// Æû submit Àü¿¡ È®ÀÎÇÏ´Â ÇÔ¼ö
function f_Submit(form)
{
	var Alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
	var Digit = '1234567890'
	var jumin = form.jumin1.value+form.jumin2.value
		
	if (targetCheck(form.name, '¼º¸í', '', 1, 12,'name')) return false;
	if (targetCheck(form.jumin1, 'ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®', Digit, 6, 6,'jumin1')) return false;
	if (targetCheck(form.jumin2, 'ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®', Digit, 7, 7,'jumin2')) return false;
	
	if (jumin_chk(jumin)) { 
	    alert("ÁÖ¹Îµî·Ï¹øÈ£°¡ Æ²¸³´Ï´Ù.");
	    form.jumin1.focus();
	    return false;
	}
	
	if (f_birth()) {
		form.jumin1.focus();
		return false;
	}
	
	if (targetCheck(form.user_id, 'È¸¿øID', Alpha+Digit, 4, 10,'user_id')) return false;
	if (targetCheck(form.pw, 'ºñ¹Ð¹øÈ£', '', 4, 12,'pw')) return false;
	if (f_PwdConfirm(form)) return false;

	
	if (targetCheck(form.email1, 'E-mailÁÖ¼ÒÀÇ ¾ÆÀÌµð', '', 1, 20,'email1')) return false;
	if (targetCheck(form.email2, 'E-mailÁÖ¼ÒÀÇ µµ¸ÞÀÎ', Alpha+Digit+'_-.', 4, 30,'email2')) return false;
	
	if (emailFormCheck(form.email2.value)){
		alert("E-mail ÁÖ¼ÒÀÇ µµ¸ÞÀÎ Çü½ÄÀÌ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù.");
		form.email2.focus();
		return false;
	}
	
	if (targetCheck(form.zipcode1, '¿ìÆí¹øÈ£(¾ÕÀÚ¸®)', Digit, 3, 3,'zipcode1')) return false;
	if (targetCheck(form.zipcode2, '¿ìÆí¹øÈ£(µÞÀÚ¸®)', Digit, 3, 3,'zipcode2')) return false;
	if (targetCheck(form.address1, 'ÁÖ¼Ò', '', 8, 120,'address1')) return false;
	if (targetCheck(form.address2, '¼¼ºÎÁÖ¼Ò', '', 5, 120,'address2')) return false;
	
	/*
	if (form.desired_college.value == ""){
		alert("Èñ¸Á°è¿­À» ¼±ÅÃÇÏ¼¼¿ä.");
		form.desired_college.focus();
		return false;	
	}
	*/	
	if (form.telephone1.value == ""){
		alert("ÀüÈ­¹øÈ£ÀÇ Áö¿ª¹øÈ£¸¦ ¼±ÅÃÇÏ¼¼¿ä");
		form.telephone1.focus();
		return false;	
	}
	
	if (targetCheck(form.telephone2,  'ÀüÈ­¹øÈ£ÀÇ ¾Õ¹øÈ£', Digit, 3, 4, 'telephone2')) return false;
	if (targetCheck(form.telephone3,  'ÀüÈ­¹øÈ£ÀÇ µÞ¹øÈ£', Digit, 4, 4, 'telephone3')) return false;
	
	if (telephoneCheck(form)){
		alert("ÀüÈ­¹øÈ£ÀÇ ±¸ºÐ°ú Áö¿ª¹øÈ£°¡ ¸ÂÁö ¾Ê½À´Ï´Ù.");
		form.telephone1.focus();
		return false;
	}
	
	if (form.handphone1.value == ""){
		alert("ÇÚµåÆùÀÇ Áö¿ª¹øÈ£¸¦ ¼±ÅÃÇÏ¼¼¿ä");
		form.handphone1.focus();
		return false;	
	}
	
	if (targetCheck(form.handphone2,  'ÇÚµåÆùÀÇ ¾Õ¹øÈ£', Digit, 3, 4, 'handphone2')) return false;
	if (targetCheck(form.handphone3,  'ÇÚµåÆùÀÇ µÞ¹øÈ£', Digit, 4, 4, 'handphone3')) return false;
	
	if (targetCheck(form.school,  'ÇÐ±³¸í', '', 1, 20, 'school')) return false;
	if (targetCheck(form.department,  'ÇÐ°ú¸í', '', 1, 20, 'department')) return false;

	/*
	count = 0;
	for (i=0;form.enrollment_classification.length;i++){
		if (form.enrollment_classification[i].checked) {
			count = i;
			break;	
		}
	}

	

	if (form.enrollment_classification[count].value == "1" || form.enrollment_classification[count].value == "2"){
		if (form.school_year.value == "0"){
			alert("ÀçÇÐÁßÀÌ°Å³ª ÈÞÇÐÁßÀÌ½Ã¸é ÇÐ³âÀ» ¼±ÅÃÇÏ¼¼¿ä.");
			form.school_year.focus();
			return false;	
		}	
		
		if (form.registration_year.value == ""){
			alert("ÀÔÇÐ³âµµ¸¦ ¼±ÅÃÇÏ¼¼¿ä.");
			form.registration_year.focus();
			return false;	
		}	
	}else{
		if (form.registration_year.value == ""){
			alert("ÀÔÇÐ³âµµ¸¦ ¼±ÅÃÇÏ¼¼¿ä.");
			form.registration_year.focus();
			return false;	
		}	
	
		if (form.graduation_year.value == ""){
			alert("Á¹¾÷(¼ö·á)³âµµ¸¦ ¼±ÅÃÇÏ¼¼¿ä.");
			form.graduation_year.focus();
			return false;	
		}
	}
			
	if (targetCheck(form.desired_school1,  '1Áö¸Á Èñ¸Á´ëÇÐ', '', 1, 20, 'desired_school1')) return false;
	if (targetCheck(form.desired_department1,  '1Áö¸Á ÇÐ°ú¸í', '', 1, 20, 'desired_department1')) return false;
	
	if (targetCheck(form.desired_school2,  '2Áö¸Á Èñ¸Á´ëÇÐ', '', 1, 20, 'desired_school2')) return false;
	if (targetCheck(form.desired_department2,  '2Áö¸Á ÇÐ°ú¸í', '', 1, 20, 'desired_department2')) return false;
	
	if (!form.english.checked && !form.chemistry.checked && !form.biology.checked && !form.math.checked 
      && !form.nur.checked && !form.oriental.checked && !form.chinese.checked && !form.interview.checked && !form.etc.checked){
	 	alert("¼ö°­Èñ¸Á°ú¸ñÀ» ÇÏ³ª ÀÌ»ó ¼±ÅÃÇÏ¼¼¿ä.");
	 	form.english.focus();
	 	return false;	   	
	}		
			
	
	if (form.desired_year.value == ""){
		alert("¼ö°­Èñ¸Á½Ã±âÀÇ ³âµµ¸¦ ¼±ÅÃÇÏ¼¼¿ä.");
		form.desired_year.focus();
		return false;	
	}
	
	if (form.desired_month.value == ""){
		alert("¼ö°­Èñ¸Á½Ã±âÀÇ ¿ùÀ» ¼±ÅÃÇÏ¼¼¿ä.");
		form.desired_month.focus();
		return false;	
	}
  
	if (!form.hope_region_kangnam.checked && !form.hope_region_cyber.checked){
	 	alert("¼ö°­Èñ¸ÁÁö¿ªÀ» ÇÏ³ª ÀÌ»ó ¼±ÅÃÇÏ¼¼¿ä.");
	 	form.hope_region_kangnam.focus();
	 	return false;	   	
	}		
	*/
	return true;	
}

// ÁÖ¹Î¹øÈ£°¡ Á¤È®ÇÑÁö È®ÀÎÇÏ´Â ÇÔ¼ö
function jumin_chk(it) {
    var IDtot = 0;
    var IDAdd = "234567892345";
	
	for(i=0;i<12;i++){
	IDtot=IDtot+parseInt(it.substring(i,i+1))*parseInt(IDAdd.substring(i,i+1));
		}
		
    IDtot=11-(IDtot%11);
    if (IDtot==10) {
       IDtot=0;
       }
    else if (IDtot==11) {
       IDtot=1;
       }
       
    if(parseInt(it.substring(12,13))!=IDtot) return true;
}

// ÁÖ¹Î¹øÈ£°¡ Á¤È®ÇÑÁö È®ÀÎÇÏ´Â ÇÔ¼ö2
function f_birth()
{
	var s_Day1 = document.user_reg.jumin1.value
	var s_Day2 = document.user_reg.jumin2.value
	
	if (s_Day1 != '' && s_Day2 != ''){
		if(s_Day2.substring(0,1) == '3' || s_Day2.substring(0,1) == '4'){
			var iYear = parseInt('20' + s_Day1.substring(0,2));
			var iMonth = parseInt(s_Day1.substring(2,4));
			var iDay = parseInt(s_Day1.substring(4,6));

			if (ValueCheck(s_Day1.substring(2,4), 'Áß°£µÎÀÚ¸®', 1, 12)){
				alert('ÁÖ¹Îµî·Ï ¹øÈ£ ÀÔ·ÂÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.');
				return true;
			}
			
			if (ValueCheck(s_Day1.substring(4,6), '¸¶Áö¸·µÎÀÚ¸®', 1, 31)){
				alert('ÁÖ¹Îµî·Ï ¹øÈ£ ÀÔ·ÂÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.');
				return true;
			}
			
			return false;
		}else if(s_Day2.substring(0,1) == '1' || s_Day2.substring(0,1) == '2'){
			var iYear = parseInt('19' + s_Day1.substring(0,2));
			var iMonth = parseInt(s_Day1.substring(2,4));
			var iDay = parseInt(s_Day1.substring(4,6));
			
			if (ValueCheck(s_Day1.substring(2,4), 'Áß°£µÎÀÚ¸®', 1, 12)){
				alert('ÁÖ¹Îµî·Ï ¹øÈ£ ÀÔ·ÂÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.');
				return true;
			}
			
			if (ValueCheck(s_Day1.substring(4,6), '¸¶Áö¸·µÎÀÚ¸®', 1, 31)){
				alert('ÁÖ¹Îµî·Ï ¹øÈ£ ÀÔ·ÂÀÌ Àß¸øµÇ¾ú½À´Ï´Ù.');
				return true;
			}
			
			return false;
		}
	}
}

// ÁÖ¹Î¹øÈ£°¡ Á¤È®ÇÑÁö È®ÀÎÇÏ´Â ÇÔ¼ö2¿¡ ¾²ÀÌ´Â ÇÔ¼ö
function ValueCheck(target, cmt, vmin, vmax)
{
	var t = target
	var Digit = '1234567890'
	if (t != null){	
        for (i=0; i<t.length; i++){
        	if(Digit.indexOf(t.substring(i,i+1))<0) {
					alert('ÁÖ¹Îµî·Ï¹øÈ£°¡ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù.');
					return;
			}
		}
		
		if (t.length < 1 || t < vmin || t > vmax) {
			alert('ÁÖ¹Îµî·Ï¹øÈ£°¡ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù.');
			document.user_reg.jumin1.value = ""
			return;
		} 
		
		return;
	}
}

// ÀÌ¸ÞÀÏ ÁÖ¼Ò Çü½Ä Ã¼Å©ÇÏ±â
function emailFormCheck(domain){
			
	strPart = new Array();
	count = 0;
	strSplit = domain;
	
	do{
		dotPos = strSplit.indexOf(".");
								
		strPart[count] = strSplit.substring(0, dotPos);
		
		strSplit = strSplit.substring(dotPos + 1, strSplit.length);
		
		count++;
		
	}while(strSplit.indexOf(".") >= 0);
	
	strPart[count] = strSplit;
	
	for(i=0;i<strPart.length;i++){
		if(strPart[i].length < 2){
			return true;	
		}		
	}
		 
	return false;	
}

// ÀüÈ­¹øÈ£ ±¸ºÐ, Áö¿ª¹øÈ£ Ã¼Å©
function telephoneCheck(form){
	
	if (form.telephone_category[2].checked){
		if (form.telephone1.selectedIndex > 5){
			return true;	
		}	
	}else{
		if (form.telephone1.selectedIndex < 6){
			return true;	
		}
	}	
	
	return false;
}

// ÁÖ¼Ò °Ë»ö ÆË¾÷¿¡¼­ Á¤º¸ ¹Þ¾Æ¿À´Â ÇÔ¼ö
function put_postno(s_PNo1, s_PNo2, s_Sido, s_Gugun, s_Dong, s_Ri, s_Gubun)
{
	if (s_Gubun==1){
		document.user_reg.zipcode1.value = s_PNo1;
		document.user_reg.zipcode2.value = s_PNo2;
		document.user_reg.address1.value = s_Sido + ' ' + s_Gugun + ' ' + s_Dong + ' ' + s_Ri;
		document.user_reg.address2.focus();
	}			
	
}

// ÀÔ·ÂµÇ¾î ÀÖ´ø Á¤º¸ »Ñ·ÁÁÖ±â
function init(){
	
	// Èñ¸Á°è¿­ ¼¼ÆÃ
	selectOptions(document.user_reg.desired_college, document.user_reg.desired_college_hidden);
	
	// ÀüÈ­¹øÈ£ ±¹¹ø ¼¼ÆÃ
	selectOptions(document.user_reg.telephone1, document.user_reg.telephone1_hidden);
	
	// ÇÚµåÆù ±¹¹ø ¼¼ÆÃ
	selectOptions(document.user_reg.handphone1, document.user_reg.handphone1_hidden);
	
	// ÀüÈ­¹øÈ£ ±¸ºÐ ¼¼ÆÃ
	selectRadio(document.user_reg.telephone_category, document.user_reg.telephone_category_hidden);
	
	// ÁÖ¾ß°£ ¼¼ÆÃ
	selectRadio(document.user_reg.day_school, document.user_reg.day_school_hidden);

	// ÀçÇÐ±¸ºÐ ¼¼ÆÃ
	selectRadio(document.user_reg.enrollment_classification, document.user_reg.enrollment_classification_hidden);
	
	// ÇÐ³â ¼¼ÆÃ
	selectOptions(document.user_reg.school_year, document.user_reg.school_year_hidden);
	
	// ÀÔÇÐ³âµµ ¼¼ÆÃ
	selectOptions(document.user_reg.registration_year, document.user_reg.registration_year_hidden);
	
	// Á¹¾÷³âµµ ¼¼ÆÃ
	selectOptions(document.user_reg.graduation_year, document.user_reg.graduation_year_hidden);

	// ÀçÇÐ±¸ºÐ¿¡ µû¸¥ ÇÐ³â, ÀÔÇÐ³âµµ, Á¹¾÷³âµµ È°¼ºÈ­ ¼¼ÆÃ	
	count = 0;
	for (i=0;document.user_reg.enrollment_classification.length;i++){
		if (document.user_reg.enrollment_classification[i].checked) {
			count = i;
			break;	
		}
	}

	if (document.user_reg.enrollment_classification[count].value == "1" || document.user_reg.enrollment_classification[count].value == "2"){
		document.user_reg.graduation_year.disabled = true;
	}else{
		document.user_reg.school_year.disabled = true;
	}
	
	
	// ÆíÀÔÀ¯Çü ¼¼ÆÃ
	selectRadio(document.user_reg.transfer_type, document.user_reg.transfer_type_hidden);
	
	// Èñ¸ÁÇÐ±â ¼¼ÆÃ
	selectRadio(document.user_reg.desired_term, document.user_reg.desired_term_hidden);
	
	
	// ¼ö°­Èñ¸Á½Ã±â ¼¼ÆÃ
	selectOptions(document.user_reg.desired_year, document.user_reg.desired_year_hidden);
	selectOptions(document.user_reg.desired_month, document.user_reg.desired_month_hidden);
  
  // ÀÌ¸ÞÀÏ ¼ö½Å¿©ºÎ ¼ÂÆÃ
	selectRadio(document.user_reg.email_yn, document.user_reg.email_yn_hidden);

			
}

// select¹Ú½º Á¦¾î
function selectOptions(target_select, target_value){
	
	for(i=0;i<target_select.length;i++){
		if(target_select.options[i].value == target_value.value){
			target_select.selectedIndex = i;
			break;	
		}	
	}
} 

// ¶óµð¾î¹öÆ° Á¦¾î
function selectRadio(target_radio, target_value){
	
	for(i=0;i<target_radio.length;i++){
		if(target_radio[i].value == target_value.value){
			target_radio[i].checked = true;
			break;	
		}	
	}

}
