function changeMail(tmp)
{
	if ( $(tmp+'emailserver').value == "")
	{
		$(tmp+'email2').value = "";
		$(tmp+'email2').readOnly = false;
	}
	else
	{
		$(tmp+'email2').readOnly = true;
		$(tmp+'email2').value = $(tmp+'emailserver').value;
	}

}
 
function input_bizaddress(tmp, tmp_ori)
{	
	if ($('check_'+tmp+'address').checked == true )
	{
		$(tmp+'zipcode1').value = $(tmp_ori+'zipcode1').value;
		$(tmp+'zipcode2').value = $(tmp_ori+'zipcode2').value;
		$(tmp+'address').value = $(tmp_ori+'address').value;
		$(tmp+'addressadd').value = $(tmp_ori+'addressadd').value;
		return;
	}
	else
	{		
		$(tmp+'zipcode1').value = "";
		$(tmp+'zipcode2').value = "";
		$(tmp+'address').value = "";
		$(tmp+'addressadd').value = "";
		return;

	}
}


function check_jumin()
{
	var jumin = $('check_ida').value + $('check_idb').value;

	if( $('check_ida').length != 6  && $('check_idb').length != 7 && jumin.length != 13)
	{
		alert ("주민등록번호를 확인하십시오.");
		$('check_ida').focus();
		return false;
	}

	for (var i = 0; i < jumin.length ; i++)
	{
		var ch1 = jumin.substring(i, i+1);
		if (ch1 < "0" || ch1 > "9")
		{
			alert("주민등록번호를 확인하신후 다시 입력하십시오.");
			$('check_idb').focus();
			return false;
		}
	}

	var sex = $('check_idb').value.substring(0,1);
	if ( sex != "1" && sex != "2" && sex != "3" && sex != "4" )
	{
		alert("주민등록번호를 확인하신후 다시 입력하십시오.");
		$('check_ida').focus();
		return false;
	}
	
	var chk = 0 ;
	for (var i = 0; i <=5 ; i++)
	{
		chk = chk + ((i%8+2) * parseInt($('check_ida').value.substring(i,i+1)));
	}
	for (var i = 6; i <=11 ; i++)
	{
		chk = chk + ((i%8+2) * parseInt($('check_idb').value.substring(i-6,i-5)));
	}
	
	chk = 11 - (chk %11)
	chk = chk % 10;
	
	if (chk != $('check_idb').value.substring(6,7))
	{
		alert ("유효하지 않은 주민등록번호입니다.");
		$('check_ida').focus();
		return false;
	}
	return true;
}

function check_jumin2()
{
	var jumin = $('check_ida').value + $('check_idb').value;
	
	if (jumin == '')
	{
		alert("외국인 등록 번호를 입력해 주세요.");
		$('check_ida').focus();
		return false;
	}

	if (jumin.length != 13)
	{
		alert("외국인 등록 번호 자리수가 맞지 않습니다.");
		$('check_ida').value = "";
		$('check_idb').value = "";
		$('check_ida').focus();
		return false;
	}

	if ((jumin.charAt(6) == "5") || (jumin.charAt(6) == "6"))
	{
		birthYear = "19";
	}
	else if ((jumin.charAt(6) == "7") || (jumin.charAt(6) == "8"))
	{
		birthYear = "20";
	}
	else if ((jumin.charAt(6) == "9") || (jumin.charAt(6) == "0"))
	{
		birthYear = "18";
	}
	else
	{
		alert("잘못된 외국인 등록번호입니다. 확인하고 다시 입력해 주세요.");
		$('check_ida').value = "";
		$('check_idb').value = "";
		$('check_ida').focus();
		return false;
	}

	birthYear += jumin.substr(0, 2);
	birthMonth = jumin.substr(2, 2) - 1;
	birthDate = jumin.substr(4, 2);
	birth = new Date(birthYear, birthMonth, birthDate);

	if ( birth.getYear() % 100 != jumin.substr(0, 2) || birth.getMonth() != birthMonth || birth.getDate() != birthDate)
	{
		alert("잘못된 외국인 등록번호입니다. 확인하고 다시 입력해 주세요.");
		$('check_ida').value = "";
		$('check_idb').value = "";
		$('check_ida').focus();
		return false;
	 }

	if (foreignerSSNCheckSum(jumin) == false)
	{
		alert("잘못된 외국인 등록번호입니다. 확인하고 다시 입력해 주세요.");
		$('check_ida').value = "";
		$('check_idb').value = "";
		$('check_ida').focus();
		return false;
	 }

	return true;
}

function foreignerSSNCheckSum(reg_no)
{
	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 false;
	}

	if ((buf[11] != 6)&&(buf[11] != 7)&&(buf[11] != 8)&&(buf[11] != 9))
	{
		return 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 false;
	}
 
	return true;
}

function checkid(target, cmt)
{
	var ascii, i;

	if (target.value == "")
	{
		alert("아이디를 입력해주세요.");
		return false;
	}

	for (i=0;i < target.value.length ;i++)
	{
		ascii = target.value.charCodeAt(i);
		if ((i==0) && ((ascii < 97) || (ascii  > 122)))
		{
			alert("첫 글자는 영문소문자만 가능합니다.");
			target.focus();
			return false;
		}
		else if (   ascii >= 65 && ascii <= 90 )
		{
			alert(" 영문 대문자는 사용할 수 없습니다.");
			target.focus();
			return false;
		}
		else if (ascii > 122)
		{
			alert("한글을 비롯한 특수문자는 사용할 수 없습니다.");
			target.focus();
			return false;
		}
		
	}
    
	for (i = 0; i < target.value.length; i++)
	{
		if (target.value.charAt(i) >= "0" && target.value.charAt(i) <= "9")
		{
			continue;
		}
		else if (target.value.charAt(i) >= "a" && target.value.charAt(i) <= "z")
		{
			continue;
		}
		else if (target.value.charAt(i) >= "A" && target.value.charAt(i) <= "Z")
		{
			continue;
		}
		else if (target.value.charAt(i) == "_")
		{
			continue;
		}
		else if (target.value.charAt(i) == " ")
		{
			alert("회원 아이디(ID)는 띄어쓰기 없이 영문자와 숫자 조합과 '_'만 가능합니다. ");
	  		target.focus();
			return false;
		}
		else
		{
			alert("회원 아이디(ID)는 띄어쓰기 없이 5~15자리의 영문자와 숫자 조합과 '_'만 가능합니다.");
			target.focus();
			return false;
		}
	}
	 
	if (target.value.length < 5)
	{
		alert("ID는 5자 이상이어야 합니다.");
		target.focus();
		return false;
	}	
}

function check_join_mem()
{
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var alphaS= 'abcdefghijklmnopqrstuvwxyz';
	var numeric = '1234567890';
	var dash = '_';
	var special = '`~!@%^*-_<>';
	
	if ( $('checkok').value != "Y" )
	{
		alert("가입확인하셔야 가입하실 수 있습니다.");
		return false;
	}	
	
	if ( checknorm($('muid'),'회원 아이디(ID)',alphaS+numeric+dash,12,5) ) return false ; 
	if ( checkid($('muid'),'회원 아이디(ID)') ) return false ;
	if ( $('checkmuid').value == "" )
	{ 
		alert( '중복확인은 필수 입니다.' )
		return false ;
	}
	if ( checknorm($('mpass'),'비밀번호',alpha+numeric+special,15,4) ) return false ; 
	if ( checknorm($('rempass'),'재확인비밀번호',alpha+numeric+special,15,4) ) return false ; 
	if ( $('mpass').value != $('rempass').value )
	{
		alert(" 비밀번호가 일치하지 않습니다.");
		$('mpass').focus();
		return false ;                                 
	}
	
	
	if ( $('mode').value == "mem2" )
	{
		$('bizno').value = $('bizno1').value + $('bizno2').value + $('bizno3').value;
		if ( checknorm($('mname'),'대표자명','',20,'')) return false ;  
		if ( checknorm($('ida'),'법인등록번호/대표자주민번호','',6,'')) return false ;  
		if ( checknorm($('idb'),'법인등록번호/대표자주민번호','',7,'')) return false ;  
	}
	else if ( $('mode').value == "mem1" )
	{
		if ( checknorm($('ida'),'주민등록번호','',6,6)) return false ;  
		if ( checknorm($('idb'),'주민등록번호','',7,7)) return false ; 
	}

	if ( checknorm($('email1'),'E-Mail','',50,'')) return false ;  
    if ( checknorm($('email2'),'E-Mail','',40,'')) return false ; 	

	if ($('email2').value.indexOf(".") < 0)
	{
		alert("올바르지 않은 E-Mail 주소입니다. 다시 입력해 주세요.");
		$('email2').value = "";
		$('email2').focus();
		return false ;
	}
	
	if ( checknorm($('tel1'),'전화번호','',4,2)) return false ;
	if ( checknorm($('tel2'),'전화번호',numeric,4,3)) return false ; 
	if ( checknorm($('tel3'),'전화번호',numeric,4,4)) return false ; 
	
	if ( checknorm($('hphone1'),'휴대폰번호','',4,2)) return false ; 
	if ( checknorm($('hphone2'),'휴대폰번호',numeric,4,3)) return false ; 
	if ( checknorm($('hphone3'),'휴대폰번호',numeric,4,4)) return false ; 
	 
	if ( $('mode').value == "mem2" )
	{
		if ( checknorm($('fax1'),'팩스','',4,2)) return false ; 
		if ( checknorm($('fax2'),'팩스',numeric,4,3)) return false ; 
		if ( checknorm($('fax3'),'팩스',numeric,4,4)) return false ; 
		$('fax').value = $('fax1').value + "-" + $('fax2').value + "-" + $('fax3').value;
		if ( checknorm($('bizstatus'),'업태','',50,'')) return false ; 
		if ( checknorm($('biztrade'),'업종','',50,'')) return false ; 
	}	 

	if ( checknorm($('zipcode1'),'우편번호',numeric,3,3)) return false ;  
	if ( checknorm($('zipcode2'),'우편번호',numeric,3,3)) return false ; 
	if ( checknorm($('address'),'주소','',100,'')) return false ; 
	if ( checknorm($('addressadd'),'상세주소','',50,'')) return false ; 

	if ( $('mode').value == "mem2" )
	{
		if ( checknorm($('bizzipcode1'),'사업장우편번호',numeric,3,3)) return false ;  
		if ( checknorm($('bizzipcode2'),'사업장우편번호',numeric,3,3)) return false ; 
		$('bizzipcode').value = $('bizzipcode1').value + $('bizzipcode2').value;
		if ( checknorm($('bizaddress'),'사업장주소','',100,'')) return false ; 
		if ( checknorm($('bizaddressadd'),'사업장상세주소','',50,'')) return false ;  
	}	 	

	if ( $('idb').value.substr(0,1) == "1" || $('idb').value.substr(0,1) == "3")
	{
		$('sex').value = "1";
	}
	else if ( $('idb').value.substr(0,1) == "2" || $('idb').value.substr(0,1) == "4")
	{
		$('sex').value = "2";
	}

	if ( $('idb').value.substr(0,1) == "1" || $('idb').value.substr(0,1) == "2")
	{
		$('age').value = "19" + $('ida').value.substr(0,2);
	}
	else if ( $('idb').value.substr(0,1) == "3" || $('idb').value.substr(0,1) == "4")
	{
		$('sex').value = "20" + $('ida').value.substr(0,2);
	}		
		
	if(confirm(" 입력하신 정보로 회원등록을 하시겠습니까?"))
	{
		$('email').value = $('email1').value + "@" + $('email2').value;
		$('zipcode').value = $('zipcode1').value + $('zipcode2').value;
		$('tel').value = $('tel1').value + "-" +  $('tel2').value + "-" +  $('tel3').value;
		$('hphone').value = $('hphone1').value + "-" +  $('hphone2').value + "-" +  $('hphone3').value;
		if ( $('mode').value == "mem2" )
		{
			var tmp_url = "/member/join_step3_mem2.php";
		}
		else
		{
			var tmp_url = "/member/join_step3_mem1.php";
		}
		$('mode').value = "write";
		$('memberForm').action = tmp_url;
		$('memberForm').submit();
	}
	
	return false ; 	
}

function check_mody_mem()
{
    var alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var alphaS= 'abcdefghijklmnopqrstuvwxyz';
	var numeric = '1234567890';
	var dash = '_';
	var special = '`~!@%^*-_<>';

	if ( checknorm($('mpass'),'비밀번호',alpha+numeric+special,15,4) ) return false ; 
	if ( checknorm($('rempass'),'재확인비밀번호',alpha+numeric+special,15,4) ) return false ; 
	if ( $('mpass').value != $('rempass').value )
	{
		alert(" 비밀번호가 일치하지 않습니다.");
		$('mpass').focus();
		return false ;                                 
	}

	if ( checknorm($('ida'),'주민등록번호','',6,6)) return false ;  
	if ( checknorm($('idb'),'주민등록번호','',7,7)) return false ; 
	
	if ( checknorm($('email1'),'E-Mail','',50,'')) return false ;  
    if ( checknorm($('email2'),'E-Mail','',40,'')) return false ; 	

	if ($('email2').value.indexOf(".") < 0)
	{
		alert("올바르지 않은 E-Mail 주소입니다. 다시 입력해 주세요.");
		$('email2').value = "";
		$('email2').focus();
		return false ;
	}
	
	if ( checknorm($('tel1'),'전화번호','',4,2)) return false ;
	if ( checknorm($('tel2'),'전화번호',numeric,4,3)) return false ; 
	if ( checknorm($('tel3'),'전화번호',numeric,4,4)) return false ; 
	
	if ( checknorm($('hphone1'),'휴대폰번호','',4,2)) return false ; 
	if ( checknorm($('hphone2'),'휴대폰번호',numeric,4,3)) return false ; 
	if ( checknorm($('hphone3'),'휴대폰번호',numeric,4,4)) return false ; 
	 
	if ( checknorm($('zipcode1'),'우편번호',numeric,3,3)) return false ;  
	if ( checknorm($('zipcode2'),'우편번호',numeric,3,3)) return false ; 
	if ( checknorm($('address'),'주소','',100,'')) return false ; 
	if ( checknorm($('addressadd'),'상세주소','',50,'')) return false ; 

	if(confirm(" 입력하신 정보로 수정 하시겠습니까?"))
	{
		$('email').value = $('email1').value + "@" + $('email2').value;
		$('zipcode').value = $('zipcode1').value + $('zipcode2').value;
		$('tel').value = $('tel1').value + "-" +  $('tel2').value + "-" +  $('tel3').value;
		$('hphone').value = $('hphone1').value + "-" +  $('hphone2').value + "-" +  $('hphone3').value;
		$('mode').value = "mody";
		$('modyForm').submit();
	}
	
	return false ; 	
}

function open_zipcode(item)
{
	window.open("/adminnew/member/pop_zipnum.php?item="+item, "zipcode", "width=427,height=320,scrollbars=yes,resizable=yes,status=1");
}


function open_zipnum(item)
{
	window.open("/popup/pop_zipnum.php?item="+item, "zipcode", "width=427,height=320,scrollbars=yes,resizable=yes,status=1");
}

function check_bizno()
{
	var chkRule = "137137135";
	var ThisVal1=$('check_bizno1').value;
	var ThisVal2=$('check_bizno2').value;
	var ThisVal3=$('check_bizno3').value;

	var strCorpNum = ThisVal1 + ThisVal2 + ThisVal3;
	var step1, step2, step3, step4, step5, step6, step7;

	step1 = 0;

	for (i=0; i<7; i++)
	{
		step1 = step1 + (strCorpNum.substring(i, i+1) *chkRule.substring(i, i+1));
	}

	step2 = step1 % 10;
	step3 = (strCorpNum.substring(7, 8) * chkRule.substring(7, 8))% 10;
	step4 = strCorpNum.substring(8, 9) * chkRule.substring(8, 9);
	step5 = Math.round(step4 / 10 - 0.5);
	step6 = step4 - (step5 * 10);
	step7 = (10 - ((step2 + step3 + step5 + step6) % 10)) % 10;

	if (strCorpNum.substring(9, 10) != step7) 
	{
		alert("사업자 등록 번호에 이상이 있습니다.\n\n확인하시고 다시 입력해 주세요. ")
		$('check_bizno1').value = "";
		$('check_bizno2').value = "";
		$('check_bizno3').value = "";
		$('check_bizno1').focus();
		return false;
	}
	return true;
}

function smCheckSpecial(target,cmt)
{
	var special = "`%^&{}|=<>?#'$\\\";:";
	var i; 
	var t =target.value; 	
	if (special .length >= 1) 
	{
		for (i=0; i<t.length; i++)
		{
			if(special .indexOf(t.substring(i,i+1)) >= 0)
			{
				alert(cmt + "에 [~()_-*@!'+/]외의 특수문자는 사용불가 합니다. ");					
				target.focus()
				return false;
			}
		}
	}
	return true;
}

function check_mininame()
{
	if ( $('title').value == "" )
	{
		alert("미니샵이름을 입력해주세요.");
		return;
	}	
	
	var tmp_post = "title="+$('title').value;
	new ajax.xhr.Request("/common/inc/member/check_mininame.php", tmp_post , check_mininameok, 'POST');	
}

function check_mininameok(xmlDoc)
{
	var code = getNodeValue( xmlDoc.getElementsByTagName( 'code' ) );

	if (code == 'success') 
	{
		$('msg').innerHTML = getNodeValue(xmlDoc.getElementsByTagName( 'message' ) );
		$('used').style.display = "";
	}		
	else if (code == 'error') 
	{
		$('msg').innerHTML = getNodeValue(xmlDoc.getElementsByTagName( 'message' ) );
	}
}

function check_muid()
{
	checkid($('muid'),'')
	
	var tmp_post = "muid="+$('muid').value;
	new ajax.xhr.Request("/common/inc/member/check_muid.php", tmp_post , check_muidok, 'POST');	
}

function check_muidok(xmlDoc)
{
	var code = getNodeValue( xmlDoc.getElementsByTagName( 'code' ) );

	if (code == 'success') 
	{
		$('msg').innerHTML = getNodeValue(xmlDoc.getElementsByTagName( 'message' ) );
		$('used').style.display = "";
	}		
	else if (code == 'error') 
	{
		$('msg').innerHTML = getNodeValue(xmlDoc.getElementsByTagName( 'message' ) );
	}
}

function pop_muid()
{
	
	if ( checkid($('muid'),'회원 아이디(ID)') == false )
	{
		return;
	}
	else
	{
		window.open('/popup/pop_muid.php?muid='+$('muid').value,'','toolbar=no, width=415, height=220, top=10, left=10, scrollbars=no, resizable=no');	
	}
}

function pop_minishop()
{
	window.open('/popup/pop_minishopname.php?title='+$('title').value,'','toolbar=no, width=415, height=200, top=10, left=10, scrollbars=yes, resizable=no');	
}
