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

if (!$is_member) {
    goto_url(G5_BBS_URL.'/login.php?url='.urlencode(G5_URL.'/shoppoint/orderform4withdraw.php'));
}

// add_javascript('js 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
// add_javascript(G5_POSTCODE_JS, 0);    //다음 주소 js

$sw_direct = preg_replace('/[^a-z0-9_]/i', '', $sw_direct);

// 모바일 주문인지
$is_mobile_order = is_mobile();

set_session("ss_direct", $sw_direct);

// microtime() 함수를 사용하여 현재 시간의 마이크로초까지 구함
list($microseconds, $seconds) = explode(" ", microtime());
$microseconds = (int)($microseconds * 1000);
$microseconds = str_pad($microseconds, 3, '0', STR_PAD_LEFT); // 마이크로 초 4자리만 사용

$od_id = get_uniqid();
set_session('ss_order_id', $od_id . $microseconds);

$s_cart_id = $tmp_cart_id;
if($default['de_pg_service'] == 'inicis' || $default['de_inicis_lpay_use'])
    set_session('ss_order_inicis_id', $od_id);

$g5['title'] = "포인트 출금신청 Withdrawal Points";

$goods = "포인트 출금";

if(G5_IS_MOBILE)
    // include_once(G5_MSHOP_PATH.'/_head.php');
    include_once(G5_SHOP_PATH.'/_head.php');
else
    include_once(G5_SHOP_PATH.'/_head.php');

// 희망배송일 지정
if ($default['de_hope_date_use']) {
    include_once(G5_PLUGIN_PATH.'/jquery-ui/datepicker.php');
}

// 기기별 주문폼 include
if($is_mobile_order) {
    $order_action_url = G5_URL.'/shoppoint/orderformupdate4withdraw.php';
    require_once(G5_PATH.'/shoppoint/orderform.sub4withdraw.php');
} else {
    $order_action_url = G5_URL.'/shoppoint/orderformupdate4withdraw.php';
    require_once(G5_PATH.'/shoppoint/orderform.sub4withdraw.php');
}

?>
<script>
(function(){
    var targetSelectors = [
        '#point_charge_select',
        'input[name="point_charge_select"]',
        'input.ct_pricing_count',
        'input[name^="ct_pricing_count["]'
    ];

    function isVisible(el) {
        if (!el || el.disabled || el.readOnly) {
            return false;
        }
        var rect = el.getBoundingClientRect();
        if (rect.width <= 0 || rect.height <= 0) {
            return false;
        }
        try {
            var s = window.getComputedStyle(el);
            if (!s || s.display === 'none' || s.visibility === 'hidden') {
                return false;
            }
        } catch (e) {}
        return true;
    }

    function isTarget(el) {
        if (!el || el.tagName !== 'INPUT') {
            return false;
        }
        for (var i = 0; i < targetSelectors.length; i++) {
            try {
                if (el.matches(targetSelectors[i])) {
                    return true;
                }
            } catch (e) {}
        }
        var key = ((el.id || '') + ' ' + (el.name || '') + ' ' + (el.className || '') + ' ' + (el.placeholder || '')).toLowerCase();
        return key.indexOf('point') >= 0 || key.indexOf('charge') >= 0 || key.indexOf('pricing') >= 0 || key.indexOf('포인트') >= 0 || key.indexOf('충전') >= 0 || key.indexOf('출금') >= 0;
    }

    function forceNumeric(el) {
        el.setAttribute('inputmode', 'numeric');
        el.setAttribute('pattern', '[0-9]*');
        el.setAttribute('enterkeyhint', 'done');
        if ((el.type || '').toLowerCase() === 'text') {
            try { el.type = 'tel'; } catch (e) { el.setAttribute('type', 'tel'); }
        }
    }

    function keepVisible(el) {
        if (!isVisible(el)) return;
        try {
            el.scrollIntoView({behavior:'smooth', block:'center', inline:'nearest'});
        } catch (e) {
            try { el.scrollIntoView(true); } catch (e2) {}
        }
    }

    function bind(el) {
        if (!isTarget(el) || !isVisible(el)) {
            return;
        }
        if (el.dataset && el.dataset.vpnlinkNumericBound === '1') {
            return;
        }
        forceNumeric(el);
        el.addEventListener('focus', function(){ forceNumeric(el); keepVisible(el); }, true);
        el.addEventListener('click', function(){ forceNumeric(el); keepVisible(el); }, true);
        el.addEventListener('touchstart', function(){ forceNumeric(el); }, {passive:true});
        el.addEventListener('input', function(){ el.value = String(el.value || '').replace(/[^0-9]/g, ''); }, true);
        if (el.dataset) {
            el.dataset.vpnlinkNumericBound = '1';
        }
    }

    function applyAll() {
        var inputs = document.querySelectorAll('input');
        for (var i = 0; i < inputs.length; i++) {
            bind(inputs[i]);
        }
    }

    document.addEventListener('focusin', function(e){
        var t = e && e.target;
        if (isTarget(t)) {
            forceNumeric(t);
        }
    }, true);

    if (window.visualViewport && !window.__vpnlinkPointViewportBound) {
        window.__vpnlinkPointViewportBound = true;
        var viewportHandler = function() {
            var active = document.activeElement;
            if (active && isTarget(active)) {
                keepVisible(active);
            }
        };
        window.visualViewport.addEventListener('resize', viewportHandler);
    }

    applyAll();
    setTimeout(function(){ if(typeof vpnUpdateFeePreview === "function") vpnUpdateFeePreview(); }, 300);

    if (window.MutationObserver && !window.__vpnlinkPointInputObserver) {
        window.__vpnlinkPointInputObserver = new MutationObserver(function(){ applyAll(); });
        window.__vpnlinkPointInputObserver.observe(document.body, {childList:true, subtree:true});
        setTimeout(function(){
            try {
                if (window.__vpnlinkPointInputObserver) {
                    window.__vpnlinkPointInputObserver.disconnect();
                    window.__vpnlinkPointInputObserver = null;
                }
            } catch (e) {}
        }, 10000);
    }
})();
</script>
<?php

if(G5_IS_MOBILE) {
    // include_once(G5_MSHOP_PATH.'/_tail.php');
    include_once(G5_SHOP_PATH.'/_tail.php');
} else {
    include_once(G5_SHOP_PATH.'/_tail.php');
}



?>
