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

	$nav_title = "차량 판매 > 차량 정보 입력";
	$HEADER_LOC = 'main';

	$mode="Step1";

//	$s_cd_sale 		= $_SESSION['s_cd_sale'];
	$s_cd_car 		= $_SESSION['s_cd_car'];
	$s_cd_userid	= $_SESSION['s_cd_userid'];
//	echo $s_cd_car;
	$s_nm_name 		= $_SESSION['s_nm_name'];
	$s_ds_type 		= $_SESSION['s_ds_type'];	//$_SESSION['s_ds_type']= "C0"
	$s_car_update_ing = $_SESSION['s_car_update_ing'];

	$s_ds_area_user = $_SESSION['s_ds_area_user'];

	$ds_cate = 'A0';

	$ds_model_cate = $ds_cate;

	if($s_cd_car !="" || $s_cd_car != null){

		$sql ="SELECT *
					FROM car_master mst
					WHERE  cd_car='$s_cd_car' AND ds_delind='N'";
/*
		$sql ="SELECT *
			FROM car_master mst
				inner join sale_master s
				on (
					mst.cd_car = s.cd_car
					AND mst.ds_delind='N'
					AND s.cd_sale = '$s_cd_sale'
				) ";
*/

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

		if (!empty($col['cd_car'])){

			$cd_car 			= $col['cd_car'];
			$cd_brand  			= $col['cd_brand'];
			$cd_category  		= $col['cd_category'];
			$cd_model  			= $col['cd_model'];
			$cd_model_sub  		= $col['cd_model_sub'];
			$cd_grade  			= $col['cd_grade'];
			$cd_car_history  	= $col['cd_car_history'];
			$car_report  		= $col['car_report'];
			$ds_type  			= $col['ds_type'];
			$ds_year  			= $col['ds_year'];
			$nm_mileage  		= $col['nm_mileage'];
			$ds_driving_system  = $col['ds_driving_system'];
			$ds_transmission  	= $col['ds_transmission'];
			$ds_oil  			= $col['ds_oil'];
			$nm_gearbox  		= $col['nm_gearbox'];
			$ds_accident  		= $col['ds_accident'];
			$nm_cont_accident  	= $col['nm_cont_accident'];
			$nm_regdate  		= $col['nm_regdate'];
			$ds_sales  			= $col['ds_sales'];
			$nm_btitle  		= $col['nm_btitle'];
			$nm_stitle  		= $col['nm_stitle'];
			$nm_ltitle  		= $col['nm_ltitle'];
			$nm_cont  			= $col['nm_cont'];
			$ds_open  			= $col['ds_open'];
			$ds_status  		= $col['ds_status'];
			$ds_logo  			= $col['ds_logo'];
			$nm_price 			= $col['nm_price'];
			$nm_name  			= $col['nm_name'];
			$nm_color 			= $col['nm_color'];
			$nm_incolor			= $col['nm_incolor'];
			$nm_cc 				= $col['nm_cc'];
			$nm_number 			= $col['nm_number'];
			$ds_trade 			= $col['ds_trade'];
			$nm_regdate_yyyy  	= $col['nm_regdate_yyyy'];
			$nm_regdate_mm  	= $col['nm_regdate_mm'];
			$nm_regdate_dd  	= $col['nm_regdate_dd'];
			$nm_guide  			= $col['nm_guide'];
			$ds_main  			= $col['ds_main'];
			$ds_cate 			= $col['ds_cate'];

			$nm_chk_carno  		= $col['nm_chk_carno'];
			$nm_chk_cnt  		= $col['nm_chk_cnt'];
			$nm_chk_s1 			= $col['nm_chk_s1'];
			$nm_chk_s2 			= $col['nm_chk_s2'];
			$nm_chk_s3 			= $col['nm_chk_s3'];
			$nm_chk_s4 			= $col['nm_chk_s4'];
			$nm_chk_advisor 	= $col['nm_chk_advisor'];
			$nm_chk_date 		= $col['nm_chk_date'];
			$nm_chk_p1 			= $col['nm_chk_p1'];
			$nm_chk_p2 			= $col['nm_chk_p2'];
			$nm_chk_p3 			= $col['nm_chk_p3'];
			$nm_file_chk 		= $col['nm_file_chk'];
			$nm_act_chgno 		= $col['nm_act_chgno'];
			$nm_act_chgnm 		= $col['nm_act_chgnm'];
			$nm_act_s1 			= $col['nm_act_s1'];
			$nm_act_s2 			= $col['nm_act_s2'];
			$nm_act_s3 			= $col['nm_act_s3'];
			$nm_act_s4 			= $col['nm_act_s4'];
			$nm_act_my 			= $col['nm_act_my'];
			$nm_act_my_amt 		= $col['nm_act_my_amt'];
			$nm_act_other 		= $col['nm_act_other'];
			$nm_act_other_amt 	= $col['nm_act_other_amt'];
			$nm_act_searchdt  	= $col['nm_act_searchdt'];
			$nm_act_cnt 		= $col['nm_act_cnt'];
			$nm_file_act 		= $col['nm_file_act'];

			$ds_accident_check	= $col['ds_accident_check'];
			$ds_damage_check	= $col['ds_damage_check'];


			$upload_file_report_name = $col['nm_file_report'];
			$upload_file_report_back_name = $col['nm_file_report_back'];

			$upload_file_main_name = $col['nm_file_main'];
			$upload_file_list_name = $col['nm_file_list'];

		}else{
			AlertBack("게시물을 가져오지 못하였습니다.");
		}
		$PageNo = $PageNo;
//		$mode = "Update";
	}else{
//		$mode="Add";
	}

	if ($mode=="Add"){
//		$cd_userid = $_SESSION[admin_cd_userid];
	}

	if($ds_open==""){$ds_open="Y";}
	if($cd_category==""){$cd_category="1";}



	$sql ="SELECT *
				FROM member_master mst
				WHERE cd_userid = '$s_cd_userid' AND ds_delind='N'
			LIMIT 1";
/*
	$sql ="SELECT *
		FROM car_master mst
			inner join sale_master s
			on (
				mst.cd_car = s.cd_car
				AND mst.ds_delind='N'
				AND s.cd_sale = '$s_cd_sale'
			) ";
*/
	// echo $sql;
	// exit;
	$member_col = mysql_fetch_array(mysql_query($sql));

	list($nm_hp1, $nm_hp2, $nm_hp3) = explode("-", $member_col['nm_hp']);
	// print_r($member_col);

?>
<?php  include("../inc/inc_header.php"); ?>

<style>
.pos{position:relative;}
.color_pick_popup{display:none;position:absolute;top:33px;right:0;padding:13px 0 0 13px;width:320px;height:280px;background:#fff;}
.color_pick_popup .close{overflow:hidden;position:absolute;top:8px;right:5px;width:32px;height:32px;background:url('/m/img/btn_popup_close.png') 50% no-repeat;background-size:11px;text-indent:-9999px;cursor:pointer;}
.color_pick_popup ul{overflow:hidden;padding-top:5px;}
.color_pick_popup ul li{float:left;position:relative;margin:9px 7px 0 0;width:52px;height:25px;font-size:11px;line-height:23px;color:#fff;text-align:center;cursor:pointer;}
.color_pick_popup ul li:before{content:'';display:block;position:absolute;top:0;right:0;width:50%;height:100%;}
.color_pick_popup ul li em{position:relative;z-index:10;}
.color_pick_popup ul li:first-child{background:#000;}
.color_pick_popup ul li:nth-child(2){border:1px solid #dbdbdb;line-height:21px;color:#000;}
.color_pick_popup ul li:nth-child(3){background:#818376;}
.color_pick_popup ul li:nth-child(4){background:#11417f;}
.color_pick_popup ul li:nth-child(5){background:#cb001c;}
.color_pick_popup ul li:nth-child(6){background:#7a265a;}
.color_pick_popup ul li:nth-child(7){background:#474747;}
.color_pick_popup ul li:nth-child(7):before{background:#000;}
.color_pick_popup ul li:nth-child(8){background:#f8f7e2;color:#000;}
.color_pick_popup ul li:nth-child(9){background:#8e8574;}
.color_pick_popup ul li:nth-child(10){background:#74929a;}
.color_pick_popup ul li:nth-child(11){background:#fe7902;}
.color_pick_popup ul li:nth-child(12){background:#65007f;}
.color_pick_popup ul li:nth-child(13){background:#626262;}
.color_pick_popup ul li:nth-child(14){border:1px solid #dbdbdb;line-height:21px;color:#000;}
.color_pick_popup ul li:nth-child(14):before{background:#dbdbdb;}
.color_pick_popup ul li:nth-child(15){background:#675b33;}
.color_pick_popup ul li:nth-child(16){background:#d0d9e8;}
.color_pick_popup ul li:nth-child(17){background:#1c444c;}
.color_pick_popup ul li:nth-child(18){background:#ffc2d7;}
.color_pick_popup ul li:nth-child(19){background:#e5e5e5;color:#000;}
.color_pick_popup ul li:nth-child(20){background:#f7f7e2;color:#000;}
.color_pick_popup ul li:nth-child(20):before{background:#deddc9;}
.color_pick_popup ul li:nth-child(21){background:#675b35;}
.color_pick_popup ul li:nth-child(21):before{background:#464741;}
.color_pick_popup ul li:nth-child(22){background:#837538;}
.color_pick_popup ul li:nth-child(23){background:#01cc00;}
.color_pick_popup ul li:nth-child(24){background:#fff847;color:#000;}
.color_pick_popup ul li:nth-child(25){background:#bcbcbc;color:#000;}
.color_pick_popup ul li:nth-child(26){background:#c0c0c0;color:#000;}
.color_pick_popup ul li:nth-child(26):before{background:#464742;}
.color_pick_popup ul li:nth-child(27){background:#a6b2b0;}
.color_pick_popup ul li:nth-child(28){background:#837537;}
.color_pick_popup ul li:nth-child(28):before{background:#464741;}
.color_pick_popup ul li:nth-child(29){background:#277c79;}
.color_pick_popup ul li:nth-child(30){background:#9ab95c;}
.color_pick_popup ul li:nth-child(31){color:#000;}
</style>


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

	<form id="frmForm" name="frmForm" method="post" action="proc.php" enctype="multipart/form-data">
	<input type="hidden" name="car_report" id="car_report" value="<?=$car_report?>"/>
	<input type="hidden" name="ds_cate" id="ds_cate" value="<?=$ds_cate?>"/>
	<input type="hidden" name="cd_car" id="cd_car" value="<?=$cd_car?>"/>
	<input type="hidden" name="mode" id="mode" value="<?=$mode?>"/>
	<input type="hidden" name="cd_userid" id="cd_userid" value="<?=$cd_userid?>"/>
	<input type="hidden" name="PageNo" id="PageNo" value="<?=$PageNo?>"/>
	<input type="hidden" name="upload_file_report_name" id="upload_file_report_name" value="<?=$upload_file_report_name?>"/>
	<input type="hidden" name="upload_file_report_back_name" id="upload_file_report_back_name" value="<?=$upload_file_report_back_name?>"/>
	<input type="hidden" name="upload_file_main_name" id="upload_file_report_name" value="<?=$upload_file_main_name?>"/>
	<input type="hidden" name="upload_file_list_name" id="upload_file_list_name" value="<?=$upload_file_list_name?>"/>
	<input type="hidden" name="cd_category" id="cd_category" value="<?=$cd_category?>"/>
	<input type='hidden' name="cd_car_history" id="cd_car_history" value="<?=$cd_car_history?>">
	<!--input type="hidden" name="s_nm_name" id="s_nm_name" value="<?=$s_nm_name?>"/-->
	<input type="hidden" name="carinfochkresult" id="carinfochkresult" value="<? if ($s_car_update_ing != "Y"){ ?>N<? }else{ ?>Y<? } ?>"/>

	<section>
		<div class="owner--information--wrap">
			<h2>소유주 정보</h2>
			<div class="sch--modules--wrap">
				<div class="form--group user--info">
					<input type="text" name="nm_name" id="nm_name" value="<?=$s_nm_name?>" placeholder="소유주명">
				</div>
				<div class="form--group car--numb">
					<input type="text" name="nm_number" id="nm_number" value="<?=$nm_number?>" placeholder="차량 번호">
				</div>
				<div class="form--group phone--numb">
					<input type="text" name="nm_hp" id="nm_hp" maxlength=20 value="<?=$member_col['nm_hp']?>" placeholder="판매자 휴대전화 번호">
				</div>
				<button type="button" id="btn_car_search">차량 조회<i class="sch--ic"></i></button>
			</div>
		</div>
	</section>

	<section>
		<div class="car--info--wrap">
			<h2>차량 정보 입력</h2>
			<div class="form--wrap">
				<div class="form--groups">
					<h2>제조사</h2>
					<div class="form--group">
						<select id="cd_brand" name="cd_brand"></select>
					</div>
				</div>

				<div class="form--groups">
					<h2>모델</h2>
					<div class="form--group">
						<select id="cd_model" name="cd_model"></select>
					</div>
				</div>

				<!-- <div class="form--groups">
					<h2>세부 모델</h2>
					<div class="form--group">
						<select name="" id="">
							<option value="">선택</option>
						</select>
					</div>
				</div>

				<div class="form--groups">
					<h2>등급</h2>
					<div class="form--group">
						<select name="" id="">
							<option value="">선택</option>
						</select>
					</div>
				</div> -->

				<div class="form--groups">
					<h2>변속기</h2>
					<div class="form--group">
						<select id="ds_transmission" name="ds_transmission"></select>
					</div>
				</div>

				<div class="form--groups">
					<h2>연식 (최초 등록일)</h2>
					<div class="form--group ty2">
						<select  name="nm_regdate_yyyy" id="nm_regdate_yyyy" style="max-width:134px;">
						<?php
							$cur_year = date("Y");
							$cur_year = (int)$cur_year;
							// echo $cur_year;
							// exit;
							for($i=1990; $i<=$cur_year; $i++){
						?>
								<option value="<?=$i?>" <? if($i == $nm_regdate_yyyy){ ?>selected<? } ?>><?=$i?></option>
						<?php
							}
						?>
						</select>

						<label for="nm_regdate_yyyy" class="ml10">년</label>

						<select name="nm_regdate_mm" id="nm_regdate_mm" class="ml20" style="max-width:70px;">
						<?php
							for($i=1; $i<=12; $i++){
						?>
								<option value="<?=($i<10)?"0".$i:$i?>" <? if($i == $nm_regdate_mm){ ?>selected<? } ?>><?=($i<10)?"0".$i:$i?></option>
						<?php
							}
						?>
						</select>
						<label for="nm_regdate_mm" class="ml10">월</label>

					</div>
				</div>

				<div class="form--groups">
					<h2>형식 년도</h2>
					<div class="form--group ty2">
						<select id="ds_year" name="ds_year"></select>
						<label for="ds_year" class="ml10">년</label>
					</div>
				</div>

				<div class="form--groups">
					<h2>배기량</h2>
					<div class="form--group ty2">
						<input type="text" name="nm_cc" id="nm_cc" placeholder="배기량을 입력해주세요" maxlength="50" value="<?=$nm_cc?>">
						<label for="nm_cc" class="ml10">cc</label>
					</div>
				</div>

				<div class="form--groups">
					<h2>연료</h2>
					<div class="form--group">
						<input type="text" name="ds_oil" id="ds_oil" placeholder="사용연료를 입력해주세요" maxlength="50" value="<?=$ds_oil?>">
					</div>
				</div>

				<div class="form--groups">
					<h2>색상</h2>
					<div class="form--group ty2" style='position:relative;'>
						<input type="text" name="nm_color" id="nm_color" maxlength="50" value="<?=$nm_color?>" placeholder="색상을 입력해주세요">

						<!-- color pick -->
						<div class="color_pick_popup">
							<p>기본 색상 선택<em class="txt_red">(1개를 선택해주세요)</em></p>
							<ul>
								<li><em>검정색</em></li>
								<li><em>흰색</em></li>
								<li><em>갈대색</em></li>
								<li><em>청색</em></li>
								<li><em>빨간색</em></li>
								<li><em>자주색</em></li>
								<li><em>검정투톤</em></li>
								<li><em>진주색</em></li>
								<li><em>연금색</em></li>
								<li><em>하늘색</em></li>
								<li><em>주황색</em></li>
								<li><em>보라색</em></li>
								<li><em>쥐색</em></li>
								<li><em>흰색투톤</em></li>
								<li><em>갈색</em></li>
								<li><em>명은색</em></li>
								<li><em>담녹색</em></li>
								<li><em>분홍색</em></li>
								<li><em>은색</em></li>
								<li><em>진주투톤</em></li>
								<li><em>갈색투톤</em></li>
								<li><em>금색</em></li>
								<li><em>녹색</em></li>
								<li><em>노란색</em></li>
								<li><em>은회색</em></li>
								<li><em>은색투톤</em></li>
								<li><em>은하색</em></li>
								<li><em>금색투톤</em></li>
								<li><em>청옥색</em></li>
								<li><em>연두색</em></li>
								<li><em>기타</em></li>
							</ul>
							<div class="close" onclick="closeColorLayer();">레이어팝업 닫기</div>
						</div>
						<!-- // color pick -->
					</div>
				</div>

				<div class="form--groups">
					<h2>주행거리</h2>
					<div class="form--group ty2">
						<input type="text" name="nm_mileage" id="nm_mileage" value="<?=$nm_mileage?>" placeholder="주행거리를 입력해주세요">
						<label for="nm_mileage" class="ml10">km</label>
					</div>
				</div>

				<div class="form--groups">
					<h2>사고 유무</h2>
					<div class="form--group">
						<select id="ds_accident" name="ds_accident"></select>
					</div>
				</div>

				<div class="form--groups">
					<h2>판매 희망 지역</h2>
					<div class="form--group">
						<select name="ds_area" id="ds_area">
							<option value="">판매희망 선택하세요</option>
						</select>
					</div>
				</div>

				<div class="form--groups">
					<h2>사업자 유,무</h2>
					<div class="form--group">
						<select name="ds_business_num" id="ds_business_num">
							<option value="">사업자 유,무를 선택하세요</option>
						</select>
					</div>
				</div>

				<div class="form--groups">
					<h2>추가 옵션 및 특이사 항</h2>
					<div class="form--group">
						<input type="text" name="nm_cont_pac" id="nm_cont_pac" placeholder="추가 옵션 및 특이사항을 입력해주세요" value="<?=$nm_cont_pac?>">
					</div>
				</div>

				<div class="form--groups">
					<h2>판매 시기</h2>
					<div class="form--group">
						<select name="ds_sale_period" id="ds_sale_period"></select>
					</div>
				</div>

				<div class="form--groups">
					<h2>사고 이력 정보</h2>
					<div class="form--group">
						<button type="button" class="sch--btn--bl" id="btn_accident_view">사고 이력 정보 보기<i class="sch--ic--bl"></i></button>
					</div>
				</div>

				<div class="form--groups">
				<h2>사고부위 체크(판금,교환등)</h2>
				<div class="form--group">
					<input type="text" name="ds_accident_check" id="ds_accident_check" value="<?=$ds_accident_check?>" placeholder="사고부위를 입력해주세요">
				</div>



				</div>


				<div class="form--groups">
				<h2>데미지 체크(수리가 필요한곳 기재)</h2>
				<div class="form--group">
				<input type="text" name="ds_damage_check" id="ds_damage_check" value="<?=$ds_damage_check?>" placeholder="수리가 필요한곳을 입력해주세요">
				</div>
				</div>
			</div>



		</div>
	</section>


	<div class="btn--wrapper car--btn--wrapper floating--btn">
		<button type='button' class="next--btn" id="btn_write">다음(옵션 입력)<i class="next--ic"></i></button>
	</div>




	<!--
    썸네일 클릭시 표현될 레이아웃
    display: flex; 로 활성화
  -->
	<div class="gallery--wrappers" style="display: none">
		<div class="fotorama" data-nav="thumbs">
			<a href="/design/staff/assets/img/samp.png" data-caption="차량 전면"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="차량 후면"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="운전석 측면"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="조수석 측면"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="계기판"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진1"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진2"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진3"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진4"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진5"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진6"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진7"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진8"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진9"><img src="/design/staff/assets/img/samp.png"></a>
			<a href="/design/staff/assets/img/samp.png" data-caption="추가사진10"><img src="/design/staff/assets/img/samp.png"></a>
		</div>
	</div>

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

</main>

<!-- 레이어 팝업 -->
<?php include("../../common/inc/inc_layer_popup_m.php") ?>



<script language="javascript" type="text/javascript">
	var cd_car_history = "<?=$cd_car_history?>";

	function raiseObjClickEvent(arg){
		$("#"+arg).trigger("click");
	}

	function controlObjCarInfo(arg_type,arg_bool){
		if (arg_bool){
			$("#cd_brand,#cd_model,#ds_year,#nm_regdate_yyyy,#nm_regdate_mm").removeAttr("disabled", "disabled");

			if (arg_type == "all"){
				// $("#nm_number").attr('readonly',false);
				$("#nm_cc").attr('readonly',false);
			}

	//		$("#btnCarInfo").css({"display":""});
		}else{
			/*
			$("#cd_brand option[value!="+CARINFO.CD_BRAND+"]").remove();
			$("#cd_model option[value!="+CARINFO.CD_MODEL+"]").remove();
			$("#cd_model_sub option[value!="+CARINFO.CD_MODEL_SUB+"]").remove();

			$("#ds_year option[value!="+CARINFO.YEAR_TYPE+"]").remove();
			$("#ds_transmission option[value!="+CARINFO.ISTD_TRANS+"]").remove();
			$("#ds_oil option[value!="+CARINFO.FUEL+"]").remove();
			*/
			$("#cd_brand,#cd_model,#ds_year,#nm_regdate_yyyy,#nm_regdate_mm").attr("disabled", "disabled");

			// $("#nm_number").attr('readonly',true);
			$("#nm_cc").attr('readonly',true);

	//			$("#btnCarInfo").css({"display":"none"});
		}
	}
	function closeColorLayer() {
		$(".color_pick_popup").hide();
	}
	$(document).ready(function() {

		controlObjCarInfo("all",false);	//car_info all object

		var vISTD_TRANS = null;
		var vFUEL = null;
//		setCodeSelect("listcategory","cd_category", "car_category","cd_category","<?=$cd_category?>","선택하세요","");

		setCodeSelect("listBrandBycate","cd_brand","car_brand","cd_brand",'<?=$cd_brand?>','선택하세요','');
<? if (!empty($cd_model)){ ?>
		setCodeSelect("listModelBybrand","cd_model","car_model","cd_model",'<?=$cd_model?>','선택하세요','<?=$cd_brand?>');
<? } ?>
<? if (!empty($cd_model_sub)){ ?>
		// setCodeSelect("listModelSubByModel","cd_model_sub","car_model_sub","cd_model_sub",'<?=$cd_model_sub?>','선택하세요','<?=$cd_model?>');
<? } ?>
<? if (!empty($cd_grade)){ ?>
		// setCodeSelect("listGradeByModelSub","cd_grade","car_grade","cd_grade",'<?=$cd_grade?>','선택하세요','<?=$cd_model_sub?>');
<? } ?>
		setCodeSelect("listcode","ds_area", "member_master","ds_area","<?=$sell_ds_area?>","선택하세요","");
		// setCodeSelect("listcode","ds_area_user", "member_master","ds_area","<?=$s_ds_area_user?>","선택하세요","");

		setCodeSelect("areacode","nm_hp1", "","","<?=$nm_hp1?>","선택","");

		setCodeSelect("listcode","ds_business_num", "car_master","ds_business_num","<?=$ds_business_num?>","사업자 유,무를 선택하세요","");
		setCodeSelect("listcode","ds_sale_period", "sale_master","ds_sale_period","<?=$ds_sale_period?>","판매시기를 선택하세요","");


// 		$("#cd_brand").change(function(){
// 			setCodeSelect("listModelBybrand","cd_model","car_model","cd_model","",'선택하세요',$(this).val());
// 		});
//
// 		$("#cd_model").change(function(){
// 			setCodeSelect("listModelSubByModel","cd_model_sub","car_model_sub","cd_model_sub","",'선택하세요',$(this).val());
// 		});
//
// 		$("#cd_model_sub").change(function(){
// 			setCodeSelect("listGradeByModelSub","cd_grade","car_grade","cd_grade","",'선택하세요',$(this).val());
// 		});
//
		setCodeSelect("listcode","ds_year", "car_master","ds_year","<?=$ds_year?>","선택하세요","");
		setCodeSelect("listcode","ds_transmission", "car_master","ds_transmission","<?=$ds_transmission?>","선택하세요","");
// //		setCodeSelect("listcode","ds_oil", "car_master","ds_oil","<?=$ds_oil?>","선택하세요","");
		setCodeSelect("listcode","ds_accident", "car_master","ds_accident","<?=$ds_accident?>","선택하세요","");

<? if ($ds_accident != "A0"){ ?>
//		$("#nm_cont_accident").css({"display":"none"});
<? } ?>

		// #ds_accident
// 		$("#ds_accident").on("change", function(){
// 			if($("#ds_accident").val() == "A0"){
// //				$("#nm_cont_accident").css({"display":""});
// 			}else{
// //				$("#nm_cont_accident").css({"display":"none"});
// 			}
// 		});

		// // color pick
		$("input#nm_color").on("click", function(){
			$(this).next().show();
		});

		$(".color_pick_popup li").click(function(){
			var text = $(this).find("em").text();
			$("input#nm_color").val(text);
			$(".color_pick_popup").hide();
		});

		// $(".loading_wrap").removeClass("hide");

		$("#btn_write").bind("click",function(){

			var custom_opts = {
				title : '',
				btn_close_show : false,
			}

			controlObjCarInfo("select",true);	//car_info all object

//nm_number,cd_brand,cd_model,cd_grade,nm_regdate_yyyy,nm_regdate_mm,ds_year,nm_cc,ds_transmission,ds_oil,nm_color,nm_mileage,ds_accident

			var fieldlist = [["cd_brand","제조사"],["nm_hp1","판매자 연락처"],["nm_hp2","판매자 연락처"],["nm_hp3","판매자 연락처"]
							,["cd_model","모델"],["nm_regdate_yyyy","연식(최초등록일)"],["nm_regdate_mm","연식(최초등록일)"]
							,["ds_year","형식연도"],["nm_cc","배기량"],["ds_transmission","변속기"],["ds_oil","연료"],["nm_color","색상"],["nm_mileage","주행거리"]
							,["ds_accident","사고유무"],["ds_area","판매희망지역"],["aap_dealer_name","희망 AAP SA"],["ds_business_num", "사업자 유,무"],["ds_sale_period", "판매시기"]
			];

			if (!fnCheckForm(fieldlist)){
				return false;
			}

			// if($("#carinfochkresult").val() != "Y"){
			// 	alert("차량번호 확인을 해 주세요.");
			// 	$("#nm_number").focus();
			// 	return false;
			// }

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

					$(".loading_wrap").removeClass("hide");

					$("#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();

							$(".loading_wrap").addClass("hide");

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

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

							$(".loading_wrap").addClass("hide");

							custom_modal_confirm_close();

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

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

			// var c = confirm("처리하시겠습니까?");
			// if(c){
			// 	$("#frmForm").submit();
			// }else{
			// 	return false;
			// }
		});

		$("#btnCarInfo").bind("click",function(){

			if($("#nm_name").val() == ""){
				alert("차량소유주명을 입력하세요.");
				$("#nm_name").focus();
				return false;
			}

			if($("#nm_number").val() == ""){
				alert("차량 번호를 입력하세요.");
				$("#nm_number").focus();
				return false;
			}

			//차량정보 가져오기 시 페이지 제어
			lockLayer('loading');

			$("#btnCarInfo").css({"display":"none"});

			$.post("car_info_proc.php", { nm_name: $("#nm_name").val(), nm_number: $("#nm_number").val()},function(data) {
				return false;
//alert(data);
				var obj = JSON.parse(data);	//JSON형식으로 리턴 받을 때
				var INFO = obj.INFO;

				if(INFO.PROCESS_IMPRTY_RESN_CODE == "000"){	//정상
					var CARINFO = null;
					var GRADE_LIST = null;
						CARINFO = INFO.CARINFO;
						GRADE_LIST = CARINFO.GRADE_LIST;


					setCodeSelect("listBrandBycate","cd_brand","car_brand","cd_brand",CARINFO.CD_BRAND,'선택하세요','');

					setCodeSelect("listModelBybrand","cd_model","car_model","cd_model",CARINFO.CD_MODEL,'선택하세요',CARINFO.CD_BRAND);

					setCodeSelect("listModelSubByModel","cd_model_sub","car_model_sub","cd_model_sub",CARINFO.CD_MODEL_SUB,'선택하세요',CARINFO.CD_MODEL);

					setCodeSelect("listGradeByModelSub","cd_grade","car_grade","cd_grade",'','선택하세요',CARINFO.CD_MODEL_SUB);

					setCodeSelect("listcode","ds_year", "car_master","ds_year",CARINFO.YEAR_TYPE,"선택하세요","");

					$("#nm_regdate_yyyy").val(CARINFO.FIRST_REGIST_DT.substring(0,4));
					$("#nm_regdate_mm").val(CARINFO.FIRST_REGIST_DT.substring(4,6));
					$("#nm_cc").val(CARINFO.ENGINESIZE);
					$("#cd_category").val(CARINFO.CD_CATEGORY);
 /*
					$("#ds_transmission option:contains('"+CARINFO.ISTD_TRANS+"')").attr('selected','selected');

					$("#ds_oil option:contains('" + CARINFO.FUEL + "')").filter(function(i){
						return $(this).text() === CARINFO.FUEL;
					}).attr("selected", true)
*/

					vISTD_TRANS = CARINFO.ISTD_TRANS;
					vFUEL = CARINFO.FUEL;
/*
alert(CARINFO.ISTD_TRANS);
alert(CARINFO.FUEL);
		setCodeSelect("listcode","ds_transmission", "car_master","ds_transmission",CARINFO.ISTD_TRANS,"선택하세요","");
		setCodeSelect("listcode","ds_oil", "car_master","ds_oil",CARINFO.FUEL,"선택하세요","");
*/
/*
					$("#ds_transmission option:contains('" + CARINFO.ISTD_TRANS + "')").filter(function(i){
						return $(this).text() == CARINFO.ISTD_TRANS;
					}).attr("selected", true)

					$("#ds_oil option:contains('" + CARINFO.FUEL + "')").filter(function(i){
						return $(this).text() == CARINFO.FUEL;
					}).attr("selected", true)
*/
//alert(CARINFO.ISTD_TRANS);
//alert(CARINFO.FUEL);
/*
var s_transmission = $('#ds_transmission option').filter(function () { return $(this).html() == CARINFO.ISTD_TRANS; }).val();
var s_oil = $('#ds_oil option').filter(function () { return $(this).html() == CARINFO.FUEL; }).val();
//alert(s_transmission);
alert(s_oil);

					$("#ds_transmission").val(s_transmission);
					$("#ds_oil").val(s_oil);
*/
   $('#ds_transmission option').map(function () {
       if ($(this).text() == CARINFO.ISTD_TRANS) return this;
      }).attr('selected', 'selected');


    $('#ds_oil option').map(function () {
       if ($(this).text() == CARINFO.FUEL) return this;
      }).attr('selected', 'selected');



					controlObjCarInfo("all",false);	//car_info all object

					$("#carinfochkresult").val("Y");

				}else{	// 에러
//					alert("["+INFO.PROCESS_IMPRTY_RESN_CODE+"]"+INFO.PROCESS_IMPRTY_RESN_DTLS);
//					alert("차량 정보 조회에 실패하였습니다.");
					alert("["+INFO.PROCESS_IMPRTY_RESN_CODE+"]"+"차량 정보 조회에 실패하였습니다.");
<? if ($s_ds_type == "A0" && $s_car_update_ing != "Y"){ ?>
					$("#btnCarInfo").css({"display":""});
<? } ?>

					$("#carinfochkresult").val("N");

				}

			//차량정보 가져오기 시 페이지 제어
			unlockLayer('loading');

            });

			return false;

		});

<?php  if ($s_car_update_ing == "Y"){ ?>
		controlObjCarInfo("all",false);	//car_info all object
<?php  } ?>


<?php if (!empty($nm_number) && $s_ds_type == "C0" && $s_car_update_ing != "Y"){ ?>
		// raiseObjClickEvent("btnCarInfo");
//		setCodeSelect("listcode","ds_transmission", "car_master","ds_transmission",vISTD_TRANS,"선택하세요","");
//		setCodeSelect("listcode","ds_oil", "car_master","ds_oil",vFUEL,"선택하세요","");
<?php } ?>

		//차량이력정보 보기 팝업
		$("#btn_accident_view").on("click", function() {

			var custom_opts = {
				title : '',
				btn_close_show : false,
			}

			if(cd_car_history == 0) {
				custom_opts.title = '차량조회를 먼저 해주세요';
				custom_modal_alert(custom_opts);
				// alert(res.MSG);
				return false;
			}
			$.get("/sell/car_info_car_history_view.php", { mode: 'view', cd_car_history: cd_car_history, device : 'm'},function(data) {
				$("#history_scr_cont").html(data);
				$("#historyModal").modal("show");
				// viewLayerPopup('car_history');
			});

			// $.get("/sell/car_info_car_history_view.php", { mode: 'view', cd_car_history: cd_car_history},function(data) {
			// 	$("#scr_cont").html(data);
			// 	viewLayerPopup('car_history');
			// });
		});

		$(".car_history_popup .close").on("click", function() {
			closeLayerPopup('car_history');
		});


		//세부 코드들을 다 가져온 다음에 잠금
		$(document).ajaxStop(function () {
			controlObjCarInfo("all",false);	//car_info all object
		});

	});



</script>

<?php include("../inc/inc_bottom.php"); ?>
<?php
mysql_close($connect);
?>
