var searchId = "";
$(document).ready(function() {
	$("#nameForm").validn()
	.validnAdd("name", "required", "이름을 입력하세요")
	.validnAdd("juminNo1", "required; number; len(6)", "주민등록번호를 정확히 입력하세요.")
	.validnAdd("juminNo2", "required; number; len(7)", "주민등록번호를 정확히 입력하세요.")
	;

	$("input[name=authType]").click(function() {
		if ( "N" == this.value ) {
			$(".personNumberObj").show();
			$(".ipinObj").hide();
		} else {
			$(".ipinObj").show();
			$(".personNumberObj").hide();
		}
	});
	$(".findPwButton").click(function() { location.href = "/service/findPw.do?id=" + searchId; return false; });
	$(".loginButton").click(function() { location.href = "/login/loginForm.do?id=" + searchId; });
	$(".nameCheckButton").click(nameFormCheck);
	$(".ipinCheckButton").click(function() {
		goIpinCheck();
		return false;
	});
	$("input[name=juminNo1]").keyup(function() {
		if ( this.value.length==6) {
			try { $("input[name=juminNo2]").focus(); } catch(e) {}
		}
	});
	$("input[name=juminNo2]").keypress(function(evt) {
		if ( evt.keyCode == 13 ) nameFormCheck();
	});
});
function nameFormCheck() {
	if ( $("#nameForm").validnValidate() ) {
		var name = $("#nameForm input[name=name]").val();
		var juminNo = $("#nameForm input[name=juminNo1]").val() + $("#nameForm input[name=juminNo2]").val();
		var sendInfo = makeSendInfo( name, juminNo, "10", "1" );
		getCheckResultJSON("N", sendInfo);
	}
	return false;
}
function getCheckResultJSON(authType, sendInfo) {
	jQuery.getJSON("/service/findIdResultJSON.do", { authType:authType, sendInfo:sendInfo }, function(data) {
		searchId = data.id;
		var msg = data.msg;
		if ( searchId && searchId!="" ) {
			$(".searchedIdSpan").html(searchId);
			$(".checkResultObj").show();
		} else {
			$(".checkResultObj").hide();
			searchId = "";
			showDialogEffect(msg);
		}
	});
}
function goIpinCheck() {
	if ( strNiceId == "" ) { showDialogEffect( getCheckMessage( "S60" ) ); return false;
	} else if ( strPingInfo == "" ) { showDialogEffect( getCheckMessage( "S61" ) ); return false;
	} else if ( strReturnUrl == "" ) { showDialogEffect( getCheckMessage( "S64" ) ); return false;
	}

	document.reqForm.SendInfo.value = makeCertKeyInfoPA( strNiceId, strPingInfo, strOrderNo, strInqRsn, strReturnUrl, strSIKey );
	document.reqForm.ProcessType.value = strPersonalCertKey;
	var popupWindow = window.open( "", "popupCertKey", "top=100, left=200, status=0, width=417, height=490" );
	document.reqForm.target = "popupCertKey";
	document.reqForm.action = strCertKeyServiceUrl;
	document.reqForm.submit();
	popupWindow.focus();
}
function callbackIpin(si) {
	getCheckResultJSON("I", si);
}

