<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

require_once(G5_PATH.'/mylib/rpc_grade.lib.php');

$_rpc_it_grade = strtoupper(trim((string)(isset($it['it_spec_grade']) ? $it['it_spec_grade'] : '')));
if ($_rpc_it_grade === '') {
    $_rpc_it_grade = rpc_ensure_grade(
        $it_id,
        '',
        isset($it['it_spec_cpu']) ? $it['it_spec_cpu'] : '',
        isset($it['it_spec_ram']) ? $it['it_spec_ram'] : '',
        isset($it['it_spec_ssd']) ? $it['it_spec_ssd'] : '',
        isset($it['it_spec_hdd']) ? $it['it_spec_hdd'] : ''
    );
}
$_rpc_it_ca_id = isset($it['ca_id']) ? $it['ca_id'] : (isset($ca_id) ? $ca_id : '10');

// 관련상품 전체 추출을 위해서 재세팅함
$rmods = 100;
$rrows = 1;

// 버튼컬러
$btn1 = (isset($wset['btn1']) && $wset['btn1']) ? $wset['btn1'] : 'black';
$btn2 = (isset($wset['btn2']) && $wset['btn2']) ? $wset['btn2'] : 'color';

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
$item_skin_css_ver = @filemtime($item_skin_path.'/style.css');
add_stylesheet('<link rel="stylesheet" href="'.$item_skin_url.'/style.css?v='.$item_skin_css_ver.'" media="screen">', 0);

if($is_orderable) echo '<script src="'.$item_skin_url.'/shop.js"></script>'.PHP_EOL;

// 이미지처리
$j=0;
$thumbnails = array();
$item_image = '';
$item_image_href = '';
for($i=1; $i<=10; $i++) {
	if(!$it['it_img'.$i])
		continue;

	$thumb = get_it_thumbnail($it['it_img'.$i], 60, 60);

	if($thumb) {
		$org_url = G5_DATA_URL.'/item/'.$it['it_img'.$i];
		$img = apms_thumbnail($org_url, 600, 600, false, true);
		$thumb_url = ($img['src']) ? $img['src'] : $org_url;
		if($j == 0) {
			$item_image = $thumb_url; // 큰이미지
			$item_image_href = G5_SHOP_URL.'/largeimage.php?it_id='.$it['it_id'].'&amp;ca_id='.$ca_id.'&amp;no='.$i; // 큰이미지 주소
		}
		$thumbnails[$j] = '<a data-href="'.G5_SHOP_URL.'/largeimage.php?it_id='.$it['it_id'].'&amp;ca_id='.$ca_id.'&amp;no='.$i.'" data-ref="'.$thumb_url.'" class="thumb_item_image">'.$thumb.'<span class="sound_only"> '.$i.'번째 이미지 새창</span></a>';
		$j++;
	}
}

// 카운팅
$it_comment_cnt = ($it['pt_comment'] > 0) ? ' <b class="orangered en">'.number_format($it['pt_comment']).'</b>' : '';
$it_use_cnt = ($item_use_count > 0) ? ' <b class="orangered en">'.number_format($item_use_count).'</b>' : '';
$it_qa_cnt = ($item_qa_count > 0) ? ' <b class="orangered en">'.number_format($item_qa_count).'</b>' : '';

// 판매자
$is_seller = ($it['pt_id'] && $it['pt_id'] != $config['cf_admin']) ? true : false;

?>

<?php if($nav_title) { ?>
	<aside class="item-nav">
		<span class="page-nav pull-right text-muted">
			<i class="fa fa-home"></i> 홈
			<?php
				if($is_nav) {
					$nav_cnt = count($nav);
					for($i=0;$i < $nav_cnt; $i++) {
						$nav[$i]['cnt'] = ($nav[$i]['cnt']) ? '('.number_format($nav[$i]['cnt']).')' : '';
			?>
					>
					<a href="./list.php?ca_id=<?php echo $nav[$i]['ca_id'];?>">
						<span class="text-muted"><?php echo $nav[$i]['name'];?><?php echo $nav[$i]['cnt'];?></span>
					</a>
				<?php } ?>
			<?php } else {
				echo ($page_nav1) ? ' > '.$page_nav1 : '';
				echo ($page_nav2) ? ' > '.$page_nav2 : '';
				echo ($page_nav3) ? ' > '.$page_nav3 : '';
				}
			?>
		</span>
		<h3 class="div-title-underbar">
			<span class="div-title-underbar-bold font-22 border-<?php echo (isset($wset['ncolor']) && $wset['ncolor']) ? $wset['ncolor'] : 'color';?>">
				<?php echo $nav_title;?>
			</span>
		</h3>
	</aside>
<?php } ?>

<?php echo $it_head_html; // 상단 HTML; ?>

<div class="item-head">
	<div class="row">
		<?php
			$row_pt_name = get_member($it['pt_id'], 'mb_nick, seller_manners_temp');
			$seller_nick_raw = isset($row_pt_name['mb_nick']) ? $row_pt_name['mb_nick'] : '';
			if (function_exists('cut_str')) {
				$seller_nick_display = cut_str($seller_nick_raw, 18, '…');
			} else {
				$seller_nick_display = mb_strimwidth($seller_nick_raw, 0, 18, '…', 'UTF-8');
			}
		?>
		<div class="col-sm-6">
			<style>
				.item-head {
					background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
					border: 1px solid #e8edf5;
					border-radius: 16px;
					padding: 18px;
					box-shadow: 0 14px 34px rgba(16, 24, 40, 0.08);
				}
				.item-summary-card {
					background: #fff;
					border: 1px solid #e8edf5;
					border-radius: 14px;
					padding: 16px;
					box-shadow: 0 12px 28px rgba(15, 23, 42, 0.06);
				}
				.item-title-row {
					display: flex;
					align-items: center;
					justify-content: space-between;
					gap: 12px;
					margin-bottom: 8px;
					padding-bottom: 8px;
					border-bottom: 1px solid #edf2f8;
				}
				.item-title-main {
					font-size: 36px;
					line-height: 1.2;
					font-weight: 800;
					color: #101828;
					letter-spacing: -0.4px;
					margin: 0;
					display: flex;
					align-items: center;
					min-height: 0;
				}
				.item-title-meta {
					position: static;
					text-align: right;
					font-size: 12px;
					line-height: 1.3;
					color: #777;
					white-space: nowrap;
					font-weight: 400;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: flex-end;
					gap: 3px;
					margin-left: auto;
				}
				.item-title-meta.page-nav {
					margin-top: 0;
				}
				.item-title-meta b { color:inherit; font-weight:400; }
				.item-title-meta .seller-meta-line {
					display: inline-flex;
					align-items: center;
					gap: 5px;
					max-width: 100%;
				}
				.item-title-meta .manner-temp-line {
					display: inline-flex;
					align-items: center;
					gap: 4px;
				}
				.item-title-meta .seller-nick {
					display: inline-block;
					max-width: 96px;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					vertical-align: middle;
				}
				.item-title-meta .seller-stars,
				.item-title-meta .seller-stars i,
				.item-title-meta .seller-stars .fa {
					font-size: 12px !important;
					line-height: 1;
					vertical-align: middle;
				}
				.modern-item-form .table {
					border: 1px solid #e7ecf3;
					border-radius: 12px;
					overflow: hidden;
					margin-bottom: 16px;
					background: #ffffff;
				}
				.modern-item-form .table > tbody > tr > th {
					width: 34%;
					background: #f6f9fd;
					font-weight: 700;
					color: #475467;
					border-bottom: 1px solid #edf2f7;
					vertical-align: middle;
					padding: 13px 14px;
				}
				.modern-item-form .table > tbody > tr > td {
					border-bottom: 1px solid #edf2f7;
					vertical-align: middle;
					padding: 13px 14px;
					color: #111827;
					font-weight: 500;
				}
				.modern-item-form .item-price-table {
					table-layout: fixed;
				}
				.modern-item-form .item-price-table > tbody > tr > th {
					writing-mode: horizontal-tb !important;
					text-orientation: mixed !important;
					white-space: nowrap;
					word-break: keep-all;
				}
				.modern-item-form .item-price-table > tbody > tr > td {
					word-break: keep-all;
					overflow-wrap: anywhere;
				}
				.modern-item-form .table > tbody > tr:last-child > th,
				.modern-item-form .table > tbody > tr:last-child > td {
					border-bottom: 0;
				}
				.modern-item-form .table > tbody > tr:hover > th,
				.modern-item-form .table > tbody > tr:hover > td {
					background: #fbfdff;
				}
				#item_option .list-group-item {
					border: 1px solid #e7ecf3;
					border-radius: 12px;
					padding: 14px;
					background: #fff;
				}
				#item_option .it_opt_subj {
					white-space: nowrap;
					word-break: keep-all;
					overflow-wrap: normal;
					display: inline-block;
				}
				#io_install_price_disp {
					white-space: nowrap;
					word-break: keep-all;
					overflow-wrap: normal;
					display: inline-block;
				}
				@media (min-width: 768px) {
					#it_sel_option .it_opt_list .row,
					#it_sel_option_hour .it_opt_list .row {
						display: flex;
						align-items: center;
					}
					#it_sel_option .it_opt_list .row > .col-sm-4,
					#it_sel_option .it_opt_list .row > .col-sm-3,
					#it_sel_option .it_opt_list .row > .col-sm-5,
					#it_sel_option_hour .it_opt_list .row > .col-sm-4,
					#it_sel_option_hour .it_opt_list .row > .col-sm-3,
					#it_sel_option_hour .it_opt_list .row > .col-sm-5 {
						float: none;
					}
					#it_sel_option .it_opt_list .col-sm-4 label,
					#it_sel_option .it_opt_list .col-sm-3 label,
					#it_sel_option_hour .it_opt_list .col-sm-4 label,
					#it_sel_option_hour .it_opt_list .col-sm-3 label {
						display: inline-flex;
						align-items: center;
						height: 40px;
						margin: 0;
					}
				}
				#item_option .input-group .form-control {
					height: 40px;
					border-color: #d6dfeb;
					box-shadow: none;
				}
				#item_option .input-group-btn .btn {
					height: 40px;
					border-color: #d6dfeb;
					background: linear-gradient(180deg, #ffffff 0%, #f4f7fb 100%);
					color: #334155;
					transition: all .2s ease;
				}
				#item_option .input-group-btn .btn:hover {
					background: #eef3fa;
				}
				#item_option .it_qty_plus i,
				#item_option .it_qty_minus i {
					font-size: 16px;
				}
				.item-buy-btn li { padding: 4px !important; }
				.item-buy-btn .btn {
					height: 48px;
					line-height: 34px;
					font-weight: 700;
					border-radius: 10px;
					letter-spacing: -0.2px;
					transition: transform .15s ease, box-shadow .15s ease;
				}
				.item-buy-btn .btn:hover { transform: translateY(-1px); }
				.item-buy-btn .btn-black { background: #1f2530; border-color:#1f2530; box-shadow: 0 8px 18px rgba(31, 37, 48, 0.22); color:#fff !important; }
				.item-buy-btn .btn-color {
					background: linear-gradient(135deg, #ff2d55 0%, #ef233c 100%) !important;
					border-color:#ef233c !important;
					box-shadow: 0 10px 22px rgba(239, 35, 60, 0.28);
					color:#ffffff !important;
					text-shadow: 0 1px 1px rgba(0,0,0,0.12);
				}
				.item-buy-btn .btn-color:hover,
				.item-buy-btn .btn-color:focus,
				.item-buy-btn .btn-color:active {
					background: linear-gradient(135deg, #ff2d55 0%, #ef233c 100%) !important;
					border-color:#ef233c !important;
					color:#ffffff !important;
					box-shadow: 0 14px 26px rgba(239, 35, 60, 0.35);
				}
				#item_option h4 {
					margin-top: 16px;
					margin-bottom: 18px;
					font-weight: 700;
					color: #344054;
				}
				#it_tot_price {
					font-size: 34px;
					font-weight: 800;
					color: #0f172a;
					letter-spacing: -0.4px;
				}
				#item-tab .nav-tabs {
					border-bottom: 1px solid #e7ecf3;
					background: #fff;
					border-radius: 12px 12px 0 0;
					overflow: hidden;
				}
				#item-tab .nav-tabs > li > a {
					border: 0;
					border-right: 1px solid #eef2f7;
					color: #4b5563;
					background: #f8fafc;
					padding: 14px 10px;
					font-weight: 700;
				}
				#item-tab .nav-tabs > li:last-child > a { border-right:0; }
				#item-tab .nav-tabs > li.active > a,
				#item-tab .nav-tabs > li.active > a:hover,
				#item-tab .nav-tabs > li.active > a:focus {
					background: #ffffff;
					color: #ef233c;
					box-shadow: inset 0 -3px 0 #ef233c;
				}
				#item-tab .tab-content {
					border: 1px solid #e7ecf3 !important;
					border-top: 0 !important;
					background: #fff;
					padding: 20px !important;
					border-radius: 0 0 12px 12px;
					box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
				}
				.btn-group-justified > .btn {
					height: 46px;
					line-height: 32px;
					font-weight: 700;
					letter-spacing: -0.2px;
				}
				.item-image {
					position: relative;
					display: block;
					width: 100%;
					max-width: 100%;
					border: 1px solid #e5eaf1;
					border-radius: 12px;
					background: #f8fafc;
					overflow: hidden;
				}
				.item-image #item_image {
					opacity: 0.06;
					filter: grayscale(100%) saturate(60%);
				}
				.shadow-line {
					display: none; /* 모바일 모드에서 이미지 아래에 그림자 효과 제거를 위함 */
				}
				.overlay-table {
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					height: 100%;
					display: flex;
					justify-content: center;
					align-items: center;
					pointer-events: none; /* 테이블이 클릭을 차단하지 않도록 설정 */
					padding: 20px;
					border: 0;
					background: rgba(248, 250, 252, 0.96);
					box-shadow: none;
					border-radius: 12px;
					overflow: hidden;
				}
				.overlay-table table {
					border-collapse: collapse;
					width: 100%;
					height: 100%;
					font-size: 14px; /* 우측 정보영역과 동일 체감 크기 */
					font-family: 'Noto Sans KR', sans-serif;
				}
				.overlay-table td {
					text-align: left;
					color: #475467; /* 라벨 색상 */
					font-weight: 700;
					font-size: 14px;
					padding: 9px 10px;
					border-bottom: 1px solid #edf2f7;
					width: 30%;
				}
				.overlay-table th {
					text-align: left;
					color: #111827; /* 값 색상 */
					font-size: 14px;
					padding: 9px 10px;
					border-bottom: 1px solid #edf2f7;
					font-weight: 500;
				}
				.overlay-table tr:last-child td,
				.overlay-table tr:last-child th {
					border-bottom: none;
				}
				.flags-icons {
					display: flex;
					flex-wrap: nowrap;
					align-items: center;
				}
				.spec-inline-icon {
					display: inline-flex;
					align-items: center;
					vertical-align: middle;
					margin-right: 8px;
				}
				.overlay-table .spec-cell-wrap {
					display: flex;
					align-items: center;
					gap: 10px;
					line-height: 1.45;
				}
				.overlay-table .spec-logo-badge {
					width: 38px;
					height: 38px;
					border-radius: 10px;
					background: linear-gradient(180deg, #ffffff 0%, #eef3f9 100%);
					border: 1px solid transparent;
					display: inline-flex;
					align-items: center;
					justify-content: center;
					flex-shrink: 0;
				}
				.overlay-table .spec-logo-badge .os_img2,
				.overlay-table .spec-logo-badge .cpu_logo_img2,
				.overlay-table .spec-logo-badge .gpu_logo_img2,
				.overlay-table .spec-logo-badge .nation_flag_img2 {
					width: 26px;
					height: 26px;
					object-fit: contain;
				}
				.overlay-table .spec-logo-badge .nation_flag_img2 {
					border: 0 !important;
					box-shadow: none !important;
					background: transparent !important;
					border-radius: 0;
				}
				.overlay-table .spec-cell-text {
					color: #172033;
					font-weight: 500;
					word-break: keep-all;
				}

				.flags-icons img {
					max-height: 30px;
					margin-right: 5px;
				}
				.nation_flag_img2 {
					width: 25px;
					height: 17px;
					margin-left: 0px;
					margin-right: 5px;
				}

				@media screen and (max-width: 600px) {
					.modern-item-form .item-price-table > tbody > tr > th {
						width: 88px !important;
						min-width: 88px;
						padding: 10px 8px;
						font-size: 15px;
						line-height: 1.35;
						white-space: nowrap;
						word-break: keep-all;
					}
					.modern-item-form .item-price-table > tbody > tr > td {
						padding: 10px 10px;
						line-height: 1.5;
						word-break: keep-all;
						overflow-wrap: anywhere;
					}
					#io_install_price_disp {
						white-space: normal;
					}
					#it_sel_option .ct_total_hours_inline {
						flex-direction: row;
						flex-wrap: nowrap;
						align-items: stretch;
						gap: 6px;
					}
					#it_sel_option .ct_total_hours_inline .ct_day_select,
					#it_sel_option .ct_total_hours_inline .input-group,
					#it_sel_option .ct_total_hours_inline .ct_hour_select {
						min-width: 0 !important;
					}
					#it_sel_option .ct_total_hours_inline .ct_pricing_unit {
						width: 55% !important;
						max-width: 55% !important;
						flex: 0 0 55% !important;
					}
					#it_sel_option .ct_total_hours_inline .ct_pricing_count_wrap {
						width: calc(45% - 6px) !important;
						max-width: calc(45% - 6px) !important;
						flex: 0 0 calc(45% - 6px) !important;
					}
					.item-head {
						padding: 10px;
						border-radius: 10px;
					}
					.overlay-table {
						padding: 10px;
						border-radius: 8px;
					}
					.overlay-table table {
						font-size: 0.88em;
					}
					.item-summary-card {
						padding: 10px;
						border-radius: 10px;
					}
					.item-title-row {
						display: flex;
						flex-direction: column;
						align-items: flex-start;
						gap: 6px;
						margin-bottom: 8px;
						padding-bottom: 8px;
					}
					.item-title-main {
						font-size: 24px;
					}
					.item-title-meta {
						position: static;
						text-align: left;
						white-space: normal;
						align-items: flex-start;
						margin-top: 4px;
						margin-left: 0;
					}
					.item-title-meta .seller-meta-line {
						display: flex;
						flex-wrap: wrap;
					}
					.item-title-meta .seller-nick {
						max-width: 150px;
					}
					#it_tot_price {
						font-size: 26px;
					}
					.flags-icons img {
						max-height: 30px;
						margin-right: 3px;
					}
					.overlay-table .spec-logo-badge {
						width: 34px;
						height: 34px;
						border-radius: 9px;
					}
					.overlay-table .spec-logo-badge .os_img2,
					.overlay-table .spec-logo-badge .cpu_logo_img2,
					.overlay-table .spec-logo-badge .gpu_logo_img2,
					.overlay-table .spec-logo-badge .nation_flag_img2 {
						width: 22px;
						height: 22px;
					}
					.overlay-table .spec-logo-badge .nation_flag_img2 {
						border: 0 !important;
						box-shadow: none !important;
					}
					.nation_flag_img2 {
						width: 25px;
						height: 17px;
						margin-left: 0px;
						margin-right: 5px;
					}
				}
			</style>

			<div class="item-image">
				<a href="javascript:void(0);" class="popup_item_image" onclick="return false;" style="cursor:default;">
					<img id="item_image" src="<?php echo $item_image;?>" alt="">
				</a>
				<?php if($wset['shadow']) echo apms_shadow($wset['shadow']); //그림자 ?>

				<div class="overlay-table">
					<table>
						<?php
						$ca_id_current = isset($ca_id) ? (string)$ca_id : '';
						$item_ca_id_current = isset($it['ca_id']) ? (string)$it['ca_id'] : '';
						$is_vpn_category = (
							in_array($ca_id_current, ['30', '40'], true)
							|| in_array(substr($ca_id_current, 0, 2), ['30', '40'], true)
							|| in_array(substr($item_ca_id_current, 0, 2), ['30', '40'], true)
						);
						$headers = $is_vpn_category
							? ["IP 할당국가", "VPN프로토콜", "VPN사용환경", "VPN접속정보"]
							: ["IP 할당국가", "OS", "CPU", "GPU", "IP주소", "RAM", "SSD", "HDD", "USB", "Remoter"];
						$rows = [];

						$result_api_data = sql_query("SELECT * FROM {$g5['g5_shop_item_table']} WHERE it_id='{$it_id}' ORDER BY it_id DESC LIMIT 1");
						while($api_data = sql_fetch_array($result_api_data)){
							$it_id = $api_data['it_id'];
							$it_origin_mgr_from_api = $api_data['it_origin_mgr_from_api'];
							$M_storeid = explode("Ž",$api_data['it_origin_mgr_from_api'])[0]." ".explode("Ž",$api_data['it_origin_mgr_from_api'])[1];
							$M_storename = explode("Ž",$api_data['it_origin_mgr_from_api'])[2];

							// JSON 데이터
							$jsonData_it_spec_remote_sw = $api_data['it_spec_remote_sw'];

							// JSON 데이터를 배열로 디코드
							$dataArray_it_spec_remote_sw = json_decode($jsonData_it_spec_remote_sw, true);

							// RemoteIP 값을 추출하여 $extIP 변수에 저장
							$extIP = isset($dataArray_it_spec_remote_sw[0]['RemoteIP__0']) ? $dataArray_it_spec_remote_sw[0]['RemoteIP__0'] : null;
							$remote_ip_org = explode(" ", $extIP)[0];
							$remote_ip_parts = explode(".", $remote_ip_org); // IP 주소를 점(.)으로 분리

							// 각 부분을 3자리로 맞추기 위해 앞에 0을 추가
							foreach ($remote_ip_parts as &$part) {
								$part = str_pad($part, 3, '0', STR_PAD_LEFT);
							}
							// 마스킹할 부분을 선택
							$remote_ip_parts[1] = '***';
							$remote_ip_parts[3] = '***';
							// 마스킹된 IP 주소를 다시 조합
							$masked_ip = implode(".", $remote_ip_parts);
							$remote_ip = $masked_ip; // 출력: 111.***.022.***

							$remote_ip_country_code = strtolower($dataArray_it_spec_remote_sw[0]['RemoteIP_CountryCode__0']);
							$remote_ip_country_name = $dataArray_it_spec_remote_sw[0]['RemoteIP_CountryName__0'];
							$remote_ip_city_name = $dataArray_it_spec_remote_sw[0]['RemoteIP_City__0'];
							$remote_ip_country_flag = "<img src='" . G5_DATA_URL . "/item/img_nation_flag/svg/{$remote_ip_country_code}.svg' class='nation_flag_img2'>";

							$it_spec_remote_sw_arr = [];
							for ($i_sw = 0; $i_sw < count($dataArray_it_spec_remote_sw); $i_sw++) {
								$it_spec_remote_sw_arr[] = $dataArray_it_spec_remote_sw[$i_sw]['Program__' . $i_sw];
							}
							$it_spec_remote_sw_disp = implode(" , ", $it_spec_remote_sw_arr);

							//$it_spec_cpu_arr = explode("Ž", trim(str_ireplace(array("(R)", "(TM)", "Intel", "AMD", "with Radeon Graphics", "with Radeon Vega Graphics", "CPU", "Core ", " Cores", "Eight-Processor"), array("", "", "", "", "", "", "", "", "C", ""), $api_data['it_spec_cpu'])));
							$it_spec_cpu_arr = explode("Ž", trim(str_ireplace(array("(R)", "(TM)", "with Radeon Graphics", "with Radeon Vega Graphics", "CPU", "Core ", "Eight-Processor"), array("", "", "", "", "", "", ""), $api_data['it_spec_cpu'])));
							if (count($it_spec_cpu_arr) == 1) {
								$it_spec_cpu = $it_spec_cpu_arr[0];
							} else if (count($it_spec_cpu_arr) == 2) {
								$it_spec_cpu = "[Dual] " . $it_spec_cpu_arr[0];
							} else if (count($it_spec_cpu_arr) == 3) {
								$it_spec_cpu = "[Triple] " . $it_spec_cpu_arr[0];
							} else if (count($it_spec_cpu_arr) == 4) {
								$it_spec_cpu = "[Quad] " . $it_spec_cpu_arr[0];
							}
							if (stripos($it_spec_cpu, 'intel') !== false) {
								$logo_cpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_intel.png' class='cpu_logo_img2'>";
							} else if (stripos($it_spec_cpu, 'amd') !== false) {
								$logo_cpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_amd.png' class='cpu_logo_img2'>";
							} else {
								$logo_cpu = "";
							}

							// CPU 데이터
							$cpu_data = $api_data['it_spec_cpu'];

							// 정규식을 사용하여 괄호 속에 "Cores"라는 단어가 포함된 숫자를 추출
							if (preg_match('/\((\d+) Cores\)/', $cpu_data, $matches)) {
								// 추출된 숫자를 $cpu_core 변수에 저장
								$cpu_core = $matches[1];
							} else {
								// "Cores"가 포함된 문자열이 없는 경우
								$cpu_core = null;
							}
							$it_spec_mainboard = $api_data['it_spec_mainboard'];
							$it_spec_ram = $api_data['it_spec_ram'];
							$it_spec_ram_type = $api_data['it_spec_ram_type'];
							//$SSDinfo = $api_data['SSDinfo'];
							$it_spec_ssd_raw = trim((string)$api_data['it_spec_ssd']);
							$it_spec_ssd_numeric = preg_replace('/[^0-9.]/', '', $it_spec_ssd_raw);
							$it_spec_ssd_is_not_installed = ($it_spec_ssd_raw === '' || $it_spec_ssd_raw === '0' || (is_numeric($it_spec_ssd_numeric) && (float)$it_spec_ssd_numeric <= 0));
							$it_spec_ssd = $it_spec_ssd_is_not_installed ? "<div style='width:100%; min-width:40px; text-align:left;'>Not installed</div>" : $it_spec_ssd_raw;
							$it_spec_ssd_type = $api_data['it_spec_ssd_type'];
							//$SSD = $api_data['SSD'];
							//$HDDinfo = $api_data['HDDinfo'];
							$it_spec_hdd_raw = trim((string)$api_data['it_spec_hdd']);
							$it_spec_hdd_numeric = preg_replace('/[^0-9.]/', '', $it_spec_hdd_raw);
							$it_spec_hdd_is_not_installed = ($it_spec_hdd_raw === '' || $it_spec_hdd_raw === '0' || (is_numeric($it_spec_hdd_numeric) && (float)$it_spec_hdd_numeric <= 0));
							$it_spec_hdd = $it_spec_hdd_is_not_installed ? "<div style='width:100%; min-width:40px; text-align:left;'>Not installed</div>" : $it_spec_hdd_raw;
							$it_spec_hdd_type = $api_data['it_spec_hdd_type'];
							//$HDD = $api_data['HDD'];
							$it_spec_gpu_arr = explode("Ž", trim(str_ireplace(array("(R)", "(TM)"), array("", ""), $api_data['it_spec_gpu'])));
							if (count($it_spec_gpu_arr) == 1) {
								$it_spec_gpu = $it_spec_gpu_arr[0];
							} else if (count($it_spec_gpu_arr) > 1) {
								if ((strpos($it_spec_gpu_arr[0], "NVIDIA") !== false) || (strpos($it_spec_gpu_arr[0], "AMD") !== false)) {
									$it_spec_gpu = $it_spec_gpu_arr[0];
								} else if ((strpos($it_spec_gpu_arr[1], "NVIDIA") !== false) || (strpos($it_spec_gpu_arr[1], "AMD") !== false)) {
									$it_spec_gpu = $it_spec_gpu_arr[1];
								} else {
									$it_spec_gpu = $it_spec_gpu_arr[0] . "<br>" . $it_spec_gpu_arr[1];
								}
							}
							$logo_gpu = "";
							if (stripos($it_spec_gpu, 'nvidia') !== false) {
								$logo_gpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_nvidia.png' class='gpu_logo_img2'>";
							}
							if (stripos($it_spec_gpu, 'quadro') !== false) {
								$logo_gpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_nvidia_quadro.png' class='gpu_logo_img2'>";
							}
							if (stripos($it_spec_gpu, 'geforce') !== false) {
								$logo_gpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_nvidia_geforce.png' class='gpu_logo_img2'>";
							}
							if (stripos($it_spec_gpu, 'radeon') !== false) {
								$logo_gpu = "<img src='" . G5_DATA_URL . "/item/img_logo/logo_amd_radeon.png' class='gpu_logo_img2'>";
							}

							//$gpu_ram = $api_data['gpu_ram'];

							//$it_spec_os = trim(str_ireplace(array("Microsoft", "Windows", "(64Bit)"), array("", "Win", ""), $api_data['it_spec_os']));
							$it_spec_os = trim($api_data['it_spec_os']);
							if (stripos($it_spec_os, 'Windows 11') !== false || stripos($it_spec_os, 'Windows11') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/Windows11.png' class='os_img2'>";
							} else if (stripos($it_spec_os, 'Windows 10') !== false || stripos($it_spec_os, 'Windows10') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/Windows10.png' class='os_img2'>";
							} else if (stripos($it_spec_os, 'Windows 8') !== false || stripos($it_spec_os, 'Windows8') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/Windows8.png' class='os_img2'>";
							} else if (stripos($it_spec_os, 'Windows 7') !== false || stripos($it_spec_os, 'Windows7') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/Windows7.png' class='os_img2'>";
							} else if (stripos($it_spec_os, 'Windows Server 2016') !== false) {
								$it_spec_os = (stripos($it_spec_os, 'Microsoft') !== false) ? $it_spec_os : "Microsoft " . $it_spec_os;
								$OS_flag = "<img src='" . G5_DATA_URL . "/item/img_os/WindowsServer2016.png' class='os_img2'>";
							} else {
								$OS_flag = "";
							}

							// OS화면표시언어를 $it_spec_os 변숭에 추가함
							$it_spec_os_disp_lang = $api_data['it_spec_os_disp_lang'];
							if ($it_spec_os_disp_lang != "") {
								$os_country_disp = array_search($it_spec_os_disp_lang, $countries);
								if ($os_country_disp === false) {
									$os_country_disp = "Unknown";
								}
								$it_spec_os .= " (Display Language : " . $os_country_disp . ")";
							}

							$rantal_fee_type = $api_data['rantal_fee_type'];
							$rental_fee = $api_data['rental_fee'];
							$rental_setting_fee = $api_data['rental_setting_fee'];
							$rental_fee_first_daily = round(($rental_fee + $rental_setting_fee) / 30);
							$rental_fee_ext_daily = round(($rental_fee) / 30);
							$rental_stat = $api_data['rental_stat'];
							$client_number = $api_data['client_number'];
							$cpu_clock = $api_data['cpu_clock'];
							$AppVer = $api_data['AppVer'];

							$it_spec_keyboard = !empty(trim($api_data['it_spec_keyboard'])) ? "KEYBOARD(O)" : "KEYBOARD(X)";
							$it_spec_mouse = !empty(trim($api_data['it_spec_mouse'])) ? "MOUSE(O)" : "MOUSE(X)";

							// Initialize the array
							$it_spec_device_arr = [];

							// Check if $it_spec_keyboard is not empty and add to array
							if (!empty(trim($it_spec_keyboard))) {
								$it_spec_device_arr[] = $it_spec_keyboard;
							}

							// Check if $it_spec_mouse is not empty and add to array
							if (!empty(trim($it_spec_mouse))) {
								$it_spec_device_arr[] = $it_spec_mouse;
							}

							// Join array elements with a comma if there are multiple elements
							$it_spec_devices = (count($it_spec_device_arr) > 0) ? implode(', ', $it_spec_device_arr) : "KEYBOARD(X) MOUSE(X)";

							$os_logo_markup = $OS_flag ? "<span class='spec-logo-badge'>{$OS_flag}</span>" : "";
							$cpu_logo_markup = $logo_cpu ? "<span class='spec-logo-badge'>{$logo_cpu}</span>" : "";
							$gpu_logo_markup = $logo_gpu ? "<span class='spec-logo-badge'>{$logo_gpu}</span>" : "";
							$country_logo_markup = $remote_ip_country_flag ? "<span class='spec-logo-badge'>{$remote_ip_country_flag}</span>" : "";
							$country_text = !empty(trim($remote_ip_country_name)) ? $remote_ip_country_name : "Unknown";
							$country_display_markup = "<div class='spec-cell-wrap'>{$country_logo_markup}<span class='spec-cell-text'>{$country_text}</span></div>";
							$os_display_markup = "<div class='spec-cell-wrap'>{$os_logo_markup}<span class='spec-cell-text'>{$it_spec_os}</span></div>";
							$cpu_display_markup = "<div class='spec-cell-wrap'>{$cpu_logo_markup}<span class='spec-cell-text'>{$it_spec_cpu}</span></div>";
							$gpu_display_markup = "<div class='spec-cell-wrap'>{$gpu_logo_markup}<span class='spec-cell-text'>{$it_spec_gpu}</span></div>";

							if ($is_vpn_category) {
								$rows[] = [
									$country_display_markup,
									'IKEv2-VPN',
									'Windows, MacOS, Linux, Android, iOS',
									'결제 완료 후 주문내역에서 확인할 수 있습니다.'
								];
							} else {
								$rows[] = [
									//$it_id,
									//number_format($rental_fee_first_daily) . " Point",
									//number_format($rental_fee_ext_daily) . " Point",
									//$ip_country_flag.$OS_flag.$logo_cpu.$logo_gpu,
									$country_display_markup,
									$os_display_markup,
									$cpu_display_markup,
									$gpu_display_markup,
									$remote_ip,
									$it_spec_ram . (!empty($it_spec_ram_type) ? " ($it_spec_ram_type)" : ""),
									$it_spec_ssd_is_not_installed ? $it_spec_ssd : ($it_spec_ssd . (!empty($it_spec_ssd_type) ? " ($it_spec_ssd_type)" : "")),
									$it_spec_hdd_is_not_installed ? $it_spec_hdd : ($it_spec_hdd . (!empty($it_spec_hdd_type) ? " ($it_spec_hdd_type)" : "")),
									$it_spec_devices,
									$it_spec_remote_sw_disp
								];
							}
						}

						// foreach ($headers as $index => $header) {
						// 	echo "<tr>";
						// 	echo "<td>$header</td>";
						// 	foreach ($rows as $row) {
						// 		echo "<th>{$row[$index]}</th>";
						// 	}
						// 	echo "</tr>";
						// }

						$ignore_headers = $headers;

						echo "<tr>";
						echo "<th colspan='2' style='padding:10px 10px 12px; border-bottom:1px solid #edf2f7;'>";
						echo "<div style='display:flex; align-items:flex-start; justify-content:space-between; gap:10px;'>";
						echo "<span class='overlay-item-name' style='font-size:clamp(24px, 1.8vw, 28px); line-height:1.1; font-weight:800; color:#101828; letter-spacing:-0.4px;'>";
						echo "<span style='display:block; margin-bottom:4px; line-height:1;'>" . rpc_category_badge_html($_rpc_it_ca_id) . ($_rpc_it_grade !== '' ? rpc_grade_badge_html($_rpc_it_grade) : '') . "</span>";
						echo stripslashes($it['it_name']);
						echo "</span>";
						echo "<span style='text-align:right; font-size:12px; line-height:1.4; color:#777; white-space:nowrap;'>";
						echo "<span style='display:block;'>".get_text($seller_nick_display);
						if ($is_ip_view) {
							echo " (".get_text($ip).")";
						}
						echo " ".apms_get_star($it['it_use_avg'], 'red')."</span>";
						echo "<span style='display:block;'>매너온도 ".get_pt_manner_temperature($it['pt_id'])."</span>";
						echo "</span>";
						echo "</div>";
						echo "</th>";
						echo "</tr>";

						foreach ($headers as $index => $header) {
							if ($header === "IP주소") continue;
                            // Check if the row has any meaningful content
                            $hasContent = false;
                            foreach ($rows as $row) {
                                $val = strip_tags($row[$index]);
                                $rawVal = $row[$index];
                                // Check for common "empty" indicators
                                if (trim($val) != "" &&
                                    trim($val) != "Not installed" &&
                                    trim($val) != "0 GB" &&
                                    strpos($rawVal, "0 GB") === false &&
                                    strpos($rawVal, "KEYBOARD(X) MOUSE(X)") === false
                                   ) {
                                    $hasContent = true;
                                    break;
                                }
                            }
                            if (!$hasContent) continue;

							echo "<tr>";
							if (!in_array($header, $ignore_headers)) {
								foreach ($rows as $row) {
									echo "<th colspan='2'>{$row[$index]}</th>";
								}
							} else {
								echo "<td>$header </td>";
								foreach ($rows as $row) {
									echo "<th>{$row[$index]}</th>";
								}
							}

							echo "</tr>";
						}
						?>
					</table>
				</div>
			</div>

			<div class="item-thumb text-center">
			<?php
				for($i=0; $i < count($thumbnails); $i++) {
					//echo $thumbnails[$i];
				}
			?>
			</div>
			<script>
				$(function(){
					$(".thumb_item_image").hover(function() {
						var img = $(this).attr("data-ref");
						var url = $(this).attr("data-href");
						$("#item_image").attr("src", img);
						$("#item_image_href").attr("href", url);
						return true;
					});
					// 이미지 크게보기
					// $(".popup_item_image").click(function() {
					// 	var url = $(this).attr("href");
					// 	var top = 10;
					// 	var left = 10;
					// 	var opt = 'scrollbars=yes,top='+top+',left='+left;
					// 	popup_window(url, "largeimage", opt);

					// 	return false;
					// });
				});
			</script>
			<div class="h30 visible-xs"></div>
		</div>
		<div class="col-sm-6">
			<div class="item-summary-card">
			<?php if($it['it_basic']) { // 기본설명 ?>
				<p class="help-block"><?php echo $it['it_basic']; ?></p>
			<?php } ?>
			<?php // $action_url =  "./cartupdate.php" */ ?>
			<form name="fitem" method="post" action="<?php echo $action_url; ?>" class="form item-form modern-item-form" role="form" onsubmit="return fitem_submit(this);">
			<input type="hidden" name="it_id[]" value="<?php echo $it_id; ?>">
			<input type="hidden" name="it_msg1[]" value="<?php echo $it['pt_msg1']; ?>">
			<input type="hidden" name="it_msg2[]" value="<?php echo $it['pt_msg2']; ?>">
			<input type="hidden" name="it_msg3[]" value="<?php echo $it['pt_msg3']; ?>">
			<input type="hidden" name="sw_direct">
			<input type="hidden" name="url">
			<input type="hidden" id="mb_point_balance" value="<?php echo (int)(isset($member['mb_point']) ? $member['mb_point'] : 0); ?>">

			<table class="div-table table item-price-table">
			<col width="120">
			<tbody>

			<tr><th scope="row">상품종류 / 등급</th><td style="padding:5px 8px;">
				<?php echo rpc_category_badge_html($_rpc_it_ca_id); if ($_rpc_it_grade !== '') echo rpc_grade_badge_html($_rpc_it_grade); ?>
				<span style="display:inline-block;font-size:11px;color:#64748b;vertical-align:middle;margin-left:2px;">원격제어컴퓨터</span>
			</td></tr>

			<?php if ($it['it_use_avg']) { /* ?>
				<tr><th scope="row"></th><td><b><?php echo $row_pt_name[mb_nick] ?> <?php if ($is_ip_view) { echo "&nbsp;($ip)"; } ?></b></td></tr>
			<?php */ } ?>
			<?php if ($it['it_maker']) { ?>
				<tr><th scope="row">제조사</th><td><?php echo $it['it_maker']; ?></td></tr>
			<?php } ?>
			<?php if ($it['it_origin']) { ?>
				<tr><th scope="row">원산지</th><td><?php echo $it['it_origin']; ?></td></tr>
			<?php } ?>
			<?php if ($it['it_brand']) { ?>
				<tr><th scope="row">브랜드</th><td><?php echo $it['it_brand']; ?></td></tr>
			<?php } ?>
			<?php if ($it['it_model']) { ?>
				<tr><th scope="row">모델</th><td><?php echo $it['it_model']; ?></td></tr>
			<?php } ?>
			<?php if (!$it['it_use']) { // 판매가능이 아닐 경우 ?>
				<tr><th scope="row">판매가격</th><td>판매중지</td></tr>
			<?php } else if ($it['it_tel_inq']) { // 전화문의일 경우 ?>
				<tr><th scope="row">판매가격</th><td>전화문의</td></tr>
			<?php } else { // 전화문의가 아닐 경우?>
				<?php
					$billing_plan = apms_billing_plan_normalize(isset($it['it_billing_plan']) ? $it['it_billing_plan'] : '');
					$usage_sale_enabled = apms_usage_sale_enabled_from_item($it);
					$allowed_units = apms_allowed_pricing_units_from_item($it);
					$allowed_plan_text = apms_allowed_pricing_units_text($it);
					$hourly_price = apms_item_hourly_base_price($it);
					$daily_price = apms_pricing_unit_package_price_by_item($it, 'day', $hourly_price);
					$monthly_price = apms_pricing_unit_package_price_by_item($it, 'month', $hourly_price);
					$yearly_price = apms_pricing_unit_package_price_by_item($it, 'year', $hourly_price);
					$usage_deposit_price = apms_usage_deposit_price_from_item($it);
					$fee_guide_by_unit = array(
						'hour' => '1시간 이용권: '.display_point($hourly_price),
						'day' => '1일 이용권: '.display_point($daily_price),
						'month' => '1개월(30일) 이용권: '.display_point($monthly_price),
						'year' => '1년(365일) 이용권: '.display_point($yearly_price),
						'usage' => '트래픽 '.display_point((int)$it['it_billing_traffic_cost']).' / GB, 시간 '.display_point((int)$it['it_billing_time_cost']).' / 1시간'
					);
					$initial_guide_unit = '';
					$guide_priority = array('hour', 'day', 'month', 'year', 'usage');
					foreach ($guide_priority as $guide_unit) {
						if (!empty($allowed_units[$guide_unit])) {
							$initial_guide_unit = $guide_unit;
							break;
						}
					}
					$fee_guide_text = ($initial_guide_unit !== '' && isset($fee_guide_by_unit[$initial_guide_unit])) ? $fee_guide_by_unit[$initial_guide_unit] : '-';
					$range_min_hours = apms_buy_qty_to_hours($it['it_buy_min_qty']);
					if($range_min_hours <= 0) {
						$range_min_hours = 1;
					}
					$range_max_hours = apms_buy_qty_to_hours($it['it_buy_max_qty']);
					$range_min_text = apms_contract_hours_text($range_min_hours);
					$range_max_text = ($range_max_hours > 0) ? apms_contract_hours_text($range_max_hours) : '제한없음';
					$range_guide_text = '최소 '.$range_min_text.' ~ 최대 '.$range_max_text;
				?>
				<?php if ($it['it_cust_price']) { ?>
					<tr><th scope="row">시중가격</th><td><?php echo display_price($it['it_cust_price']); ?></td></tr>
				<?php } // 시중가격 끝 ?>
					<tr><th scope="row">구매가능 요금제</th><td><?php echo $allowed_plan_text ? $allowed_plan_text : '-'; ?></td></tr>
					<tr><th scope="row">RPC 요금안내</th><td id="fee_guide_text_rpc"
						data-fee-hour="<?php echo htmlspecialchars($fee_guide_by_unit['hour'], ENT_QUOTES); ?>"
						data-fee-day="<?php echo htmlspecialchars($fee_guide_by_unit['day'], ENT_QUOTES); ?>"
						data-fee-month="<?php echo htmlspecialchars($fee_guide_by_unit['month'], ENT_QUOTES); ?>"
						data-fee-year="<?php echo htmlspecialchars($fee_guide_by_unit['year'], ENT_QUOTES); ?>"
						data-fee-usage="<?php echo htmlspecialchars($fee_guide_by_unit['usage'], ENT_QUOTES); ?>"><?php echo $fee_guide_text ? $fee_guide_text : '-'; ?><input type="hidden" id="it_price" value="<?php echo $hourly_price; ?>"></td></tr>
					<tr><th scope="row">주문가능기간</th><td><?php echo $range_guide_text; ?></td></tr>
			<?php } ?>
			<?php
				/* 재고 표시하는 경우 주석 해제
				<tr><th scope="row">재고수량</th><td><?php echo number_format(get_it_stock_qty($it_id)); ?> 일</td></tr>
				*/
			?>
			<?php if ($config['cf_use_point'] && $it['it_point']) { // 포인트 사용하고, 적립포인트 백분률이 0이 아니면 ?>
				<tr>
				<th scope="row">적립포인트</th>
				<td>
					<?php
						if($it['it_point_type'] == 2) {
							//echo '주문금액(추가옵션 제외)의 '.$it['it_point'].'%';
							echo '주문합계 × '.$it['it_point'].'%';
						} else {
							$it_point = get_item_point($it);
							echo display_point(number_format($it_point));
						}
					?>
				</td>
				</tr>
			<?php } ?>



			<input type="hidden" name="default_install_price" id="default_install_price" value="<?php echo $it['it_install_price'];?>">
			<input type="hidden" name="io_install_price" id="io_install_price" value="<?php echo $it['it_install_price'];?>">
			<input type="hidden" id="install_free_start_hours" value="<?php echo (int)$it['it_10']; ?>">

			<?php $install_rule_text = apms_install_rule_text($it); ?>
			<tr><th>개통비/설치비</th><td><span id="io_install_price_disp" data-rule-text="<?php echo htmlspecialchars($install_rule_text ? ' '.$install_rule_text : '', ENT_QUOTES); ?>"><?php echo number_format((int)$it['it_install_price']); ?> Point<?php echo $install_rule_text ? ' '.$install_rule_text : ''; ?></span></td></tr>

			<?php
				$ct_send_cost_label = '배송비결제';

				if($it['it_sc_type'] == 1)
					$sc_method = '무료배송';
				else {
					if($it['it_sc_method'] == 1)
						$sc_method = '수령후 지불';
					else if($it['it_sc_method'] == 2) {
						$ct_send_cost_label = '<label for="ct_send_cost">배송비결제</label>';
						$sc_method = '<select name="ct_send_cost" id="ct_send_cost" class="form-control input-sm">
										  <option value="0">주문시 결제</option>
										  <option value="1">수령후 지불</option>
									  </select>';
					}
					else
						$sc_method = '주문시 결제';
				}
			?>
			<?php if ($sc_method != "무료배송") { ?>
				<tr>
					<th><?php echo $ct_send_cost_label; ?></th><td><?php echo $sc_method; ?></td>
				</tr>
			<?php } ?>

			</tbody>
			</table>

			<div id="item_option">
				<?php if($option_item) { ?>
					<p>&nbsp; <b><i class="fa fa-check-square-o fa-lg"></i> 선택옵션</b></p>
					<table class="div-table table item-price-table">
					<col width="120">
					<tbody>
					<?php echo $option_item; // 선택옵션	?>
					</tbody>
					</table>
				<?php }	?>

				<?php if($supply_item) { ?>
					<p>&nbsp; <b><i class="fa fa-check-square-o fa-lg"></i> 추가옵션</b></p>
					<table class="div-table table item-price-table">
					<col width="120">
					<tbody>
					<?php echo $supply_item; // 추가옵션 ?>
					</tbody>
					</table>
				<?php }	?>

				<?php if ($is_orderable) { ?>
					<div id="it_sel_option">
						<?php
						if(!$option_item) {
							if ($it['it_is_hour_sale'] == "1") { // 1시간 단위판매 허용 체크된 경우
								$it['it_buy_min_qty'] = 1;
							} else {
								if(!$it['it_buy_min_qty']) {
									$it['it_buy_min_qty'] = 24;
								}
							}
						?>
							<ul id="it_opt_added" class="list-group">
								<li class="it_opt_list list-group-item">
									<input type="hidden" name="io_type[<?php echo $it_id; ?>][]" value="0">
									<input type="hidden" name="io_id[<?php echo $it_id; ?>][]" value="">
									<input type="hidden" name="io_value[<?php echo $it_id; ?>][]" value="<?php echo $it['it_name']; ?>">
									<input type="hidden" class="io_price" value="0">
									<input type="hidden" class="io_stock" value="<?php echo $it['it_stock_qty']; ?>">
									<div class="row">
										<div class="col-sm-3" style="padding-right:0px;">
											<label style="margin:0;">
																<span class="it_opt_subj">RPC 이용권 선택</span>
												<span class="it_opt_prc"></span>
											</label>
										</div>
										<div class="col-sm-9">
														<div class="ct_total_hours_inline" style="display:flex; align-items:stretch; gap:8px; flex-wrap:nowrap; min-width:0; width:100%;">
														<?php
															$min_contract_hours = apms_buy_qty_to_hours($it['it_buy_min_qty']);
															if($min_contract_hours <= 0) {
																$min_contract_hours = 1;
															}
															$max_contract_hours = apms_buy_qty_to_hours($it['it_buy_max_qty']);
															if($max_contract_hours <= 0) {
																$max_contract_hours = (365 * 24);
															}
															$allowed_units = apms_allowed_pricing_units_from_item($it);
															$total_contract_hours = max(1, $min_contract_hours);
															$default_unit = apms_pricing_unit_from_day_hour((int)floor($total_contract_hours / 24), (int)($total_contract_hours % 24));
															if(empty($allowed_units[$default_unit])) {
																$default_unit = apms_best_pricing_unit_for_hours($it, $total_contract_hours, 'hour');
															}
															$auto_best_unit = apms_best_pricing_unit_for_hours($it, $total_contract_hours, $default_unit);
															$default_count = apms_pricing_count_from_day_hour((int)floor($total_contract_hours / 24), (int)($total_contract_hours % 24), $default_unit);
															if($default_unit === 'usage') {
																$default_count = (int)$usage_deposit_price;
																if($default_count < 5000) $default_count = 5000;
																if($default_count > 1000000) $default_count = 1000000;
															}
															list($default_day_qty, $default_hour_qty) = apms_day_hour_from_pricing_unit($default_unit, $default_count);
															$discount_hour = apms_pricing_unit_discount_for_item($it, 'hour');
															$discount_day = apms_pricing_unit_discount_for_item($it, 'day');
															$discount_month = apms_pricing_unit_discount_for_item($it, 'month');
															$discount_year = apms_pricing_unit_discount_for_item($it, 'year');
															$discount_usage = apms_pricing_unit_discount_for_item($it, 'usage');
														?>
															<select id="ct_pricing_unit_<?php echo $i; ?>" class="form-control input-sm ct_pricing_unit" style="flex:1 1 58%; min-width:0; width:58%; height:44px;"
															data-discount-hour="<?php echo $discount_hour; ?>"
															data-discount-day="<?php echo $discount_day; ?>"
															data-discount-month="<?php echo $discount_month; ?>"
															data-discount-year="<?php echo $discount_year; ?>"
															data-discount-usage="<?php echo $discount_usage; ?>"
															data-package-usage="<?php echo (int)$usage_deposit_price; ?>"
															data-allow-hour="<?php echo $allowed_units['hour'] ? '1' : '0'; ?>"
															data-allow-day="<?php echo $allowed_units['day'] ? '1' : '0'; ?>"
															data-allow-month="<?php echo $allowed_units['month'] ? '1' : '0'; ?>"
															data-allow-year="<?php echo $allowed_units['year'] ? '1' : '0'; ?>"
															data-auto-year="<?php echo (apms_pricing_unit_package_price_by_item($it, 'year') > 0) ? '1' : '0'; ?>"
															data-allow-usage="<?php echo $allowed_units['usage'] ? '1' : '0'; ?>">
															<?php if($allowed_units['usage']) { ?><option value="usage" <?php echo get_selected('usage', $default_unit); ?>>종량제 이용권</option><?php } ?>
															<?php if($allowed_units['hour']) { ?><option value="hour" <?php echo get_selected('hour', $default_unit); ?>>1시간 이용권</option><?php } ?>
															<?php if($allowed_units['day']) { ?><option value="day" <?php echo get_selected('day', $default_unit); ?>>1일 이용권</option><?php } ?>
															<?php if($allowed_units['month']) { ?><option value="month" <?php echo get_selected('month', $default_unit); ?>>1개월(30일) 이용권</option><?php } ?>
															<?php if($allowed_units['year']) { ?><option value="year" <?php echo get_selected('year', $default_unit); ?>>1년(365일) 이용권</option><?php } ?>
														</select>
															<div class="input-group ct_pricing_count_wrap" style="flex:1 1 calc(42% - 8px); min-width:0; width:calc(42% - 8px); max-width:calc(42% - 8px);">
																<div class="ct_pricing_count_field">
																	<input type="number" name="ct_pricing_count[<?php echo $it_id; ?>][]" min="1" step="1" value="<?php echo (int)$default_count; ?>" class="form-control input-sm ct_pricing_count" inputmode="numeric" pattern="[0-9]*" style="height:44px; width:100%;">
																	<div class="ct_count_stepper" aria-label="수량 조절">
																		<button type="button" class="btn btn-default btn-xs ct_count_btn ct_count_plus" aria-label="수량 증가">▲</button>
																		<button type="button" class="btn btn-default btn-xs ct_count_btn ct_count_minus" aria-label="수량 감소">▼</button>
																	</div>
																</div>
															<span class="input-group-addon ct_pricing_suffix">시간</span>
															<input type="hidden" name="ct_pricing_unit[<?php echo $it_id; ?>][]" value="<?php echo $auto_best_unit; ?>" class="ct_pricing_unit_hidden">
															<input type="hidden" name="ct_pricing_discount[<?php echo $it_id; ?>][]" value="<?php echo apms_pricing_unit_discount_for_item($it, $auto_best_unit); ?>" class="ct_pricing_discount_hidden">
															<input type="hidden" name="ct_qty[<?php echo $it_id; ?>][]" value="<?php echo $default_day_qty; ?>" id="ct_qty_<?php echo $i; ?>" min="<?php echo $min_contract_hours; ?>" max="<?php echo $max_contract_hours; ?>" class="ct_qty_hidden">
															<input type="hidden" name="ct_qty_hour[<?php echo $it_id; ?>][]" value="<?php echo $default_hour_qty; ?>" id="ct_qty_hour_<?php echo $i; ?>" min="0" max="23" class="ct_qty_hour_hidden">
														</div>
														</div>
														<div class="ct_human_time_hint" style="width:100%; font-size:12px; color:#666; margin-top:4px;"><?php echo ($default_unit === 'usage') ? ('유효기한: 주문일로부터 365일 / 충전필요금액: '.number_format(max(0, (int)$default_count - (int)(isset($member['mb_point']) ? $member['mb_point'] : 0))).' Point') : ('선택기간: '.apms_contract_hours_text($total_contract_hours)); ?></div>
														<div class="ct_auto_pricing_notice" style="width:100%; font-size:12px; color:#0b6e4f; margin-top:2px; display:none;"></div>
										</div>
										</div>
									</div>
									<?php if($it['pt_msg1']) { ?>
										<div style="margin-top:10px;">
											<input type="text" name="pt_msg1[<?php echo $it_id; ?>][]" class="form-control input-sm" placeholder="<?php echo $it['pt_msg1'];?>">
										</div>
									<?php } ?>
									<?php if($it['pt_msg2']) { ?>
										<div style="margin-top:10px;">
											<input type="text" name="pt_msg2[<?php echo $it_id; ?>][]" class="form-control input-sm" placeholder="<?php echo $it['pt_msg2'];?>">
										</div>
									<?php } ?>
									<?php if($it['pt_msg3']) { ?>
										<div style="margin-top:10px;">
											<input type="text" name="pt_msg3[<?php echo $it_id; ?>][]" class="form-control input-sm" placeholder="<?php echo $it['pt_msg3'];?>">
										</div>
									<?php } ?>
								</li>
							</ul>
							<script>
							$(function() {
								price_calculate();
							});
							</script>
						<?php } ?>
					</div>


					<!-- 총 구매액 -->
					<h4 style="text-align:center; margin-bottom:15px;">
						<!-- 총 금액 : <span id="it_tot_price">0원</span> -->
						주문합계 : <span id="it_tot_price">0 Point</span>
					</h4>
				<?php } ?>
			</div>

			<?php if($is_soldout) { ?>
				<!-- <p id="sit_ov_soldout">재고가 부족하여 구매할 수 없습니다.</p> -->
				<p id="sit_ov_soldout" style="color:orangered;">판매완료 상품입니다. 주문할 수 없습니다.</p>
			<?php } ?>

			<?php if ($is_orderable) { ?>
				<div style="text-align:center; padding:12px 0;">
					<ul class="item-buy-btn">
					<li style="width:33.33%;"><input type="submit" onclick="document.pressed=this.value;" value="바로구매" class="btn btn-<?php echo $btn2;?> btn-block"></li>
					<li style="width:33.33%;"><input type="submit" onclick="document.pressed=this.value;" value="장바구니" class="btn btn-<?php echo $btn1;?> btn-block"></li>
					<li style="width:33.33%;"><a href="#" class="btn btn-<?php echo $btn1;?> btn-block" onclick="apms_wishlist('<?php echo $it['it_id']; ?>'); return false;">위시리스트</a></li>
					<!-- <li><a href="#" class="btn btn-<?php echo $btn1;?> btn-block" onclick="apms_recommend('<?php echo $it['it_id']; ?>', '<?php echo $ca_id; ?>'); return false;">추천하기</a></li> -->
					</ul>
				</div>
				<?php if ($naverpay_button_js) { ?>
					<div style="margin-bottom:15px;"><?php echo $naverpay_request_js.$naverpay_button_js; ?></div>
				<?php } ?>
			<?php } ?>
			<?php if(!$is_orderable && $it['it_soldout'] && $it['it_stock_sms']) { ?>
				<div style="text-align:center; padding:12px 0;">
					<button type="button" onclick="popup_stocksms('<?php echo $it['it_id']; ?>','<?php echo $ca_id; ?>');" class="btn btn-primary">재입고알림(SMS)</button>
				</div>
			<?php } ?>
			</form>

			<script>
				(function() {
					if (window.__guestLoginLayerInit) {
						return;
					}
					window.__guestLoginLayerInit = true;

					document.addEventListener("change", function(ev) {
						if (ev.target && ev.target.id === "guest_login_auto_login" && ev.target.checked) {
							if(!confirm("자동로그인을 사용하시면 다음부터 회원아이디와 비밀번호를 입력하실 필요가 없습니다.\n\n공공장소에서는 개인정보가 유출될 수 있으니 사용을 자제하여 주십시오.\n\n자동로그인을 사용하시겠습니까?")) {
								ev.target.checked = false;
							}
						}
					});
				})();

				// BS3
				$(function() {
					$("select.it_option").addClass("form-control input-sm");
					$("select.it_supply").addClass("form-control input-sm");

					function unitHours(unit) {
						if (unit === 'day') return 24;
						if (unit === 'month') return 24 * 30;
						if (unit === 'year') return 24 * 365;
						if (unit === 'usage') return 1;
						return 1;
					}

					function unitDiscount(unit, $li) {
						var $unitSelect = $li.find('.ct_pricing_unit');
						if (unit === 'day') return parseFloat($unitSelect.data('discount-day')) || 1;
						if (unit === 'month') return parseFloat($unitSelect.data('discount-month')) || 1;
						if (unit === 'year') return parseFloat($unitSelect.data('discount-year')) || 1;
						if (unit === 'usage') return parseFloat($unitSelect.data('discount-usage')) || 1;
						return parseFloat($unitSelect.data('discount-hour')) || 1;
					}

					function unitSuffix(unit) {
						if (unit === 'day') return '일';
						if (unit === 'month') return '개월';
						if (unit === 'year') return '년';
						if (unit === 'usage') return 'Point';
						return '시간';
					}

						function isAllowedUnit(unit, $li) {
							var $unitSelect = $li.find('.ct_pricing_unit');
							if (unit === 'day') return String($unitSelect.data('allow-day')) === '1';
							if (unit === 'month') return String($unitSelect.data('allow-month')) === '1';
							if (unit === 'year') return String($unitSelect.data('allow-year')) === '1' || String($unitSelect.data('auto-year')) === '1';
							if (unit === 'usage') return String($unitSelect.data('allow-usage')) === '1';
							return String($unitSelect.data('allow-hour')) === '1';
						}

						function bestAllowedUnit($li, totalHours, fallbackUnit) {
							var units = ['hour', 'day', 'month', 'year', 'usage'];
							var bestUnit = '';
							var bestTotal = null;

							for (var i = 0; i < units.length; i++) {
								var u = units[i];
								if (!isAllowedUnit(u, $li)) continue;
								var unitH = unitHours(u);
								var packagePrice = Math.round((parseFloat($('#it_price').val()) || 0) * unitDiscount(u, $li) * unitH);
								var lineTotal = Math.max(1, Math.ceil(totalHours / unitH)) * packagePrice;
								if (bestTotal === null || lineTotal < bestTotal) {
									bestTotal = lineTotal;
									bestUnit = u;
								}
							}

							if (!bestUnit && fallbackUnit && isAllowedUnit(fallbackUnit, $li)) {
								bestUnit = fallbackUnit;
							}
							if (!bestUnit) {
								bestUnit = 'hour';
							}

							return bestUnit;
						}

					function syncContractPeriod($li) {
						var $qtyHidden = $li.find("input.ct_qty_hidden");
						var minHoursRaw = parseFloat($qtyHidden.attr("min"));
						var maxHoursRaw = parseFloat($qtyHidden.attr("max"));
						if (isNaN(minHoursRaw) || minHoursRaw < 1) minHoursRaw = 1;
						if (isNaN(maxHoursRaw) || maxHoursRaw < minHoursRaw) maxHoursRaw = (365 * 24);
						var minHours = Math.max(1, Math.ceil(minHoursRaw));
						var maxHours = Math.max(minHours, Math.floor(maxHoursRaw));

						var $unitSelect = $li.find('.ct_pricing_unit');
						var unit = String($unitSelect.val() || 'hour');
						var hoursPerUnit = unitHours(unit);
						$li.find('.ct_pricing_suffix').text(unitSuffix(unit));

						var $feeGuide = $('#fee_guide_text_rpc');
						if ($feeGuide.length) {
							var feeText = $feeGuide.data('fee-' + unit);
							if (typeof feeText === 'undefined' || feeText === null || String(feeText).trim() === '') {
								feeText = '-';
							}
							$feeGuide.contents().first()[0].textContent = String(feeText);
						}

						var $countInput = $li.find('.ct_pricing_count');
						var $countWrap = $li.find('.ct_pricing_count_wrap');
						var count = parseInt($countInput.val(), 10);
						if (isNaN(count) || count < 1) count = 1;
						if (unit === 'usage') {
							if (count < 5000) count = 5000;
							if (count > 1000000) count = 1000000;
							$countInput.attr('min', '5000').attr('max', '1000000').attr('step', '1000').prop('disabled', false).val(String(count));
							$countWrap.show();
							$li.find('.ct_pricing_unit_hidden').val('usage');
							$li.find('.ct_pricing_discount_hidden').val(String(unitDiscount('usage', $li)));
							$li.find("input[name^='ct_qty']").val(0);
							$li.find("input[name^='ct_qty_hour']").val(1);
							var mbPoint = parseInt($('#mb_point_balance').val(), 10);
							if (isNaN(mbPoint) || mbPoint < 0) mbPoint = 0;
							var needAmount = Math.max(0, count - mbPoint);
							$li.find('.ct_human_time_hint').text('유효기한: 주문일로부터 365일 / 충전필요금액: ' + number_format(String(needAmount)) + ' Point');
							price_calculate();
							return;
						} else {
							$countInput.attr('min', '1').removeAttr('max').attr('step', '1');
							$countInput.prop('disabled', false);
							$countWrap.show();
						}

						var totalHours = count * hoursPerUnit;
						if (totalHours < minHours) totalHours = minHours;
						if (totalHours > maxHours) totalHours = maxHours;

						count = Math.max(1, Math.round(totalHours / hoursPerUnit));
						totalHours = count * hoursPerUnit;
						if (totalHours > maxHours) {
							totalHours = maxHours;
						}

						var day = Math.floor(totalHours / 24);
						var hour = totalHours % 24;

						$countInput.val(String(count));
							var autoUnit = (unit === 'usage') ? 'usage' : bestAllowedUnit($li, totalHours, unit);
							$li.find('.ct_pricing_unit_hidden').val(autoUnit);
							$li.find('.ct_pricing_discount_hidden').val(String(unitDiscount(autoUnit, $li)));

						$li.find("input[name^='ct_qty']").val(day);
						$li.find("input[name^='ct_qty_hour']").val(hour);

						price_calculate();
					}

					$(document).on('change', '.ct_pricing_unit', function() {
						syncContractPeriod($(this).closest("li"));
					});

					$(document).on('input', '.ct_pricing_count', function() {
						var value = String($(this).val() || '');
						if (value === '') {
							return;
						}
						syncContractPeriod($(this).closest("li"));
					});

					$(document).on('change blur', '.ct_pricing_count', function() {
						syncContractPeriod($(this).closest("li"));
					});

					$(document).on('click', '.ct_count_minus, .ct_count_plus', function() {
						var $btn = $(this);
						var $li = $btn.closest('li');
						var $input = $li.find('.ct_pricing_count');
						var step = parseInt($input.attr('step'), 10);
						if (isNaN(step) || step < 1) step = 1;

						var min = parseInt($input.attr('min'), 10);
						if (isNaN(min) || min < 1) min = 1;

						var max = parseInt($input.attr('max'), 10);
						if (isNaN(max)) max = null;

						var value = parseInt($input.val(), 10);
						if (isNaN(value)) value = min;

						if ($btn.hasClass('ct_count_minus')) {
							value = value - step;
							if (value < min) value = min;
						} else {
							value = value + step;
							if (max !== null && value > max) value = max;
						}

						$input.val(String(value));
						syncContractPeriod($li);
					});

					$(document).on('focus', '.ct_pricing_count', function() {
						this.select();
					});

					$("#it_sel_option li").each(function() {
						syncContractPeriod($(this));
					});
				});

				// 재입고SMS 알림
				function popup_stocksms(it_id, ca_id) {
					url = "./itemstocksms.php?it_id=" + it_id + "&ca_id=" + ca_id;
					opt = "scrollbars=yes,width=616,height=420,top=10,left=10";
					popup_window(url, "itemstocksms", opt);
				}

				var shopActionConfirmHandler = null;
				function openShopActionConfirm(title, message, subMessage, confirmText, cancelText, onConfirm) {
					var modal = document.getElementById("shop-action-modal");
					if (!modal) return;

					var titleEl = document.getElementById("shop-action-title");
					var messageEl = document.getElementById("shop-action-message");
					var subMessageEl = document.getElementById("shop-action-submessage");
					var confirmBtn = document.getElementById("shop-action-confirm-btn");
					var cancelBtn = document.getElementById("shop-action-cancel-btn");

					if (titleEl) titleEl.textContent = title || "알림";
					if (messageEl) messageEl.textContent = message || "";
					if (subMessageEl) {
						subMessageEl.textContent = subMessage || "";
						subMessageEl.style.display = subMessage ? "block" : "none";
					}
					if (confirmBtn) confirmBtn.textContent = confirmText || "확인";
					if (cancelBtn) cancelBtn.textContent = cancelText || "취소";

					shopActionConfirmHandler = (typeof onConfirm === "function") ? onConfirm : null;

					modal.classList.add("is-open");
					document.body.classList.add("lnb-modal-open");
					if (confirmBtn) confirmBtn.focus();
				}

				function closeShopActionConfirm() {
					var modal = document.getElementById("shop-action-modal");
					if (!modal) return;
					modal.classList.remove("is-open");
					document.body.classList.remove("lnb-modal-open");
					shopActionConfirmHandler = null;
				}

				function doShopActionConfirm() {
					var handler = shopActionConfirmHandler;
					closeShopActionConfirm();
					if (handler) handler();
				}

				var guestLoginMaxAttempts = 5;
				var guestLoginCaptchaRequired = false;
				var guestLoginCaptchaSessionUrl = "<?php echo G5_CAPTCHA_URL; ?>/kcaptcha_session.php";
				var pendingGuestAction = "";
				var pendingGuestForm = null;

				function setGuestLoginStatus(message, isError) {
					var statusEl = document.getElementById("guest-login-required-status");
					if (!statusEl) return;

					if (!message) {
						statusEl.textContent = "";
						statusEl.style.display = "none";
						statusEl.className = "guest-login-status";
						return;
					}

					statusEl.textContent = message;
					statusEl.style.display = "block";
					statusEl.className = isError ? "guest-login-status is-error" : "guest-login-status is-info";
				}

				function setGuestLoginFormLocked(locked) {
					var submitBtn = document.getElementById("guest-login-submit-btn");
					var idInput = document.getElementById("guest_login_mb_id");
					var pwInput = document.getElementById("guest_login_mb_password");
					var autoInput = document.getElementById("guest_login_auto_login");

					if (submitBtn) submitBtn.disabled = !!locked;
					if (idInput) idInput.disabled = false;
					if (pwInput) pwInput.disabled = false;
					if (autoInput) autoInput.disabled = false;
				}

				function refreshGuestCaptchaImage(url, sessionUrl) {
					var img = document.getElementById("guest-login-captcha-image");
					if (!img) return;
					var baseUrl = url || "<?php echo G5_CAPTCHA_URL; ?>/kcaptcha_image.php";
					var sessionApi = sessionUrl || guestLoginCaptchaSessionUrl;
					var applyImage = function() {
						var sep = baseUrl.indexOf("?") >= 0 ? "&" : "?";
						img.src = baseUrl + sep + "t=" + new Date().getTime();
					};

					if (typeof $ !== "undefined" && sessionApi) {
						$.ajax({
							type: "POST",
							url: sessionApi,
							cache: false
						}).always(applyImage);
					} else {
						applyImage();
					}
				}

				function setGuestLoginCaptchaRequired(required, imageUrl, sessionUrl) {
					guestLoginCaptchaRequired = !!required;
					if (sessionUrl) {
						guestLoginCaptchaSessionUrl = sessionUrl;
					}
					var wrap = document.getElementById("guest-login-captcha-wrap");
					var keyInput = document.getElementById("guest_login_captcha_key");

					if (wrap) {
						wrap.style.display = guestLoginCaptchaRequired ? "block" : "none";
					}

					if (keyInput) {
						keyInput.value = "";
						keyInput.required = guestLoginCaptchaRequired;
					}

					if (guestLoginCaptchaRequired) {
						refreshGuestCaptchaImage(imageUrl, sessionUrl);
					}
				}

				function executePendingGuestAction() {
					if (!pendingGuestForm || !pendingGuestAction) {
						return;
					}

					if (pendingGuestAction === "cart") {
						$.post("./itemcart.php", $(pendingGuestForm).serialize(), function(error) {
							if (error != "OK") {
								alert(error.replace(/\\n/g, "\n"));
								return;
							}

							document.location.href = "./cart.php";
						});
					} else if (pendingGuestAction === "buy") {
						pendingGuestForm.submit();
					}
				}

				function submitGuestLoginLayerForm(ev) {
					if (ev) ev.preventDefault();

					var idInput = document.getElementById("guest_login_mb_id");
					var pwInput = document.getElementById("guest_login_mb_password");
					var autoInput = document.getElementById("guest_login_auto_login");
					var captchaInput = document.getElementById("guest_login_captcha_key");
					var submitBtn = document.getElementById("guest-login-submit-btn");
					if (!idInput || !pwInput) return false;

					var mbId = (idInput.value || "").trim();
					var mbPassword = (pwInput.value || "").trim();
					var captchaKey = captchaInput ? (captchaInput.value || "").trim() : "";
					var autoLogin = autoInput && autoInput.checked ? 1 : 0;

					if (!mbId || !mbPassword) {
						setGuestLoginStatus("회원아이디와 비밀번호를 입력해 주세요.", true);
						return false;
					}

					if (guestLoginCaptchaRequired && !captchaKey) {
						setGuestLoginStatus("자동등록방지 숫자를 입력해 주세요.", true);
						return false;
					}

					if (submitBtn) submitBtn.disabled = true;
					setGuestLoginStatus("로그인 확인 중입니다...", false);

					$.ajax({
						url: "<?php echo G5_BBS_URL; ?>/ajax.layer_login.php",
						type: "POST",
						dataType: "json",
						data: {
							mb_id: mbId,
							mb_password: mbPassword,
							captcha_key: captchaKey,
							auto_login: autoLogin
						}
					}).done(function(res) {
						if (!res || !res.ok) {
							var remaining = (res && typeof res.remaining_attempts !== "undefined") ? parseInt(res.remaining_attempts, 10) : guestLoginMaxAttempts;
							if (isNaN(remaining)) remaining = guestLoginMaxAttempts;

							var msg = (res && res.message) ? res.message : "로그인에 실패했습니다. 아이디 또는 비밀번호를 확인해 주세요.";
							if (remaining > 0) {
								msg += "\n남은 시도 " + remaining + "회";
							}
							setGuestLoginStatus(msg, true);
							setGuestLoginCaptchaRequired(!!(res && res.captcha_required), res && res.captcha_image_url ? res.captcha_image_url : "", res && res.captcha_session_url ? res.captcha_session_url : "");
							setGuestLoginFormLocked(false);
							return;
						}

						setGuestLoginStatus("로그인에 성공했습니다. 주문을 계속 진행합니다.", false);
						if (typeof g5_is_member !== "undefined") {
							g5_is_member = true;
						}
						closeGuestLoginLayer();
						executePendingGuestAction();
					}).fail(function() {
						setGuestLoginStatus("로그인 요청 중 오류가 발생했습니다. 잠시 후 다시 시도해 주세요.", true);
					}).always(function() {
						if (submitBtn && !submitBtn.disabled) {
							submitBtn.disabled = false;
						} else if (submitBtn) {
							var idDisabled = idInput && idInput.disabled;
							if (!idDisabled) {
								submitBtn.disabled = false;
							}
						}
					});

					return false;
				}

				function openGuestLoginLayer(message, subMessage) {
					var modal = document.getElementById("guest-login-required-modal");
					if (!modal) return;

					var messageEl = document.getElementById("guest-login-required-message");
					var subMessageEl = document.getElementById("guest-login-required-submessage");
					if (messageEl) {
						messageEl.textContent = message || "회원이시라면 로그인하신 후에 주문하여 주십시오.";
					}
					if (subMessageEl) {
						subMessageEl.textContent = subMessage || "비회원은 상품을 구입할 수 있는 권한이 없습니다.";
					}
					setGuestLoginStatus("", false);
					setGuestLoginFormLocked(false);
					setGuestLoginCaptchaRequired(false, "");

					modal.classList.add("is-open");
					document.body.classList.add("lnb-modal-open");

					var idInput = document.getElementById("guest_login_mb_id");
					var pwInput = document.getElementById("guest_login_mb_password");
					if (pwInput) {
						pwInput.value = "";
					}
					if (idInput) {
						idInput.focus();
					}
				}

				function closeGuestLoginLayer() {
					var modal = document.getElementById("guest-login-required-modal");
					if (!modal) return;
					modal.classList.remove("is-open");
					document.body.classList.remove("lnb-modal-open");
				}

				document.addEventListener("keydown", function(ev) {
					if (ev.key === "Escape") {
						closeShopActionConfirm();
						closeGuestLoginLayer();
					}
				});

				// 바로구매, 장바구니 폼 전송
				function fitem_submit(f) {

					f.action = "<?php echo $action_url; ?>";
					f.target = "";

					if (document.pressed == "장바구니") {
						f.sw_direct.value = 0;
					} else { // 바로구매
						f.sw_direct.value = 1;
					}

					// 판매가격이 0 보다 작다면
					if (document.getElementById("it_price").value < 0) {
						alert("전화로 문의해 주시면 감사하겠습니다.");
						return false;
					}

					if($(".it_opt_list").length < 1) {
						alert("선택옵션을 선택해 주십시오.");
						return false;
					}

					var result = true;
					var sum_qty = 0;
					var min_qty = parseInt(<?php echo (int)apms_buy_qty_to_hours($it['it_buy_min_qty']); ?>, 10);
					var max_qty = parseInt(<?php echo (int)apms_buy_qty_to_hours($it['it_buy_max_qty']); ?>, 10);
					if (isNaN(min_qty) || min_qty < 1) min_qty = 1;

					$("#it_sel_option li").each(function() {
						var $li = $(this);
						var day = parseInt($li.find("input[name^='ct_qty']").val(), 10);
						var hour = parseInt($li.find("input[name^='ct_qty_hour']").val(), 10);
						if (isNaN(day) || day < 0) day = 0;
						if (isNaN(hour) || hour < 0) hour = 0;
						if (hour > 23) hour = 23;

						var totalHours = (day * 24) + hour;
						if (totalHours < 1) {
							alert("계약일수와 계약시간이 모두 0입니다.\n주문은 최소 1시간 이상이어야 합니다!");
							result = false;
							return false;
						}

						sum_qty += totalHours;
					});

					if(!result) {
						return false;
					}

					if(min_qty > 0 && sum_qty < min_qty) {
						alert("계약시간 총합은 "+number_format(String(min_qty))+"시간 이상으로 주문해 주십시오.");
						return false;
					}

					if(max_qty > 0 && sum_qty > max_qty) {
						alert("계약시간 총합은 "+number_format(String(max_qty))+"시간 이하로 주문해 주십시오.");
						return false;
					}

					if (!g5_is_member) {
						pendingGuestForm = f;
						pendingGuestAction = (document.pressed == "장바구니") ? "cart" : "buy";
						openGuestLoginLayer(
							"회원이시라면 로그인하신 후에 주문하여 주십시오.",
							"비회원은 상품을 구입할 수 있는 권한이 없습니다."
						);
						return false;
					}

					if (document.pressed == "장바구니") {
						$.post("./itemcart.php", $(f).serialize(), function(error) {
							if(error != "OK") {
								alert(error.replace(/\\n/g, "\n"));
								return false;
							} else {
								openShopActionConfirm(
									"장바구니",
									"장바구니에 담겼습니다.",
									"바로 확인하시겠습니까?",
									"확인",
									"취소",
									function() {
										document.location.href = "./cart.php";
									}
								);
							}
						});
						return false;
					} else {
						return true;
					}
				}

				// Wishlist
				function apms_wishlist(it_id) {
					if(!it_id) {
						alert("코드가 올바르지 않습니다.");
						return false;
					}

					$.post("./itemwishlist.php", { it_id: it_id },	function(error) {
						if(error != "OK") {
							alert(error.replace(/\\n/g, "\n"));
							return false;
						} else {
							openShopActionConfirm(
								"위시리스트",
								"위시리스트에 담겼습니다.",
								"바로 확인하시겠습니까?",
								"확인",
								"취소",
								function() {
									document.location.href = "./wishlist.php";
								}
							);
						}
					});

					return false;
				}

				// Recommend
				function apms_recommend(it_id, ca_id) {
					if (!g5_is_member) {
						alert("회원만 추천하실 수 있습니다.");
					} else {
						url = "./itemrecommend.php?it_id=" + it_id + "&ca_id=" + ca_id;
						opt = "scrollbars=yes,width=616,height=420,top=10,left=10";
						popup_window(url, "itemrecommend", opt);
					}
				}
			</script>

			<style>
				.guest-login-layer {
					position: fixed;
					inset: 0;
					z-index: 10050;
					display: none;
				}
				.guest-login-layer.is-open {
					display: block;
				}
				.guest-login-layer .guest-login-backdrop {
					position: absolute;
					inset: 0;
					background: rgba(15, 23, 42, 0.52);
				}
				.guest-login-layer .guest-login-dialog {
					position: relative;
					max-width: 460px;
					width: calc(100% - 24px);
					margin: 10vh auto 0;
					background: #fff;
					border-radius: 14px;
					box-shadow: 0 22px 48px rgba(2, 6, 23, 0.28);
					overflow: hidden;
				}
				.guest-login-layer .guest-login-head {
					padding: 16px 18px;
					border-bottom: 1px solid #eef2f7;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}
				.guest-login-layer .guest-login-head strong {
					font-size: 19px;
					font-weight: 800;
					color: #111827;
				}
				.guest-login-layer .guest-login-close {
					background: transparent;
					border: 0;
					font-size: 22px;
					line-height: 1;
					color: #6b7280;
				}
				.guest-login-layer .guest-login-body {
					padding: 18px;
				}
				.guest-login-layer .guest-login-message {
					font-size: 17px;
					font-weight: 700;
					color: #111827;
					line-height: 1.45;
					margin-bottom: 4px;
				}
				.guest-login-layer .guest-login-submessage {
					font-size: 15px;
					color: #374151;
					line-height: 1.5;
					margin-bottom: 14px;
				}
				.guest-login-layer .guest-login-status {
					display: none;
					margin-bottom: 10px;
					font-size: 13px;
					line-height: 1.45;
					white-space: pre-line;
					padding: 8px 10px;
					border-radius: 8px;
				}
				.guest-login-layer .guest-login-status.is-error {
					background: #fef2f2;
					color: #b91c1c;
					border: 1px solid #fecaca;
				}
				.guest-login-layer .guest-login-status.is-info {
					background: #eff6ff;
					color: #1d4ed8;
					border: 1px solid #bfdbfe;
				}
				.guest-login-layer .guest-login-form .input-group {
					width: 100%;
					margin-bottom: 10px;
				}
				.guest-login-layer .guest-login-form .input-group-addon {
					width: 46px;
					background: #f3f4f6;
					border-color: #d1d5db;
					color: #6b7280;
				}
				.guest-login-layer .guest-login-form .form-control {
					height: 44px;
					border-color: #d1d5db;
					box-shadow: none;
				}
				.guest-login-layer .guest-login-form .btn-login-submit {
					width: 100%;
					height: 46px;
					margin-top: 2px;
					border: 0;
					border-radius: 8px;
					background: #2f3b4a;
					color: #fff;
					font-size: 16px;
					font-weight: 700;
				}
				.guest-login-layer .guest-login-form .guest-login-auto {
					margin: 12px 0 8px;
					font-size: 15px;
					color: #4b5563;
					display: flex;
					align-items: center;
					gap: 6px;
				}
				.guest-login-layer .guest-login-form .guest-login-auto input {
					margin: 0;
				}
				.guest-login-layer .guest-login-foot {
					padding: 0 18px 18px;
					display: flex;
					justify-content: flex-end;
				}
				.guest-login-layer .guest-login-close-btn {
					border: 1px solid #d1d5db;
					background: #fff;
					color: #374151;
					border-radius: 999px;
					padding: 8px 16px;
					font-weight: 600;
				}
			</style>

			<div id="shop-action-modal" class="lnb-logout-modal" aria-hidden="true">
				<div class="lnb-logout-backdrop" onclick="closeShopActionConfirm()"></div>
				<div class="lnb-logout-dialog" role="dialog" aria-modal="true" aria-labelledby="shop-action-title">
					<div class="lnb-logout-head">
						<strong id="shop-action-title">알림</strong>
					</div>
					<div class="lnb-logout-body">
						<div id="shop-action-message"></div>
						<span id="shop-action-submessage" style="display:block; margin-top:8px;"></span>
					</div>
					<div class="lnb-logout-foot">
						<button type="button" class="lnb-btn-confirm" id="shop-action-confirm-btn" onclick="doShopActionConfirm()">확인</button>
						<button type="button" class="lnb-btn-cancel" id="shop-action-cancel-btn" onclick="closeShopActionConfirm()">취소</button>
					</div>
				</div>
			</div>

			<div id="guest-login-required-modal" class="guest-login-layer" aria-hidden="true">
				<div class="guest-login-backdrop" onclick="closeGuestLoginLayer()"></div>
				<div class="guest-login-dialog" role="dialog" aria-modal="true" aria-labelledby="guest-login-required-message">
					<div class="guest-login-head">
						<strong>로그인 안내</strong>
						<button type="button" class="guest-login-close" onclick="closeGuestLoginLayer()" aria-label="닫기">&times;</button>
					</div>
					<div class="guest-login-body">
						<div id="guest-login-required-message" class="guest-login-message">회원이시라면 로그인하신 후에 주문하여 주십시오.</div>
						<div id="guest-login-required-submessage" class="guest-login-submessage">비회원은 상품을 구입할 수 있는 권한이 없습니다.</div>
						<div id="guest-login-required-status" class="guest-login-status"></div>

						<form action="#" method="post" class="guest-login-form" autocomplete="off" onsubmit="return submitGuestLoginLayerForm(event);">
							<input type="hidden" name="url" value="<?php echo htmlspecialchars(G5_SHOP_URL.'/item.php?it_id='.$it['it_id'].'&ca_id='.$ca_id, ENT_QUOTES); ?>">
							<div class="input-group">
								<span class="input-group-addon"><i class="fa fa-user"></i></span>
								<input type="text" name="mb_id" id="guest_login_mb_id" class="form-control" maxlength="32" placeholder="아이디 또는 이메일" required>
							</div>
							<div class="input-group">
								<span class="input-group-addon"><i class="fa fa-lock"></i></span>
								<input type="password" name="mb_password" id="guest_login_mb_password" class="form-control" maxlength="32" placeholder="비밀번호" required>
							</div>
							<div id="guest-login-captcha-wrap" style="display:none; margin-bottom:10px;">
								<div style="display:flex; align-items:center; gap:8px; margin-bottom:8px;">
									<img id="guest-login-captcha-image" src="<?php echo G5_CAPTCHA_URL; ?>/kcaptcha_image.php" alt="자동등록방지" style="height:42px; border:1px solid #d1d5db; border-radius:6px;">
									<button type="button" class="btn btn-default btn-sm" onclick="refreshGuestCaptchaImage()">새로고침</button>
								</div>
								<input type="text" name="captcha_key" id="guest_login_captcha_key" class="form-control" maxlength="6" placeholder="자동등록방지 숫자 입력" inputmode="numeric" pattern="[0-9]*">
							</div>
							<label class="guest-login-auto" for="guest_login_auto_login">
								<input type="checkbox" name="auto_login" value="1" id="guest_login_auto_login">
								자동로그인 및 로그인 상태 유지
							</label>
							<input type="submit" class="btn-login-submit" id="guest-login-submit-btn" value="Login">
						</form>
					</div>
					<div class="guest-login-foot">
						<button type="button" class="guest-login-close-btn" onclick="closeGuestLoginLayer()">로그인 없이 닫기</button>
					</div>
				</div>
			</div>

			<div class="pull-right">
				<?php // 소셜정보 SNS 표시안함 include_once(G5_SNS_PATH."/item.sns.skin.php"); ?>
			</div>
			<div class="clearfix"></div>

			<?php if ($is_tag) { // 태그 ?>
				<p class="item-tag"><i class="fa fa-tags"></i> <?php echo $tag_list;?></p>
			<?php } ?>

			</div>
		</div>
	</div>
</div>

<?php if($is_viewer || $is_link) {
	// 보기용 첨부파일 확장자에 따른 FA 아이콘 - array(이미지, 비디오, 오디오, PDF)
	$viewer_fa = array("picture-o", "video-camera", "music", "file-powerpoint-o");
?>
	<?php echo apms_line('fa', 'fa-gift'); //라인 ?>

	<div class="item-view-box">
		<?php if($is_link) { ?>
			<?php for($i=0; $i < count($link); $i++) { ?>
				<a href="<?php echo $link[$i]['url']; ?>" target="_blank" class="at-tip" title="<?php echo ($link[$i]['name']) ? $link[$i]['name'] : '관련링크'; ?>"><i class="fa fa-<?php echo ($link[$i]['fa']) ? $link[$i]['fa'] : 'link';?>"></i></a>
			<?php } ?>
		<?php } ?>

		<?php if($is_viewer) { ?>
			<?php for($i=0; $i < count($viewer); $i++) { $v = ($viewer[$i]['ext'] - 1); ?>
				<?php if($viewer[$i]['href_view']) { ?>
					<a href="<?php echo $viewer[$i]['href_view'];?>" class="view_win at-tip" title="<?php echo ($viewer[$i]['free']) ? '무료보기' : '바로보기';?>">
				<?php } else { ?>
					<a onclick="alert('구매한 회원만 볼 수 있습니다.');" class="at-tip" title="유료보기">
				<?php } ?>
					<i class="fa fa-<?php echo $viewer_fa[$v];?>"></i>
				</a>
			<?php } ?>
		<?php } ?>
		<script>
			var view_win = function(href) {
				var new_win = window.open(href, 'view_win', 'left=0,top=0,width=640,height=480,toolbar=0,location=0,scrollbars=0,resizable=1,status=0,menubar=0');
				new_win.focus();
			}
			$(function() {
				$(".view_win").click(function() {
					view_win(this.href);
					return false;
				});
			});
		</script>
	</div>
<?php } ?>

<?php // 비디오
	$item_video = apms_link_video($link_video);
	if($item_video) {
		echo apms_line('fa', 'fa-video-camera');
		echo $item_video;
	}
?>

<?php if($is_download) { // 다운로드 ?>
	<?php echo apms_line('fa', 'fa-download'); // 라인 ?>
	<div class="panel panel-default">
		<div class="panel-heading">
			<h3 class="panel-title"><i class="fa fa-download"></i> Download</h3>
		</div>
		<div class="list-group">
			<?php for($i=0; $i < count($download); $i++) { ?>
				<a class="list-group-item break-word" href="<?php echo ($download[$i]['href']) ? $download[$i]['href'] : 'javascript:alert(\'구매한 회원만 다운로드할 수 있습니다.\');';?>">
					<?php if($download[$i]['free']) { ?>
						<?php if($download[$i]['guest_use']) { ?>
							<span class="label label-default label-item pull-right"><span class="font-11 en">Free</span></span>
						<?php } else { ?>
							<span class="label label-primary label-item pull-right"><span class="font-11 en">Join</span></span>
						<?php } ?>
					<?php } else { ?>
						<span class="label label-danger label-item pull-right"><span class="font-11 en">Paid</span></span>
					<?php } ?>
					<i class="fa fa-download"></i> <?php echo $download[$i]['source'];?> (<?php echo $download[$i]['size'];?>)
				</a>
			<?php } ?>
			<?php if($i && $is_remaintime) { //이용기간 안내
				$remain_day = (int)(($is_remaintime - G5_SERVER_TIME) / 86400); //남은일수
			?>
				<a class="list-group-item" href="#">
					<i class="fa fa-bell"></i> <?php echo date("Y.m.d H:i", $is_remaintime);?>(<?php echo number_format($remain_day);?>일 남음)까지 이용가능합니다.
				</a>
			<?php } ?>
		</div>
	</div>
<?php } ?>

<?php if ($is_torrent) { // 토렌트 파일정보 ?>
	<?php echo apms_line('fa', 'fa-cube'); // 라인 ?>
	<?php for($i=0; $i < count($torrent); $i++) { ?>
		<div class="panel panel-default">
			<div class="panel-heading">
				<h3 class="panel-title"><i class="fa fa-cube"></i> <?php echo $torrent[$i]['name'];?></h3>
			</div>
			<div class="panel-body">
				<span class="pull-right hidden-xs text-muted en font-11"><i class="fa fa-clock-o"></i> <?php echo date("Y-m-d H:i", $torrent[$i]['date']);?></span>
				<?php if ($torrent[$i]['is_size']) { ?>
						<b class="en font-16"><i class="fa fa-cube"></i> <?php echo $torrent[$i]['info']['name'];?> (<?php echo $torrent[$i]['info']['size'];?>)</b>
				<?php } else { ?>
					<p><b class="en font-16"><i class="fa fa-cubes"></i> Total <?php echo $torrent[$i]['info']['total_size'];?></b></p>
					<div class="text-muted font-12">
						<?php for ($j=0;$j < count($torrent[$i]['info']['file']);$j++) {
							echo ($j + 1).'. '.implode(', ', $torrent[$i]['info']['file'][$j]['name']).' ('.$torrent[$i]['info']['file'][$j]['size'].')<br>'."\n";
						} ?>
					</div>
				<?php } ?>
			</div>
			<ul class="list-group">
				<li class="list-group-item en font-14 break-word"><i class="fa fa-magnet"></i> <?php echo $torrent[$i]['magnet'];?></li>
				<li class="list-group-item break-word">
					<div class="text-muted" style="font-size:12px;">
						<?php for ($j=0;$j < count($torrent[$i]['tracker']);$j++) { ?>
							<i class="fa fa-tags"></i> <?php echo $torrent[$i]['tracker'][$j];?><br>
						<?php } ?>
					</div>
				</li>
				<?php if($torrent[$i]['comment']) { ?>
					<li class="list-group-item en font-14 break-word"><i class="fa fa-bell"></i> <?php echo $torrent[$i]['comment'];?></li>
				<?php } ?>
			</ul>
		</div>
	<?php } ?>
<?php } ?>

<?php echo apms_line('fa'); // 라인 ?>

<div class="item-explan">
	<?php if ($it['pt_explan']) { // 구매회원에게만 추가로 보이는 상세설명 ?>
		<div class="well"><?php echo apms_explan($it['pt_explan']); ?></div>
	<?php } ?>
	<?php echo apms_explan($it['it_explan']); ?>
</div>

<?php if ($is_good) { // 추천 ?>
	<div class="item-good-box">
		<span class="item-good">
			<a href="#" onclick="apms_good('<?php echo $it_id;?>', '', 'good', 'it_good'); return false;">
				<b id="it_good"><?php echo number_format($it['pt_good']) ?></b>
				<br>
				<i class="fa fa-thumbs-up"></i>
			</a>
		</span>
		<span class="item-nogood">
			<a href="#" onclick="apms_good('<?php echo $it_id;?>', '', 'nogood', 'it_nogood'); return false;">
				<b id="it_nogood"><?php echo number_format($it['pt_nogood']) ?></b>
				<br>
				<i class="fa fa-thumbs-down"></i>
			</a>
		</span>
	</div>
<?php } ?>

<?php if ($is_ccl) { // CCL ?>
	<div class="h20"></div>
	<div class="well">
		<img src="<?php echo $ccl_img;?>" alt="CCL" />  &nbsp; 본 자료는 <u><?php echo $ccl_license;?></u>에 따라 이용할 수 있습니다.
	</div>
<?php } ?>

<?php if($is_seller && $wset['seller']) { // 판매자 ?>
	<div class="panel panel-default item-seller">
		<div class="panel-heading">
			<h3 class="panel-title">
				<?php if($author['partner']) { ?>
					<a href="<?php echo $at_href['myshop'];?>?id=<?php echo $author['mb_id'];?>" class="pull-right">
						<span class="label label-primary"><span class="font-11 en">마이샵</span></span>
					</a>
				<?php } ?>
				Seller
			</h3>
		</div>
		<div class="panel-body">
			<div class="pull-left text-center auth-photo">
				<div class="img-photo">
					<?php echo ($author['photo']) ? '<img src="'.$author['photo'].'" alt="">' : '<i class="fa fa-user"></i>'; ?>
				</div>
				<div class="btn-group" style="margin-top:-30px;white-space:nowrap;">
					<button type="button" class="btn btn-color btn-sm" onclick="apms_like('<?php echo $author['mb_id'];?>', 'like', 'it_like'); return false;" title="Like">
						<i class="fa fa-thumbs-up"></i> <span id="it_like"><?php echo number_format($author['liked']) ?></span>
					</button>
					<button type="button" class="btn btn-color btn-sm" onclick="apms_like('<?php echo $author['mb_id'];?>', 'follow', 'it_follow'); return false;" title="Follow">
						<i class="fa fa-users"></i> <span id="it_follow"><?php echo $author['followed']; ?></span>
					</button>
				</div>
			</div>
			<div class="auth-info">
				<div style="margin-bottom:4px;">
					<span class="pull-right">Lv.<?php echo $author['level'];?></span>
					<b><?php echo $author['name']; ?></b> &nbsp;<span class="text-muted font-11"><?php echo $author['grade'];?></span>
				</div>
				<div class="div-progress progress progress-striped no-margin">
					<div class="progress-bar progress-bar-exp" role="progressbar" aria-valuenow="<?php echo round($author['exp_per']);?>" aria-valuemin="0" aria-valuemax="100" style="width: <?php echo round($author['exp_per']);?>%;">
						<span class="sr-only"><?php echo number_format($author['exp']);?> (<?php echo $author['exp_per'];?>%)</span>
					</div>
				</div>
				<p style="margin-top:10px;">
					<?php echo ($author['signature']) ? $author['signature'] : '등록된 서명이 없습니다.'; ?>
				</p>
			</div>
			<div class="clearfix"></div>
		</div>
	</div>
<?php } ?>

<?php if ($is_relation) { ?>
	<div class="div-title-wrap">
		<div class="div-title" style="line-height:30px;">
			<i class="fa fa-cubes fa-lg lightgray"></i> <b>관련아이템</b>
		</div>
		<div class="div-sep-wrap">
			<div class="div-sep sep-bold"></div>
		</div>
	</div>
	<?php include_once('./itemrelation.php'); ?>
<?php } ?>

<?php // 위젯에서 해당글 클릭시 이동위치 : icv - 댓글, iuv - 후기, iqv - 문의 ?>
<div id="item-tab" class="div-tab tabs<?php echo ($wset['tabline']) ? '' : ' trans-top';?>">
	<ul class="nav nav-tabs nav-justified">
		<li class="active"><a href="#item-review" data-toggle="tab"><b>후기글<?php echo $it_use_cnt;?></b></a></li>
		<li><a href="#item-qa" data-toggle="tab"><b>문의글<?php echo $it_qa_cnt;?></b></a></li>
		<?php if($is_comment) { // 댓글 ?>
			<li><a href="#item-cmt" data-toggle="tab"><b>댓글<?php echo $it_comment_cnt;?></b></a></li>
		<?php } ?>
		<?php if($is_ii) { // 상품정보고시 ?>
			<li><a href="#item-info" data-toggle="tab"><b>필수표기정보</b></a></li>
		<?php } ?>
		<li><a href="#item-delivery" data-toggle="tab"><b>배송/교환/반품</b></a></li>
	</ul>
	<div class="tab-content" style="border:0px; padding:20px 0px;">
		<div class="tab-pane active" id="item-review">
			<div id="iuv"></div>
			<div id="itemuse">
				<?php include_once('./itemuse.php'); ?>
			</div>
		</div>
		<div class="tab-pane" id="item-qa">
			<div id="iqv"></div>
			<div id="itemqa">
				<?php include_once('./itemqa.php'); ?>
			</div>
		</div>
		<?php if($is_comment) { // 댓글 ?>
			<div class="tab-pane" id="item-cmt">
				<div id="icv"></div>
				<?php include_once('./itemcomment.php'); ?>
			</div>
		<?php } ?>
		<?php if($is_ii) { // 상품정보고시 ?>
			<div class="tab-pane" id="item-info">

				<div class="tbox-head no-line">
					<i class="fa fa-check-square fa-lg lightgray"></i> 상품요약정보 : <?php echo $item_info[$gubun]['title']; ?>
				</div>
				<div class="tbox-body">
					<div class="table-responsive">
						<table class="div-table table top-border">
						<caption>상품정보고시</caption>
						<tbody>
							<?php for($i=0; $i < count($ii); $i++) { ?>
								<tr>
									<th><?php echo $ii[$i]['title']; ?></th>
									<td><?php echo $ii[$i]['value']; ?></td>
								</tr>
							<?php } ?>
						</tbody>
						</table>
					</div>
				</div>

				<div class="tbox-head no-line">
					<i class="fa fa-check-square fa-lg lightgray"></i> 거래조건에 관한 정보
				</div>
				<div class="tbox-body">
					<div class="table-responsive">
						<table class="div-table table top-border">
						<caption>거래조건</caption>
						<tbody>
							<tr>
								<th>재화 등의 배송방법에 관한 정보</th>
								<td>상품 상세설명페이지 참고</td>
							</tr>
							<tr>
								<th>주문 이후 예상되는 배송기간</th>
								<td>상품 상세설명페이지 참고</td>
							</tr>
							<tr>
								<th>제품하자가 아닌 소비자의 단순변심, 착오구매에 따른 청약철회 시 소비자가 부담하는 반품비용 등에 관한 정보</th>
								<td>배송ㆍ교환ㆍ반품 상세설명페이지 참고</td>
							</tr>
							<tr>
								<th>제품하자가 아닌 소비자의 단순변심, 착오구매에 따른 청약철회가 불가능한 경우 그 구체적 사유와 근거</th>
								<td>배송ㆍ교환ㆍ반품 상세설명페이지 참고</td>
							</tr>
							<tr>
								<th>재화등의 교환ㆍ반품ㆍ보증 조건 및 품질보증 기준</th>
								<td>소비자분쟁해결기준(공정거래위원회 고시) 및 관계법령에 따릅니다.</td>
							</tr>
							<tr>
								<th>재화등의 A/S 관련 전화번호</th>
								<td>상품 상세설명페이지 참고</td>
							</tr>
							<tr>
								<th>대금을 환불받기 위한 방법과 환불이 지연될 경우 지연에 따른 배상금을 지급받을 수 있다는 사실 및 배상금 지급의 구체적 조건 및 절차</th>
								<td>배송ㆍ교환ㆍ반품 상세설명페이지 참고</td>
							</tr>
							<tr>
								<th>소비자피해보상의 처리, 재화등에 대한 불만처리 및 소비자와 사업자 사이의 분쟁처리에 관한 사항</th>
								<td>소비자분쟁해결기준(공정거래위원회 고시) 및 관계법령에 따릅니다.</td>
							</tr>
							<tr>
								<th>거래에 관한 약관의 내용 또는 확인할 수 있는 방법</th>
								<td>상품 상세설명페이지 및 페이지 하단의 이용약관 링크를 통해 확인할 수 있습니다.</td>
							</tr>
						</tbody>
						</table>
					</div>
				</div>
			</div>
		<?php } ?>
		<div class="tab-pane" id="item-delivery">
			<?php include_once($item_skin_path.'/item.delivery.php'); ?>
		</div>
	</div>
</div>

<?php echo $it_tail_html; // 하단 HTML ?>

<div class="btn-group btn-group-justified">
	<?php if($prev_href) { ?>
		<a class="btn btn-<?php echo $btn1;?>" href="<?php echo $prev_href;?>" title="<?php echo $prev_item;?>"><i class="fa fa-chevron-circle-left"></i> 이전</a>
	<?php } ?>
	<?php if($next_href) { ?>
		<a class="btn btn-<?php echo $btn1;?>" href="<?php echo $next_href;?>" title="<?php echo $next_item;?>"><i class="fa fa-chevron-circle-right"></i> 다음</a>
	<?php } ?>
	<?php if($edit_href) { ?>
		<a class="btn btn-<?php echo $btn1;?>" href="<?php echo $edit_href;?>"><i class="fa fa-plus"></i><span class="hidden-xs"> 수정</span></a>
	<?php } ?>
	<?php if ($write_href) { ?>
		<a class="btn btn-<?php echo $btn1;?>" href="<?php echo $write_href;?>"><i class="fa fa-upload"></i><span class="hidden-xs"> 등록</span></a>
	<?php } ?>
	<?php if($item_href) { ?>
		<a class="btn btn-<?php echo $btn1;?>" href="<?php echo $item_href;?>"><i class="fa fa-th-large"></i><span class="hidden-xs"> 관리</span></a>
	<?php } ?>
	<?php if($setup_href) { ?>
		<a class="btn btn-<?php echo $btn1;?> win_memo" href="<?php echo $setup_href;?>"><i class="fa fa-cogs"></i><span class="hidden-xs"> 스킨설정</span></a>
	<?php } ?>
	<a class="btn btn-<?php echo $btn2;?>" href="<?php echo $list_href;?>"><i class="fa fa-bars"></i> 목록</a>
</div>

<div class="h30"></div>

<script>
$(function() {
	$("a.view_image").click(function() {
		window.open(this.href, "large_image", "location=yes,links=no,toolbar=no,top=10,left=10,width=10,height=10,resizable=yes,scrollbars=no,status=no");
		return false;
	});

	function syncItemDetailHeights() {
		var isMobile = window.matchMedia('(max-width: 767px)').matches;
		var $leftImage = $('.item-head .item-image');
		var $rightCard = $('.item-head .item-summary-card');
		var $leftCol = $('.item-head .row > .col-sm-6').eq(0);
		var $rightCol = $('.item-head .row > .col-sm-6').eq(1);
		var $overlay = $('.item-head .overlay-table');
		var $overlayTable = $('.item-head .overlay-table table');

		if (!$leftImage.length || !$rightCard.length) return;

		if (isMobile) {
			$leftImage.css('min-height', '');
			$leftCol.css('min-height', '');
			$rightCol.css('min-height', '');
			return;
		}

		var rightHeight = Math.ceil($rightCol.outerHeight());
		var overlayNeedHeight = 0;
		if ($overlay.length && $overlayTable.length) {
			var overlayPaddingTop = parseInt($overlay.css('padding-top'), 10) || 0;
			var overlayPaddingBottom = parseInt($overlay.css('padding-bottom'), 10) || 0;
			overlayNeedHeight = Math.ceil($overlayTable.outerHeight() + overlayPaddingTop + overlayPaddingBottom + 8);
		}

		var targetHeight = Math.max(rightHeight, overlayNeedHeight);
		if (targetHeight > 0) {
			$leftCol.css('min-height', targetHeight + 'px');
			$leftImage.css('min-height', targetHeight + 'px');
		}
	}

	syncItemDetailHeights();
	$(window).on('load resize', syncItemDetailHeights);
});
</script>

<?php include_once('./itemlist.php'); // 분류목록 ?>
