﻿//====================================
// 주민등록번호 검사
//====================================
function id_no_chk(obj1,obj2)	
{
	// CheckSum 체크
	if (chksumID(obj1,obj2) == false)
		return false;
	else
		return true
		
	// 생성기로 만든게 아닌가 생년월일과 남녀필드 체크
	if (ValidRegNo(obj1,obj2) == false)
		return false;
	else
		return true
	
	// YYMMDD가 맞는지 확인한다.
	if (ValidRegNo2(obj1) == false)
		return false;
	else
		return true
}



function ValidRegNo(obj1,obj2)	
{
	strReg1 = obj1.value;
	strReg2 = obj2.value;
	sGender = strReg2.substring(0,1);
	sYear = strReg1.substring(0,2);
	
	// 두번째 단락 첫번째 숫자는 4보다 클 수 없다.
	if (sGender > 4) {
		return false;
	}
	
	// 2000년도 이전은 남자는 1, 여자는 2
	// 2000년도 이후는 남자는 3, 여자는 4
	if (sYear != '00') {
		if ((sGender != '1') && (sGender != '2')) {
			return false;
		}
	}
	
	return true;
}

// YYMMDD가 맞는지 확인한다.
function ValidRegNo2(obj1)	
{
	strReg1 = obj1.value;

	a = new String(strReg1);

	if(a == '') return false;
	if(a.length != 6 ) return false;

	intYear = parseInt(a.substring(0,2) , 10);
	intMonth = parseInt(a.substring(2,4) , 10);
	intDay = parseInt(a.substring(4,6) , 10);
	
	if(intMonth < 0 || intMonth > 12){ 
		return false;
	}
		
	switch(intMonth){
		case 2 :
			if(intDay < 0 || intDay > 29){
				return false;
				breake;
			}
		case 4 :
			if(intDay < 0 || intDay > 30){
				return false;
				breake;
			}
		case 6 :
			if(intDay < 0 || intDay > 30){
				return false;
				breake;
			}
		case 9 :
			if(intDay < 0 || intDay > 30){
				return false;
				breake;
			}
		case 11 :
			if(intDay < 0 || intDay > 30){
				return false;
				breake;
			}
		default :
			if(intDay < 0 || intDay > 31){
				return false;
				breake;
			}
	}
	
	return true;
}

function chksumID(obj1,obj2)	
{
	str1 = obj1.value;
	str2 = obj2.value;
	var li_lastid,li_mod,li_minus,li_last;
	var value0,value1,value2,value3,value4,value5,value6;
	var value7,value8,value9,value10,value11,value12;
	
	if (IsInteger(str1) &&  IsInteger(str2)) {
		li_lastid    = parseInt(str2.substring(6,7));
		value0  = parseInt(str1.substring(0,1))  * 2;
		value1  = parseInt(str1.substring(1,2))  * 3;
		value2  = parseInt(str1.substring(2,3))  * 4;
		value3  = parseInt(str1.substring(3,4))  * 5;
		value4  = parseInt(str1.substring(4,5))  * 6;
		value5  = parseInt(str1.substring(5,6))  * 7;
		value6  = parseInt(str2.substring(0,1))  * 8;
		value7  = parseInt(str2.substring(1,2))  * 9;
		value8  = parseInt(str2.substring(2,3))  * 2;
		value9  = parseInt(str2.substring(3,4))  * 3;
		value10 = parseInt(str2.substring(4,5))  * 4;
		value11 = parseInt(str2.substring(5,6))  * 5;
		value12 = 0;
		
		value12 = value0+value1+value2+value3+value4+value5+value6+value7+value8+value9+value10+value11+value12 ;
		
		li_mod = value12 %11;
		li_minus = 11 - li_mod;
		li_last = li_minus % 10;
		if (li_last != li_lastid){
			obj2.select();
			alert ("정확한 주민등록번호를 입력하세요!!");
			obj2.focus();
			return false;
		} else
			return true;
	} else
	obj2.select();
	obj2.focus();
	return false;
}

//==================================
// 주어진 문자열이 숫자로만 이루어져있는지 검사한다.
//==================================
function IsInteger(st) {
	if (!IsEmpty(st)) {
		for (j = 0; j < st.length; j++)
			if (((st.substring(j, j+1) < "0") || (st.substring(j, j+1) > "9")))
				return false;
	}
	else
		return false;
	return true;
}

//==================================
// 주어진 문자열이 비어있는지 검사한다.
//==================================
function IsEmpty(toCheck) {
	var chkstr = toCheck + "";
	var is_Space = true;

	if (( chkstr == "") || (chkstr == null))
		return false;

	for (j = 0; is_Space && j < chkstr.length; j++) {
		if (chkstr.substring(j, j+1) != " ")
			is_Space = false ;
	}

	return is_Space;
}

	


//===================================
//	아이디 영문자만 사용
//===================================

function CheckEnglishOnly(field, info){
	var ln = field.value.length;
	var chSpecial = false;

	for (var i=0; i<ln; ++i) {
		var ch = field.value.charAt(i);
		if (ch == '-' ||ch == '_') continue;
		if (ch > 'z' || ch < '0' || ch == '^' || ch == ';' || ch == ':') chSpecial = true;
		if (ch == '\\' || ch == '`' || ch == '<' || ch == '>' || ch == '=' || ch == ' ' ) chSpecial = true;
	}
	
	if(chSpecial) {
		alert(info + "란은 한글, 공란, 특수문자를 사용할 수 없습니다.\n영문자, 숫자, '-', '_'의 조합을 사용해주세요.");
		field.focus();
		return false;
	}
	else
		return true;
}



//===================================
//	숫자만 입력
//===================================
function chkNumeric(objText) {
	var chrTmp;
	var strTmp = objText.value;
	var chkAlpha = false;
	var resString = '';
 
	for (var i=0; i<=strTmp.length; i++) {
	    chrTmp = strTmp.charCodeAt(i);

		if ((chrTmp <=47 && chrTmp > 31) || chrTmp >= 58) {
			chkAlpha = true;
		} else {
			resString = resString + String.fromCharCode(chrTmp);
		}
	}
	if (chkAlpha == true) {
		alert("숫자만을 입력하세요");
		objText.value = resString;
		objText.focus();
		return false;
	}
	return true;
}

//==================================
// 글자 수 체크
//==================================
function check_length (field , info, min_len, max_len){ 
	if (min_len == max_len){
		if ( field.value.length != min_len){
			alert ( info + "란은 " + min_len +"글자이어야 합니다.");
			field.focus();
			return false;
		}
		else {
			return true;
		}
	}
	else {
		if ( field.value.length < min_len || field.value.length > max_len){
			alert ( info + "란의 글자수는 "+ min_len + "자 이상 " + max_len + "자 이하만 가능합니다.\n\n 입력하신 글자수는 "+ field.value.length +"자 입니다.");
			field.focus();
			return false; 
		}
		return true;
	}
}


//==================================
// Null값 체크 하기 시작 1
//==================================
function CheckNullValue (field , info ){ 
	if (field.value == "" ){
			alert ( info + " 입력하세요.");
			field.focus();
			return false; 
		
	}
	return true;
}


//		if(rform.real4_3[0].checked  ) {


//==================================
// Null값 체크 하기 시작 - 성별
//==================================
function CheckNullValue_chk (field,info){ 

var f = document.forms['listform'];
	var i,j;
	if(typeof(field) == 'object') {
		if(field.length) {
			for (i=0,j=0;i<field.length;i++) { if(field[i].checked) { j++; }}
			if(!j) { alert(info+' 선택하여 주세요.');return; }
		} else {
			if(!field.checked) { alert(info+' 선택하여 주세요.');return; }
		}
		return true;
	} else {
		alert ( info + " 선택하여 주세요!.");
		return false; 
	}
}


//==================================
// 실명인증 체크값
//==================================
function CheckNull_secure (field){ 
	if (field.value !="ok"){
			alert ( "실명인증 확인해 주세요!");
			return false; 
		
	}
	return true;
}


//==================================
// Null값 체크 하기 시작2
//==================================
function CheckNullValue2 (field , info ){ 
	if (field.value == "" ){
			alert ( info + " 입력하세요.");
			field.focus();
			return false; 	
	}
	return true;
}


//==================================
// 회원가입 이메일 선택
//==================================
function res(){
var f = document.write_Form;
	if(f.email3.value=="a"){
	f.email2.readOnly= false;
	f.email2.value="";
	f.email2.focus();
	}else if(f.email3.value=="b"){
	f.email2.readOnly= false;
	f.email2.value="";
	}else{
	f.email2.readOnly= false;
	f.email2.value=f.email3.value;
	}
}


//==================================
// 아이디중복검색
//==================================
function idWinOpen(data) {
	var form=document.write_Form;

	if (CheckNullValue(form.userid, "아이디를"))
	if (CheckEnglishOnly(form.userid, "아이디를"))
	if (check_length(form.userid, "아이디를", 4, 20))
	
	window.open("/member/id_search.php?userid="+form.userid.value+"&method="+data,"","scrollbars=no, width=400, height=250");
}

//==================================
// 우편번호찾기
//==================================
function postWinOpen(data) {
	window.open("/member/post_search.php?method="+data, "","scrollbars=yes, width=505, height=400");
}


//==================================
//성별 자동 체크
//==================================
	function AutoBirth(){
		jumin1=document.write_Form.jumin1.value;
		byear=jumin1.substr(0,2);	// 0번째 부터 2전까지..0.1
		bmonth=jumin1.substr(2,2);//월
		bday=jumin1.substr(4,2);//일
		chksex=document.write_Form.jumin2.value.substr(0,1); //성별 1 or 2
		
		if(chksex=="1" || chksex=="3" || chksex=="5"){
			document.write_Form.sex[0].checked=true;
			document.write_Form.sex[1].disabled=true;
			document.write_Form.sex[0].disabled=false;
		}else if(chksex=="2" || chksex=="4"  || chksex=="6"){
			document.write_Form.sex[1].checked=true;
			document.write_Form.sex[0].disabled=true;
			document.write_Form.sex[1].disabled=false;
		}

			/* */
	//생년월일 체크
	/*
	if(chksex=="1" || chksex=="2")
		document.write_Form.birth_year.value="19"+byear;
	else if(chksex=="3" || chksex=="4")
		document.write_Form.birth_year.value="20"+byear;
		
		document.write_Form.birth_month.value=bmonth;
		document.write_Form.birth_day.value=bday;
	*/

	}
	
//==================================
//주민번호 onkey_up
//==================================
	function move_focus(field1,field2){
		var str=field1.value.length;
		if(str==6)
		field2.focus();
	}

//==================================
//실명&가입여부 주민번호 onkey_up
//==================================
	function move_focus2(){
		var str=document.joinChk_Form.jumin1.value.length;
		if(str==6)
		document.joinChk_Form.jumin2.focus();
	}


//==================================
// 비번 비교
//==================================
function check_pass (pass, repass){ 
	if ( pass.value != repass.value ){
		alert ("비밀번호가 일치 하지 않습니다.");
    	pass.focus();
    	return false; 
	}
	return true;
}








//==================================
// TextBox 
//==================================
/* 전송하고자 하는 메세지의 바이트수를 체크한다. */
function checkMsg()
{
	var str,msg;
	var len = 0;
	var temp;
	var count = 0;

	msg = document.write_Form.position.value;
	str = new String(msg);
	len = str.length;

	for (k=0 ; k<len ; k++)
	{
		temp = str.charAt(k);

		if (escape(temp).length > 4) 
		{
			count += 2;
		}
		else if (temp == '\r' && str.charAt(k+1) == '\n') 
		{
			count += 2;
		}
		else if (temp != '\n') 
		{
			count++;
		}
	}
	document.write_Form.msgLen.value = count;

	if(count > 80) 
	{
		document.write_Form.position.blur();
		document.write_Form.position.focus();		
		alert("메시지 내용은 80바이트까지만 작성가능합니다."); 
		CutChar();
	}
}

/* 지정된 바이트가 초과경우 문자를 삭제한다. */
function CutChar() 
{
	var str,msg;
	var len=0;
	var temp;
	var count;
	count = 0;
 
	msg = document.write_Form.position.value;
	str = new String(msg);
	len = str.length;

	for(k=0 ; k<len ; k++) 
	{
		temp = str.charAt(k);

		if(escape(temp).length > 4) 
		{
			count += 2;
		}
		else if(temp == '\r' && str.charAt(k+1) == '\n') 
		{ 
			count += 2;
		}		
		else if(temp != '\n') 
		{
			count++;
		}

		if(count > 80) 
		{
			str = str.substring(0,k);
			break;
		}
	}
	document.write_Form.position.value = str;
	checkMsg(str);
}
function DefaultMsgCut(target)
{
	if (target.value == target.defaultValue)
	{
		target.value = "";
	}
}

function DefaultMsgPaste(target)
{
	if (!target.value)
	{
		target.value = target.defaultValue;
	}
}









/*
//==================================
//	로그인 Function
//==================================

function Chk_login() {
	var form	=	document.login_Form;
	if (CheckNullValue2(form.userid, "아이디를 "))
	if (CheckNullValue2(form.passwd, "비밀번호를 "))
		return form.submit();
}



//==================================
//	아이디찾기 Function
//==================================

function Chk_Find1() {
	var form	=	document.id_Form;
	if (CheckNullValue2(form.name, "이름을 "))
	if (CheckNullValue2(form.jumin1, "주민번호 앞자리를"))
	if (check_length(form.jumin1, "주민번호앞자리", 6, 6))
	if (chkNumeric(form.jumin1, "주민번호 앞자리"))
	if (CheckNullValue2(form.jumin2, "주민번호 뒷자리를"))
	if (check_length(form.jumin2, "주민번호 뒷자리", 7, 7))
	if (chkNumeric(form.jumin2, "주민번호 뒷자리"))
	if (id_no_chk(form.jumin1, form.jumin2))
		return form.submit();
}

//==================================
//	비번찾기 Function
//==================================

function Chk_Find2() {
	var form	=	document.pass_Form;

	if (CheckNullValue2(form.userid_pw, "아이디를 "))	
	if (CheckNullValue2(form.name_pw, "이름을 "))
	if (CheckNullValue2(form.jumin1_pw, "주민번호 앞자리를"))
	if (check_length(form.jumin1_pw, "주민번호앞자리", 6, 6))
	if (chkNumeric(form.jumin1_pw, "주민번호 앞자리"))
	if (CheckNullValue2(form.jumin2_pw, "주민번호 뒷자리를"))
	if (check_length(form.jumin2_pw, "주민번호 뒷자리", 7, 7))
	if (chkNumeric(form.jumin2_pw, "주민번호 뒷자리"))
	if (id_no_chk(form.jumin1_pw, form.jumin2_pw))
		return form.submit();


}

*/










/*

//==================================
//	[관리자]개인회훤 VS 기업회원 구분 Function
//==================================
function distView3(v) {
	if(v=='i'){
		document.getElementById('tr1').style.display	=	'';
		document.getElementById('tr2').style.display	=	'none';
	}else{
		document.getElementById('tr1').style.display	=	"none";
		document.getElementById('tr2').style.display	=	'';
	}
}


//==================================
//	TOP MENU Function
//==================================

function Top_login() {
	var form	=	document.login_Form;
	if (CheckNullValue2(form.userid, "아이디를 "))
	if (CheckNullValue2(form.passwd, "비밀번호를 "))
		return form.submit();
}

*/


//==================================
//	실명&가입여부 Function
//==================================
/*
function Chk_join() {
	var form	=	document.joinChk_Form;
	
	if (CheckNullValue(form.name, "이름을"))
	if (CheckNullValue(form.jumin1, "주민번호 앞자리를"))
	if (check_length(form.jumin1, "주민번호앞자리", 6, 6))
	if (chkNumeric(form.jumin1, "주민번호 앞자리"))
	if (CheckNullValue(form.jumin2, "주민번호 뒷자리를"))
	if (check_length(form.jumin2, "주민번호 뒷자리", 7, 7))
	if (chkNumeric(form.jumin2, "주민번호 뒷자리"))
	if (id_no_chk(form.jumin1, form.jumin2))
		return form.submit();
}
*/

//==================================
//	다운로드 Function
//==================================

function down_chk() {
	
		var form	=	document.write_Form;


	

		//if(form.foreigner[0].checked == true){
				var chrTmp;
				var strTmp = form.jumin1.value;
				var chkAlpha = false;
				var resString = '';

				for (var i=0; i<=strTmp.length; i++) {
					chrTmp = strTmp.charCodeAt(i);

					if ((chrTmp <=47 && chrTmp > 31) || chrTmp >= 58) {
						chkAlpha = true;
					} else {
						resString = resString + String.fromCharCode(chrTmp);
					}
				}



				var chrTmp2;
				var strTmp2 = form.jumin2.value;
				var chkAlpha2 = false;
				var resString2 = '';

				for (var j=0; j<=strTmp2.length; j++) {
					chrTmp2 = strTmp2.charCodeAt(j);

					if ((chrTmp2 <=47 && chrTmp2 > 31) || chrTmp2 >= 58) {
						chkAlpha2 = true;
					} else {
						resString2 = resString2 + String.fromCharCode(chrTmp2);
					}
				}


				if(form.name.value==""){
					alert ( "이름을 입력하세요.");
					form.name.focus();
					return false; 
				}else if(form.jumin1.value==""){
					if(form.foreigner[0].checked=='true'){
						alert ( "주민번호 앞자리를 입력하세요.");
					}else{
						alert ( "외국인 등록번호 앞자리를 입력하세요.");
					}
					form.jumin1.focus();
					return false; 
				}else if(form.jumin1.value.length != '6'){
					if(form.foreigner[0].checked=='true'){
						alert ( "주민번호 앞자리는 6 글자이어야 합니다.");
					}else{
						alert ( "외국인 등록번호 앞자리는 6 글자이어야 합니다.");
					}
					form.jumin1.focus();
					return false;				
				}else if(chkAlpha == true) {
					alert("숫자만을 입력하세요");
					form.jumin1.value = resString;
					form.jumin1.focus();
					return false;
				}else if(form.jumin2.value==""){
					if(form.foreigner[0].checked=='true'){
						alert ( "주민번호 뒷자리를 입력하세요.");
					}else{
						alert ( "외국인 등록번호 뒷자리를 입력하세요.");
					}
					form.jumin2.focus();
					return false;
				}else if(form.jumin2.value.length != '7'){
					if(form.foreigner[0].checked=='true'){
						alert ( "주민번호 뒷자리는 7 글자이어야 합니다.");
					}else{
						alert ( "외국인 등록번호 뒷자리는 7 글자이어야 합니다.");
					}
					form.jumin2.focus();
					return false;
				}else if(chkAlpha2 == true) {
					alert("숫자만을 입력하세요");
					form.jumin2.value = resString2;
					form.jumin2.focus();
					return false;					
				}else if(form.secure_chk.value=="" && form.foreigner[0].checked=='true'){
					alert ( "실명인증 확인을 하여주세요!");
					return false; 
				}else if(form.email.value==""){
					alert ( "이메일을 입력하세요.");
					form.email.focus();
					return false; 
				}else if(form.email2.value==""){
					alert ( "이메일을 입력하세요.");
					form.email2.focus();
					return false; 

				}else if(form.sex[0].checked == false && form.sex[1].checked == false){
					alert ( "성별을 선택하세요!.");
					form.sex.focus();
					return false; 
				}else if(form.agree_chk[0].checked != true){
					alert ( "메일수신을 동의하지 않으면 교환권 다운로드가 불가능합니다.");
					return false; 

				/*}else if(form.agree_chk[0].checked == false && form.agree_chk[1].checked == false){
					alert ( "메일수신동의를 선택하세요!.");
					return false; 
					*/
				}else if(confirm('교환권 출력시 정보수정은 불가능합니다.\n 교환권을 출력하시겠습니까?')==true){
					form.action ="index02_proc.php";
					form.target="_self";
					return form.submit();
				}

/*


					if (CheckNullValue(form.name, "이름을"))
					if (CheckNullValue(form.jumin1, "주민번호 앞자리를"))
					if (check_length(form.jumin1, "주민번호앞자리", 6, 6))
					if (chkNumeric(form.jumin1, "주민번호 앞자리"))
					if (CheckNullValue(form.jumin2, "주민번호 뒷자리를"))
					if (check_length(form.jumin2, "주민번호 뒷자리", 7, 7))
					if (chkNumeric(form.jumin2, "주민번호 뒷자리"))
					if (id_no_chk(form.jumin1, form.jumin2))
				if (CheckNull_secure(form.secure_chk))
				if (CheckNullValue(form.email,"이메일을"))
				if (CheckNullValue(form.email2,"이메일을"))
				if (CheckNullValue_chk(form.sex,"성별을"))
				if (CheckNullValue_chk(form.agree_chk,"메일수신동의를 "))		
				
				form.action ="index02_proc.php";
				form.target="_self";
				return form.submit();		

*/
				//return form.submit();
	
		/*
		}else if(form.foreigner[1].checked == true){
				if (CheckNullValue(form.name, "이름을"))
				if (CheckNullValue(form.jumin1, "외국인 등록번호 앞자리를"))
				if (CheckNullValue(form.jumin2, "외국인 등록번호 뒷자리를"))
				if (CheckNull_secure(form.secure_chk))
				if (CheckNullValue(form.email,"이메일을"))
				if (CheckNullValue(form.email2,"이메일을"))
				if (CheckNullValue_chk(form.sex,"성별을"))
				if (CheckNullValue_chk(form.agree_chk,"메일수신동의를 "))

			

				return form.submit();
		}
		*/

}




//==================================
//	다운로드-재발급 Function
//==================================

function down_chk2() {
	
		var form	=	document.re_write_Form;

		//if(form.foreigner.value=='1'){
		if (CheckNullValue(form.jumin_1, "주민번호 앞자리를"))
		if (check_length(form.jumin_1, "주민번호앞자리", 6, 6))
		if (chkNumeric(form.jumin_1, "주민번호 앞자리"))
		if (CheckNullValue(form.jumin_2, "주민번호 뒷자리를"))
		if (check_length(form.jumin_2, "주민번호 뒷자리", 7, 7))
		if (chkNumeric(form.jumin_2, "주민번호 뒷자리"))
		//if (id_no_chk(form.jumin_1, form.jumin_2))

		return form.submit();


		/*
		}else if(form.foreigner.value=='2'){
				if (CheckNullValue(form.jumin_1, "외국인 등록번호 앞자리를"))
				if (CheckNullValue(form.jumin_2, "외국인 등록번호 뒷자리를"))

				return form.submit();


		}
		*/
}





/*
//==================================
//	회원정보수정 Function
//==================================

function Chk_join2() {
	var form	=	document.write_Form;

	if (CheckNullValue(form.passwd, "비밀번호를"))
	if (CheckEnglishOnly(form.passwd, "비밀번호를"))
	if (check_length(form.passwd, "비밀번호를", 4, 20))
	if (CheckNullValue(form.re_passwd, "비밀번호를"))
	if (check_pass(form.passwd, form.re_passwd))
	if (CheckNullValue(form.email,"이메일을"))
	if (CheckNullValue(form.email2,"이메일을"))
	if (CheckNullValue(form.tel1, "집전화번호 앞자리을"))	
	if (chkNumeric(form.tel1, "집전화번호 앞자리를"))
	if (CheckNullValue(form.tel2, "집전화번호 가운데 자리를"))
	if (check_length(form.tel2, "집전화번호 가운데 자리", 3, 4))
	if (chkNumeric(form.tel2, "집전화번호 가운데 자리"))
	if (CheckNullValue(form.tel3, "집전화번호 번호 끝자리를"))
	if (check_length(form.tel3, "집전화번호 끝자리를", 4, 4))
	if (chkNumeric(form.tel3, "집전화번호 끝자리를"))
	if (CheckNullValue(form.zip1, "우편번호를"))
	if (CheckNullValue(form.zip2, "우편번호를"))
	if (CheckNullValue(form.add1, "주소를"))
	if (CheckNullValue(form.add2, "상세주소를"))

		return form.submit();
}
*/

/*
//==================================
//	회원탈퇴 Function
//==================================
function out_Chk(){
	var oForm	=	document.out_Form;


	if(oForm.userid.value=="") {
		alert("아이디를 입력해 주십시오.");
		oForm.userid.focus();
	} else if( oForm.passwd.value=="") {
		alert("비밀번호를 입력해 주십시오.");
		oForm.passwd.focus();
	} else if( oForm.name.value=="") {
		alert("이름을 입력해 주십시오.");
		oForm.name.focus();
	} else if( oForm.jumin1.value=="") {
		alert("주민번호앞자리를 입력해 주십시오.");
		oForm.jumin1.focus();
	} else if( oForm.jumin2.value=="") {
		alert("주민번호뒷자리를 입력해 주십시오.");
		oForm.jumin2.focus();
	} else {
		oForm.submit();			
	}
}
*/