<?
include_once $_SERVER[DOCUMENT_ROOT] . "/module/board/board.lib.php";

//DB연결
$dblink = SetConn($_conf_db["main_db"]);

//전체 카테고리 가져오기
$arrAllCategory = getCategoryAll();

//현재 상품정보 가져오기
if($_REQUEST[idx]){
	$arrInfo = getGoodInfo(mysql_real_escape_string($_REQUEST[idx]));
}else{
	$arrInfo = getGoodInfoGcode(mysql_real_escape_string($_REQUEST[g_code]));
}

//카테고리 정보
$arrCatCode = explode("/", $arrInfo["list"][0]["cat_code"]);

//서브 카테고리 목록
$categorySubList = getCategoryList(mysql_real_escape_string($arrCatCode[0]));

//존재여부 검사
if($arrInfo["total"]==0){
	jsMsg("존재하지 않는 상품입니다.");
	jsHistory();
}

//진열여부 검사
if($arrInfo["list"][0][is_show]=="N"){
	jsMsg("진열중인 상품이 아닙니다.");
	jsHistory();
}

//상품 조회수 증가
setGoodHitsUpdate($arrInfo["list"][0]["idx"]);

//DB해제
//SetDisConn($dblink);

//오늘본 상품 세션에 추가
if(is_array($_SESSION[$_SITE["DOMAIN"]]["SHOP"]["VIEW"])){
	if(!in_array(array($arrInfo["list"][0][idx],$arrInfo["list"][0][image_s]),$_SESSION[$_SITE["DOMAIN"]]["SHOP"]["VIEW"])){
		$_SESSION[$_SITE["DOMAIN"]]["SHOP"]["VIEW"][] = array($arrInfo["list"][0][idx],$arrInfo["list"][0][p_image]);
	}
	if(sizeof($_SESSION[$_SITE["DOMAIN"]]["SHOP"]["VIEW"]) > 20){
		array_shift($_SESSION[$_SITE["DOMAIN"]]["SHOP"]["VIEW"]);
	}
}else{
	$_SESSION[$_SITE["DOMAIN"]]["SHOP"]["VIEW"][] = array($arrInfo["list"][0][idx],$arrInfo["list"][0][p_image]);
}
?>
<script>
function incAmount(){
	var qty = document.frmGoodDetail.qty.value;
	document.frmGoodDetail.qty.value = ++qty;

	setOptPrice();
}

// 수량 감소
function decAmount(){
   var qty = document.frmGoodDetail.qty.value;
	if(qty > 1)
		document.frmGoodDetail.qty.value = --qty;

	setOptPrice();
}
</script>

<div class="contain">
	<div id="contentArea">
		<div class="sub-title">
			<h2><?=$arrAllCategory[$CateCode[0]]?></h2>
		</div>
		<div class="sub-menu">
			<?
			if ($categorySubList["total"] > 0) {
				for ($i = 0;$i < $categorySubList["total"];$i++) {
					$arrSubList = getGoodListBaseNFileFromCat($categorySubList["list"][$i]["cat_no"], $order_by, "", "", $scale, $_REQUEST[offset],"Y");
			?>
			<a href="/shop.php?goPage=GoodList&cat_no=<?=$categorySubList["list"][$i]["cat_no"]?>" class="<?=$cat_no==$categorySubList["list"][$i]["cat_no"]?"on":"";?>">
			<?=$categorySubList["list"][$i]["cat_name"]?> (<?=number_format($arrSubList["total"])?>)</a>
			<span class="var">|</span>
			<?}}?>
		</div>
		<form id="frmGoodDetail" name="frmGoodDetail">
		<input type="hidden" id="basicPrice" name="basicPrice" value="<?=$arrInfo["list"][0][price]?>">
		<input type="hidden" id="basicPoint" name="basicPoint" value="<?=$arrInfo["list"][0][point]?>">
		<div class="real-cont">
			<!--// content -->	
			<script type="text/javascript">
			/* 이미지 확대보기 - 새창 */
			function goZoom(idx){
			 w = 630;
			 h = 650;
			 x = (screen.availWidth - w) / 2;
			 y = (screen.availHeight - h) / 2;
			 window.open('../shop/zoom.php?idx='+idx+'', idx,'width='+w+', height='+h+', left='+x+', top='+y+', scrollbars=no');
			}
			/* 상품리뷰 - 새창 */
			function goReview(idx){
			 w = 780;
			 h = 750;
			 x = (screen.availWidth - w) / 2;
			 y = (screen.availHeight - h) / 2;
			 window.open('../shop/reviewForm.php?g_idx='+idx+'', 'reviewFrom','width='+w+', height='+h+', left='+x+', top='+y+', scrollbars=yes');
			}
			/* 상품문의 - 새창 */
			function goQna(idx){
			 w = 780;
			 h = 750;
			 x = (screen.availWidth - w) / 2;
			 y = (screen.availHeight - h) / 2;
			 window.open('../shop/qnaForm.php?g_idx='+idx+'', 'qnaFrom','width='+w+', height='+h+', left='+x+', top='+y+', scrollbars=yes');
			}
			/* 이미지 변환 */
			function OverImg(imageUrl)
			{
				if (document.images.overimage)
					document.images.overimage.src = imageUrl;
			}
			/* 상품문의/답변 */
			var faqAnswer = '';
			function faqDetail(trQna,tdQna) {
				if( faqAnswer != trQna && faqAnswer != tdQna ) {
					if( faqAnswer !='' ) {
						faqAnswer.style.display = 'none';
				}
				trQna.style.display = 'table-row';
				tdQna.style.display = 'table-cell';
				faqAnswer = trQna;
				} else {
					trQna.style.display = 'none';
					tdQna.style.display = 'none';
					faqAnswer = '';
				}
			}
			</script>
			<!--// 상품상세 상단 -->
			<div class="goods-summary">
				<div class="photo">
					<div class="img">
						<img src="/uploaded/shop_good/<?=$arrInfo["files"][0][b_idx]?>/<?=$arrInfo["files"][0][re_name]?>" name="overimage" width="448" height="298" alt="">		
					</div>	
					<div class="thumb">
						<ul>
							<?
							for($k=0;$k<$arrInfo["total_files"];$k++){
							?>
							<li><a href="javascript:;" onmouseover="OverImg('/uploaded/shop_good/<?=$arrInfo["files"][$k][b_idx]?>/<?=$arrInfo["files"][$k][re_name]?>')"><img src="/uploaded/shop_good/<?=$arrInfo["files"][$k][b_idx]?>/<?=$arrInfo["files"][$k][re_name]?>" width="48" height="32" alt=""></a></li>
							<?
							}
							?>
						</ul>
					</div>
				</div>			
				<div class="info">
					<h2 class="title">								
						<?=stripslashes($arrInfo["list"][0][g_name])?>
						<span>
							<?=stripslashes($arrInfo["list"][0][memo])?>
						</span>
					</h2>					
					<div class="table">
						<table>
							<colgroup>
								<col width="140">
								<col width="*">
							</colgroup>
							<tbody>
								<tr>
									<th scope="row">상품번호</th>
									<td><?=stripslashes($arrInfo["list"][0][g_code])?></td>
								</tr>
								<tr>
									<th scope="row">판매가</th>
									<td><span class="price"><?=number_format($arrInfo["list"][0][price])?>원</span></td>
								</tr>
								<tr>
									<th scope="row">제조사</th>
									<td><?=stripslashes($arrInfo["list"][0][madein])?></td>
								</tr>
								<tr>
									<th scope="row">원산지</th>
									<td><?=stripslashes($arrInfo["list"][0][vendor])?></td>
								</tr>
								<tr>
									<th scope="row">제조년도</th>
									<td><?=stripslashes($arrInfo["list"][0][etc_8])?></td>
								</tr>
								<tr>
									<th scope="row">배송비</th>
									<td>
										<?if($_SITE["SHOP"]["SHIP"]["DELIVERY_GB"]=="1"){?>
										<span class="delivery">무료배송</span>
										<?}else if($_SITE["SHOP"]["SHIP"]["DELIVERY_GB"]=="2"){?>
										<span class="delivery">수신자부담(착불)</span>
										<?}else if($_SITE["SHOP"]["SHIP"]["DELIVERY_GB"]=="3"){?>
										<span class="delivery"><?=number_format($_SITE["SHOP"]["SHIP"]["DEFAULT_PRICE"])?>원</span>
										<?}else if($_SITE["SHOP"]["SHIP"]["DELIVERY_GB"]=="4"){?>
										<span class="delivery"><?=number_format($_SITE["SHOP"]["SHIP"]["LOW_PRICE"])?>원</span> (<?=number_format($_SITE["SHOP"]["SHIP"]["FREE_PRICE"])?>만원 이상 무료배송)
										<?}?>
									</td>
								</tr>
								<tr>
									<th scope="row">보유수량</th>
									<td><?=number_format($arrInfo["list"][0][stock])?></td>
								</tr>
								<tr>
									<th scope="row"><label for="qty">수량</label></th>
									<td>
										<div class="qty-wrap">
											<input type="text" name="qty" id="qty" value="1" class="input">
											<span class="qty">
												<a href="javascript:incAmount();"><img src="../images/shop/qty_up.gif" alt="증가"></a>
												<a href="javascript:decAmount();"><img src="../images/shop/qty_down.gif" alt="감소"></a>
											</span>
										</div>
									</td>
								</tr>
								<? if($arrInfo["total_opt"] > 0){?>
								<? for($i=0;$i<$arrInfo["total_opt"];$i++){?>
								<tr>
									<th scope="col"><?=stripslashes($arrInfo["opt"][$i]["opt_1"])?></th>
									<td>
										<input type="hidden" id="opt_name_<?=$i?>" name="opt_name_<?=$i?>" value="<?=stripslashes($arrInfo["opt"][$i]["opt_1"])?>">
										<select id="opt_contents_<?=$i?>" name="opt_contents_<?=$i?>" onchange="setOptPrice();" class="select" style="width:180px;">
											<option value=""><?=stripslashes($arrInfo["opt"][$i]["opt_1"])?> 선택</option>
											<?
											for($j=0;$j<$arrInfo["total_opt_info"];$j++){
											if($arrInfo["opt"][$i]["opt_1"]==$arrInfo["opt_info"][$j]["opt_1"]){
											?>
											<option value="<?=$arrInfo["opt_info"][$j]["opt_1_value"]?>|<?=$arrInfo["opt_info"][$j]["price"]?>"><?=$arrInfo["opt_info"][$j]["opt_1_value"]?> <?if($arrInfo["opt_info"][$j]["price"]>0){?>(+<?=number_format($arrInfo["opt_info"][$j]["price"])?>)<?}?>
											<?if($arrInfo["opt_info"][$j]["price"]<0){?>(<?=number_format($arrInfo["opt_info"][$j]["price"])?>)<?}?></option>
											<?
											}
											}
											?>
										</select>
									</td>
								</tr>
								<?}}?>
								<!-- <tr>
									<th scope="row"><label for="opt1">옵션</label></th>
									<td>
										<select name="opt1" id="opt1" class="select" style="width:200px;">
											<option value="">선택하세요</option>
										</select>
									</td>
								</tr> -->
							</tbody>
						</table>
					</div>
					<dl class="total">
						<dt>총 상품금액</dt>
						<dd><span id="divPrice"><?=number_format($arrInfo["list"][0][price])?></span>원</dd>
					</dl>
					<div class="btn">
						<?if($arrInfo['list'][0]['stock_type']=="2" && $arrInfo['list'][0]['stock']<1){?>
						<span class="btn-pack xlarge dark">품절</span>
						<?}else{?>
						<a href="javascript:buyDirect('<?=$arrInfo["list"][0][idx]?>', document.frmGoodDetail.qty.value)"><img src="../images/shop/btn_buy.gif" alt="바로구매"></a>
						<a href="javascript:addCart('<?=$arrInfo["list"][0][idx]?>', document.frmGoodDetail.qty.value)"><img src="../images/shop/btn_cart.gif" alt="장바구니"></a>
						<a href="javascript:addWish('<?=$arrInfo["list"][0][idx]?>','<?=$_SERVER[REQUEST_URI]?>')"><img src="../images/shop/btn_wishlist.gif" alt="위시리스트"></a>
						<?}?>
					</div>

					<!-- // 네이버 페이 -->
				</div>
			</div>
			<!-- 상품상세 상단 //-->


			<!--// 상품상세설명 -->
			<div id="viewDetail">
				<div class="goods-view-tab">
					<ul>
						<li class="active"><a href="#viewDetail">상품상세정보</a></li>
						<li><a href="#viewInfo">교환/반품 안내</a></li>
						<li><a href="#viewReview">상품후기</a></li>
						<li><a href="#viewQna">상품문의</a></li>
					</ul>
				</div>
				<h4 class="goods-detail-tit">전자상거래 등에서의 상품정보제공 고시</h4>

				<?=stripslashes($arrInfo["list"][0][contents])?>
				<br>
			</div>			
			<!-- 상품상세설명 //-->
			
			<!--// 교환/반품 안내 -->
			<div id="viewInfo">
				<div class="goods-view-tab">
					<ul>
						<li><a href="#viewDetail">상품상세정보</a></li>
						<li class="active"><a href="#viewInfo">교환/반품 안내</a></li>
						<li><a href="#viewReview">상품후기</a></li>
						<li><a href="#viewQna">상품문의</a></li>
					</ul>
				</div>
				<div class="goods-sub-tit">
					<div class="tit">
						<h4>교환/반품 안내</h4>
					</div>
				</div>
				<div class="shop-guide">
					<table>
						<caption>교환/반품 안내</caption>
						<colgroup>
							<col>
							<col>
						</colgroup>
						<tbody>
							<tr>
								<th scope="row">교환/반품 비용</th>
								<td>- 왕복비용(단, 고객 변심의 경우에만 발생)<br>
								- 도서산간 및 일부 지역 추가비용 발생<br>
								- 부분반품 시, 남은 금액이 무료배송 조건을 유지하면 편도 배송비용만 부과</td>
							</tr>
							<tr>
								<th scope="row">교환/반품 신청 기준일</th>
								<td>- 단순변심에 의한 교환/반품은 상품 수령 후 7일 이내까지만 가능(배송비용과 교환/반품비용 왕복 배송비 고객부담)<br>
								- 상품의 내용이 표시‧광고의 내용과 다른 경우에는 상품을 수령한 날부터 3개월 이내, 그 사실을 안 날 또는 알 수 있었던 날부터<br>
								&nbsp;&nbsp; 30일이내에 청약철회 가능</td>
							</tr>
							<tr>
								<th scope="row">교환/반품 제한사항</th>
								<td>- 주문/제작 상품의 경우, 상품의 제작이 이미 진행된 경우<br>
								- 고객의 사용, 시간경과, 일부 소비에 의하여 상품의 가치가 현저히 감소한 경우<br>
								- 세트상품 일부 사용, 구성품을 분실하였거나 취급 부주의로 인한 파손/고장/오염으로 재판매 불가한 경우<br>
								- 모니터 해상도의 차이로 인해 색상이나 이미지가 실제와 달라, 고객이 단순 변심으로 교환/반품을 무료로 요청하는 경우</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
			<!-- 교환/반품 안내 //-->

			<!--// 상품후기 -->			
			<?
			//DB연결
			$dblink = SetConn($_conf_db["main_db"]);

			$boardid = "review";	
			$arrBoardInfo = getBoardInfo($_conf_tbl[board_info], mysql_real_escape_string($boardid));
			$_GET[sw]="e"; 
			if(!$_GET[sk]){$_GET[sk]=$arrInfo["list"][0]["idx"]; }
			$_REQUEST[g_idx] = $arrInfo["list"][0]["idx"];
			$arrBoardList = getBoardListBaseNFile($arrBoardInfo["list"][0]["boardid"], $_GET["category"], $_GET[sw], $_GET[sk], "999", $_GET[offset]);
			$pages=intval($arrBoardList["total"]/$arrBoardInfo["list"][0]["scale"]); 
			if ($arrBoardList["total"] % $arrBoardInfo["list"][0]["scale"]) { 
				$pages++; 
			} 
			
			if($_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"]){//회원로그인을 한 상태라면
				$arrOrderList = getOrderListCheck($_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"], $scale, $_REQUEST[offset],$_REQUEST[g_idx]);
			}
			?>
			<div id="viewReview">
				<div class="goods-view-tab">
					<ul>
						<li><a href="#viewDetail">상품상세정보</a></li>
						<li><a href="#viewInfo">교환/반품 안내</a></li>
						<li class="active"><a href="#viewReview">상품후기</a></li>
						<li><a href="#viewQna">상품문의</a></li>
					</ul>
				</div>

				<div class="goods-sub-tit">
					<div class="tit">
						<h4>상품후기</h4>
					</div>
					<div class="btn">
						<?if($arrOrderList["total"]>0){?>
						<a href="javascript:goReview(<?=$arrInfo["list"][0][idx]?>);" title="상품리뷰작성 - 새창열림" class="btn-pack small dark">후기 작성</a>
						<?}else{?>
						<span class="btn_pack medium"><a href="javascript:alert('구매완료하신 고객님만 작성하실 수 있습니다.');" title="상품리뷰작성 - 새창열림" class="btn-pack small dark">후기 작성</a></span>
						<?}?>
					</div>
				</div>

				<iframe src="/shop/_review.php?sw=<?=$_GET[sw]?>&sk=<?=$_GET[sk]?>&g_idx=<?=$_REQUEST[g_idx]?>" name="reviewFrame" id="reviewFrame" scrolling="no" frameborder="0" title="상품후기" width="100%"></iframe>
			</div>
			<!-- 상품후기 //-->



			<!--// 상품문의 -->			
			<?
			//DB연결
			$dblink = SetConn($_conf_db["main_db"]);

			$boardid = "shopqna";	
			$arrBoardInfo = getBoardInfo($_conf_tbl[board_info], mysql_real_escape_string($boardid));
			$_GET[sw]="e"; 
			if(!$_GET[sk]){$_GET[sk]=$arrInfo["list"][0]["idx"]; }
			$_REQUEST[g_idx] = $arrInfo["list"][0]["idx"];
			$arrBoardList = getBoardListBaseNMemoCnt($arrBoardInfo["list"][0]["boardid"], $_GET["category"], $_GET[sw], $_GET[sk], "999", $_GET[offset]);
			$pages=intval($arrBoardList["total"]/$arrBoardInfo["list"][0]["scale"]); 
			if ($arrBoardList["total"] % $arrBoardInfo["list"][0]["scale"]) { 
				$pages++; 
			} 
			
			if($_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"]){//회원로그인을 한 상태라면
				$arrOrderList = getOrderListCheck($_SESSION[$_SITE["DOMAIN"]]["MEMBER"]["ID"], $scale, $_REQUEST[offset],$_REQUEST[g_idx]);
			}
			?>
			<div id="viewQna">
				<div class="goods-view-tab">
					<ul>
						<li><a href="#viewDetail">상품상세정보</a></li>
						<li><a href="#viewInfo">교환/반품 안내</a></li>
						<li><a href="#viewReview">상품후기</a></li>
						<li class="active"><a href="#viewQna">상품문의</a></li>
					</ul>
				</div>

				<div class="goods-sub-tit">
					<div class="tit">
						<h4>상품문의</h4>
					</div>
					<div class="btn">
						<a href="javascript:goQna(<?=$arrInfo["list"][0][idx]?>);" title="상품문의작성 - 새창열림" class="btn-pack small dark">문의 작성</a>
					</div>
				</div>

				<iframe src="/shop/_qna.php?sw=<?=$_GET[sw]?>&sk=<?=$_GET[sk]?>&g_idx=<?=$_REQUEST[g_idx]?>" name="qnaFrame" id="qnaFrame" scrolling="no" frameborder="0" title="상품문의" width="100%"></iframe>
			</div>
			<!-- 상품문의 //-->



			<script type="text/javascript">
			var isIE = (navigator.appName == "Microsoft Internet Explorer");
			var isIE9 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 9") != -1);
			var isIE10 = (navigator.appVersion.indexOf("MSIE 10") !== -1);
			if (isIE && !isIE9 && !isIE10) {
				window.frames.qnaFrame.resizeParent();
				window.frames.reviewFrame.resizeParent();
			} else {
				//jQuery("#reviewFrame").attr("contentWindow").resizeParent();
				//jQuery("#qnaFrame").attr("contentWindow").resizeParent();
			}
			</script>

			<!-- content //-->
		</div>
		</form>
	</div>

<script type="text/javascript">
function resizeFrame(frm) {
 frm.style.height = "auto";
 contentHeight = frm.contentWindow.document.body.scrollHeight;
 frm.style.height = contentHeight + 200 + "px";
}
</script> 
<div style="display:none">
<iframe id="iframeHidden" name="iframeHidden" border="0" width="0" height="0"></iframe>
</div>
