
const KOPER02010_GRID_ID = '#ITP_KOPER02010_jqGrid';
const KOPER02010_GRID_LIST = '#ITP_KOPER02010_jqGrid_list';
const KOPER02010_GRID_PAGER = '#ITP_KOPER02010_jqGridPager';
const KOPER02010_GRID_EMPTY = '#ITP_KOPER02010_jqGridEmpty';

let ITP_FORM_KOPER02010_DETAIL_IS_DUPLICATE = false;
let ITP_FORM_KOPER02010_DETAIL_IS_WRITING = false;

let SALES_USER_GRID_LIST = '/api/sauser/grid-list';
let SALES_USER_INFO = '/api/sauser/info-salesuser';
let SALES_USER_SAVE = '/api/sauser/save-salesusesr';
let SALES_USER_CHECK_DUPLICATE = '/api/sauser/check-duplicate';
let USER_INTI_USERPW = '/api/user/inti-userpw';

require(['config'], function() {
	require([
		'jquery', 
		'kakao.postcode', 
		'kakao.maps'
	], function($) {
		// 버튼 권한설정
		fn_proc_btn_auth('KOPER02010');
		// 공통코드 표시
		fn_make_select(CODE_LIST, 'USE_STAT_CD', 'ITP_FORM_KOPER02010_SEARCH_USE_STAT_CD');
		fn_make_select(CODE_LIST, 'USE_STAT_CD', 'ITP_FORM_KOPER02010_DETAIL_USE_STAT_CD', true, '선택');
		fn_make_select(CODE_LIST, 'SALES_TYPE_CD', 'ITP_FORM_KOPER02010_DETAIL_SALES_TYPE_CD', true, '선택');
		
		// 조회일자 지정
		// var now = new Date();
		$('#ITP_TAB_KOPER02010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);
		// $('#ITP_FORM_KOPER02010_SEARCH_FROM_DT').datepicker('setDate', new Date(now.setMonth(now.getMonth() - 1)));
		// $('#ITP_FORM_KOPER02010_SEARCH_TO_DT').datepicker('setDate', new Date());
				
		// 그리드				
		itp_fn_jqgrid_resize(KOPER02010_GRID_ID, KOPER02010_GRID_LIST, 'lg');
		itp_fn_KOPER02010_grid.init();
    	itp_fn_fire_window_resize();

		// 조회    	
    	itp_fn_KOPER02010_search();
    	
		// 조회 버튼 클릭
		$('#ITP_BTN_KOPER02010_SRH').on('click', function() {
			itp_KOPER02010_search = true;
			let param = $('#ITP_FORM_KOPER02010_SEARCH').serializeObject();
			param.gridSize = $.jgrid.defaults.rowNum;
			param.gridPage = $.jgrid.defaults.page;
			$(KOPER02010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
		});
		
		// 수정 버튼
		$('#ITP_BTN_KOPER02010_MODIFY').on('click', function() {
			itp_fn_form_clear_validate(null, '#ITP_FORM_KOPER02010_DETAIL');			
			const salesUserIdVal = $('#ITP_FORM_KOPER02010_VIEW_SALES_USER_ID').val();
			const key = {salesUserId: salesUserIdVal, viewCd: 'R'};
			var param = $.param(key);
			itp_fn_KOPER02010_detail(param);	
		});
		
		// 신규등록 버튼
		$('#ITP_BTN_KOPER02010_NEWREG').on('click', function() {
			itp_fn_KOPER02010_switch_screen('ADD');			
			itp_fn_form_clear_validate(null, '#ITP_FORM_KOPER02010_DETAIL');
			itp_fn_KOPER02010_detail_map($('#ITP_FORM_KOPER02010_DETAIL_STREET_ADDRESS').val());				
		});
		
		// 취소/목록 버튼
		$('#ITP_BTN_KOPER02010_CANCELLIST').on('click', function() {
			itp_fn_KOPER02010_search();
    	});
		
		// 삭제 버튼
		$('#ITP_BTN_KOPER02010_DELETE').on('click', function() {
			
		});
		
		// 저장 버튼
		$('#ITP_BTN_KOPER02010_SAVE').on('click', function() {			
			const formId = '#ITP_FORM_KOPER02010_DETAIL';
			itp_fn_form_clear_validate(null, formId);			
			var vali_salesUserId = itp_fn_form_validate(formId, formId + '_SALES_USER_ID', ['empty'], undefined);
			var vali_salesTypeCd = itp_fn_form_validate(formId, formId + '_SALES_TYPE_CD', ['empty'], undefined);
			var vali_useStatCd = itp_fn_form_validate(formId, formId + '_USE_STAT_CD', ['empty'], undefined);
			var vali_salesUserNm = itp_fn_form_validate(formId, formId + '_SALES_USER_NM', ['empty'], undefined);			
			var vali_telNo = itp_fn_form_validate(formId, formId + '_TEL_NO', ['empty'], undefined);
			var vali_email = itp_fn_form_validate(formId, formId + 'EMAIL', ['empty'], undefined);
			
			if (vali_salesUserId && vali_salesTypeCd && vali_useStatCd && vali_salesUserNm && vali_telNo && vali_email) {
				
				if($('#ITP_FORM_KOPER02010_DETAIL_ZIPNO').val() == '' || $('#ITP_FORM_KOPER02010_DETAIL_ADRES').val() == '') {
					itp_fn_modal_alert('주소 검색을 통해 회사 주소를 입력하세요.');
					return;
				}
				
				if (ITP_FORM_KOPER02010_DETAIL_IS_DUPLICATE) {
					itp_fn_modal_duplicate('영업담당자 ID 중복체크를 해주세요.', formId + '_SALES_USER_ID');
				} else {
					let param = $(formId).serializeObject();
					var searhFn = function() {
						ITP_FORM_KOPER02010_DETAIL_IS_WRITING = false;
						itp_fn_KOPER02010_search();
					};
					console.log(JSON.stringify(param));
					fn_ajax_call(SALES_USER_SAVE, JSON.stringify(param), searhFn, 'POST');	
				}
			}
		});		
		
		// 중복체크
		$('#ITP_FORM_KOPER02010_DETAIL_DUP').on('click', function() {
			const formId = '#ITP_FORM_KOPER02010_DETAIL';
			itp_fn_form_clear_validate(null, formId + '_DETAIL');
			var vali_salesUserId = itp_fn_form_validate(formId + '_DETAIL', formId + '_SALES_USER_ID', ['empty'], undefined);
			if (vali_salesUserId) {
				var dupFn = function(result) {
					if (result.code == 'N') {
						ITP_FORM_KOPER02010_DETAIL_IS_DUPLICATE = false;
					} else {
						ITP_FORM_KOPER02010_DETAIL_IS_DUPLICATE = true;
					}
				};
				const key = {'salesUserId':  $(formId + '_SALES_USER_ID').val()};
				const param = $.param(key);
				fn_ajax_call(SALES_USER_CHECK_DUPLICATE, param, dupFn, 'GET');
			}
		});
		
		// 상세:비밀번호 초기화
		$('#ITP_BTN_KOPER02010_RESET_PW').on('click', function() {
			var resetPwFn = {
				callBack: function(args) {
					const key = {'userId':  $('#ITP_FORM_KOPER02010_DETAIL_SALES_USER_ID').val()};
					const param = $.param(key);
					fn_ajax_call(USER_INTI_USERPW, param, undefined, 'GET');					
				}
			};
			itp_fn_modal_confirm(ITP_MSG_LOCALE.message.ajax.askResetUserPw, resetPwFn, null);		
		});
		
		$('#ITP_FORM_KOPER02010_DETAIL_ADRES_SCH').on('click', function() {
			new daum.Postcode({
		    	oncomplete: function(data) {
					// 전체주소 리턴
					document.getElementById('ITP_FORM_KOPER02010_DETAIL_ZIPNO').value = data.zonecode;
					document.getElementById('ITP_FORM_KOPER02010_DETAIL_ADRES').value = data.roadAddress;
					document.getElementById('ITP_FORM_KOPER02010_DETAIL_LOTS_ADDRESS').value = !!data.autoJibunAddress ? data.autoJibunAddress : data.jibunAddress;
					document.getElementById('ITP_FORM_KOPER02010_DETAIL_STREET_ADDRESS').value = data.roadAddress;
					document.getElementById('ITP_FORM_KOPER02010_DETAIL_HJ_DONG').value = !!data.hname ? data.hname : data.bname;
					document.getElementById('ITP_FORM_KOPER02010_DETAIL_BJ_DONG').value = data.bname;
					
					itp_fn_KOPER02010_detail_map(data.roadAddress);
					document.getElementById('ITP_FORM_KOPER02010_DETAIL_ADRES_DTL').focus();		  
		        }
			}).open();
		});
		
	});
});

var itp_fn_KOPER02010_detail_map = function(locate) {
	
	kakao.maps.load(function() {
				
		var mapContainer = document.getElementById('ITP_FORM_KOPER02010_DETAIL_MAP'), // 지도를 표시할 div 
		    mapOption = {
		        center: new kakao.maps.LatLng(37.56684, 126.97865), // 지도의 중심좌표
		        level: 3, // 지도의 확대 레벨
		        mapTypeId : kakao.maps.MapTypeId.ROADMAP // 지도종류
		    }; 
	
		// 지도를 생성한다 
		var map = new kakao.maps.Map(mapContainer, mapOption); 
		
		// 마우스 휠과 모바일 터치를 이용한 지도 확대, 축소를 막는다
		map.setZoomable(false);   
	
		// 지도에 확대 축소 컨트롤을 생성한다
		//var zoomControl = new kakao.maps.ZoomControl();
	
		// 지도의 우측에 확대 축소 컨트롤을 추가한다
		//map.addControl(zoomControl, kakao.maps.ControlPosition.RIGHT);
	
		function searchDetailAddrFromCoords(coords, callback) {
		    // 좌표로 법정동 상세 주소 정보를 요청합니다
		    geocoder.coord2Address(coords.getLng(), coords.getLat(), callback);
		}
		
		// 주소-좌표 변환 객체를 생성합니다
		var geocoder = new kakao.maps.services.Geocoder();	
		var map;
		
		if( !locate || locate.length == 0 ) {
			// 지도에 마커를 생성하고 표시한다
		    	marker = new kakao.maps.Marker({
		  	    position: new kakao.maps.LatLng(37.56684, 126.97865), // 마커의 좌표
		   	    map: map // 마커를 표시할 지도 객체
	    	});
		} else {
			// 주소로 좌표를 검색합니다
			geocoder.addressSearch(locate, function(result, status) {
			    // 정상적으로 검색이 완료됐으면 
			     if (status === kakao.maps.services.Status.OK) {
		
			        var coords = new kakao.maps.LatLng(result[0].y, result[0].x);
			        document.getElementById('ITP_FORM_KOPER02010_DETAIL_LAT').value = result[0].y;
			        document.getElementById('ITP_FORM_KOPER02010_DETAIL_LNG').value = result[0].x;
			        
			        // 결과값으로 받은 위치를 마커로 표시합니다
			        	marker = new kakao.maps.Marker({
			            map: map,
			            position: coords
			        });
		
			        // 지도의 중심을 결과값으로 받은 위치로 이동시킵니다
			        map.setCenter(coords);
			    }
			});    
		}
		
		// 지도 드래깅 이벤트를 등록한다 (드래그 시작 : dragstart, 드래그 종료 : dragend)
		kakao.maps.event.addListener(map, 'drag', function () {
		    searchDetailAddrFromCoords(map.getCenter(), function(result, status) {
		        if (status === kakao.maps.services.Status.OK) {
	
	   		        document.getElementById('ITP_FORM_KOPER02010_DETAIL_LOTS_ADDRESS').value = result[0].address.address_name ;
	   		        document.getElementById('ITP_FORM_KOPER02010_DETAIL_ADRES').value = !!result[0].road_address ? result[0].road_address.address_name : result[0].address.address_name ;
	   		        document.getElementById('ITP_FORM_KOPER02010_DETAIL_STREET_ADDRESS').value = !!result[0].road_address ? result[0].road_address.address_name : $('#ITP_FORM_KOPER02010_DETAIL_STREET_ADDRESS').val();
	   		        document.getElementById('ITP_FORM_KOPER02010_DETAIL_ZIPNO').value = !!result[0].road_address ? result[0].road_address.zone_no : $('#ITP_FORM_KOPER02010_DETAIL_CMPY_ZIPNO').val() ;
			        document.getElementById('ITP_FORM_KOPER02010_DETAIL_LAT').value = map.getCenter().getLat();
			        document.getElementById('ITP_FORM_KOPER02010_DETAIL_LNG').value = map.getCenter().getLng();
		                        
		            // 마커를 클릭한 위치에 표시합니다
		            marker.setPosition(map.getCenter());
		            marker.setMap(map);
		        }   
		    });
			/* 	var message = '지도를 드래그 하고 있습니다. 지도의 중심 좌표는 ' + map.getCenter().toString() +' 입니다.';
			console.log(message); */
		});
	});
};

var itp_fn_KOPER02010_view_map = function(locate) {
	
	kakao.maps.load(function() {
				
		var mapContainer = document.getElementById('ITP_FORM_KOPER02010_VIEW_MAP'), // 지도를 표시할 div 
		    mapOption = {
		        center: new kakao.maps.LatLng(37.56684, 126.97865), // 지도의 중심좌표
		        level: 3, // 지도의 확대 레벨
		        mapTypeId : kakao.maps.MapTypeId.ROADMAP // 지도종류
		    }; 
	
		// 지도를 생성한다 
		var map = new kakao.maps.Map(mapContainer, mapOption); 
		
		// 마우스 휠과 모바일 터치를 이용한 지도 확대, 축소를 막는다
		map.setZoomable(false);   
	
		// 지도에 확대 축소 컨트롤을 생성한다
		//var zoomControl = new kakao.maps.ZoomControl();
	
		// 지도의 우측에 확대 축소 컨트롤을 추가한다
		//map.addControl(zoomControl, kakao.maps.ControlPosition.RIGHT);
		
		// 주소-좌표 변환 객체를 생성합니다
		var geocoder = new kakao.maps.services.Geocoder();	
		var map;
		
		if( !locate || locate.length == 0 ) {
			// 지도에 마커를 생성하고 표시한다
		    	marker = new kakao.maps.Marker({
		  	    position: new kakao.maps.LatLng(37.56684, 126.97865), // 마커의 좌표
		   	    map: map // 마커를 표시할 지도 객체
	    	});
		} else {
			// 주소로 좌표를 검색합니다
			geocoder.addressSearch(locate, function(result, status) {
			    // 정상적으로 검색이 완료됐으면 
			     if (status === kakao.maps.services.Status.OK) {
		
			        var coords = new kakao.maps.LatLng(result[0].y, result[0].x);
			        
			        // 결과값으로 받은 위치를 마커로 표시합니다
			        marker = new kakao.maps.Marker({
			            map: map,
			            position: coords
			        });
		
			        // 지도의 중심을 결과값으로 받은 위치로 이동시킵니다
			        map.setCenter(coords);
			    }
			});    
		}
	});
};
	
var itp_fn_KOPER02010_switch_screen = function(mode) {
	if(mode == 'LIST') { // 목록
		$('#ITP_BTN_KOPER02010_MODIFY').hide();
		$('#ITP_BTN_KOPER02010_CANCELLIST').hide();
		$('#ITP_BTN_KOPER02010_DELETE').hide();
		$('#ITP_BTN_KOPER02010_SAVE').hide();
		fn_show_btn_auth('#ITP_BTN_KOPER02010_SRH');
		fn_show_btn_auth('#ITP_BTN_KOPER02010_NEWREG');
		
		$('#ITP_AJAX_KOPER02010_LIST_CONTAINER').show();
		$('#ITP_AJAX_KOPER02010_DETAIL_CONTAINER').hide();		
		$('#ITP_AJAX_KOPER02010_VIEW_CONTAINER').hide();
	} else if(mode == 'ADD') { // 등록
		ITP_FORM_KOPER02010_DETAIL_IS_DUPLICATE = true;
	
		$('#ITP_BTN_KOPER02010_SRH').hide();
		$('#ITP_BTN_KOPER02010_MODIFY').hide();
		$('#ITP_BTN_KOPER02010_NEWREG').hide();
		$('#ITP_BTN_KOPER02010_DELETE').hide();
		$('#ITP_BTN_KOPER02010_RESET_PW').hide();
		fn_show_btn_auth('#ITP_BTN_KOPER02010_CANCELLIST');
		fn_show_btn_auth('#ITP_BTN_KOPER02010_SAVE');
		
		$('#ITP_AJAX_KOPER02010_LIST_CONTAINER').hide();
		$('#ITP_AJAX_KOPER02010_DETAIL_CONTAINER').show();
		$('#ITP_AJAX_KOPER02010_VIEW_CONTAINER').hide();		
		$('#ITP_FORM_KOPER02010_DETAIL_SALES_USER_ID').removeAttr('readonly');
		$('#ITP_FORM_KOPER02010_DETAIL_DUP').removeAttr('disabled');
		
		$('#ITP_FORM_KOPER02010_DETAIL_VIEW_CD').val('C');
		$('#ITP_FORM_KOPER02010_DETAIL_SALES_USER_NM').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_SALES_TYPE_CD').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_USE_STAT_CD').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_SALES_USER_ID').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_TEL_NO').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_FAX_NO').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_EMAIL').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_ZIPNO').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_ADRES').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_ADRES_DTL').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_LOTS_ADDRESS').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_STREET_ADDRESS').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_LAT').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_LNG').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_HJ_DONG').val('');
		$('#ITP_FORM_KOPER02010_DETAIL_BJ_DONG').val('');
		
	} else if(mode == 'MODIFY') { // 수정
		$('#ITP_BTN_KOPER02010_SRH').hide();
		$('#ITP_BTN_KOPER02010_MODIFY').hide();
		$('#ITP_BTN_KOPER02010_NEWREG').hide();		
		$('#ITP_BTN_KOPER02010_DELETE').hide();
		fn_show_btn_auth('#ITP_BTN_KOPER02010_RESET_PW');
		fn_show_btn_auth('#ITP_BTN_KOPER02010_CANCELLIST');
		fn_show_btn_auth('#ITP_BTN_KOPER02010_SAVE');
		
		$('#ITP_AJAX_KOPER02010_LIST_CONTAINER').hide();
		$('#ITP_AJAX_KOPER02010_DETAIL_CONTAINER').show();
		$('#ITP_AJAX_KOPER02010_VIEW_CONTAINER').hide();
		$('#ITP_FORM_KOPER02010_DETAIL_SALES_USER_ID').attr('readonly', true);
		$('#ITP_FORM_KOPER02010_DETAIL_DUP').attr('disabled', true);
	} else if(mode == 'VIEW') { // 보기
		$('#ITP_BTN_KOPER02010_SRH').hide();
		$('#ITP_BTN_KOPER02010_NEWREG').hide();		
		$('#ITP_BTN_KOPER02010_DELETE').hide();
		$('#ITP_BTN_KOPER02010_SAVE').hide();
		fn_show_btn_auth('#ITP_BTN_KOPER02010_MODIFY');
		fn_show_btn_auth('#ITP_BTN_KOPER02010_CANCELLIST');
		
		$('#ITP_AJAX_KOPER02010_LIST_CONTAINER').hide();
		$('#ITP_AJAX_KOPER02010_DETAIL_CONTAINER').hide();
		$('#ITP_AJAX_KOPER02010_VIEW_CONTAINER').show();
	}	
};

var itp_fn_KOPER02010_grid = {
	init: function() {
		// 데이터 없을때
		itp_fn_KOPER02010_empty.push();
		$(KOPER02010_GRID_EMPTY).on('click', function() {
			itp_fn_KOPER02010_empty.back();
			itp_KOPER02010_param.gridSize = $.jgrid.defaults.rowNum;
			$(KOPER02010_GRID_ID).setGridParam({'postData': JSON.stringify(itp_KOPER02010_param)}).trigger('reloadGrid');
		});	
	},
	callBack: function() {
		let param = $('#ITP_FORM_KOPER02010_SEARCH').serializeObject();
		param.gridSize = $.jgrid.defaults.rowNum;	
		$(KOPER02010_GRID_ID).jqGrid({
			colModel: [
				{
					index: 'SALES_USER_ID', name: 'salesUserId',
					label: '영업담당자ID', 
					width: '6', fixed: false, align: 'center',
					sortable: false, hidden: false
				},
				{
					index: 'SALES_USER_NM', name: 'salesUserNm',
					label: '영업담당자명', 
					width: '10', fixed: false, align: 'center',
					sortable: false, hidden: false
				},
				{
					index: 'SALES_TYPE_NM', name: 'salesTypeNm',
					label: '영업타입', 
					width: '6', fixed: false, align: 'center',
					sortable: false, hidden: false
				},
				{
					index: 'USE_STAT_NM', name: 'useStatNm',
					label: '상태', 
					width: '6', fixed: false, align: 'center',
					sortable: false, hidden: false
				},
				{
					index: 'ADD_DT', name: 'addDt',
					label: '가입일자', 
					width: '8', fixed: false, align: 'center',
					sortable: false, hidden: false
				}
			],
			loadBeforeSend: function(jqXHR) {
			    jqXHR.setRequestHeader('X-AUTH-TOKEN', CONN_KEY);
			},
			postData: JSON.stringify(param),
			url: DOMAIN + SALES_USER_GRID_LIST,
			pager: KOPER02010_GRID_PAGER,
			multiselect: false,
			rownumbers: true, 
			onCellSelect: function(rowId, cellIdx, cellValue) {
				var cm = $(this).jqGrid('getGridParam', 'colModel');
				var colNm = cm[cellIdx].name;
				if (colNm == 'salesUserId') {
					const salesUserIdVal = $(this).jqGrid('getCell', rowId, 'salesUserId');
					const key = {salesUserId: salesUserIdVal, viewCd: 'R'};
					var param = $.param(key);
					itp_fn_KOPER02010_view(param);
				}
		   	},
			loadComplete: function(data) {
				console.log(JSON.stringify(data));
				itp_fn_grid_load_complete(data, KOPER02010_GRID_ID, true, 'number', 'KOPER02010', itp_KOPER02010_search, itp_fn_KOPER02010_empty, true, data.gridRecords, true);
				var ids = $(KOPER02010_GRID_ID).getDataIDs();
				$.each(ids, function(idx, rowId) {
					$(KOPER02010_GRID_ID).jqGrid('setCell', rowId, 'salesUserId', '', ITP_GRID_COL_STYLE.link);
				});	
		    },
		    loadError: function(jqXHR, textStatus, errorThrown) {
		    	itp_fn_grid_load_error(jqXHR, textStatus, errorThrown);
		    },
		    onPaging: function(action) {
		    	itp_fn_grid_paging(KOPER02010_GRID_ID, action, param);
		    }
		}).navGrid(KOPER02010_GRID_PAGER, ITP_GRID_NAV_DEFAULTS.navGrid);
	},
	clearData : function() {
		$(KOPER02010_GRID_ID).jqGrid('clearGridData', true);
		$(KOPER02010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
		$(KOPER02010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
		$(KOPER02010_GRID_EMPTY).show();
	}, 
	unload : function() {
		$.jgrid.gridUnload(KOPER02010_GRID_ID); 
	}
};

var itp_fn_KOPER02010_search = function() {
	itp_fn_KOPER02010_switch_screen('LIST');	
	itp_fn_KOPER02010_grid.unload();
	itp_fn_KOPER02010_grid.callBack();
};

let itp_KOPER02010_param = {};
let itp_KOPER02010_search = false;
var itp_fn_KOPER02010_empty = {
	push: function() {
		let param = $('#ITP_FORM_KOPER02010_SEARCH').serializeObject();
		itp_KOPER02010_param = param;
	},
	back: function() {
		$('#ITP_FORM_KOPER02010_DEVI_TP_CD').val(itp_KOPER02010_param.deviTpCd);
		$('#ITP_FORM_KOPER02010_ORDER_YN').val(itp_KOPER02010_param.orderYn);
		$('#ITP_FORM_KOPER02010_ADT_AUTH_CD').val(itp_KOPER02010_param.adtAuthCd);
		$('#ITP_FORM_KOPER02010_EMAIL_RCV_YN').val(itp_KOPER02010_param.emailRcvYn);
		$('#ITP_FORM_KOPER02010_SMS_RCV_YN').val(itp_KOPER02010_param.smsRcvYn);
		$('#ITP_FORM_KOPER02010_MEMB_EXIT_DT').val(itp_KOPER02010_param.membExitDt);
		$('#ITP_FORM_KOPER02010_FROM_DT').val(itp_KOPER02010_param.fromDt);
		$('#ITP_FORM_KOPER02010_TO_DT').val(itp_KOPER02010_param.toDt);
		$('#ITP_FORM_KOPER02010_KEYWORD').val(itp_KOPER02010_param.keyword);
	}
};

var itp_fn_KOPER02010_view = function(param) {
	fn_ajax_call(SALES_USER_INFO, param, itp_fn_KOPER02010_view_callback, 'GET');
};

var itp_fn_KOPER02010_view_callback = function(result) {
	// console.log(result);
	itp_fn_KOPER02010_switch_screen('VIEW');
	$('#ITP_FORM_KOPER02010_VIEW #ITP_FORM_KOPER02010_VIEW_SALES_USER_ID').val(result.salesUserId);
	$('#ITP_FORM_KOPER02010_VIEW .fnSalesUserId').text(result.salesUserId);
	$('#ITP_FORM_KOPER02010_VIEW .fnSalesUserNm').text(result.salesUserNm);
	$('#ITP_FORM_KOPER02010_VIEW .fnSalesTypeCd').text(result.salesTypeCd);
	$('#ITP_FORM_KOPER02010_VIEW .fnUseStatCd').text(result.useStatCd);
	$('#ITP_FORM_KOPER02010_VIEW .fnSalesTypeNm').text(result.salesTypeNm);
	$('#ITP_FORM_KOPER02010_VIEW .fnUseStatNm').text(result.useStatNm);
	$('#ITP_FORM_KOPER02010_VIEW .fnTelNo').text(result.telNo);
	$('#ITP_FORM_KOPER02010_VIEW .fnFaxNo').text(result.faxNo);
	$('#ITP_FORM_KOPER02010_VIEW .fnEmail').text(result.email);
	$('#ITP_FORM_KOPER02010_VIEW .fnCmpyAddress').text('('+ result.zipno + ') ' + result.adres + ' ' + result.adresDtl);
	
	$('#ITP_FORM_KOPER02010_VIEW .fnAddDt').text(result.addDt);
	$('#ITP_FORM_KOPER02010_VIEW .fnChgDt').text(result.chgDt);
	
	itp_fn_KOPER02010_view_map(result.adres);	
};

var itp_fn_KOPER02010_detail = function(param) {
	fn_ajax_call(SALES_USER_INFO, param, itp_fn_KOPER02010_detail_callback, 'GET');
};

var itp_fn_KOPER02010_detail_callback = function(result) {
	 console.log(result);
	itp_fn_KOPER02010_switch_screen('MODIFY');
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_VIEW_CD').val('U');
	
	$('#ITP_FORM_KOPER02010_VIEW #ITP_FORM_KOPER02010_VIEW_SALES_USER_ID').val(result.salesUserId);
	$('#ITP_FORM_KOPER02010_VIEW .fnSalesUserId').text(result.salesUserId);
	$('#ITP_FORM_KOPER02010_VIEW .fnSalesUserNm').text(result.salesUserNm);
	$('#ITP_FORM_KOPER02010_VIEW .fnSalesTypeCd').text(result.salesTypeCd);
	$('#ITP_FORM_KOPER02010_VIEW .fnUseStatCd').text(result.useStatCd);
	$('#ITP_FORM_KOPER02010_VIEW .fnSalesTypeNm').text(result.salesTypeNm);
	$('#ITP_FORM_KOPER02010_VIEW .fnUseStatNm').text(result.useStatNm);
	$('#ITP_FORM_KOPER02010_VIEW .fnTelNo').text(result.telNo);
	$('#ITP_FORM_KOPER02010_VIEW .fnFaxNo').text(result.faxNo);
	$('#ITP_FORM_KOPER02010_VIEW .fnEmail').text(result.email);
	
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_SALES_USER_NM').val(result.salesUserNm);
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_SALES_TYPE_CD').val(result.salesTypeCd);
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_USE_STAT_CD').val(result.useStatCd);
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_SALES_USER_ID').val(result.salesUserId);	
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_SALES_TYPE_NM').val(result.salesTypeNm);
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_USE_STAT_NM').val(result.useStatNm);
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_TEL_NO').val(result.telNo);
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_FAX_NO').val(result.faxNo);
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_EMAIL').val(result.email);
		
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_ZIPNO').val(result.zipno);	
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_ADRES').val(result.adres);	
	$('#ITP_FORM_KOPER02010_DETAIL #ITP_FORM_KOPER02010_DETAIL_ADRES_DTL').val(result.adresDtl);		
	
	$('#ITP_FORM_KOPER02010_DETAIL .fnAddDt').text(result.addDt);
	$('#ITP_FORM_KOPER02010_DETAIL .fnChgDt').text(result.chgDt);
	
	itp_fn_KOPER02010_detail_map($('#ITP_FORM_KOPER02010_DETAIL_ADRES').val());
	
};
