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

	$mode = $_REQUEST[mode];

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

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

	$ds_cate = $_REQUEST[ds_cate];
	if(!$ds_cate) $ds_cate='A0';
	
	$ds_model_cate= $ds_cate;
	
	if($s_cd_car !="" || $s_cd_car != null){
	
		$sql ="SELECT a.*, s.nm_recommend 
			FROM car_master a left outer join sale_master s on ( a.cd_car = s.cd_car )
			WHERE  a.cd_car='$s_cd_car' AND a.ds_delind='N'";

		$col=mysql_fetch_array(mysql_query($sql));
			
		if (!empty($col[cd_car])){
			 
			$cd_car = $col[cd_car];

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

			$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];
			$nm_recommend = $col[nm_recommend];

		}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";}


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

	$ds_cate = $_REQUEST[ds_cate];
	if(!$ds_cate) $ds_cate='A0';
	
	$ds_model_cate= $ds_cate;
	
?>
<? include("../include/inc_top.php") ?>
<? include("../include/inc_header.php") ?>

<style>
#dropzone_wr{margin:0 auto;padding:0 0px;}
#dropzone
{
	border:1px solid #dadbde;
	min-height:300px;
	color:#92AAB0;
	text-align:center;
	font-size:24px;
	padding-top:20px;
	margin-top:10px;
	padding-bottom:20px;
	overflow:hidden;
	position:relative;
}
#dropzone .imgwr{width:115px;height:82px;padding:5px;float:left;overflow:hidden;font-size:11px;border:2px solid none;position:relative;}

#dropzone .imgwr .img{width:100%;min-height:150px;}
.imgwr .del_i_btn{position:absolute;top:0px;right:0px;width:50px;cursor:pointer;display:none;}
.btn_type{margin-top:20px;padding-left:10px;padding-right:10px;height:24px;line-height:24px;cursor:pointer;color:#92AAB0;border:1px solid #b0afaf;float:left;}
.del_btn{margin-right:10px;}
.submit{margin-left:10px;}
</style>
<script>
$(function () {
     var obj = $("#dropzone");

     obj.on('dragenter', function (e) {
          e.stopPropagation();
          e.preventDefault();
          $(this).css('border', '2px solid #5272A0');
     });

     obj.on('dragleave', function (e) {
          e.stopPropagation();
          e.preventDefault();
          $(this).css('border', '2px dotted #8296C2');
     });

     obj.on('dragover', function (e) {
          e.stopPropagation();
          e.preventDefault();
     });

     obj.on('drop', function (e) {
          e.preventDefault();
          $(this).css('border', '2px dotted #8296C2');

          var files = e.originalEvent.dataTransfer.files;
          if(files.length < 1)
               return;

          F_FileMultiUpload(files);
     });


	var filesUpload = document.getElementById("filename");

	filesUpload.onchange = function () { 
		F_FileMultiUpload(this.files); 
	};
	$(".test").click(function(){
		console.log(farrdata);
	});

	$(".del_btn").click(function(){
		if("<?=$s_car_update_ing?>" == ""){
			$("#dropzone").html("Drag & Drop Files Here");
			farrdata.splice(0, farrdata.length);		
		}else if("<?=$s_car_update_ing?>" == "Y"){
			if(confirm("전체삭제하시겠습니까?")){
				$("#AllCarImgDelete").submit()		
			}else{
				return false;
			}
		}

	});
	$(".mt_btn").click(function(){
		$("#filename").click();
	});

	$(document).on("mouseenter",".imgwr",function(){
		$(this).find(".del_i_btn").stop(true,true).fadeIn(200);
	});
	$(document).on("mouseleave",".imgwr",function(){
		$(this).find(".del_i_btn").stop(true,true).fadeOut(200);
	});
	$(document).on("mousedown",".del_i_btn",function(e){
		e.preventDefault();
		e.stopPropagation();
	});
	$(document).on("click",".del_i_btn",function(e){

		if(!$(this).hasClass("del_up_btn")){
			e.preventDefault();
			e.stopPropagation();
			var datanimg = $(this).closest(".imgwr").data("nimg");
			var datasimg = $(this).closest(".imgwr").data("simg");

			var index = -1;
			for(var i = 0 ; i < farrdata.length; i++){
				if(farrdata[i].name == datanimg && farrdata[i].size == datasimg){
					index = i;
				}
			}
			farrdata.splice(index, 1);
			
			$(this).closest(".imgwr").remove();
		}
		
	});


	var smthis = "";
	var ismove = false;
	$(document).on("mousedown",".imgwr",function(e){
		smthis = $(this);
		var smtop = e.pageY - smthis.offset().top;
		var smleft = e.pageX - smthis.offset().left;
		var smwrap = smthis.closest("#dropzone");
		var smwraptop = smwrap.offset().top; // 전체wrap의 offset (기준 relative)
		var smwrapleft = smwrap.offset().left; // 전체wrap의 offset (기준 relative)

		$(document).on("mousemove",function(e){
			ismove = true;
			var currentY = e.pageY;
			var currentX = e.pageX;
			smthis.css({"position":"absolute", "top" : currentY - smtop - smwraptop + "px" , "left" : currentX - smleft - smwrapleft + "px" , "z-index" : 100});
			// 마우스 offset - 마우스 클릭위치와 상품 position과의 거리 - relative
			e.preventDefault();
			e.stopPropagation();
		});

	});

	$(document).on("mouseup",function(e){
		if(ismove){
			e.preventDefault();
			e.stopPropagation();
			var smtop = e.pageY;
			var smleft = e.pageX;
			var imgwrlen = true;
			$(".imgwr").each(function(idx){
				if( smthis.index() == idx  ){
					return true;
				}
				var thitop = $(this).offset().top;
				var thitoph = thitop+$(this).height();
				var thileft = $(this).offset().left;
				var thilefth = thileft+$(this).width();
				
				if( ( thitop < smtop && thitoph > smtop ) && ( thileft < smleft && thilefth > smleft )){
					$(this).before(smthis);
					smthis.attr("style","");
					imgwrlen = false;
					return false;
				}
			});
			if(imgwrlen){
				$("#dropzone").append(smthis);
				smthis.attr("style","");
				imgwrlen = false;
			}
			fnChangeSortFileAjax();

			$(document).off("mousemove");
			ismove = false;
		}
	});
	
	//$("").click(file_save);
});

// 전역변수
var fdata = new FormData();
var farrdata = new Array();
// 이미지파일데이터담기
function F_FileMultiUpload(files) {
	if ("<?=$s_car_update_ing?>" == ""){
		for (var i = 0; i < files.length; i++) {
			farrdata.push(files[i]);
		}
		
		traverseFiles(files);
	}else if ("<?=$s_car_update_ing?>" == "Y"){

		var sdata = new FormData();
		for (var i = 0; i < files.length; i++) {
			sdata.append("file[]", files[i]);
		}
		sdata.append('mode', 'AddFileAjax');
		sdata.append("cd_car", "<?=$cd_car?>");

		var url = "/sell/proc.php";
		$.ajax({
			url: url,
			type: 'post',
			data: sdata,
			//dataType: 'json',
			processData: false,
			contentType: false,
			success: function(res) {
				var arr = res.split("||");
				$("#dropzone").append("<div class=\"imgwr imgwr_up test\" data-upimg=\""+arr[1]+"\"><img class=\"del_i_btn del_up_btn\" onclick=\"fnDeleteFile('"+arr[1]+"');return false;\" src=\"del.png\" /><img class='img' src='"+arr[0]+"' /></div>");
			}
		});

	}
}

// 이미지 미리보기html
function traverseFiles(files){
	
	if($("#dropzone .imgwr").length == 0){
		$("#dropzone").text("");
	}
	
	for (var i = 0, f; f = files[i]; i++) {
		var reader = new FileReader();
		reader.onload = (function(theFile) {
			return function(e) {
				//$("#dropzone").append("<div>name : "+escape(theFile.name)+"<img src='" + e.target.result + "' /></div>");
				$("#dropzone").append("<div class='imgwr test' data-simg='"+theFile.size+"' data-nimg='"+theFile.name+"'><img class='del_i_btn' src='del.png' /><img class='img' src='" + e.target.result + "' /></div>");
			};
		})(f);
		reader.readAsDataURL(f);
	}
}

// 파일 멀티 업로드 save
function file_save(){

		var sdata = new FormData();
		if ("<?=$s_car_update_ing?>" == ""){
			$(".imgwr").each(function(idx){
				var datanimg = $(this).data("nimg");
				var datasimg = $(this).data("simg");
				for(var i = 0 ; i < farrdata.length; i++){
					if(farrdata[i].name == datanimg && farrdata[i].size == datasimg){
						//sdata.append("file["+i+"]", farrdata[i]);
						sdata.append("file[]", farrdata[i]);
						break;
					}
				}
			});
		}else if ("<?=$s_car_update_ing?>" == "Y"){
			var firimg = "";
			var firimgsrc = $("#dropzone > .imgwr").eq(0).find(".img").attr("src");
			
			if(firimgsrc.indexOf("/") > -1){
				var firimgArr = firimgsrc.split("/");
				firimg = firimgArr[firimgArr.length-1];
			}

			$("#upload_file_main_name").val(firimg);
			$("#upload_file_list_name").val(firimg);

		}

		
		$("#frmForm input, #frmForm select, #frmForm textarea").each(function(idx, item){
			var _inputName = $(this).attr("name");
			var _inputVale = $(this).val();
			var _inputType = $(this).attr("type");

			if(_inputType == "radio" || _inputType == "checkbox"){
				console.log(_inputName);
				console.log(_inputVale);
				_inputVale = $("[name="+_inputName+"]:checked").val();
				if($(this).prop("checked")){
					sdata.append(_inputName, _inputVale);	
				}
			}else{
				sdata.append(_inputName, _inputVale);
			}
		});
		/*
		sdata.append('details', $("#frmForm").serialize());
		sdata.append('mode', 'Add');
		
		*/
		//sdata.append("nm_file_report", $("#nm_file_report")[0].files[0]);	//파일 한개
		//sdata.append("nm_file_report_back", $("#nm_file_report_back")[0].files[0]);	//파일 한개
//		sdata.append("nm_file_chk", $("#nm_file_chk")[0].files[0]);	//파일 한개
//		sdata.append("nm_file_act", $("#nm_file_act")[0].files[0]);	//파일 한개

		sdata.append("nm_file_front", $("#nm_file_front")[0].files[0]);	//파일 한개
		sdata.append("nm_file_side1", $("#nm_file_side1")[0].files[0]);	//파일 한개
		sdata.append("nm_file_side2", $("#nm_file_side2")[0].files[0]);	//파일 한개
		sdata.append("nm_file_back", $("#nm_file_back")[0].files[0]);	//파일 한개
		sdata.append("nm_file_dashboard", $("#nm_file_dashboard")[0].files[0]);	//파일 한개

		//var url = "/common/lib/uploadAPI.php";
		var url = "/sell/proc.php";
		$.ajax({
			url: url,
			type: 'post',
			data: sdata,
			//dataType: 'json',
			processData: false,
			contentType: false,
			success: function(res) {
				if(res == "200"){
					//F_FileMultiUpload_Callback(res.files);
					alert("정상처리 되었습니다.");
					location.href = "./sell_step4.php?mode=Step4";
				}else{
					alert("실패하였습니다. 다시 시도해 주세요.");
				}
				
			}
		});
}
// 파일 멀티 업로드 Callback
function F_FileMultiUpload_Callback(files) {
     for(var i=0; i < files.length; i++){
         console.log(files[i].file_nm + " - " + files[i].file_size);
	 }
}

</script>

<section id="wrap">
	<section id="visual" class="visual_sell">
		<h2>내차팔기</h2>
		<p>쉽고 간편한 내차팔기, 견적산출, 최종 매각까지 어떤 수수료도 요구하지 않습니다.</p>
	</section>

	<section id="content">
		<ul class="location">
			<li><a href="/" class="home">홈</a></li>
			<li><span class="depth1">내차팔기</span></li>
			<li><span class="depth2">입찰하기</span></li>
		</ul>

		<h3>차량사진 입력</h3>
<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="<?=$s_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_main_name" id="upload_file_main_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="upload_file_front_name" id="upload_file_front_name" value="<?=$upload_file_front_name?>"/>
<input type="hidden" name="upload_file_back_name" id="upload_file_back_name" value="<?=$upload_file_back_name?>"/>
<input type="hidden" name="upload_file_side1_name" id="upload_file_side1_name" value="<?=$upload_file_side1_name?>"/>
<input type="hidden" name="upload_file_side2_name" id="upload_file_side2_name" value="<?=$upload_file_side2_name?>"/>
<input type="hidden" name="upload_file_dashboard_name" id="upload_file_dashboard_name" value="<?=$upload_file_dashboard_name?>"/>
<input type="hidden" name="cd_category" id="cd_category" value="<?=$cd_category?>"/>
<input type="hidden" name="recommend_confirm" id="recommend_confirm" value="N"/>
<!--
.photo_input li:nth-child(1) .thumb{background-image:url('/img/sell/ic_car_photo1.png');}
.photo_input li:nth-child(2) .thumb{background-image:url('/img/sell/ic_car_photo2.png');}
.photo_input li:nth-child(3) .thumb{background-image:url('/img/sell/ic_car_photo3.png');}
.photo_input li:nth-child(4) .thumb{background-image:url('/img/sell/ic_car_photo4.png');}
.photo_input li:nth-child(5) .thumb{background-image:url('/img/sell/ic_car_photo5.png');}
-->
		<ul class="photo_input">
			<li>
				<span class="thumb"<? if($nm_file_front!=""){ ?> style="background-image:url('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_front?>');"<? } ?>></span>
				<em>차량전면</em>
				<div class="filebox ty2">
					<input class="upload-name" value="">
					<label for="nm_file_front">등록</label>
					<input type="file" name="nm_file_front" id="nm_file_front" class="upload-hidden" onchange="viewThumb(0,this)">
				</div>
			</li>
			<li>
				<span class="thumb"<? if($nm_file_side1!=""){ ?> style="background-image:url('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_side1?>');"<? } ?>></span>
				<em>운전석 측면</em>
				<div class="filebox ty2">
					<input class="upload-name" value="">
					<label for="nm_file_side1">등록</label>
					<input type="file" name="nm_file_side1" id="nm_file_side1" class="upload-hidden" onchange="viewThumb(1,this)">
				</div>
			</li>
			<li>
				<span class="thumb"<? if($nm_file_side2!=""){ ?> style="background-image:url('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_side2?>');"<? } ?>></span>
				<em>조수석 측면</em>
				<div class="filebox ty2">
					<input class="upload-name" value="">
					<label for="nm_file_side2">등록</label>
					<input type="file" name="nm_file_side2" id="nm_file_side2" class="upload-hidden" onchange="viewThumb(2,this)">
				</div>
			</li>
			<li>
				<span class="thumb"<? if($nm_file_back!=""){ ?> style="background-image:url('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_back?>');"<? } ?>></span>
				<em>차량 후면</em>
				<div class="filebox ty2">
					<input class="upload-name" value="">
					<label for="nm_file_back">등록</label>
					<input type="file" name="nm_file_back" id="nm_file_back" class="upload-hidden" onchange="viewThumb(3,this)">
				</div>
			</li>
			<li>
				<span class="thumb"<? if($nm_file_dashboard!=""){ ?> style="background-image:url('<?=UPLOAD_PATH_CAR?>nm_file_main/<?=$nm_file_dashboard?>');"<? } ?>></span>
				<em>계기판</em>
				<div class="filebox ty2">
					<input class="upload-name" value="">
					<label for="nm_file_dashboard">등록</label>
					<input type="file" name="nm_file_dashboard" id="nm_file_dashboard" class="upload-hidden" onchange="viewThumb(4,this)">
				</div>
			</li>
		</ul>

		<h3>추가 사진등록</h3>
		<div class="photo_add">
			<p>추가 사진을 등록하시면 더 정확한 매입가를 확인 하실 수 있습니다.</p>
			<!--div class="filebox">
				<label for="file_photo">찾아보기</label>
				<input class="upload-name" value="">
				<input type="file" id="file_photo" class="upload-hidden">
				<input type="submit" class="file_add" title="추가" value="+추가">
			</div-->
			<div id="dropzone_wr">
				<div style="display:none;"><input multiple="multiple" accept="image/*" type="file" id="file" name="file[]" /></div>
				<div style="overflow:hidden;">
					<div class="btn_type del_btn">전체삭제</div>
					<div class="btn_type mt_btn">사진추가</div>
					<!--<div class="btn_type submit">전송</div>-->
				</div>
				
				<div style="display:none;"><input multiple="multiple" accept="image/*" type="file" id="filename" name="filename[]" /></div>
				<div id="dropzone">
					<?
						if($s_car_update_ing=="Y"){
							$r = mysql_query("SELECT * FROM car_file WHERE cd_car = '$cd_car' and ds_type='' and ds_delind='N' Order by no_sort asc, cd_car ASC ");
							$i=1;
							while($imgs = mysql_fetch_array($r)) {
					?> 
								<div class='imgwr imgwr_up test' data-upimg='<?=$imgs[cd_file]?>'><img class='del_i_btn del_up_btn' onclick="fnDeleteFile('<?=$imgs[cd_file]?>');return false;" src='del.png' /><img class='img' src='<?=UPLOAD_PATH_CAR?><?=$imgs[cd_car]?>_detail/<?=$imgs[nm_file]?>' /></div>
					<?	
							}
						}else{
					?>
						Drag & Drop Files Here
					<?	
						}
					?>
				</div>
				<!-- <div class="test">test</div> -->
			</div>
		</div>

		<h3>추천인 등록</h3>
		<div class="person_add">
			<p><input type="text" class="inp_txt" name="nm_recommend" id="nm_recommend" value="<?=$nm_recommend?>"></p>
		</div>

		<div class="btn_center">
			<input type="button" class="button" title="등록하기" value="등록하기" id="btn_write">
		</div>
</form>
		<!-- layer popup -->
		<div class="layer_popup recomm_popup">
			<div class="popup_wrap">
				<p class="msg">추천인을 확인해주세요! <span>추천인이 없으면 확인 버튼을 눌러주세요</span></p>
				<div class="btn_center">
					<a href="#" class="button" id="btn_recommend_confirm">확인</a>
					<a href="#" class="button gray" onclick="closeLayer('recomm'); return false;">취소</a>
				</div>
			</div>
		</div>
		<!-- // layer popup -->
	</section>
</section>

<form id="delFrm" name="delFrm" method="post" action="./proc.php">
	<input type="hidden" name="mode" id="mode" value="Delete"/>
	<input type="hidden" name="cd_car" id="cd_car_del"/>
	<input type="hidden" name="ds_cate" value="<?=$ds_cate?>"/>
</form>

<form id="AllCarImgDelete" name="AllCarImgDelete" method="post" action="./proc.php">
	<input type="hidden" name="mode" id="all_mode_file_del" value="AllCarImgDelete"/>
	<input type="hidden" name="cd_car" id="cd_car" value="<?=$cd_car?>"/>
</form>

<form id="delFileFrm" name="delFileFrm" method="post" action="./proc.php">
	<input type="hidden" name="mode" id="mode_file_del" value="CarImgDelete"/>
	<input type="hidden" name="cd_car" id="cd_car" value="<?=$cd_car?>"/>
	<input type="hidden" name="cd_file" id="cd_del_file" value=""/>
	<input type="hidden" name="ds_cate" value="<?=$ds_cate?>"/>
	<input type="hidden" name="no_sort" id="no_sort_file" value=""/>
</form>

<form id="delFileReport" name="delFileReport"  method="post" action="./proc.php">
	<input type="hidden" name="mode" id="mode_del_file_report" value="DelFileReport"/>
	<input type="hidden" name="cd_car" id="cd_car_delFileReport" value="<?=$cd_car?>"/>
</form>

<form id="delFileReportBack" name="delFileReportBack"  method="post" action="./proc.php">
	<input type="hidden" name="mode" id="mode_del_file_report_back" value="DelFileReportBack"/>
	<input type="hidden" name="cd_car" id="cd_car_delFileReportBack" value="<?=$cd_car?>"/>
</form>

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

	function fnDelete(seq){
		$("#cd_car_del").val(seq);
		var c = confirm("삭제하시겠습니까?");
		if(c){
			$("#delFrm").submit();
		}
	}
	
	function fnDeleteFile(seq){
		$("#cd_del_file").val(seq);
		if(confirm("삭제하시겠습니까?")){
			$("#delFileFrm").submit()		
		}else{
			return false;
		}
	}
	
	function fnDelFileReport(){
		if(confirm("삭제하시겠습니까?")){
			$("#delFileReport").submit()		
		}else{
			return false;
		}
	}
	
	function fnDelFileReportBack(){
		if(confirm("삭제하시겠습니까?")){
			$("#delFileReportBack").submit()		
		}else{
			return false;
		}
	}
	
	function fnChangeSortFile(seq){
		$("#cd_del_file").val(seq);
		
		if($("#no_sort_"+seq).val()=="" || !ChkNum($("#no_sort_"+seq).val())){
			alert("숫자만 입력가능합니다.");
			return false;
		}else{
			$("#no_sort_file").val($("#no_sort_"+seq).val());
			$("#mode_file_del").val("UpdateSortFile");	
		}
		
		if(confirm("순서를 변경하시겠습니까?")){
			$("#delFileFrm").submit()		
		}else{
			return false;
		}
	}

	function fnChangeSortFileAjax(){

		var sdata = new FormData();
		sdata.append("mode", "UpdateSortFileAjax");
		sdata.append("cd_car", "<?=$cd_car?>");
		
		var cngsort = [];
		$("#dropzone > .imgwr").each(function(){
			cngsort.push($(this).data("upimg"));
		});

		sdata.append("cngsort", cngsort);

		var url = "/sell/proc.php";
		$.ajax({
			url: url,
			type: 'post',
			data: sdata,
			processData: false,
			contentType: false,
			success: function(res) {
				if(res == "N"){
					alert("실패하였습니다. 다시 시도해 주세요.");
					window.location.reload();
				}
				
			}
		});

	}
	
	function viewThumb(seq, arg){
/*
$('#img_select').change(function(){
setImageFromFile(this, '#preview');
});
 
function setImageFromFile(input, expression) {
    if (input.files && input.files[0])
    {
        var reader = new FileReader();
 
            reader.onload = function (e) {
                $(expression).attr('src', e.target.result);
           }
           reader.readAsDataURL(input.files[0]);
     }
}
[출처] jquery로 input file로 이미지 선택 시 바로 보이게 하기|작성자 내꺼는내꺼


*/
		if (arg.files && arg.files[0])
		{
			var reader = new FileReader();

			reader.onload = function (e) {
				$(".photo_input li .thumb:eq("+seq+")").css("background-image","url('"+e.target.result+"')");
			}
			reader.readAsDataURL(arg.files[0]);
		}
	}

	$(document).ready(function() {

		$("#btn_write").bind("click",function(){
<? if ($s_car_update_ing != "Y"){ ?>
			var fieldlist = [["nm_file_front","차량 전면 사진"],["nm_file_side1","운전석 측면 사진"],["nm_file_side2","조수석 측면 사진"],["nm_file_back","차량 후면 사진"],["nm_file_dashboard","계기판 사진"]] ;
//			var fieldlist = [["nm_file_front","차량 전면 사진"]] ;

			if (!fnCheckForm(fieldlist)){
				return false;
			}
<? } ?>
			
			if ($("#nm_recommend").val() == "" && $("#recommend_confirm").val() != "Y")
			{
				openLayer('recomm');
				return false;
			}
/*
			//추가 옵션 사진
			if ("<?=$mode?>" == "Step3"){
				$(".imgwr").each(function(idx){
					var datanimg = $(this).data("nimg");
					var datasimg = $(this).data("simg");
					var arrFile = $("#file");
					for(var i = 0 ; i < farrdata.length; i++){
						if(farrdata[i].name == datanimg && farrdata[i].size == datasimg){
							arrFile[i] = farrdata[i];
							break;
						}
					}
				});
			}
*/
			var c = confirm("처리하시겠습니까?");
			if(c){
//				$("#frmForm").submit();
				file_save();
			}else{
				return false;
			}
		});

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

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

			closeLayer('recomm');

		});

	});
</script>

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