/**
 *  개인회원 디스플레이
 */
function setPersonal(sFlag)
{
    try {
        document.getElementById('dPersonalSSN').style.display = sFlag;
    } catch(e) {
    }
}

/**
 *  개인사업자 디스플래이
 */
function setCompPersonal(sFlag)
{
    try {
        document.getElementById('dCompNo').style.display = sFlag;
    } catch(e) {
    }
}
/**
 *  법인회원 디스플래이
 */
function setComp(sFlag)
{
    try {
        document.getElementById('dCorporationNo').style.display = sFlag;
    } catch(e) {
    }
}

/**
 *  외국인회원 디스플래이
 */
function setForeigner(sFlag)
{
    try {
        document.getElementById('dForeignerFrgNo').style.display = sFlag;
    } catch(e) {
    }
}
/**
 * 아이핀 디스플레이
 */
function setIpinAuth(sFlag)
{
    try {
        document.getElementById('IpinAuth').style.display = sFlag;
    } catch(e) {
    }
}

/**
 * 디스플래이
 */
function setIdDisplay(sValue)
{
      try {
        if (sValue == 'P') {
            setPersonal('');
            setCompPersonal('none');
            setComp('none');
            setForeigner('none');
            setIpinAuth('');
        }
        if (sValue == 'B') {
            setPersonal('none');
            setCompPersonal('');
            setComp('none');
            setForeigner('none');
            setIpinAuth('none');
        }
        if (sValue == 'BP') {
            setPersonal('none');
            setCompPersonal('');
            setComp('none');
            setForeigner('none');
            setIpinAuth('');
        }
        if (sValue == 'F') {
            setPersonal('none');
            setCompPersonal('none');
            setComp('none');
            setForeigner('');
            setIpinAuth('');
        }
      } catch(e) {
      }
}

/**
 *  폼체킹
 */
function idFindFormCheck()
{
    frm = document.idFindForm;


    if (frm.name.value == '') {
        alert('이름을 입력하세요');
        frm.name.focus();
        return false;
    }

    var aMatching = new Array ();
    aMatching[0] = Array( 'ssn1','ssn2');
    aMatching[1] = Array( 'u_comp_reg_no1','u_comp_reg_no2','u_comp_reg_no3');
    aMatching[2] = Array( 'u_corporation1','u_corporation2');
    aMatching[3] = Array( 'sForeignValue');
    aMatching[4] = Array( 'email');
    aMatching[5] = Array( 'ipin_key');

    /*
    for (i = 0; i < frm.is_check.length; i++) {
        if (frm.is_check[i].checked  === true) {
            for (j = 0; j < aMatching[i].length; j++) {
                if (document.getElementById(aMatching[i][j]).value == '') {
                    alert('선택한 값을 입력해주세요.');
                    document.getElementById(aMatching[i][j]).focus();
                    return false;
                }
            }

        }
    }
    */


    // 파라미터 암호화 인코딩
	AuthSSLManager.weave({
		'auth_mode': 'encrypt'
		, 'aEleId': ['u_mem_type','name','ssn1','ssn2','u_comp_reg_no1','u_comp_reg_no2','u_comp_reg_no3','u_corporation1','u_corporation2','sForeignKey','sForeignValue','is_check','email','ipin_key']
		, 'auth_callbackName': 'encryptSubmit_Complete'
	});

    return false;

}

/**
 * callback
 * @param String output
 */
function encryptSubmit_Complete(output) {

	if( AuthSSLManager.isError(output) == true ) {
		alert('재시도해 주시기 바랍니다.');
		return false;
	}else{
		  var formObject = document.createElement("form");
		   formObject.setAttribute("method","post");
		   formObject.action = "/front/php/lost_id/lost_id_a.php";
		   document.appendChild(formObject);

		   var frm = document.idFindForm;
		   var buyIdObject = document.createElement("input");
		   buyIdObject.setAttribute("type","hidden");
		   buyIdObject.setAttribute("name", "encriptStr" );
		   buyIdObject.setAttribute("value", output);
		   formObject.appendChild(buyIdObject);
		   formObject.submit();
		   return false;
	}
}

/**
 * 아이핀 팝업 호출 함수
 * 공통으로 쓰입니다. c_3, c_4
 */
function IpinPopup()
{
    var sOriAction = document.idFindForm.action;
    var sOriTarget = document.idFindForm.target;
    window.open('', 'popupIpin','width=448, height=500');
    document.idFindForm.target = "popupIpin";
    document.idFindForm.action = "https://i-pin.cafe24.com/ipin/?cont=callIpinPopup&cpKey=I0001";
    document.idFindForm.submit();

    document.idFindForm.target = sOriTarget;
    document.idFindForm.action = sOriAction;
}

/**
 * 아이디찾기::new 아이디찾기(c_4) 에서 쓰이는 함수 입니다.
 */
function FindIdFormInit()
{
    document.getElementById('trEmailRow').style.display = 'none';
    document.getElementById('MemAuthTypeR').checked = true;
    if(document.getElementById('trIpinRow')) {
        document.getElementById('trIpinRow').style.display = 'none';
    }
    setDispCheck();
}
function setDispCheck(sReq) {
    try {
        if(document.getElementById('trIpinRow')) {
            document.getElementById('trIpinRow').style.display = 'none';
        }
        document.getElementById('trMemNameRow').style.display = 'none';
        document.getElementById('trEmailRow').style.display = 'none';
        document.getElementById('trMemKeyRow').style.display = 'none';
        var AuthType = document.getElementById('is_check');
        if(sReq == 'I') {
            document.getElementById('trIpinRow').style.display = '';
            AuthType.value = '6';
        } else if(sReq == 'E') {
            document.getElementById('trMemNameRow').style.display = '';
            document.getElementById('trEmailRow').style.display = '';
            AuthType.value = '2';
        } else {
            document.getElementById('trMemNameRow').style.display = '';
            document.getElementById('trMemKeyRow').style.display = '';
            AuthType.value = '7';
        }
    } catch(e) {
        alert(e);
    }
}
function FindIdFormCheck()
{
    var oForm = document.getElementById('idFindForm');
    var sAuthType = getAuthType();
    if(!document.getElementById('name').value) {
        alert("이름 또는 법인명을 입력해주세요.");
        document.getElementById('name').focus();
        return false;
    }
    if(sAuthType == "I") {
        if(!document.getElementById('ipin_key').value) {
            alert("아이핀을 통해 본인 인증을 해주세요.");
            return false;
        }
    } else if(sAuthType == "E") {
        if(!document.getElementById('email').value) {
            document.getElementById('email').focus();
            alert("이메일 주소를 입력해주세요.");
            return false;
        }
    } else {
        if(!document.getElementById('MemKey').value) {
            document.getElementById('MemKey').focus();
            alert("주민등록번호 또는 법인번호를 입력해주세요.");
            return false;
        }
    }
    oForm.submit();
}
function getAuthType()
{
    var oTarget = document.getElementsByName('MemAuthType');
    for(var i = 0 ; i < oTarget.length ; i ++) {
        if(oTarget[i].checked === true) {
            var sReturn = oTarget[i].value;
        }
    }               
    return sReturn;
}

function encryptSubmit(frm) {

    if (frm.name.value == '') {
        alert('이름을 입력하세요!');
        frm.name.focus();
        return false;
    }

    // 파라미터 암호화 인코딩
	AuthSSLManager.weave({
		'auth_mode': 'encrypt'
		, 'aEleId': ['u_mem_type','name','ssn1','ssn2','u_comp_reg_no1','u_comp_reg_no2','u_comp_reg_no3','u_corporation1','u_corporation2','sForeignKey','sForeignValue','is_check','email','ipin_key']
		, 'auth_callbackName': 'encryptSubmit_Complete'
	});

    return false;

}

/**
 *  아이디/비밀번호찾기 submit 폼체크
 *  2010-06-21 jykim
 */
function getTargetForm(sAction)
{
    var oAllForm = document.getElementsByTagName('form');
    var iLen = oAllForm.length;
    for (var i = 0; i < iLen; i++) {
        if (oAllForm[i].action == sAction) {
            return oAllForm[i];
        }
    }
}


/**
 *  아이디/비밀번호 찾기 form 설정
 *  2010-06-18 jykim
 */
var _iCntTrySubmitEvt = 0;
function initOnSubmitEvt(sActionUrl)
{
    try {
        document.getElementsByName('ssn[]')[0].id = "ssn1";
        document.getElementsByName('ssn[]')[1].id = "ssn2";
        oForm = getTargetForm(sActionUrl);
        oForm.onsubmit = function () {
            encryptSubmit(oForm);
            return false;
        }
    } catch (e) {
        if (_iCntTrySubmitEvt < 100) {
            setTimeout('initOnSubmitEvt("/Front/Member/?url=FindidDao")', 500);
        }
        _iCntTrySubmitEvt++;
    }
}

initOnSubmitEvt("/Front/Member/?url=FindidDao");
