
<link rel="stylesheet" type="text/css" href="<?=ADMIN_PATH?>/css/admin_view.css">
<script src="https://code.jquery.com/ui/1.9.1/jquery-ui.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" type="text/css" media="all" />



<?
	$s_cd_dealer = $_SESSION['s_cd_dealer'];
	$s_cd_dealer_p = $_SESSION['s_cd_dealer_p'];
	$s_ds_type = $_SESSION['s_ds_type'];

	if($s_ds_type == "D0"){	//딜러
		$sql1 = " cd_dealer_p = '$s_cd_dealer' ";
	}else{	//딜러-관리자
		$sql1 = " cd_dealer = '$s_cd_dealer' ";
	}

// 	$cd_sale = $_REQUEST["cd_sale"];
//
// 	$sql ="SELECT
// 						a.*
// 						, b.nm_model
// 						, c.nm_grade
// 						, d.nm_brand
// 						, e.nm_model_sub
// 						, getCode('car_master','ds_type',a.ds_type) as nm_type
// 						, getCode('car_master','ds_year',a.ds_year) as nm_year
// 						, getCode('car_master','ds_open',a.ds_open) as nm_open
// 						, getCode('car_master','ds_sales',a.ds_sales) as nm_sales
// 						, getCode('car_master','ds_transmission',a.ds_transmission) as nm_transmission
// 						, getCode('car_master','ds_oil',a.ds_oil) as nm_oil
// 						, getCode('car_master','ds_accident',a.ds_accident) as nm_accident
// 						, getCode('sale_master','ds_usertype',s.ds_usertype) as nm_usertype
// 						, getCode('member_master','ds_area',s.ds_area) as nm_area
// 						, getCode('sale_master','ds_status',s.ds_status) as nm_status
// 						, s.nm_name nm_name_sale
// 						, s.ds_status ds_status_sale
// 						, s.nm_hp nm_hp_sale
// 						, s.nm_email nm_email_sale
// 						, s.ds_area ds_area_sale
// 						, s.nm_price nm_price_sale
// 						, s.nm_price_final nm_price_final_sale
// 						, s.nm_recommend nm_recommend_sale
// 						, s.nm_cont_return nm_cont_return_sale
// 						, s.nm_cont_tender_error nm_cont_tender_error_sale
// 						, s.ds_status_contract ds_status_contract_sale
// 						, s.ds_status_contract_step1 ds_status_contract_step1_sale
// 						, s.ds_status_contract_step2 ds_status_contract_step2_sale
// 						, s.ds_status_contract_step3 ds_status_contract_step3_sale
// 						, s.ds_status_contract_step4 ds_status_contract_step4_sale
// 						, s.nm_contract_date nm_contract_date_sale
// 						, s.nm_contract_cont_final nm_contract_cont_final_sale
// 						, s.nm_contract_fail_reason nm_contract_fail_reason_sale
// 						, s.nm_file_chk1 nm_file_chk1_sale
// 						, s.nm_file_chk2 nm_file_chk2_sale
// 						, s.nm_file_chk3 nm_file_chk3_sale
// 						, s.nm_file_chk4 nm_file_chk4_sale
// 						, s.nm_file_chk5 nm_file_chk5_sale
// 						, s.nm_file_trading nm_file_trading_sale
// 						, s.nm_file_performance nm_file_performance_sale
// 						, s.nm_file_postscript nm_file_postscript_sale
// 						FROM sale_master s
// 							inner join car_master a on (s.cd_car = a.cd_car)
// 							left outer join car_model b on (a.cd_model = b.cd_model)
// 							left outer join car_grade c on (a.cd_grade = c.cd_grade)
// 							left outer join car_brand d on (a.cd_brand = d.cd_brand)
// 							left outer join car_model_sub e on (a.cd_model_sub = e.cd_model_sub)
// 						WHERE s.cd_sale='$cd_sale' ";
//
// 	$col=mysql_fetch_array(mysql_query($sql));
// 	if (!empty($col['cd_car'])){
//
// 		$cd_car = $col['cd_car'];
// 		$cd_model = $col['cd_model'];
// 		$cd_brand = $col['cd_brand'];
// 		$ds_logo = $col['ds_logo'];
// 		$cd_category = $col['cd_category'];
// 		$cd_grade = $col['cd_grade'];
// 		$ds_cate = $col['ds_cate'];
// 		$ds_type = $col['ds_type'];
// 		$ds_year = $col['ds_year'];
// 		$nm_name = $col['nm_name'];
// 		$nm_price = $col['nm_price'];
// 		$nm_mileage = $col['nm_mileage'];
// 		$ds_driving_system = $col['ds_driving_system'];
// 		$ds_transmission = $col['ds_transmission'];
// 		$nm_file_list = $col['nm_file_list'];
// 		$nm_file_main = $col['nm_file_main'];
// 		$nm_file_report = $col['nm_file_report'];
// 		$nm_file_report_back = $col['nm_file_report_back'];
// 		$nm_file_front = $col['nm_file_front'];
// 		$nm_file_back = $col['nm_file_back'];
// 		$nm_file_side1 = $col['nm_file_side1'];
// 		$nm_file_side2 = $col['nm_file_side2'];
// 		$nm_file_dashboard = $col['nm_file_dashboard'];
// 		$ds_oil = $col['ds_oil'];
// 		$nm_gearbox = $col['nm_gearbox'];
// 		$nm_color = $col['nm_color'];
// 		$nm_incolor = $col['nm_incolor'];
// 		$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'];
// 		$nm_guide = $col['nm_guide'];
// 		$ds_open = $col['ds_open'];
// 		$ds_status = $col['ds_status'];
// 		$dt_insert = $col['dt_insert'];
// 		$nm_insert = $col['nm_insert'];
// 		$dt_update = $col['dt_update'];
// 		$nm_update = $col['nm_update'];
// 		$ds_delind = $col['ds_delind'];
// 		$nm_number = $col['nm_number'];
// 		$nm_cc = $col['nm_cc'];
// 		$ds_trade = $col['ds_trade'];
// 		$ds_main = $col['ds_main'];
// 		$nm_regdate_yyyy = $col['nm_regdate_yyyy'];
// 		$nm_regdate_mm = $col['nm_regdate_mm'];
// 		$nm_regdate_dd = $col['nm_regdate_dd'];
//
// 		$nm_brand = $col['nm_brand'];
// 		$nm_model = $col['nm_model'];
// 		$nm_model_sub = $col['nm_model_sub'];
// 		$nm_grade = $col['nm_grade'];
//
// 		$nm_year = $col['nm_year'];
// 		$nm_type = $col['nm_type'];
// 		$nm_open = $col['nm_open'];
// 		$nm_sales = $col['nm_sales'];
// 		$nm_transmission = $col['nm_transmission'];
// 		$nm_oil = $col['nm_oil'];
// 		$nm_usertype = $col['nm_usertype'];
// 		$nm_accident = $col['nm_accident'];
// 		$nm_area = $col['nm_area'];
// 		$nm_name_sale = $col['nm_name_sale'];
// 		$ds_status_sale = $col['ds_status_sale'];
// 		$nm_hp_sale = $col['nm_hp_sale'];
// 		$nm_email_sale = $col['nm_email_sale'];
// 		$ds_area_sale = $col['ds_area_sale'];
// 		$nm_price_sale = $col['nm_price_sale'];
// 		$nm_price_final_sale = $col['nm_price_final_sale'];
// 		$nm_recommend_sale = $col['nm_recommend_sale'];
// 		$nm_cont_return_sale = $col['nm_cont_return_sale'];
// 		$nm_cont_tender_error_sale = $col['nm_cont_tender_error_sale'];
// 		$ds_status_contract_sale = $col['ds_status_contract_sale'];
// 		$ds_status_contract_step1_sale = $col['ds_status_contract_step1_sale'];
// 		$ds_status_contract_step2_sale = $col['ds_status_contract_step2_sale'];
// 		$ds_status_contract_step3_sale = $col['ds_status_contract_step3_sale'];
// 		$ds_status_contract_step4_sale = $col['ds_status_contract_step4_sale'];
// 		$nm_contract_date_sale = $col['nm_contract_date_sale'];
// 		$nm_contract_cont_final_sale = $col['nm_contract_cont_final_sale'];
// 		$nm_contract_fail_reason_sale = $col['nm_contract_fail_reason_sale'];
// 		$nm_file_chk1_sale = $col['nm_file_chk1_sale'];
// 		$nm_file_chk2_sale = $col['nm_file_chk2_sale'];
// 		$nm_file_chk3_sale = $col['nm_file_chk3_sale'];
// 		$nm_file_chk4_sale = $col['nm_file_chk4_sale'];
// 		$nm_file_chk5_sale = $col['nm_file_chk5_sale'];
// 		$nm_file_trading_sale = $col['nm_file_trading_sale'];
// 		$nm_file_performance_sale = $col['nm_file_performance_sale'];
// 		$nm_file_postscript_sale = $col['nm_file_postscript_sale'];
//
// 		//보험처리
// 		$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_act_general_spec = $col['nm_act_general_spec'];
// 		$nm_act_use_record = $col['nm_act_use_record'];
// 		$nm_act_use_record_lend = $col['nm_act_use_record_lend'];
// 		$nm_act_use_record_biz = $col['nm_act_use_record_biz'];
// 		$nm_act_use_record_official = $col['nm_act_use_record_official'];
// 		$nm_act_ins_loss = $col['nm_act_ins_loss'];
// 		$nm_act_ins_wet = $col['nm_act_ins_wet'];
// 		$nm_act_ins_robbery = $col['nm_act_ins_robbery'];
// 		$nm_file_act = $col['nm_file_act'];
// 		$nm_act_yn = $col['nm_act_yn'];
//
// 		$ds_g1_01 = $col['ds_g1_01'];
// 		$ds_g1_02 = $col['ds_g1_02'];
// 		$ds_g1_03 = $col['ds_g1_03'];
// 		$ds_g1_04 = $col['ds_g1_04'];
// 		$ds_g1_05 = $col['ds_g1_05'];
// 		$ds_g2_01 = $col['ds_g2_01'];
// 		$ds_g2_02 = $col['ds_g2_02'];
// 		$ds_g2_03 = $col['ds_g2_03'];
// 		$ds_g2_04 = $col['ds_g2_04'];
// 		$ds_g2_05 = $col['ds_g2_05'];
// 		$ds_g3_01 = $col['ds_g3_01'];
// 		$ds_g3_02 = $col['ds_g3_02'];
// 		$ds_g3_03 = $col['ds_g3_03'];
// 		$ds_g3_04 = $col['ds_g3_04'];
// 		$ds_g3_05 = $col['ds_g3_05'];
// 		$ds_g4_01 = $col['ds_g4_01'];
// 		$ds_g4_02 = $col['ds_g4_02'];
// 		$ds_g4_03 = $col['ds_g4_03'];
// 		$ds_g4_04 = $col['ds_g4_04'];
// 		$ds_g4_05 = $col['ds_g4_05'];
//
// /*
// 		$arr_nm_info1 = explode("-",$nm_info1);
// 		if(count($arr_nm_info1) == 3){
// 			$nm_info11 = $arr_nm_info1[0];
// 			$nm_info12 = $arr_nm_info1[1];
// 			$nm_info13 = $arr_nm_info1[2];
// 		}else{
// 			$nm_info11 = "";
// 			$nm_info12 = "";
// 			$nm_info13 = "";
// 		}
//
// 		$arr_nm_info3 = explode("@",$nm_info3);
// 		if(count($arr_nm_info3) == 2){
// 			$nm_info31 = $arr_nm_info3[0];
// 			$nm_info32 = $arr_nm_info3[1];
// 		}else{
// 			$nm_info31 = "";
// 			$nm_info32 = "";
// 		}
// 		$nm_info3 = $col[nm_info3];
// */
//
// 	}else{
// 			AlertBack("지정되지않은 요청입니다");
// 	}

	$sql ="SELECT *
		FROM car_history_master mst
		WHERE  cd_car='$cd_car' AND ds_delind='N'";
	$history_col=mysql_fetch_array(mysql_query($sql));

	$r000  		= $history_col["r000"];
	$r001  		= $history_col["r001"];
	$r002  		= $history_col["r002"];
	$r004  		= $history_col["r004"];
	$r005  		= $history_col["r005"];
	$r101  		= $history_col["r101"];
	$r102  		= $history_col["r102"];
	$r103  		= $history_col["r103"];
	$r104  		= $history_col["r104"];
	$r105  		= $history_col["r105"];
	$r106  		= $history_col["r106"];
	$r107  		= $history_col["r107"];
	$r108  		= $history_col["r108"];
	$r109  		= $history_col["r109"];
	$r401  		= $history_col["r401"];
	$r402  		= $history_col["r402"];
	$r403  		= $history_col["r403"];
	$r404  		= $history_col["r404"];
	$r405  		= $history_col["r405"];
	$r406_01  	= $history_col["r406_01"];
	$r407  		= $history_col["r407"];
	$r408_01  	= $history_col["r408_01"];
	$r409  		= $history_col["r409"];
	$r410_01  	= $history_col["r410_01"];
	$r201  		= $history_col["r201"];
	$r202  		= $history_col["r202"];
	$r203  		= $history_col["r203"];
	$r204  		= $history_col["r204"];
	$r205  		= $history_col["r205"];
	$r510  		= $history_col["r510"];
	$r511_01  	= $history_col["r511_01"];
	$r501  		= $history_col["r501"];
	$r502  		= $history_col["r502"];
	$r301  		= $history_col["r301"];
	$r302  		= $history_col["r302"];
	$r303  		= $history_col["r303"];
	$r601  		= $history_col["r601"];
	$r602  		= $history_col["r602"];

?>

<style>
ul.contract_photo_list input[type="file"] {
    overflow: hidden;
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    clip: rect(0,0,0,0);
}
</style>
		<h3>낙찰리스트</h3>
		<ul class="success_confirm">
			<!-- <li>
				<p>차량정보 확인 <? if($ds_status_contract_step1_sale != "Y"){ ?><span class="no">미확인</span><? }else{ ?><span>확인</span><? } ?></p>
				<div class="confirm_cont">


					<h3>사고이력정보</h3>
					<table class="tbl_h">
						<colgroup>
							<col width="16%">
							<col width="*">
						</colgroup>
						<tr>
							<th>차량번호 변경</th>
							<td><?=number_format($r201)?> 회</td>
						</tr>
						<tr>
							<th>소유자 변경</th>
							<td><?=number_format($r204)?> 회</td>
						</tr>
						<tr>
							<th>자동차 보험 특수 사고</th>
							<td>전손 : <?=number_format($r405)?>회 / 침수전(분)손 : <?=number_format($r407)?>회 / 도난 : <?=number_format($r409)?>회</td>
						</tr>
						<tr>
							<th>보험사고 (내차피해)</th>
							<td><?=number_format($r401)?> 회(<?=number_format($r402)?> 원)</td>
						</tr>
						<tr>
							<th>보험사고 (타차가해)</th>
							<td><?=number_format($r403)?> 회(<?=number_format($r404)?> 원)</td>
						</tr>
					</table>

					<div class="btn_center">
						<a href="#" class="button" onclick="openLayer('car'); return false;">사고이력 정보 조회 보기</a>
					</div>
<? if($ds_status_contract_step1_sale != "Y" && $ds_status_contract_step1_sale != "N"){ ?>
					<div class="btn_center">
						<a href="#" class="button" onclick="openLayer('estimate'); return false;">이상없는 견적입니다.</a>
						<a href="#" class="button gray" onclick="openLayer('estimate2'); return false;" style="margin-left:40px;">견적실수</a>
					</div>
<? } ?>
				</div>
			</li> -->

		<!-- layer popup3 -->
		<div class="layer_popup photo_popup">
			<img src="/img/sell/ic_car_photo1.png" id="photoBig" style="width:500px;">
			<div class="close" onclick="closeLayer('photo');">레이어팝업 닫기</div>
		</div>
		<!-- // layer popup3 -->

<script laguage="javascript" type="text/javascript">

	function viewPhoto(arg1){

		$("#photoBig").attr("src", arg1);

		openLayer('photo'); return false;

	}

</script>
			<li>
				<p>고객통화 후 일정잡기 <? if($ds_status_contract_step2_sale != "Y"){ ?><span class="no">미확인</span><? }else{ ?><span>확인</span><? } ?></p>
				<div class="confirm_cont">
					<form id="frmFormStep2" name="frmFormStep2" method="post" action="proc.php" enctype="multipart/form-data">
					<input type="hidden" id="mode" name="mode" value="ContractStep2">
					<input type="hidden" id="cd_sale" name="cd_sale" value="<?=$cd_sale?>">
					<div class="schedule">

						<!-- calendar -->
						<div class="calendar">
							<input type="text" class="inp_txt" style="width:34%;" id="nm_contract_date" name="nm_contract_date" value="<?=$nm_contract_date_sale?>">
							<span class="btn_cal" id="btn_cal">달력보기</span>
						</div>
						<!-- // calendar -->
						<div class="tel">
							<p class="name"><?=$nm_name_sale?><br><?=$nm_hp_sale?></p>
						</div>
					</div>
				<?php if($ds_status_contract_step2_sale != "Y"){ ?>
					<div class="btn_center">
						<a href="javascript:;" class="button" id="btn_contract_step2">확인</a>
					</div>
				<?php } ?>
				</form>
				</div>
			</li>


			<li>
				<p>검차 결과 / 계약상황 입력하기 <? if($ds_status_contract_step3_sale != "Y"){ ?><span class="no">미확인</span><? }else{ ?><span>확인</span><? } ?></p>
				<div class="confirm_cont">
					<form id="frmFormStep3" name="frmFormStep3" method="post" action="proc.php" enctype="multipart/form-data">
					<input type="hidden" id="mode" name="mode" value="ContractStep3">
					<input type="hidden" id="cd_sale" name="cd_sale" value="<?=$cd_sale?>">
					<div class="deal_status">
						<h4>계약상황을 입력해주세요</h4>
						<p class="deal_check">
							<span class="check_wrap"><input type="radio" name="ds_status_contract" id="ds_status_contract1" value="Z0"<? if($ds_status_contract_sale == "Z0"){ ?> checked="checked"<? } ?>><i></i><label for="ds_status_contract1">거래완료</label></span>
							<span class="check_wrap"><input type="radio" name="ds_status_contract" id="ds_status_contract2" value="B0"<? if($ds_status_contract_sale == "B0"){ ?> checked="checked"<? } ?>><i></i><label for="ds_status_contract2">거래연기</label></span>
							<span class="check_wrap"><input type="radio" name="ds_status_contract" id="ds_status_contract3" value="C0"<? if($ds_status_contract_sale == "C0"){ ?> checked="checked"<? } ?>><i></i><label for="ds_status_contract3">실패</label></span>
							<small>(※고객이 입력한 차량 내용과 차이가 있다면 검차결과 다른점을 입력해주세요.)</small>
						</p>
						<!-- 거래완료일 경우 -->
						<div class="deal_complete">
							<p class="my_price"><input type="text" class="inp_txt" style="width:270px;" id="nm_price_final" name="nm_price_final" value="<?=$nm_price_final_sale?>" placeholder="최종금액 입력"> 만원</p>
							<p id="layout_contact_final"><textarea cols="80" rows="8" placeholder="ex) 앞 휀다교환 1개-20만원, 앞범퍼 1판-7만원 20만원으로 최종조율, 다음주 수요일 인수예정" id="nm_contract_cont_final" name="nm_contract_cont_final"style='background-color: #fff;'><?=$nm_contract_cont_final_sale?></textarea></p>
						<?php // if($ds_status_sale == "Z0" && $ds_status_contract_sale == "C0"){ ?>
							<br><br>
							<p id="layout_contact_fail" class="hide">거래실패 or 거래연기 사유<textarea cols="80" rows="4" id="nm_contract_fail_reason" name="nm_contract_fail_reason" style='background-color: #fff;' placeholder="거래실패 or 거래 연기사유를 작성해 주세요"><?=$nm_contract_fail_reason_sale?></textarea></p>
						<?php // } ?>
						<?php
							$contract_img_path = $_SERVER['DOCUMENT_ROOT'].UPLOAD_PATH."aap/contract_step/".$cd_sale."_detail/";
							$contract_img_web_path = UPLOAD_PATH."aap/contract_step/".$cd_sale."_detail/";

							// echo $contract_img_path.$nm_file_trading_sale;
							// exit;
							$nm_file_trading_class = "";
							$nm_file_trading_style = "";
							$nm_file_trading = $car_no_img;
							if(file_exists($contract_img_path.$nm_file_trading_sale)) {
								$nm_file_trading = $contract_img_web_path.$nm_file_trading_sale;
								$nm_file_trading_class = "upload--file";
								$nm_file_trading_style = "style='background: url(".$nm_file_trading.") no-repeat center; background-size:contain;'";
							}
							$nm_file_performance_class = "";
							$nm_file_performance_style = "";
							$nm_file_performance = $car_no_img;
							if(file_exists($contract_img_path.$nm_file_performance_sale)) {
								$nm_file_performance = $contract_img_web_path.$nm_file_performance_sale;
								$nm_file_performance_class = "upload--file";
								$nm_file_performance_style = "style='background: url(".$nm_file_performance.") no-repeat center; background-size:contain;'";
							}
						?>
						<dl>
							<dt>검차사진(최대 5장, 필수)</dt>
						</dl>
						<ul class="photo_list" id="layout_contract_image">
							<li>
								<input type="file" hidden="" name="nm_file_chk1" id="nm_file_chk1" class="upload-hidden " onchange="viewContractThumb(0,this)" accept="image/*">
								<?=getCarContractImage($cd_sale, $nm_file_chk1_sale, '검차사진1', true, 'car_check')?>
								<span>검차사진1</span>
								<button type="button" class="edit--btn btn_add_attach" for="nm_file_chk1">사진 등록</button>
							</li>
							<li>
								<input type="file" hidden="" name="nm_file_chk2" id="nm_file_chk2" class="upload-hidden " onchange="viewContractThumb(1,this)" accept="image/*">
								<?=getCarContractImage($cd_sale, $nm_file_chk2_sale, '검차사진2', true, 'car_check')?>
								<span>검차사진2</span>
								<button type="button" class="edit--btn btn_add_attach" for="nm_file_chk2">사진 등록</button>
							</li>
							<li>
								<input type="file" hidden="" name="nm_file_chk3" id="nm_file_chk3" class="upload-hidden " onchange="viewContractThumb(2,this)" accept="image/*">
								<?=getCarContractImage($cd_sale, $nm_file_chk3_sale, '검차사진3', true, 'car_check')?>
								<span>검차사진3</span>
								<button type="button" class="edit--btn btn_add_attach" for="nm_file_chk3">사진 등록</button>
							</li>
							<li>
								<input type="file" hidden="" name="nm_file_chk4" id="nm_file_chk4" class="upload-hidden " onchange="viewContractThumb(3,this)" accept="image/*">
								<?=getCarContractImage($cd_sale, $nm_file_chk4_sale, '검차사진4', true, 'car_check')?>
								<span>검차사진4</span>
								<button type="button" class="edit--btn btn_add_attach" for="nm_file_chk4">사진 등록</button>
							</li>
							<li>
								<input type="file" hidden="" name="nm_file_chk5" id="nm_file_chk5" class="upload-hidden " onchange="viewContractThumb(4,this)" accept="image/*">
								<?=getCarContractImage($cd_sale, $nm_file_chk5_sale, '검차사진5', true, 'car_check')?>
								<span>검차사진5</span>
								<button type="button" class="edit--btn btn_add_attach" for="nm_file_chk5">사진 등록</button>
							</li>
						</ul>
						</div>

						<!-- 거래연기 및 실패일 경우 -->
						<!-- <dl class="reason">
							<dt>거래 실패사유를 입력해주세요</dt>
							<dd><textarea cols="80" rows="8" id="nm_contract_fail_reason" name="nm_contract_fail_reason"><?=$nm_contract_fail_reason_sale?></textarea></dd>
						</dl> -->
					</div>
				<?php // if($ds_status_contract_step3_sale != "Y"){ ?>
					<div class="btn_center">
						<a href="javascript:;" class="button" id="btn_contract_step3">확인</a>
					</div>
				<?php // } ?>

				</form>
				</div>
			</li>
			<li>
				<p>거래마무리 관리 <? if($ds_status_contract_step4_sale != "Y"){ ?><span class="no">미확인</span><? }else{ ?><span>확인</span><? } ?></p>
				<div class="confirm_cont">
					<form id="frmFormStep4" name="frmFormStep4" method="post" action="proc.php" enctype="multipart/form-data">
					<input type="hidden" id="mode" name="mode" value="ContractStep4">
					<input type="hidden" id="cd_sale" name="cd_sale" value="<?=$cd_sale?>">
					<input type="hidden" name="list_url" value="<?=$list_url?>">
					<input type="hidden" name="ds_status_sale" value="<?=$ds_status_sale?>">
					<input type="hidden" name="ds_status_contract_sale" value="<?=$ds_status_contract_sale?>">
					<input type="hidden" name="ds_status_contract_step1_sale" value="<?=$ds_status_contract_step1_sale?>">
					<input type="hidden" name="ListPageNo" value="<?=$ListPageNo?>">

					<ul class="photo_list" id="layout_contract_cert_image">
						<li>
							<input type="file" hidden="" name="nm_file_trading" id="nm_file_trading" class="upload-hidden " onchange="viewContractEndThumb(0,this)" accept="image/*">
							<?=getCarContractImage($cd_sale, $nm_file_trading_sale, '상사이전 등록증', true, 'car_check')?>
							<span>상사이전 등록증</span>
							<button type="button" class="edit--btn btn_add_attach" for="nm_file_trading">사진 등록</button>
						</li>
						<li>
							<input type="file" hidden="" name="nm_file_performance" id="nm_file_performance" class="upload-hidden " onchange="viewContractEndThumb(1,this)" accept="image/*">
							<?=getCarContractImage($cd_sale, $nm_file_performance_sale, '성능지 등록', true, 'car_check')?>
							<span>성능지 등록</span>
							<button type="button" class="edit--btn btn_add_attach" for="nm_file_performance">사진 등록</button>
						</li>
						<li>
							<input type="file" hidden="" name="nm_file_regist" id="nm_file_regist" class="upload-hidden " onchange="viewContractEndThumb(2,this)" accept="image/*">
							<?=getCarContractImage($cd_sale, $nm_file_regist_sale, '전고객 등록증', true, 'car_check')?>
							<span>전고객 등록증</span>
							<button type="button" class="edit--btn btn_add_attach" for="nm_file_regist">사진 등록</button>
						</li>
					</ul>

					<!-- <dl class="deal_attach">
						<dt>상사이전등록증 등록(48시간 이내 등록해주세요)</dt>
						<dd>
							<div class="filebox">
							<? if($nm_file_trading_sale!=""){ ?>
								<label for="nm_file_trading" style="background-image:url('<?=UPLOAD_PATH?>dealer/contract_step/<?=$cd_sale?>_detail/<?=$nm_file_trading_sale?>');" onclick="viewPhoto('<?=UPLOAD_PATH?>dealer/contract_step/<?=$cd_sale?>_detail/<?=$nm_file_trading_sale?>')"></label>
								<?
								//판매 완료시 이미지 수정되게
								if($ds_status_sale == "ZS"){
								?>
								<a href="javascript:;" class="rnd_btn ty3 black btn_step4_image" for="nm_file_trading_modify" style="margin-left:10px;padding:0 10px;width:auto;font-size:12px;">이미지 업로드</a>
								<input type="file" name="nm_file_trading" id="nm_file_trading_modify" class="upload-hidden" onchange="viewThumb1(0,this)">
								<? } ?>
							<? }else { ?>
								<label for="nm_file_trading">
									등록 +
									<input type="file" name="nm_file_trading" id="nm_file_trading" class="upload-hidden" onchange="viewThumb1(0,this)">
								</label>
							<?}?>
							</div>
						</dd>
						<dt>성능지 등록 (5일 이전것으로 등록해주세요)</dt>
						<dd>
							<div class="filebox">
							<? if($nm_file_performance_sale!=""){ ?>
								<label for="nm_file_performance" style="background-image:url('<?=UPLOAD_PATH?>dealer/contract_step/<?=$cd_sale?>_detail/<?=$nm_file_performance_sale?>');" onclick="viewPhoto('<?=UPLOAD_PATH?>dealer/contract_step/<?=$cd_sale?>_detail/<?=$nm_file_performance_sale?>')"></label>
								<?
								//판매 완료시 이미지 수정되게
								if($ds_status_sale == "ZS"){
								?>
								<a href="javascript:;" class="rnd_btn ty3 black btn_step4_image" for="nm_file_performance_modify" style="margin-left:10px;padding:0 10px;width:auto;font-size:12px;">이미지 업로드</a>
								<input type="file" name="nm_file_performance" id="nm_file_performance_modify" class="upload-hidden" onchange="viewThumb1(1,this)">
								<? } ?>
							<? }else { ?>
								<label for="nm_file_performance">
									등록 +
									<input type="file" name="nm_file_performance" id="nm_file_performance" class="upload-hidden" onchange="viewThumb1(1,this)">
								</label>
							<?}?>
							</div>
						</dd>
						<dt>거래 후기 사진을 올려주세요(선택)</dt>
						<dd>
							<div class="filebox">
							<? if($nm_file_postscript_sale!=""){ ?>
								<label for="nm_file_postscript" style="background-image:url('<?=UPLOAD_PATH?>dealer/contract_step/<?=$cd_sale?>_detail/<?=$nm_file_postscript_sale?>');" onclick="viewPhoto('<?=UPLOAD_PATH?>dealer/contract_step/<?=$cd_sale?>_detail/<?=$nm_file_postscript_sale?>')"></label>
								<?
								//판매 완료시 이미지 수정되게
								if($ds_status_sale == "ZS"){
								?>
								<a href="javascript:;" class="rnd_btn ty3 black btn_step4_image" for="nm_file_postscript_modify" style="margin-left:10px;padding:0 10px;width:auto;font-size:12px;">이미지 업로드</a>
								<input type="file" name="nm_file_postscript" id="nm_file_postscript_modify" class="upload-hidden" onchange="viewThumb1(2,this)">
								<? } ?>
							<? }else { ?>
								<label for="nm_file_postscript">
									등록 +
									<input type="file" name="nm_file_postscript" id="nm_file_postscript" class="upload-hidden" onchange="viewThumb1(2,this)">
								</label>
							<?}?>
							</div>
						</dd>
					</dl> -->

<? if($ds_status_contract_step4_sale != "Y"){ ?>
					<div class="btn_center">
						<a href="javascript:;" class="button" id="btn_contract_step4">등록</a>
					</div>
<? }else { ?>
	<?
	//판매 완료일 경우에는 상사이전등록증, 성능지, 거래 후기 사진을 변경할 수 있게
	if($ds_status_sale == "ZS"){
	?>
					<div class="btn_center">
						<a href="javascript:;" class="button" id="btn_contract_step4_modify">이미지 수정</a>
					</div>
	<? } ?>
<? } ?>
</form>
				</div>
			</li>
<?
	//step1~4 의 단계가 모두
?>
			<li>
				<p>거래완료 처리 <? if($ds_status_contract_step5_sale != "Y"){ ?><span class="no">미확인</span><? }else{ ?><span>확인</span><? } ?></p>
				<div class="confirm_cont">
				<form id="frmFormStep5" name="frmFormStep5" method="post" action="proc.php" enctype="multipart/form-data">
				<input type="hidden" id="cd_sale" name="cd_sale" value="<?=$cd_sale?>">
				<input type="hidden" name="list_url" value="<?=$list_url?>">
				<input type="hidden" name="ds_status_sale" value="<?=$ds_status_sale?>">
				<input type="hidden" name="ds_status_contract_sale" value="<?=$ds_status_contract_sale?>">
				<input type="hidden" name="ds_status_contract_step1_sale" value="<?=$ds_status_contract_step1_sale?>">
				<input type="hidden" name="ListPageNo" value="<?=$ListPageNo?>">

				<input type="hidden" id="mode" name="mode" value="ContractStep5">

					<dl class="deal_attach">
						<dt>거래완료일</dt>
						<dd>
							<div class="calendar">
								<input type="text" class="inp_txt" style="width:34%;" id="dt_end" name="dt_end" value="<?=$dt_end_sale?>">
								<span class="btn_cal" id="btn_force_cal">달력보기</span>
							</div>
						</dd>
					</dl>

					<?php if($ds_status_contract_step5_sale != "Y"){ ?>
							<div class="btn_center">
								<a href="javascript:;" class="button" id="btn_contract_step5">거래완료처리</a>
							</div>
					<?php } ?>
<?php
if($ds_status_sale == "Z0"){
?>
<!-- <input type="hidden" id="mode" name="mode" value="ContractStep5">
					<div class="btn_center">
						<a href="javascript:;" class="button" id="btn_contract_step5">거래완료처리</a> -->
					<!-- </div> -->
<?php
//거래완료 처리 됐을 경우 거래완료일 변경 가능
}else if($ds_status_sale == "ZS"){
?>
<!-- <input type="hidden" id="mode" name="mode" value="ContractStep5Modify"> -->
					<!-- <div class="btn_center">
						<a href="#" class="button" id="btn_contract_step5">거래완료일 변경</a>
					</div> -->
<? } ?>
</form>
				</div>
			</li>
		</ul>



		<!-- layer popup -->
		<div class="layer_popup car_popup">
			<h3>중고차 보험처리 이력정보 보고서</h3>
			<p class="close">레이어팝업닫기</p>
			<div class="scr_cont">
				<?
					//차량 보험처리 이력 정보
					include_once($_SERVER['DOCUMENT_ROOT'].'/common/inc/inc_car_history.php');
				?>
			</div>
		</div>
		<!-- // layer popup -->
		<!-- layer popup2 -->
		<div class="layer_popup estimate_popup">
			<div class="popup_wrap">
				<p class="msg">견적에 이상이 없습니다.</p>
				<div class="btn_center">
					<a href="#" class="button" id="btn_contract_step1">이상없음</a>
					<a href="#" class="button gray" onclick="closeLayer('estimate'); return false;">아니요</a>
				</div>
			</div>
		</div>
		<!-- // layer popup2 -->
		<!-- layer popup3 -->
		<div class="layer_popup estimate2_popup">
<form id="frmFormStepError" name="frmFormStepError" method="post" action="dealer_proc.php" enctype="multipart/form-data">
<input type="hidden" id="mode" name="mode" value="ContractStepError">
<input type="hidden" id="cd_sale" name="cd_sale" value="<?=$cd_sale?>">
			<div class="popup_wrap">
				<dl>
					<dt><em>견적실수</em>에 대한 사유를 적어주세요</dt>
					<dd>
						<textarea cols="70" rows="8" id="nm_cont_tender_error" name="nm_cont_tender_error"><?=$nm_cont_tender_error_sale?></textarea>
						<p><em>관리자 확인 후 패널티 적용이 있을 수 있습니다.</em>다시 한번 더 확인 부탁 드립니다.</p>
					</dd>
				</dl>
				<div class="btn_center">
					<a href="#" class="button" id="btn_contract_step_error">확인</a>
				</div>
			</div>
</form>
			<div class="close">레이어팝업 닫기</div>
		</div>
		<!-- // layer popup3 -->

<script type="text/javascript">
	$(".success_confirm > li > p").click(function(){
		if(!$(this).hasClass("on")){
			$(this).parents(".success_confirm").find("li > p").removeClass("on");
			$(this).addClass("on");
		} else {
			$(this).removeClass("on");
		}
	});
</script>

<form id="frmFormStep1" name="frmFormStep1" method="post" action="dealer_proc.php">
<input type="hidden" id="mode" name="mode" value="ContractStep1">
<input type="hidden" id="cd_sale" name="cd_sale" value="<?=$cd_sale?>">
<input type="hidden" id="ds_status_contract_step1" name="ds_status_contract_step1" value="Y">
</form>



<script language="javascript" type="text/javascript">
	$("#nm_contract_date").datepicker({ dateFormat: 'yy-mm-dd' });
	// $("#nm_contract_final_date").datepicker({ dateFormat: 'yy-mm-dd' });
	$("#dt_end").datepicker({ dateFormat: 'yy-mm-dd' });


	function viewContractThumb(seq, arg){

		if (arg.files && arg.files[0])
		{
			var reader = new FileReader();
			reader.onload = function (e) {
				$("#car_basic li:eq("+seq+") img").attr("src", e.target.result);
				//no-repeat center; background-size:contain;
				$("#layout_contract_image li:eq("+seq+") img").attr("src", e.target.result);
				// $("#layout_contract_image li:eq("+seq+") img").css({"background-image":"url('"+e.target.result+"')","background-size":"contain","background-position":"center"})
				// .addClass("upload--file");


				// $(".photo_regist .pc_type_pv:eq("+seq+")").css({"background-image":"url('"+e.target.result+"')","background-size":"cover","background-position":"center"});
				// $(".photo_regist .pc_type_pv:eq("+seq+") span").html("");
			}
			reader.readAsDataURL(arg.files[0]);
		}
	}
	function viewContractEndThumb(seq, arg){

		if (arg.files && arg.files[0])
		{
			var reader = new FileReader();
			reader.onload = function (e) {
				//no-repeat center; background-size:contain;
				$("#layout_contract_cert_image li:eq("+seq+") img").attr("src", e.target.result);
				// $("#layout_contract_end_image div:eq("+seq+")").css({"background-image":"url('"+e.target.result+"')","background-size":"contain","background-position":"center"})
				// .addClass("upload--file");

				// $(".photo_regist .pc_type_pv:eq("+seq+")").css({"background-image":"url('"+e.target.result+"')","background-size":"cover","background-position":"center"});
				// $(".photo_regist .pc_type_pv:eq("+seq+") span").html("");
			}
			reader.readAsDataURL(arg.files[0]);
		}
	}

	function viewThumb2(seq, arg){
		if (arg.files && arg.files[0])
		{
			var reader = new FileReader();

			reader.onload = function (e) {
				$(".contract_photo_list li:eq("+seq+") img").attr("src", e.target.result);//{"background-image":"url('"++"')","background-size":"cover","background-position":"center"});
				// $(".photo_regist .pc_type_pv:eq("+seq+")").css({"background-image":"url('"+e.target.result+"')","background-size":"cover","background-position":"center"});
				// $(".photo_regist .pc_type_pv:eq("+seq+") span").html("");
			}
			reader.readAsDataURL(arg.files[0]);
		}
	}
	function viewThumb1(seq, arg){
		if (arg.files && arg.files[0])
		{
			var reader = new FileReader();

			reader.onload = function (e) {
				$(".deal_attach dd .filebox label:eq("+seq+")").css({"background-image":"url('"+e.target.result+"')","background-size":"cover","background-position":"center"});
				// $(".photo_regist .pc_type_pv:eq("+seq+")").css({"background-image":"url('"+e.target.result+"')","background-size":"cover","background-position":"center"});
				// $(".photo_regist .pc_type_pv:eq("+seq+") span").html("");
			}
			reader.readAsDataURL(arg.files[0]);
		}
	}
	function viewThumb(seq, arg){
		if (arg.files && arg.files[0])
		{
			var reader = new FileReader();

			reader.onload = function (e) {
				$(".deal_complete dd .filebox label:eq("+seq+")").css("background","url('"+e.target.result+"')");
			}
			reader.readAsDataURL(arg.files[0]);
		}
	}

	$(document).ready(function() {

		$("#btn_cal").bind("click",function(){
			$("#nm_contract_date").datepicker('show');
		});
		$("#btn_force_cal").bind("click",function(){
			$("#nm_contract_force_date").datepicker('show');
		});

		$("input[name=ds_status_contract]").on("click", function() {
			var val = $(this).val();
			switch(val) {
				case 'Z0':
					$("#layout_contact_final").removeClass("hide");
					$("#layout_contact_fail").addClass("hide");
					break;
				case 'B0':
				case 'C0':
					$("#layout_contact_final").addClass("hide");
					$("#layout_contact_fail").removeClass("hide");
					break;
			}
		});

		<?php if(!empty($ds_status_contract_sale)) { ?>
			$("input[name=ds_status_contract][value=<?=$ds_status_contract_sale?>]").click();
		<?php } ?>

		$("#btn_contract_step1").bind("click",function(){
			var fieldlist = [["ds_status_contract_step1","확인여부"]]
			if (!fnCheckForm(fieldlist)){
				return false;
			}

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

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

			var fieldlist = [["nm_contract_date","일정 만남일"]]
			if (!fnCheckForm(fieldlist)){
				return false;
			}

			custom_opts.title = '처리하시겠습니까?';
			custom_modal_confirm(custom_opts, function(confirm) {
				if(confirm) {
					var data = $("#frmFormStep2").serialize();

					$.ajax({
						url : 'proc.php',
						type: 'POST',
						data: data,
						dataType: 'json',
						success: function(res) {
							$("#btn_contract_step2").show();

							custom_modal_confirm_close();

							if(res.CODE != "0000") {
								custom_opts.title = '실패하였습니다. 다시 시도해 주세요.';
								custom_modal_alert(custom_opts);
								return false;
							}

							custom_opts.title = '처리되었습니다.';
							custom_opts.event_esc_key = false;

							custom_modal_alert(custom_opts, function() {
								reload();
							});

							return false;
						},
						error:function(request,status,error){
							$("#btn_contract_step2").show();

							custom_modal_confirm_close();

							alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
						}
					});
				}else {
					$("#btn_contract_step2").show();
					return false;
				}
			});

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

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

//			alert($('input[name="ds_status_contract"]:checked').val());
			// var fieldlist = [["ds_status_contract","계약 상황"]]
			// if (!fnCheckForm(fieldlist)){
			// 	return false;
			// }
			//
			// if ($('input[name="ds_status_contract"]:checked').val() == "Z0"){
			// 	fieldlist = [["nm_price_final","최종금액"],["nm_file_chk1","검차사진"]]
			// 	if (!fnCheckForm(fieldlist)){
			// 		return false;
			// 	}
			// }
			//
			// if ($('input[name="ds_status_contract"]:checked').val() == "C0"){
			// 	fieldlist = [["nm_contract_fail_reason","거래 실패 사유"]]
			// 	if (!fnCheckForm(fieldlist)){
			// 		return false;
			// 	}
			// }
			if($('input[name="ds_status_contract"]:checked').length < 1) {
				custom_opts.title = '계약 상황을 선택하세요.';

				custom_modal_alert(custom_opts);
				return false;
			}

			if ($('input[name="ds_status_contract"]:checked').val() == "Z0"){
				fieldlist = [["nm_price_final","최종금액"]]
				//,["nm_file_chk1","검차사진1"],["nm_file_chk2","검차사진2"],["nm_file_chk3","검차사진3"],["nm_file_chk4","검차사진4"],["nm_file_chk5","검차사진5"]
				if (!fnCheckForm(fieldlist)){
					return false;
				}
			}

			if ($('input[name="ds_status_contract"]:checked').val() == "B0" || $('input[name="ds_status_contract"]:checked').val() == "C0"){
				fieldlist = [["nm_contract_fail_reason","거래연기 or 거래 실패 사유"]]
				if (!fnCheckForm(fieldlist)){
					return false;
				}
			}


			custom_opts.title = '처리하시겠습니까?';
			custom_modal_confirm(custom_opts, function(confirm) {
				if(confirm) {
					var formData = new FormData();

					$("#frmFormStep3 input, #frmFormStep3 select, #frmFormStep3 textarea").each(function() {
						var input_name = $(this).attr("name");
						var input_value = $(this).val();
						var input_type = $(this).attr("type");
						switch(input_type) {
							case 'radio':
								formData.append(input_name, $("input[name="+input_name+"]:checked").val());
								break;
							default:
								formData.append(input_name, input_value);
								break;
						}
					});

					$("#frmFormStep3 input[type=file]").each(function() {
						var input_name = $(this).attr("name");
						var input_value = $(this)[0].files[0];
						formData.append(input_name, input_value);
					});

					$.ajax({
						url : 'proc.php',
						type: 'POST',
						dataType: 'json',
						data: formData,
						processData: false,
						contentType: false,
						success: function(res) {
							$("#btn_contract_step3").show();

							custom_modal_confirm_close();

							if(res.CODE != "0000") {
								custom_opts.title = '실패하였습니다. 다시 시도해 주세요.';
								custom_modal_alert(custom_opts);
								return false;
							}

							custom_opts.title = '처리되었습니다.';
							custom_opts.event_esc_key = false;

							custom_modal_alert(custom_opts, function() {
								reload();
							});

							return false;
						},
						error:function(request,status,error){
							$("#btn_contract_step3").show();

							custom_modal_confirm_close();

							alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
						}
					});
				}else {
					$("#btn_contract_step3").show();
					return false;
				}
			});


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

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

			// var fieldlist = [["nm_file_trading","상사이전등록증"],["nm_file_performance","성능지"],["nm_file_regist","전고객 등록증"]]
			// if (!fnCheckForm(fieldlist)){
			// 	return false;
			// }

			custom_opts.title = '처리하시겠습니까?';
			custom_modal_confirm(custom_opts, function(confirm) {
				if(confirm) {
					var formData = new FormData();

					$("#frmFormStep4 input, #frmFormStep4 select, #frmFormStep4 textarea").each(function() {
						var input_name = $(this).attr("name");
						var input_value = $(this).val();
						var input_type = $(this).attr("type");
						switch(input_type) {
							case 'radio':
								formData.append(input_name, $("input[name="+input_name+"]:checked").val());
								break;
							default:
								formData.append(input_name, input_value);
								break;
						}
					});

					$("#frmFormStep4 input[type=file]").each(function() {
						var input_name = $(this).attr("name");
						var input_value = $(this)[0].files[0];
						formData.append(input_name, input_value);
					});

					$.ajax({
						url : 'proc.php',
						type: 'POST',
						dataType: 'json',
						data: formData,
						processData: false,
						contentType: false,
						success: function(res) {
							$("#btn_contract_step4").show();

							custom_modal_confirm_close();

							if(res.CODE != "0000") {
								custom_opts.title = '실패하였습니다. 다시 시도해 주세요.';
								custom_modal_alert(custom_opts);
								return false;
							}

							custom_opts.title = '처리되었습니다.';
							custom_opts.event_esc_key = false;

							custom_modal_alert(custom_opts, function() {
								reload();
							});

							return false;
						},
						error:function(request,status,error){
							$("#btn_contract_step4").show();

							custom_modal_confirm_close();

							alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
						}
					});
				}else {
					$("#btn_contract_step4").show();
					return false;
				}
			});

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

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

			var fieldlist = [["nm_contract_final_date","거래완료일"]]
			if (!fnCheckForm(fieldlist)){
				return false;
			}

			custom_opts.title = '처리하시겠습니까?';
			custom_modal_confirm(custom_opts, function(confirm) {
				if(confirm) {
					var data = $("#frmFormStep5").serialize();

					$.ajax({
						url : 'proc.php',
						type: 'POST',
						data: data,
						dataType: 'json',
						success: function(res) {
							$("#btn_contract_step5").show();

							custom_modal_confirm_close();

							if(res.CODE != "0000") {
								custom_opts.title = '실패하였습니다. 다시 시도해 주세요.';
								custom_modal_alert(custom_opts);
								return false;
							}

							custom_opts.title = '처리되었습니다.';
							custom_opts.event_esc_key = false;

							custom_modal_alert(custom_opts, function() {
								reload();
							});

							return false;
						},
						error:function(request,status,error){
							$("#btn_contract_step5").show();

							custom_modal_confirm_close();

							alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
						}
					});
				}else {
					$("#btn_contract_step5").show();
					return false;
				}
			});



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



		$("#btn_contract_step_error").bind("click",function(){
			var fieldlist = [["nm_cont_tender_error","견적 실수 사유"]]
			if (!fnCheckForm(fieldlist)){
				return false;
			}

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


		$(".btn_step4_image").bind("click",function(){
			var id = $(this).attr("for");
			$("#"+id).click();
		});

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

			// var fieldlist = [["nm_file_trading","상사이전등록증"],["nm_file_performance","성능지"],["nm_file_regist","전고객 등록증"]]
			// if (!fnCheckForm(fieldlist)){
			// 	return false;
			// }

			custom_opts.title = '처리하시겠습니까?';
			custom_modal_confirm(custom_opts, function(confirm) {
				if(confirm) {
					var formData = new FormData();

					formData.append("cd_sale", "<?=$cd_sale?>");
					formData.append("mode", "ContractStep4Modify");

					$("#frmFormStep4 input[type=file]").each(function() {
						var input_name = $(this).attr("name");
						var input_value = $(this)[0].files[0];
						formData.append(input_name, input_value);
					});

					$.ajax({
						url : 'proc.php',
						type: 'POST',
						dataType: 'json',
						data: formData,
						processData: false,
						contentType: false,
						success: function(res) {
							$("#btn_contract_step4_modify").show();

							custom_modal_confirm_close();

							if(res.CODE != "0000") {
								custom_opts.title = '실패하였습니다. 다시 시도해 주세요.';
								custom_modal_alert(custom_opts);
								return false;
							}

							custom_opts.title = '처리되었습니다.';
							custom_opts.event_esc_key = false;

							custom_modal_alert(custom_opts, function() {
								reload();
							});

							return false;
						},
						error:function(request,status,error){
							$("#btn_contract_step4_modify").show();

							custom_modal_confirm_close();

							alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
						}
					});
				}else {
					$("#btn_contract_step4_modify").show();
					return false;
				}
			});

			// var c = confirm("처리하시겠습니까?");
			// if(c){
			// 	var sdata = new FormData();
			//
			// 	sdata.append("cd_sale", "<?=$_REQUEST["cd_sale"]?>");
			// 	sdata.append("mode", "ContractStep4Modify");
			//
			// 	//상사 이전증
			// 	var nm_file_trading = $("input[name=nm_file_trading").val();
			// 	if($.trim(nm_file_trading) != "") {
			// 		sdata.append("nm_file_trading", $("input[name=nm_file_trading")[0].files[0]);
			// 	}
			//
			// 	//성능지
			// 	var nm_file_performance = $("input[name=nm_file_performance").val();
			// 	if($.trim(nm_file_performance) != "") {
			// 		sdata.append("nm_file_performance", $("input[name=nm_file_performance")[0].files[0]);
			// 	}
			//
			// 	//전고객 등록증
			// 	var nm_file_regist = $("input[name=nm_file_regist").val();
			// 	if($.trim(nm_file_regist) != "") {
			// 		sdata.append("nm_file_regist", $("input[name=nm_file_regist")[0].files[0]);
			// 	}
			//
			// 	//거래후기
			// 	var nm_file_postscript = $("input[name=nm_file_postscript").val();
			// 	if($.trim(nm_file_postscript) != "") {
			// 		sdata.append("nm_file_postscript", $("input[name=nm_file_postscript")[0].files[0]);
			// 	}
			//
			// 	var url = "proc.php";
			// 	$.ajax({
			// 		url: url,
			// 		type: 'post',
			// 		data: sdata,
			// 		//dataType: 'json',
			// 		processData: false,
			// 		contentType: false,
			// 		success: function(res) {
			// 			if(res == "200"){
			// 				alert("정상처리 되었습니다.");
			// 				window.location.reload();
			// 			}else{
			// 				alert("실패하였습니다. 다시 시도해 주세요.");
			// 			}
			//
			// 		}
			// 	});
			//
			// }else{
			// 	return false;
			// }
		});


		$("#btn_contract_car_img_modify").bind("click",function(){
			var c = confirm("처리하시겠습니까?");
			if(c){
				var sdata = new FormData();

				sdata.append("cd_sale", "<?=$_REQUEST["cd_sale"]?>");
				sdata.append("cd_car", "<?=$cd_car?>");

				sdata.append("mode", "CarImageModify");

				//차량전면
				var nm_file_front = $("input[name=nm_file_front").val();
				if($.trim(nm_file_front) != "") {
					sdata.append("nm_file_front", $("input[name=nm_file_front")[0].files[0]);
				}
				//차량후면
				var nm_file_back = $("input[name=nm_file_back").val();
				if($.trim(nm_file_back) != "") {
					sdata.append("nm_file_back", $("input[name=nm_file_back")[0].files[0]);
				}
				//운전석 측면
				var nm_file_side1 = $("input[name=nm_file_side1").val();
				if($.trim(nm_file_side1) != "") {
					sdata.append("nm_file_side1", $("input[name=nm_file_side1")[0].files[0]);
				}
				//조수석 측면
				var nm_file_side2 = $("input[name=nm_file_side2").val();
				if($.trim(nm_file_side2) != "") {
					sdata.append("nm_file_side2", $("input[name=nm_file_side2")[0].files[0]);
				}
				//계기판
				var nm_file_dashboard = $("input[name=nm_file_dashboard").val();
				if($.trim(nm_file_dashboard) != "") {
					sdata.append("nm_file_dashboard", $("input[name=nm_file_dashboard")[0].files[0]);
				}

				var url = "proc.php";
				$.ajax({
					url: url,
					type: 'post',
					data: sdata,
					//dataType: 'json',
					processData: false,
					contentType: false,
					success: function(res) {
						if(res == "200"){
							alert("정상처리 되었습니다.");
							window.location.reload();
						}else{
							alert("실패하였습니다. 다시 시도해 주세요.");
						}

					}
				});

			}else{
				return false;
			}
		});

	});

</script>
