﻿var SSLUrl = "https://login.hidoc.co.kr/KBHealth/";

function SSL() {

    this.Name;
    this.ID;
    this.Regno1;
    this.Regno2;
    this.Password;
    this.PasswordQ;
    this.PasswordA;
    this.NickName;
    this.EmailID;
    this.EmailHost;
    this.IsEmailReceive;
    this.Tel1;
    this.Tel2;
    this.Tel3;
    this.AddressType;
    this.ZipCode;
    this.Address;
    this.DetailAddress;

    this.TargetPath; // 검증에 사용할 파일 URL
    this.ReturnUrl; // SSL 검증 후 돌아올 URL
    this.RedirectUrl; // 인증성공 후 분기 할 URL

    this.Send = function() {

        if (this.TargetPath == null) {
            alert("TargetPath가 지정되지 않았습니다.");
            return;
        }

        if (SSLUrl == null) {
            alert("SSLUrl이 지정되지 않았습니다.");
            return;
        }

        // 보낼폼을 생성
        var sslForm = document.createElement("FORM");

        // 성명
        if (this.Name != null)
            sslForm.appendChild(this.AddSSLFormObject("Name", this.Name));

        // ID
        if (this.ID != null)
            sslForm.appendChild(this.AddSSLFormObject("ID", this.ID));

        // 주민번호1
        if (this.Regno1 != null)
            sslForm.appendChild(this.AddSSLFormObject("Regno1", this.Regno1));

        // 주민번호2
        if (this.Regno2 != null)
            sslForm.appendChild(this.AddSSLFormObject("Regno2", this.Regno2));

        // 비밀번호
        if (this.Password != null)
            sslForm.appendChild(this.AddSSLFormObject("Password", this.Password));

        // 비밀번호질문
        if (this.PasswordQ != null)
            sslForm.appendChild(this.AddSSLFormObject("PasswordQ", this.PasswordQ));

        // 비밀번호답변
        if (this.PasswordA != null)
            sslForm.appendChild(this.AddSSLFormObject("PasswordA", this.PasswordA));

        // 닉네임
        if (this.NickName != null)
            sslForm.appendChild(this.AddSSLFormObject("NickName", this.NickName));

        // 이메일ID
        if (this.EmailID != null)
            sslForm.appendChild(this.AddSSLFormObject("EmailID", this.EmailID));

        // 이메일HOST
        if (this.EmailHost != null)
            sslForm.appendChild(this.AddSSLFormObject("EmailHost", this.EmailHost));
        // 소식지
        if (this.IsEmailReceive != null)
            sslForm.appendChild(this.AddSSLFormObject("IsEmailReceive", this.IsEmailReceive));            

        // 전화번호1
        if (this.Tel1 != null)
            sslForm.appendChild(this.AddSSLFormObject("Tel1", this.Tel1));

        // 전화번호2
        if (this.Tel2 != null)
            sslForm.appendChild(this.AddSSLFormObject("Tel2", this.Tel2));

        // 전화번호3
        if (this.Tel3 != null)
            sslForm.appendChild(this.AddSSLFormObject("Tel3", this.Tel3));

        // 주소타입
        if (this.AddressType != null)
            sslForm.appendChild(this.AddSSLFormObject("AddressType", this.AddressType));

        // 우편번호
        if (this.ZipCode != null)
            sslForm.appendChild(this.AddSSLFormObject("ZipCode", this.ZipCode));

        // 주소
        if (this.Address != null)
            sslForm.appendChild(this.AddSSLFormObject("Address", this.Address));

        // 상세주소
        if (this.DetailAddress != null)
            sslForm.appendChild(this.AddSSLFormObject("DetailAddress", this.DetailAddress));

        // 돌아올 페이지의 URL
        if (this.ReturnUrl == null)
            sslForm.appendChild(this.AddSSLFormObject("ReturnUrl", location.href));
        else
            sslForm.appendChild(this.AddSSLFormObject("ReturnUrl", "http://" + location.host + "/" + this.ReturnUrl));

        // 인증 후 돌아올 페이지
        if (this.RedirectUrl != null)
            sslForm.appendChild(this.AddSSLFormObject("RedirectUrl", this.RedirectUrl));
        else
            sslForm.appendChild(this.AddSSLFormObject("RedirectUrl", "/"));


        // 폼을 전송
        sslForm.setAttribute("action", SSLUrl + this.TargetPath);
        sslForm.setAttribute("method", "post");
        sslForm.setAttribute("id", "sslForm");

        $("body").append(sslForm);

        sslForm.submit();

        return false;
    }

    // 폼의 내용을 생성
    this.AddSSLFormObject = function(name, value) {

        var sslParam = document.createElement("INPUT");

        sslParam.type = "hidden";
        sslParam.name = name;
        sslParam.value = value;

        return sslParam;
    }

}

//-기본정보-
// 성명
//아이디
//주민번호1,주민번호2
//비밀번호
//비밀번호 힌트
//비밀번호 힌트답
//닉네임
//이메일ID, 이메일Host
//이메일수신여부
//연락처1,연락처2,연락처3
//주소구분 
//우편번호
//주소, 상세주소
// 
//-부가정보-
//결혼기념일
// 
//엄마이름
//마지막생리일
//출산일/예정일
//자녀수
// 
//아이이름
//아이생년월일
//아이성별

