<?php
include_once('./_common.php');

check_device('both');

if( $is_guest ) {
    alert("로그인 후 이용가능합니다.", G5_BBS_URL.'/login.php?url='.urlencode(LOTTO_URL.'/my_request_form.php'));
}

$my_cash = $member['mb_cash'] - $config['cf_3'];
if( $my_cash >= $config['cf_4'] ) {
    $valid_cash = $my_cash;
} else {
    $valid_cash = 0;
}

$cancel_href = LOTTO_URL.'/my_request.php'.($qstr ? '?'.preg_replace('/^&amp;/i', '', $qstr) : '');
$action_url = LOTTO_URL.'/my_request_form_update.php';

$g5['title'] = "캐시출금신청";

$tmenu_ = '마이로또';

include_once(G5_PATH.'/_head.php');

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.LOTTO_CSS_URL.'/lotto.css?ver='.G5_SERVER_TIME.'">', 0);
add_stylesheet('<link rel="stylesheet" href="'.LOTTO_CSS_URL.'/board.css?ver='.G5_SERVER_TIME.'">', 0);
?>
<!-- 캐시지급신청 시작 { -->
<section id="bo_w">
    <h2 class="sound_only"><?php echo $g5['title'] ?></h2>

    <form name="fmyaskform" id="fmyaskform" action="<?php echo $action_url ?>" onsubmit="return fmyaskform_submit(this);" method="post" autocomplete="off">
    <input type="hidden" name="page" value="<?php echo $page ?>">

    <div class="bo_w_info write_div">
        <div class="write_cell">
            <label>보유캐시</label>
            <div class="frm_input_text">$ <?php echo number_format($member['mb_cash']) ?></div>
        </div>
        <div class="write_cell">
            <label>이체수수료</label>
            <div id="transfer_fee" class="frm_input_text">$ <?php echo number_format($config['cf_3']) ?></div>
        </div>
        <div class="write_cell">
            <label>출금가능금액</label>
            <div class="frm_input_text">$ <?php echo number_format($valid_cash) ?></div>
        </div>
    </div>

    <div class="bo_w_info write_div">
        <div class="write_cell width_half">
            <label for="cr_content">신청내용<strong class="sound_only">필수</strong></label>
            <input type="text" name="cr_content" id="cr_content"  value="출금신청" class="frm_input width_full required" placeholder="" title="신청내용" maxlength="50" required />
        </div>
        <div class="write_cell width_half">
            <label for="cr_cash">신청금액<strong class="sound_only">필수</strong></label>
            <input type="text" name="cr_cash" id="cr_cash"  value="" class="frm_input width_full numeric required" placeholder="" title="신청금액" maxlength="20" required />
            <?php if( $config['cf_4'] > 0 ) { ?><small>($ <strong class="text-red"><?php echo number_format($config['cf_4']) ?></strong> 이상부터 신청가능합니다.)</small><?php } ?>
        </div>
    </div>

    <div class="bo_w_text write_div">
        <label>※ <strong><a href="<?php echo G5_BBS_URL ?>/member_confirm.php?url=<?php echo urlencode(G5_BBS_URL.'/register_form.php') ?>">[계좌등록하기]</a></strong> <u> 에서 계좌등록하시면 자동 노출됩니다.</u></label>
    </div>

    <div class="bo_w_info write_div">
        <label for="cr_en_name">영문이름<strong class="sound_only">필수</strong></label>
        <input type="text" name="cr_en_name" id="cr_en_name"  value="<?php echo $member['mb_6'] ?>" class="frm_input width_full required" placeholder="" title="영문이름" maxlength="20" required />
    </div>
    <div class="bo_w_info write_div">
        <label for="cr_bank">은행명<strong class="sound_only">필수</strong></label>
        <input type="text" name="cr_bank" id="cr_bank"  value="<?php echo $member['mb_3'] ?>" class="frm_input width_full required" placeholder="" title="은행명" maxlength="20" required />
    </div>
    <div class="bo_w_info write_div">
        <label for="cr_account">계좌번호<strong class="sound_only">필수</strong></label>
        <input type="text" name="cr_account" id="cr_account"  value="<?php echo $member['mb_4'] ?>" class="frm_input width_full required" placeholder="" title="계좌번호" maxlength="25" required />
    </div>
    <div class="bo_w_info write_div">
        <label for="cr_name">예금주<strong class="sound_only">필수</strong></label>
        <input type="text" name="cr_name" id="cr_name"  value="<?php echo $member['mb_5'] ?>" class="frm_input width_full required" placeholder="" title="예금주" maxlength="20" required />
    </div>
    <div class="bo_w_info write_div">
        <label for="cr_hp">휴대폰번호<strong class="sound_only">필수</strong></label>
        <input type="text" name="cr_hp" id="cr_hp"  value="<?php echo $member['mb_hp'] ?>" class="frm_input width_full required" placeholder="" title="휴대폰번호" maxlength="20" required />
    </div>
    <div class="bo_w_text write_div">
        <input type="checkbox" name="member_update" id="member_update"  value="Y" class="" title="회원정보에 반영" />
        <label for="member_update" class="display-inline-block ml-4">회원정보에 반영합니다.</label>
    </div>

    <div class="btn_confirm write_div">
        <a href="<?php echo $cancel_href ?>" class="btn_cancel btn">취소</a>
        <input type="submit" value="작성완료" id="btn_submit" accesskey="s" class="btn_submit btn">
    </div>
    </form>

    <script>
    function fmyaskform_submit(f) {
        if( f.cr_cash.value == 0 ) {
            alert('신청금액을 잘못 입력하였습니다.');
            f.cr_cash.focus();
            f.cr_cash.select();
            return false;
        }

        if( f.cr_cash.value > parseInt("<?php echo $my_cash ?>") ) {
            alert('출금가능금액을 초과할 수 없습니다.');
            f.cr_cash.focus();
            f.cr_cash.select();
            return false;
        }

        <?php if( $config['cf_4'] > 0 ) { ?>
        if( f.cr_cash.value < parseInt("<?php echo $config['cf_4'] ?>") ) {
            alert('출금신청금액은 최소 $ <?php echo number_format($config['cf_4']) ?>이상가능합니다.');
            f.cr_cash.focus();
            f.cr_cash.select();
            return false;
        }
        <?php } ?>

        var fee = document.getElementById('transfer_fee').innerText;
        var cash = f.cr_cash.value;
        var amount = cash * 1 + fee.replace(/[^0-9]/g, '') * 1;
        if( !confirm( "$ " + number_format(amount) + "를 출금신청 하시겠습니까?\n(이체수수료 $ <?php echo number_format($config['cf_3']) ?> 포함)") ) {
            return false;
        }

        document.getElementById("btn_submit").disabled = "disabled";

        return true;
    }
    </script>
</section>
<!-- 캐시지급신청 끝 { -->

<?php
include_once(G5_PATH.'/_tail.php');