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


	$MENU_ACTV = "1";	//set top nav
    $mode="Step1";

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

//	echo $s_staff_cd_car;
    $sell_nm_hp 	= $_SESSION['sell_nm_hp'];
	$sell_nm_number = $_SESSION['sell_nm_number'];
	$sell_nm_name 	= $_SESSION['sell_nm_name'];
	$sell_ds_type 	= $_SESSION['s_ds_type'];	//$_SESSION['s_ds_type']= "C0"

    $sell_ds_area 	= $_SESSION['sell_ds_area'];

	//메인에서 차량조회한 값
	$req_nm_name 	= $_REQUEST['req_nm_name'];
	$req_nm_number 	= $_REQUEST['req_nm_number'];

    list($nm_hp1, $nm_hp2, $nm_hp3) = explode("-",$sell_nm_hp);
	if(empty($nm_hp1)) {
		// $nm_hp1 = "010";
	}

	$s_staff_car_update_ing = $_SESSION['s_staff_car_update_ing'];

// print_r($_SESSION);
// exit;
	$ds_cate = $_REQUEST['ds_cate'];
	if(!$ds_cate) $ds_cate='A0';

	$ds_model_cate= $ds_cate;

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

		$sql ="SELECT mst.*
					, s.ds_sale_period
					, s.ds_tradein
					, s.ds_buy_method
					, s.ds_auction_time
					, s.cd_aap_dealer
					FROM car_master mst
					INNER JOIN sale_master s ON s.cd_car = mst.cd_car
					WHERE mst.cd_car='$s_staff_cd_car' AND mst.ds_delind='N'";
		// echo $sql;
		// exit;

		$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_business_num  	= $col['ds_business_num'];
			$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_178_q1  	= $col['nm_chk_178_q1'];
			$nm_chk_178_q2  	= $col['nm_chk_178_q2'];
			$nm_chk_178_q3  	= $col['nm_chk_178_q3'];
			$nm_chk_178_q4  	= $col['nm_chk_178_q4'];
			$nm_chk_178_q5  	= $col['nm_chk_178_q5'];
			$nm_chk_178_q6  	= $col['nm_chk_178_q6'];
			$nm_chk_178_q7  	= $col['nm_chk_178_q7'];
			$nm_chk_178_q8  	= $col['nm_chk_178_q8'];
			$nm_chk_178_q9  	= $col['nm_chk_178_q9'];
			$nm_chk_178_q10  	= $col['nm_chk_178_q10'];
			$nm_chk_178_q11  	= $col['nm_chk_178_q11'];
			$nm_chk_178_q12  	= $col['nm_chk_178_q12'];
			$nm_chk_178_q13  	= $col['nm_chk_178_q13'];

			$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_sale_period 	= $col['ds_sale_period'];
			$nm_cont_pac		= $col['nm_cont_pac'];
			$ds_tradein 		= $col['ds_tradein'];
			$ds_buy_method 		= $col['ds_buy_method'];
			$ds_auction_time 	= $col['ds_auction_time'];

			$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'];

			$cd_aap_dealer		= $col['cd_aap_dealer'];
			$cd_aap_dealer_name = "";

			$aap_sql ="SELECT *
							FROM aap_master mst
							WHERE cd_dealer = '{$col['cd_aap_dealer']}' AND ds_delind='N' ";
			$aap_col = mysql_fetch_array(mysql_query($aap_sql));
			$cd_aap_dealer_name = $aap_col['nm_name'];

			if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') {
				// echo $aap_sql;
			}

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

		$nm_name = $req_nm_name;
		$nm_number = $req_nm_number;
		$cd_aap_dealer = "";
		$cd_aap_dealer_name = "";
		// print_r($_POST);
		// exit;
//		$mode="Add";
	}

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

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

	//개발기간에만 고정 값으로
	// $sell_nm_number = "245머6418";
	// $sell_nm_number = "서울85바3080";
	// $sell_nm_number = "11고4424";
	// $sell_nm_number = "08오5060";
?>
<?php include("include/header.php") ?>

<style>
.pos{position:relative;}
.color_pick_popup{display:none;position:absolute;top:-280px;left:150px;z-index:100;padding:28px 0 0 20px;width:490px;height:300px;background:#fff;border:1px solid #b3b3b3;box-shadow:2px 2px 3px rgba(0,0,0,0.5);}
.color_pick_popup .close{overflow:hidden;position:absolute;top:15px;right:15px;width:32px;height:32px;background:url('/img/btn_popup_close.gif') 50% no-repeat;text-indent:-9999px;cursor:pointer;}
.color_pick_popup ul{overflow:hidden;padding-top:5px;}
.color_pick_popup ul li{float:left;position:relative;margin:10px 10px 0 0;width:65px;height:30px;font-size:13px;line-height:28px;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:26px;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:26px;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">
	<form id="frmForm" name="frmForm" method="post" action="sell_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="nm_hp" id="nm_hp" value="<?=$sell_nm_hp?>"/>
	<input type="hidden" name="carinfochkresult" id="carinfochkresult" value="<? if ($s_staff_car_update_ing != "Y"){ ?>N<? }else{ ?>Y<? } ?>"/>

	<input type='hidden' name="nm_cont_accident" id="nm_cont_accident" value="<?=$nm_cont_accident?>">
	<input type='hidden' name="cd_car_history" id="cd_car_history" value="<?=$cd_car_history?>">



	<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>
		<div class="owner--information--wrap">
			<h2>소유주 정보</h2>
			<div class="sch--modules--wrap">
				<div class="form--group user--info" style="max-width:170px;">
					<input type="text" name="nm_name" id="nm_name" style="width:100%" value="<?=$nm_name?>" placeholder="소유주명">
				</div>
				<div class="form--group car--numb ml20" style="width:100%; max-width:356px;">
					<input type="text" name="nm_number" id="nm_number" style="width:100%" value="<?=$nm_number?>" placeholder="차량 번호">
				</div>
				<label for="" class="ml30">판매자 연락처</label>
				<div class="phone--ftc--numb ml25" style="max-width:80px;">
					<select name="nm_hp1" id="nm_hp1"></select>
				</div>
				<label for="nm_hp2" class="ml10">-</label>
				<div class="phone--ftc--numb ml10" style="max-width:100px;">
					<input type="text" name="nm_hp2" id="nm_hp2" maxlength=4 value="<?=$nm_hp2?>">
				</div>
				<label for="nm_hp3" class="ml10">-</label>
				<div class="phone--ftc--numb ml10" style="max-width:100px;">
					<input type="text" name="nm_hp3" id="nm_hp3" maxlength=4 value="<?=$nm_hp3?>" >
				</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>Trade-in</h2>
					<div class="form--group">
						<select id="ds_tradein" name="ds_tradein"></select>
					</div>
				</div>

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

				<!-- <div class="form--groups">
					<h2>등급</h2>
					<div class="form--group">
						<select id="cd_grade" name="cd_grade" style="width:250px;"></select>
					</div>
				</div> -->



			</div>


			<div class="form--wrap">
				<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" style="margin-left:8px;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>
						<!-- <input type="text" class="ml20" style="max-width:70px;" />
						<label for="" 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>





			<div class="form--wrap">
        <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?>">
            <label for="" class="ml10"></label>
            <!-- <select id="ds_oil" name="ds_oil">
							<option value="">선택하세요</option>
							<option value="A0" <? if($ds_oil == "A0"){ ?>selected<? } ?>>Diesel</option>
							<option value="B0" <? if($ds_oil == "B0"){ ?>selected<? } ?>>Diesel/Hybrid</option>
							<option value="C0" <? if($ds_oil == "C0"){ ?>selected<? } ?>>Electric</option>
							<option value="D0" <? if($ds_oil == "D0"){ ?>selected<? } ?>>Gasoline</option>
							<option value="E0" <? if($ds_oil == "E0"){ ?>selected<? } ?>>Gasoline/Hybrid</option>
							<option value="F0" <? if($ds_oil == "F0"){ ?>selected<? } ?>>Hydrogen</option>
							<option value="G0" <? if($ds_oil == "G0"){ ?>selected<? } ?>>LPG</option>
							<option value="H0" <? if($ds_oil == "H0"){ ?>selected<? } ?>>LPG/Hybrid</option>
						</select> -->
          </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>




			<div class="form--wrap">
        <div class="form--groups" style="max-width:270px;">
          <h2>판매 희망 지역</h2>
          <div class="form--group">
            <select name="ds_area" id="ds_area">
              <option value="">판매희망 선택하세요</option>
            </select>
          </div>
        </div>

				<div class="form--groups" style="max-width:270px;">
					<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>




			<div class="form--wrap">
				<div class="form--groups" style="max-width:580px;">
					<h2>희망 AAP SA</h2>
					<div class="form--group ty2 file--wrap">
						<input type="hidden" name="cd_aap_dealer" id="cd_aap_dealer" value="<?=$cd_aap_dealer?>">
						<!-- <input type="file" id="file--add" hidden> -->
						<input type="text" name="aap_dealer_name" id="aap_dealer_name" placeholder="희망 AAP SA를 선택해주세요" readonly value="<?=$cd_aap_dealer_name?>">
						<label data-bs-toggle="modal" data-bs-target="#aapModal">선택하기</label>
					</div>
				</div>

				<div class="form--groups" style="max-width:270px;">
					<h2>판매 시기</h2>
					<div class="form--group">
						<select name="ds_sale_period" id="ds_sale_period"></select>
					</div>
				</div>

				<div class="form--groups" style="max-width:270px;">
					<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>

			<div class="form--wrap">

				<div class="form--groups" style="max-width:270px;">
					<h2>구매방식</h2>
					<div class="form--group">
						<select name="ds_buy_method" id="ds_buy_method"></select>
					</div>
				</div>

				<div class="form--groups" style="max-width:270px;">
					<h2>경매시간</h2>
					<div class="form--group">
						<select name="ds_auction_time" id="ds_auction_time"></select>
					</div>
				</div>


					<div class="form--groups" style="max-width:270px;">
					<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" style="max-width:270px;">
					<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">
		<button type='button' class="next--btn" id="btn_write">다음(옵션 입력)<i class="next--ic"></i></button>
	</div>


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


</main>


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


<!-- 희망 AAP SA 선택 모달 -->
<div class="modal fade" id="aapModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
	<div class="modal-dialog  modal-dialog-centered" style="max-width:280px;">
		<div class="modal-content">
			<div class="modal-header">
				<h1 class="modal-title" id="exampleModalLabel">희망 AAP</h1>
				<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
			</div>

			<div class="modal-body modal--body">
			<?php
				$sql ="SELECT *
						FROM aap_master mst
							where ds_status = 'Z0' and ds_delind = 'N'
								AND ds_type = 'D1'
								AND ds_company_bp = 'B0'
						order by nm_name asc";
				// echo $sql;
				$res = mysql_query($sql);
				for($i=0; $aap=mysql_fetch_array($res); $i++) {
			?>
				<div class="form-check">
					<input class="form-check-input" type="radio" name="cd_aap_dealer" id="rd_0<?=$i?>" nm_name="<?=$aap['nm_name']?>" value="<?=$aap['cd_dealer']?>">
					<label class="form-check-label" for="rd_0<?=$i?>">
						<?=$aap['nm_name']?>
					</label>
				</div>
			<?php
				}
				if($i ==0) {
			?>
				<div class="form-check">
					등록된 AAP 직원이 없습니다.
				</div>
			<?php
				}
			?>

				<!-- <div class="form-check">
					<input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault2">
					<label class="form-check-label" for="flexRadioDefault2">
						홍길동
					</label>
				</div>
				<div class="form-check">
					<input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault3">
					<label class="form-check-label" for="flexRadioDefault3">
						홍길동
					</label>
				</div>
				<div class="form-check">
					<input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault4">
					<label class="form-check-label" for="flexRadioDefault4">
						홍길동
					</label>
				</div> -->
			</div>
			<div class="modal-footer d-flex justify-content-center">
				<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">취소</button>
				<button type="button" class="btn btn-primary" id="btn_select_aap">확인</button>
			</div>
		</div>
	</div>
</div>


<script>
var confirm_cnt = 0;
var cd_car_history = "<?=$cd_car_history?>";
function raiseObjClickEvent(arg){
	$("#"+arg).trigger("click");
}

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

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

//		$("#btnCarInfo").css({"display":""});
		// $("#btn_car_search").removeClass("hide");
	}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,#ds_year,#nm_regdate_yyyy,#nm_regdate_mm").attr("disabled", "disabled");
		//,#cd_model
		//,#cd_model_sub,#ds_transmission,#ds_oil

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

		// $("#btn_car_search").addClass("hide");
	}
}
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_tradein", "car_master","ds_tradein","<?=$cd_tadein?>","선택하세요","");
	// setCodeSelect("listcode","ds_tradein_group", "car_master","ds_tradein_group","<?=$cd_tradein_group?>","선택하세요","");


	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?>","판매시기를 선택하세요","");

	setCodeSelect("listcode","ds_tradein", "sale_master","ds_tradein","<?=$ds_tradein?>","선택하세요","");
	setCodeSelect("listcode","ds_buy_method", "sale_master","ds_buy_method","<?=$ds_buy_method?>","선택하세요","");
	setCodeSelect("listcode","ds_auction_time", "sale_master","ds_auction_time","<?=$ds_auction_time?>","선택하세요","");

	// setCodeSelect("listcode","ds_area", "member_master","ds_area","<?=$sell_ds_area?>","선택하세요","");

//		$("#cd_category").change(function(){
//			setCodeSelect("listBrandBycate","cd_brand","car_brand","cd_brand","",'선택하세요',$(this).val());
//		});


<?php if($s_staff_car_update_ing == "Y"){ ?>
	$("#btn_car_search").addClass("hide");
<?php } ?>
	//2022-06-08 trade-in에 따른 그룹 노출
	// $("#ds_tradein").on("change", function() {
	// 	var tradein = $(this).val();
	//
	// 	//예
	// 	if(tradein == 'A0') {
	// 		$("#ds_tradein_group").prop("disabled", false);
	// 	}else {
	// 		$("#ds_tradein_group").val("").prop("disabled", true);
	// 	}
	// });

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

	$("#btn_select_aap").on("click", function() {
		var custom_opts = {
			title : '',
			btn_close_show : false,
		}
		var checked_length = $("input[name=cd_aap_dealer]:checked").length;

		if(checked_length < 1) {
			custom_opts.title = '희망 AAP 직원을 선택해 주세요';
			custom_modal_alert(custom_opts);
			// alert(res.MSG);
			return false;
		}
		var $checked_aap = $("input[name=cd_aap_dealer]:checked");
		var aap_name = $checked_aap.attr("nm_name");
		var aap_dealer = $checked_aap.val();

		$("#aap_dealer_name").val(aap_name);
		$("#cd_aap_dealer").val(aap_dealer);
		$("#aapModal .btn-close").click();
		// $(".modal_close_btn").click();
	});

	// $("input[name=cd_aap_dealer]").on("click", function() {
	// 	var aap_dealer = $(this).val();
	// 	var aap_name = $(this).attr("nm_name");
	// 	$("#aap_dealer_name").val(aap_name);
	// 	$("#cd_aap_dealer").val(aap_dealer);
	//
	// 	$(".modal_close_btn").click();
	// });

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

	// var swipersago = new Swiper('.swiper-container', {
	// 	pagination: {
	// 		  el: '.swiper-pagination-sago'
	// 	},
  // navigation: {
	// nextEl: '.swiper-button-next',
	// prevEl: '.swiper-button-prev',
  // },
  //
	// });
	// #ds_accident
	$("#ds_accident").on("change", function(){
		if($("#ds_accident").val() == "A0"){
			$(".sago_popup").show();
			// $("#nm_cont_accident").css({"display":""});
		}else{
			$(".sago_popup").hide();
			$("input[name='nm_accident_detail[]']").each(function(i) {
				$(this).prop("checked", false);
			});
			// $("#nm_cont_accident").css({"display":"none"});
		}
	});
	$("#btn_accident_close").on("click", function(){
		var accident_length = $("input[name='nm_accident_detail[]']:checked").length;
		if(accident_length < 1) {
			$("#ds_accident").val("");
		}
		$(".sago_popup").hide();
	});
	$(".sago_popup").hide();

	// 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();
	});

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

		var fieldlist = [["nm_name","소유주명"],["nm_number","차량 번호"]];
		//,["nm_hp1", "판매자 연락처"],["nm_hp2", "판매자 연락처"],["nm_hp3", "판매자 연락처"]];
		//

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

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

		$.post("/sell/car_info_car_history_proc.php", { nm_name: $("#nm_name").val(), nm_number: $("#nm_number").val(), cd_userid : "<?=$_SESSION['s_staff_userid']?>"},function(res) {
//alert(data);
			// var obj = JSON.parse(data);	//JSON형식으로 리턴 받을 때
			// var INFO = obj.INFO;

			if(res.CODE != "0000") {
				$(".loading_wrap").addClass("hide");
				<? if ($sell_ds_type == "A0" && $s_staff_car_update_ing != "Y"){ ?>
					$("#btnCarInfo").css({"display":""});
				<? } ?>
				$("#carinfochkresult").val("N");

				custom_opts.title = '차량 정보 조회에 실패하였습니다.';//res.MSG;
				custom_modal_alert(custom_opts);
				// alert(res.MSG);
				return false;
			}

			// var obj = JSON.parse(data);	//JSON형식으로 리턴 받을 때
			// var INFO = res.DATAS.CARINFO;
			var CARINFO = res.DATAS.CARINFO;

			//사고이력정보 세팅
			cd_car_history = CARINFO.cd_car_history;
			$("#cd_car_history").val(cd_car_history);

			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.GRADE_CODE,'선택하세요',CARINFO.CD_MODEL_SUB);

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

			var nm_regdate = CARINFO.r203[0].r203;
			$("#nm_regdate_yyyy").val(nm_regdate.substring(0,4));
			$("#nm_regdate_mm").val(nm_regdate.substring(4,6));
			$("#nm_cc").val(CARINFO.r104);
			$("#ds_oil").val(CARINFO.r106);

			//사고건수가 1건이상이면 사고유무를 자동 세팅
			if(parseInt(CARINFO.r501) > 0) {
				$("#ds_accident").val("A0");
			}else {
				$("#ds_accident").val("B0");
			}
			//주행거리 제공이면
			if(CARINFO.r601 == "1") {
				// console.log(CARINFO.r602[0]);
				for(var m in CARINFO.r602[0]) {
					if(m == "r602-03") {
						$("#nm_mileage").val(CARINFO.r602[0][m]);
					}
				}
				// var nm_mileage = ;.r602-03;
			}

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

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

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

		}, "json");

		return false;

	});



	$("#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
		if ("<?=$s_staff_cd_car?>" == ""){
			var fieldlist = [["nm_number","차량번호"],["nm_hp1","판매자 연락처"],["nm_hp2","판매자 연락처"],["nm_hp3","판매자 연락처"]
			, ["cd_brand","제조사"],["cd_model","모델"],["ds_tradein", "Trade-In"],["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", "판매시기"]
			,["ds_tradein", "Trade-In"],["ds_buy_method", "구매방식"],["ds_auction_time", "경매시간"]
		] ;
		}else{
			var fieldlist = [["cd_brand","제조사"],["nm_hp1","판매자 연락처"],["nm_hp2","판매자 연락처"],["nm_hp3","판매자 연락처"]
			,["cd_model","모델"],["ds_tradein", "Trade-In"],["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", "판매시기"]
			,["ds_tradein", "Trade-In"],["ds_buy_method", "구매방식"],["ds_auction_time", "경매시간"]
		] ;
		}

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

		if($("#carinfochkresult").val() != "Y"){
			custom_opts.title = '차량조회를 해주세요';
			custom_modal_alert(custom_opts);
			// alert(res.MSG);
			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 : 'sell_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;
			}
		});

		// custom_opts.title = '정보를 등록하시겠습니까?';
		// custom_modal_confirm(custom_opts, function(confirm) {
		// 	if(confirm) {
		// 		$("#frmForm").submit();
		//
		// 	}else {
		// 		$("#btn_write").show();
		// 		return false;
		// 	}
		// });
	});

	//차량이력정보 보기 팝업
	$("#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},function(data) {
			$("#scr_cont").html(data);
			viewLayerPopup('car_history');
		});
	});

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


	//메인에서 차량조회를 하고 넘어온 거면 차량조히를 자동으로
<?php if(!empty($req_nm_name) && !empty($req_nm_number)) {?>
	//세부 코드들을 다 가져온 다음에 object close
	$(document).ajaxStop(function () {
		controlObjCarInfo("all",false);	//car_info all object
		//여기서 가져오면 무한 로딩 됨
	});

<?php } ?>


	//직접입력
	// $("#cd_grade").on("change", function() {
	// 	var val = $(this).val();
	// 	if(val == "-1") {
	// 		$("#cd_grade_direct").show();
	// 		$("#cd_grade_direct").focus();
	// 	}else {
	// 		$("#cd_grade_direct").hide();
	// 	}
	// });


});

</script>



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