<?php
	include $_SERVER['DOCUMENT_ROOT'].'/common/lib/comm.php';
	include $_SERVER['DOCUMENT_ROOT'].'/common/auth_chk.php';

	$MENU_ACTV = "1";	//set top nav
	$mode 				= "Step5";
	$s_cd_car = $_SESSION['s_cd_car'];
	$s_car_update_ing = $_SESSION['s_car_update_ing'];


//	Auth -> Step 단계에 따른 정상적인 요청 체크
	// if($mode != "Step2") {
	// 	AlertBack("지정되지 않은 요청입니다.");
	// }

//	$s_cd_sale = $_SESSION['s_cd_sale'];

	$sql ="SELECT *
		FROM car_master a
		WHERE  cd_car = '$s_cd_car' ";

	$col = mysql_fetch_array(mysql_query($sql, $connect));

	if (empty($col['cd_car'])){
		AlertBack("게시물을 가져오지 못하였습니다.", "");
	}

	//차량 옵션에서 사용됨
	$nm_cont 		= $col['nm_cont'];
	$nm_cont_detail = $col['nm_cont_detail'];
?>
<?php include("../include/inc_header.php") ?>

<main class="pb123">
	<section>
		<div class="sub--top--visual">
			<div class="contents--inner">
				<h2>차량 판매하기</h2>
				<p>이차조아에서는 사고 이력 조회 후 최고가 내차를 판매할 수 있습니다.</p>
			</div>
		</div>
	</section>


	<section>
		<div class="top--nav--wrap">
			<div class="contents--inner">
				<div class="breadcrumbs--wrap">
					<span></span>
					<span>차량 판매하기</span>
					<span>차량 판매하기</span>
				</div>
			</div>
		</div>
	</section>

	<section class="mt60">
		<form id="frmForm" name="frmForm" method="post" action="proc.php" enctype="multipart/form-data">
			<input type="hidden" name="mode" id="mode" value="<?=$mode?>"/>
		<div class="options--wrapper">
			<h2>차량 설명하기</h2>
			<div class="editor--wrapper">
				<div class="editor--inner" style='width:100%;'>
					<textarea id="nm_desc" name="nm_desc" style='width:100%;height:600px;border:1px solid #c9c9c9'><?=$col['nm_desc']?></textarea>
				</div>
			</div>
		</div>
		</form>
	</section>

	<div class="btn--wrapper car--btn--wrapper">
		<button type="button" class="next--btn" id="btn_write">다음(등록 완료)<i class="next--ic"></i></button>
	</div>

	<!-- loading -->
	<div class="loading_wrap hide">
		<?php include("../include/loading_dim.html") ?>
	</div>
	<!-- // loading -->
</main>


<div class="modal--wrap" style="display: none" id="layout_finish">
	<div class="modal--content ty2" style="max-width:280px;">
		<div class="inner--contents">
			<div class="evt--thumb"></div>
			<h2>등록 완료</h2>
			<p>차량 등록이 완료되었습니다.</p>
		</div>
		<div class="modal--btn--wrap">
			<button type="button" id="btn_cancel">취소</button>
			<button type="button" class="on" id="btn_confirm">완료</button>
		</div>
	</div>
</div>


<script language="javascript" type="text/javascript">
	function go_main() {
		link("/index.php");
	}
	$(document).ready(function() {
		$("#btn_confirm").on("click", function() {
			go_main();
		});
		$("#btn_cancel").on("click", function() {
			go_main();
		});

		$("#btn_write").on("click",function(){
			var custom_opts = {
				title : '',
				btn_close_show : false,
			}

			custom_opts.title = '정보를 등록하시겠습니까?';
			custom_modal_confirm(custom_opts, function(confirm) {
				if(confirm) {
					custom_modal_confirm_close();

					$("#btn_write").hide();
					var data = $("#frmForm").serialize();
					$.ajax({
						url : 'proc.php',
						type: 'POST',
						dataType : 'json',
						data: data,
						success: function(res) {

							$("#btn_write").show();

							custom_modal_confirm_close();

							//세션 종료시 로그인 페이지로 이동
							if(res.CODE != "0000") {
								custom_opts.title = res.MSG;

								if(res.CODE == "4444") {
									alert(res.MSG);
									window.location.href = res.DATAS.URL;
								}
								custom_modal_alert(custom_opts);
								return false;
							}
							$("#layout_finish").show();
							// link("sell_step3.php?mode=Step3");
						},
						error:function(request,status,error){
							$("#btn_write").show();

							custom_modal_confirm_close();

							alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
						}
					});

				}else {
					$("#btn_write").show();
					return false;
				}
			  });

		});

		$("#btn_prev").on("click", function() {
			link("sell_step4.php");
		});
	});


</script>

<?php include("../include/inc_footer.php") ?>
