
$(function(){ // JQ실행 기본문법 HTML 문서가 시작되면..이라는뜻
	var token = $("meta[name='_csrf']").attr("content");
	var header = $("meta[name='_csrf_header']").attr("content");
    var searchTable = $(".search-table");  // class "search-table"를 searchTable에 담고 
    var inputStartDate = $("input[name='searchStartDate']"); // inpput태그에서 name이 searchStartDate인
    const noSearchTr = $("<tr><td class='nullRow'>조회 내용이 없습니다.</td></tr>"); // if.. 값이 null 일때  html에 넣어주려한듯. 
// test
    function init(){
	 //ajax통신시 로딩바 구현 현 js파일내에 ajax구동시 작동. 실제구동되는 ajax파일 안에 넣어서 사용가능
  	 //.ajaxSetup() : 반복 사용하는 ajax()메서드의 주요 속성을 미리 설정
		   $.ajaxSetup({
				beforeSend: function (xhr) { // 보내기전 로딩바구현
		              xhr.setRequestHeader(header, token);
		              var width = 0;
		              var height = 0;
		              var left = 0;
		              var top = 0;
		              width = 50;
		              height = 50;
		              top = ( $(window).height() - height ) / 2 + $(window).scrollTop();
		              left = ( $(window).width() - width ) / 2 + $(window).scrollLeft();
		
			              if($("#div_ajax_load_image").length != 0) {
			                     $("#div_ajax_load_image").css({"top": top+"px","left": left+"px"});
			                     $("#div_ajax_load_image").show();
			                       $('html').css("cursor", "wait");
			              }
			              else {
			                     $('body').append('<div id="div_ajax_load_image" style="position:absolute; top:' 
			                     + top + 'px; left:' + left + 'px; width:' + width + 'px; height:' + height 
			                     + 'px; z-index:9999; background:#f0f0f0; filter:alpha(opacity=50); opacity:alpha*0.5; margin:auto; padding:0; "><img src="/image/loading.gif" style="width:50px; height:50px;"></div>');
			              }
			
		       	}, complete: function () { // 완료후 숨기기
		                     $("#div_ajax_load_image").hide();
		                       $('html').css("cursor", "auto");
		        }
		
			});
	
	
            inputStartDate.on("change",()=>{
				 var beginVal=$(".searchStartDate").val();  
				 
        		 var setEndDate = new Date(beginVal.substring(0, beginVal.indexOf("-")), //년
                                   beginVal.substring(beginVal.indexOf("-")+1, beginVal.lastIndexOf("-")),1).toJSON(); //월
                
                // console.log("*****"+setEndDate);                	
                 setEndDate = setEndDate.substr(0,setEndDate.indexOf("T"));   
				
                
                 //시작 일이 min 값으로 변경
                $(".searchEndDate").prop("min", $(".searchStartDate").val());
                //시작 일 값으로 조회 기간 세팅
                $(".searchEndDate").prop("value", $(".searchStartDate").val());
                //시작 해의 31일이 max 값으로 세팅
                $(".searchEndDate").prop("max", Number(setEndDate));
                if($(".searchStartDate").val() == null || $(".searchStartDate").val() == "")$(".searchEndDate").prop("max", null);  
            });
            
			$(".search-select").on("change",()=>{
				if ( $(".search-select").val() === "apiInvoke") {
					$("option[value='userIdSearch']").text("API 별 조회");
					$(".search-user-select").text("API ID : ");
					$(".search-user-select").append($('<select  name="userId" class="userId">'
													+ '<option value="">API 를 선택해주세요</option>'
													+ '</select>'));
					setOptionApiUser("/setOptionApiUser.do");
				} else if ( $(".search-select").val() === "systemResuource") {
					$("option[value='userIdSearch']").text("SERVER 별 조회");
					$(".search-user-select").text("SERVER : ");
					$(".search-user-select").append($('<select  name="userId" class="userId">'
													+ '<option value="">SERVER를 선택해주세요</option>'
														+ '</select>'))
					setOptionResourceUser("/setOptionResourceUser.do");
				}
				
				//search-condition
			})
			
            $(".search-condition").on("change",()=>{ // 사용자가 셀렉 선택시에.. 셀렉테그의 벨류값이 무엇이지에따라 실행되는 함수를 바꿔준다
                        if($(".search-condition").val() == "") unSelectBox();
                        else if($(".search-condition").val() == "joinDateSearch") searchDateRecode($(".select-button"));
                        else if($(".search-condition").val() == "userIdSearch") searchCustomerRecode($(".select-button"));
            })
            
       		var div=$("<div>");
       		$(".result-box").append(div);
			div.addClass("page-div")
      }


 init();
 
 
 
       		
    
    
//option세팅 API 사용자조회 목록 ajax
    function setOptionApiUser(url){
		$.ajax({
			url: "/api" + url,
			async:true,
			type: "get",
			dataType: "json",
			/*data: {
				
			},*/
			success: function(result) {
				result.forEach((ii) => {
					$(".userId").append($("<option value="+ii+">" + ii + "</option>"));
					
				})
			},
			error: function(error) {
				console.log(error)
			}
		})
	}
	
	
//option세팅 Resource 사용자조회 목록 ajax
    function setOptionResourceUser(url){
		$.ajax({
			url: "/api" + url,
			async:true,
			type: "get",
			dataType: "json",
			/*data: {
				
			},*/
			success: function(result) {
				result.forEach((ii) => {
					$(".userId").append($("<option value="+ii+">" + ii + "</option>"));
				})
			},
			error: function(error) {
				console.log(error)
			}
		})
	}

	// 미선택
    function unSelectBox(){
            $(".search-condition").css("width","400px");
            $(".search-date-select").css("display","none");
            $(".search-user-select").css("display","none");
            $(".select-button").css("display","none");
    }
    
	// 접속 일자별 조회===================================
    function searchDateRecode(button){
            $(".search-condition").css("width","205px");
            $(".search-date-select").css("display","block"); // block : 블럭형태로 보이게
            $(".search-user-select").css("display","none"); // none : 안보이게
            $(".select-button").css("display","flex");
            $(".select-button").off("click");
            
            //var now = new Date(); 지금시간         
            var now = new Date().toJSON(); 
            console.log("*****now =" + now);
           
	// input 태그 name이 searchStartDate인 곳에 추가해라, value값을 , now변수값으로, substr은 문자열 자르는 함수 (0번째 부터 T 나올때까지)
			          
			$("input[name='searchStartDate']").prop("value",now.substr(0,now.indexOf("T"))) 
			$("input[name='searchEndDate']").prop("value",now.substr(0,now.indexOf("T"))) 
			// console창에 찍어보면 2021-10-22T00:50:40.409Z 이런식으로 나오는걸 T까지 잘라서 시간만 사용
            button.on('click',()=>{// *click이벤트
				var searchSelect=$(".search-select");
				var searchStartDate = $("input[name='searchStartDate']");
				var searchEndDate = $("input[name='searchEndDate']");
				
				
			/*	if(searchSelect.val()==""){
					alert("test 이력 조회 항목을 선택해주세요");
				} else if(searchStartDate.val() == ""){
					alert("test 조회 기간을 선택해주세요.");
				} else if(searchEndDate.val() == ""){
					alert("test 조회 기간을 선택해주세요.");
				} else if (searchSelect.val() !="" && searchStartDate.val() != "" && searchEndDate.val() != ""){
					setInvokeDateTable("/searchDateRecodeInvoke.do",searchSelect.val(),searchStartDate.val(),searchEndDate.val());
				}
				
				nullchecker 함수 없이 쓸경우 , 사용가능 같은뜻이다.
			*/
				
                if(nullChecker(searchSelect.val())) {
                    alert("이력 조회 항목을 선택해주세요");
                    searchSelect.focus(); // 
                }
                else if(nullChecker(searchStartDate.val())){
                    alert("조회 기간을 선택해주세요.");
                    searchStartDate.focus();
                }
                else if(nullChecker(searchEndDate.val())){
                    alert("조회 기간을 선택해주세요.");
                    searchEndDate.focus();
                }
                else if( searchSelect.val() =="apiInvoke" && !nullChecker(searchStartDate.val()) && !nullChecker(searchEndDate.val())){
                       setInvokeDateTable("/searchDateRecodeInvoke.do",searchSelect.val(),searchStartDate.val(),searchEndDate.val());
                }						//여기부터 url호출 controller이동.. 백단의시작
                else if( searchSelect.val() =="systemResuource" && !nullChecker(searchStartDate.val()) && !nullChecker(searchEndDate.val())){
                       setSystemResourceDateSearchTable("/SystemResourceDateSearch.do",searchSelect.val(),searchStartDate.val(),searchEndDate.val());
                }
            })
    }

				
				
	 // 사용자별 조회 =========================
				 function searchCustomerRecode(button){
				            $(".search-condition").css("width","300px");
				            $(".search-date-select").css("display","none");
				            $(".search-user-select").css("display","block");
				            $(".select-button").css("display","flex");
				            $(".select-button").off("click"); 
				            // 데이터가 꼬이지 않도록 초기화, 밑에서 클릭이벤트를 바로실행하기에.
				
				            button.on('click',()=>{ 
				                    if(nullChecker($(".search-select").val())) {
				                        alert("이력을 선택하지 않았습니다.");
				                        $(".search-select").focus();
				                    }
				                    else if(nullChecker($(".userId").val())){
				                        alert("ID가 입력되지 않았습니다.");
				                        $("input[name='searchStartDate']").focus();
				                    }
					             	else if($(".search-select").val() == "apiInvoke"
					                                    &&
					                                    	!nullChecker($(".userId").val())){
					                        	setInvokeTable("/searchCustomerInvoke.do",$(".search-select").val(),$(".userId").val());
													
					                    }
					                else if($(".search-select").val() =="systemResuource"
					                                    &&
					                                    	!nullChecker($(".userId").val())){
					                        	setSystemResourceUserTable("/systemResourceUserSearch.do",$(".search-select").val(),$(".userId").val());
													
					                    }    
				             
				              /*원본      
				                    else if( !nullChecker($(".search-select").val())
				                                &&
				                                    !nullChecker($("input[name='userId']").val())){
				                        	setInvokeTable("/searchCustomerInvoke.do",$(".search-select").val(),$("input[name='userId']").val());
												
				                    }
				              */       
				            })
				    }
			
// 시스템리소스 사용자별 조회 ajax
	    function setSystemResourceUserTable(url,serachCategory,userId,page){
	       $.ajax({
	          url: "/api" + url,
	          async:true,
	          cache:false,
	          type:"post",
	          dataType:"json",
			  data:{
		      	serachCategory:serachCategory,
			 	userId:userId,
			  	page:page
			  },
	          success:function(result){
				$(".search-table").empty();
				( result == null || result == undefined || result == "")?searchTable.append(noSearchTr):setTableSystemResourceUser(result,searchTable);
	
	          },error:function(error){
	            console.log(error)
	          }
	
	       })
	    }
   		    
				    
				    
				    

 // api 날짜별 조회 ajax
	 function setInvokeDateTable(url,serachCategory,searchStartDate,searchEndDate,page){
	       $.ajax( // ajax로 요청을 시작한다
			{
	          url: "/api" + url,
	          async:true, //
	          cache:false, // 캐시
	          type:"post", // 통신타입
	          dataType:"json", //응답받을 데이터 타입 설정
			  data:{ // 보낼 데이터 키 : 받는파라미터값 , "보내는 키" 명과 "controller에서 받는 parameter" 이름이 같아야한다 
				serachCategory : serachCategory,
				searchStartDate : searchStartDate,
				searchEndDate : searchEndDate,
				page:page
			  },
	          success:function(result){
				console.log("##########"+result);	
				$(".search-table").empty(); 
				( result == null || result == undefined || result == "") ? searchTable.append(noSearchTr) : setTableApiInvoke(result,searchTable);
	          }

	       	   ,error:function(error){
	            console.log(error)
	          }
	
	       	}
	       )
	    }
	    
// 시스템 리소스 날짜별 조회 ajax
	 function setSystemResourceDateSearchTable(url,serachCategory,searchStartDate,searchEndDate,page){
	       $.ajax( // ajax로 요청을 시작한다
			{
	          url:"/api" + url,
	          async:true,
	          cache:false, 
	          type:"post", 
	          dataType:"json", 
			  data:{ 
				serachCategory : serachCategory,
				searchStartDate : searchStartDate,
				searchEndDate : searchEndDate,
				page:page
			  },
	          success:function(result){
				$(".search-table").empty(); 
				( result == null || result == undefined || result == "") ? searchTable.append(noSearchTr) : setTableSystemResource(result,searchTable);
			
	          }
	           	          
	          ,error:function(error){
	            console.log(error)
	          }
	          
	         
		     	
	
	       	}
	       )
	    }  


// 시스템리소스 일자별 가져온 데이터  view단에 뿌려주기
	  function setTableSystemResource(arr,table){ 
		var {tablelist,currentPage,totPage,firstPage,lastPage}=arr;
	  			console.log(arr.clct_dt);
	            table.append('<tr style="height:30px;line-height:30px;">'
	                  +'<th class="SystemResource-th">수집 시각<br></th>'
	                  +'<th class="SystemResource-th">호스트명<br></th>'
	                  +'<th class="SystemResource-th">전체 메모리 용량<br>(Gi)</th>'
	                  +'<th class="SystemResource-th">사용 메모리 용량<br>(Gi)</th>'
	                  +'<th class="SystemResource-th">전체 Disk 용량<br>(Gi)</th>'
	                  +'<th class="SystemResource-th">사용 Disk 용량<br>(Gi)</th>'
	                  +'<th class="SystemResource-th">메모리 사용량<br>(%)</th>'
	                  +'<th class="SystemResource-th">CPU 사용량<br>(%)</th>'
	                  +'<th class="SystemResource-th">DISK 사용량<br>(%)</th>'
	                  +'<th class="SystemResource-th">실행 타스크 수<br>(EA)</th>'
	                  +'<th class="SystemResource-th">실행 스레드 수<br>(EA)</th>'
	                  +'<th class="SystemResource-th">시스템 로드 <br>5분 평균</th>'
	                  +'</tr>')
	           tablelist.forEach((sr)=>{
						console.log(sr);
	                   
	                    table.append("<tr><td>"+sr.clctDt.substring(0,10)+" "+sr.clctDt.substring(11,sr.clctDt.length)+"</td>"
	                            +"<td>"+sr.hostName+"</td>"
	                            +"<td>"+sr.totalMem+"</td>"
	                            +"<td>"+sr.useMem+"</td>"
	                            +"<td>"+sr.totalDisk+"</td>"
	                            +"<td>"+sr.useDisk+"</td>"
	                            +"<td>"+sr.useMemRate+"</td>"
	                            +"<td>"+sr.useCpuRate+"</td>"
	                            +"<td>"+sr.useDiskRate+"</td>"
	                            +"<td>"+sr.taskCnt+"</td>"
	                            +"<td>"+sr.threadCnt+"</td>"
	                            +"<td>"+sr.loadAvg+"</td></tr>"
							);
	        			})
	        			
	        		$(".page-div").empty();
			var str=[];
			
			firstPage<=1||str.push($($("<a>[PREV]</a>")))
			
			for(let i = firstPage; i<= lastPage;i++){
				i !== currentPage?str.push($("<a>["+i+"]</a>")):str.push($("<a style='font-weight:bold'>["+i+"]</a>"));
			}
			
			lastPage>=totPage||str.push($("<a>[NEXT]</a>"));
			$(".page-div").html(str);
			$(".page-div > a").css("cursor","pointer");
			var searchSelect=$(".search-select");
			var dateBegin = $("input[name='searchStartDate']");
			var dateEnd = $("input[name='searchEndDate']");
			$(".page-div > a").on("click",function(){
				var pageText=$(this).text();
				if(pageText=="[NEXT]"){
					var page=firstPage+10;
					setSystemResourceDateSearchTable("/SystemResourceDateSearch.do"
									,searchSelect.val()
									,dateBegin.val()
									,dateEnd.val()
									,page);
					return
				}
				if(pageText=="[PREV]"){
					var page=currentPage<=10?1:currentPage-10;
					setSystemResourceDateSearchTable("/SystemResourceDateSearch.do"
									,searchSelect.val()
									,dateBegin.val()
									,dateEnd.val()
									,page);
					return
				}
				setSystemResourceDateSearchTable("/SystemResourceDateSearch.do"
									,searchSelect.val()
									,dateBegin.val()
									,dateEnd.val()
									,pageText.substr(pageText.indexOf("[")+1,pageText.indexOf("]")-1));
			})
    }	
	        
	        
	        
	  
// 시스템리소스 사용자별 데이터  view단에 뿌려주기
	  function setTableSystemResourceUser(arr,table){ 
		var {tablelist,currentPage,totPage,firstPage,lastPage}=arr;
	            table.append('<tr style="height:30px;line-height:30px;">'
	                  +'<th class="SystemResource-th">수집 시각<br></th>'
	                  +'<th class="SystemResource-th">호스트명<br></th>'
	                  +'<th class="SystemResource-th">전체 메모리 용량<br>(Gi)</th>'
	                  +'<th class="SystemResource-th">사용 메모리 용량<br>(Gi)</th>'
	                  +'<th class="SystemResource-th">전체 Disk 용량<br>(Gi)</th>'
	                  +'<th class="SystemResource-th">사용 Disk 용량<br>(Gi)</th>'
	                  +'<th class="SystemResource-th">메모리 사용량<br>(%)</th>'
	                  +'<th class="SystemResource-th">CPU 사용량<br>(%)</th>'
	                  +'<th class="SystemResource-th">DISK 사용량<br>(%)</th>'
	                  +'<th class="SystemResource-th">실행 타스크 수<br>(EA)</th>'
	                  +'<th class="SystemResource-th">실행 스레드 수<br>(EA)</th>'
	                  +'<th class="SystemResource-th">시스템 로드 <br>5분 평균</th>'
	                  +'</tr>')
	           tablelist.forEach((sr)=>{
						console.log(sr);
	                   
	                    table.append("<tr><td>"+sr.clctDt.substring(0,10)+" "+sr.clctDt.substring(11,sr.clctDt.length)+"</td>"
	                            +"<td>"+sr.hostName+"</td>"
	                            +"<td>"+sr.totalMem+"</td>"
	                            +"<td>"+sr.useMem+"</td>"
	                            +"<td>"+sr.totalDisk+"</td>"
	                            +"<td>"+sr.useDisk+"</td>"
	                            +"<td>"+sr.useMemRate+"</td>"
	                            +"<td>"+sr.useCpuRate+"</td>"
	                            +"<td>"+sr.useDiskRate+"</td>"
	                            +"<td>"+sr.taskCnt+"</td>"
	                            +"<td>"+sr.threadCnt+"</td>"
	                            +"<td>"+sr.loadAvg+"</td></tr>"
							);
	        			})
	        			
	        		$(".page-div").empty();
			var str=[];
			
			firstPage<=1||str.push($($("<a>[PREV]</a>")))
			
			for(let i = firstPage; i<= lastPage;i++){
				i !== currentPage?str.push($("<a>["+i+"]</a>")):str.push($("<a style='font-weight:bold'>["+i+"]</a>"));
			}
			
			lastPage>=totPage||str.push($("<a>[NEXT]</a>"));
			$(".page-div").html(str);
			$(".page-div > a").css("cursor","pointer");
			var searchSelect=$(".search-select");
			var dateBegin = $("input[name='searchStartDate']");
			var dateEnd = $("input[name='searchEndDate']");
			$(".page-div > a").on("click",function(){
				var pageText=$(this).text();
				if(pageText=="[NEXT]"){
					var page=firstPage+10;
					setSystemResourceUserTable("/systemResourceUserSearch.do"
									,searchSelect.val()
									,$(".userId").val()
									,page);
					return
				}
				if(pageText=="[PREV]"){
					var page=currentPage<=10?1:currentPage-10;
					setSystemResourceUserTable("/systemResourceUserSearch.do"
									,searchSelect.val()
									,$(".userId").val()
									,page);
					return
				}
				setSystemResourceUserTable("/systemResourceUserSearch.do"
									,searchSelect.val()
									,$(".userId").val()
									,pageText.substr(pageText.indexOf("[")+1,pageText.indexOf("]")-1));
			})
    }		        
	        
	        
	
	    
	  

// api 일자별 데이터  view단에 뿌려주기
	   function setTableApiInvoke(arr,table){
			var {tablelist,currentPage,totPage,firstPage,lastPage}=arr;
            table.append($('<tr style="height:30px;line-height:30px;">'
                  +'<th class="invoke-th">발생시각</th>'
                  +'<th class="invoke-th">apiId</th>'
                  +'<th class="invoke-th">apiToken</th>'
                  +'<th class="invoke-th">ip 주소</th>'
                  +'<th class="invoke-th">정상 작동 여부</th>'
                  +'</tr>'))
            tablelist.forEach((api)=>{
                    var tr=$("<tr>");
                    var trError=$("<tr>")
                    tr.html("<td>"+api.eventdt.substring(0,10)+" "+api.eventdt.substring(11,api.eventdt.length)+"</td>"
                            +"<td>"+api.apiid+"</td>"
                            +"<td>"+api.apitoken+"</td>"
                            +"<td>"+api.ipaddr+"</td>"
                            +"<td>정상</td>")

                    trError.html("<td>"+api.eventdt.substring(0,10)+" "+api.eventdt.substring(11,api.eventdt.length)+"</td>"
                            +"<td>"+api.apiid+"</td>"
                            +"<td>"+api.apitoken+"</td>"
                            +"<td>"+api.ipaddr+"</td>"
                            +"<td>비정상</td>")

                    api.error==0?searchTable.append(tr):searchTable.append(trError);
        })
			$(".page-div").empty();
			var str=[];
			
			firstPage<=1||str.push($($("<a>[PREV]</a>")))
			
			for(let i = firstPage; i<= lastPage;i++){
				i !== currentPage?str.push($("<a>["+i+"]</a>")):str.push($("<a style='font-weight:bold'>["+i+"]</a>"));
			}
			
			lastPage>=totPage||str.push($("<a>[NEXT]</a>"));
			$(".page-div").html(str);
			$(".page-div > a").css("cursor","pointer");
			var searchSelect=$(".search-select");
			var dateBegin = $("input[name='searchStartDate']");
			var dateEnd = $("input[name='searchEndDate']");
			$(".page-div > a").on("click",function(){
				var pageText=$(this).text();
				if(pageText=="[NEXT]"){
					var page=firstPage+10;
					setInvokeDateTable("/searchDateRecodeInvoke.do"
									,searchSelect.val()
									,dateBegin.val()
									,dateEnd.val()
									,page);
					return
				}
				if(pageText=="[PREV]"){
					var page=currentPage<=10?1:currentPage-10;
					setInvokeDateTable("/searchDateRecodeInvoke.do"
									,searchSelect.val()
									,dateBegin.val()
									,dateEnd.val()
									,page);
					return
				}
				setInvokeDateTable("/searchDateRecodeInvoke.do"
									,searchSelect.val()
									,dateBegin.val()
									,dateEnd.val()
									,pageText.substr(pageText.indexOf("[")+1,pageText.indexOf("]")-1));
			})
    }



// api 사용자별 데이터  view단에 뿌려주기
	   function setTableApiInvokeUser(arr,table){
			var {tablelist,currentPage,totPage,firstPage,lastPage}=arr;
            table.append($('<tr style="height:30px;line-height:30px;">'
                  +'<th class="invoke-th">발생시각</th>'
                  +'<th class="invoke-th">apiId</th>'
                  +'<th class="invoke-th">apiToken</th>'
                  +'<th class="invoke-th">ip 주소</th>'
                  +'<th class="invoke-th">정상 작동 여부</th>'
                  +'</tr>'))
            tablelist.forEach((api)=>{
                    var tr=$("<tr>");
                    var trError=$("<tr>")
                    tr.html("<td>"+api.eventdt.substring(0,10)+" "+api.eventdt.substring(11,api.eventdt.length)+"</td>"
                            +"<td>"+api.apiid+"</td>"
                            +"<td>"+api.apitoken+"</td>"
                            +"<td>"+api.ipaddr+"</td>"
                            +"<td>정상</td>")

                    trError.html("<td>"+api.eventdt.substring(0,10)+" "+api.eventdt.substring(11,api.eventdt.length)+"</td>"
                            +"<td>"+api.apiid+"</td>"
                            +"<td>"+api.apitoken+"</td>"
                            +"<td>"+api.ipaddr+"</td>"
                            +"<td>비정상</td>")

                    api.error==0?searchTable.append(tr):searchTable.append(trError);
        })
			$(".page-div").empty();
			var str=[];
			
			firstPage<=1||str.push($($("<a>[PREV]</a>")))
			
			for(let i = firstPage; i<= lastPage;i++){
				i !== currentPage?str.push($("<a>["+i+"]</a>")):str.push($("<a style='font-weight:bold'>["+i+"]</a>"));
			}
			
			lastPage>=totPage||str.push($("<a>[NEXT]</a>"));
			$(".page-div").html(str);
			$(".page-div > a").css("cursor","pointer");
			var searchSelect=$(".search-select");
			$(".page-div > a").on("click",function(){
				var pageText=$(this).text();
				if(pageText=="[NEXT]"){
					var page=firstPage+10;
					setInvokeTable("/searchCustomerInvoke.do"
									,searchSelect.val()
									,$(".userId").val()
									,page);
					return
				}
				if(pageText=="[PREV]"){
					var page=currentPage<=10?1:currentPage-10;
					setInvokeTable("/searchCustomerInvoke.do"
									,searchSelect.val()
									,$(".userId").val()
									,page);
					return
				}
				setInvokeTable("/searchCustomerInvoke.do"
									,searchSelect.val()
									,$(".userId").val()
									,pageText.substr(pageText.indexOf("[")+1,pageText.indexOf("]")-1));
			})
    }



   
	// API사용자별조회 ajax
    function setInvokeTable(url,serachCategory,userId,page){
       $.ajax({
          url: "/api"+ url,
          async:true,
          cache:false,
          type:"post",
          dataType:"json",
		  data:{
			serachCategory:serachCategory,
			userId:userId,
			page:page
		  },
          success:function(result){
				console.log("find by user for API ajax ="+result);
				$(".search-table").empty();
			( result == null || result == undefined || result == "")?searchTable.append(noSearchTr):setTableApiInvokeUser(result,searchTable);

          },error:function(error){
            console.log(error)
          }

       })
    }
   

    function searchNullChecker(searchData1,searchData2,searchData3,searchData4){
            if(!nullChecker(searchData1))return searchData1;
            if(!nullChecker(searchData2))return searchData2;
            if(!nullChecker(searchData3))return searchData3;
            if(!nullChecker(searchData4))return searchData4;
            return null;
    }

    function nullChecker(item){
            var checker= (item == null || item == "")? true:false;
            return checker;
    }
    function setContentSelector(arr1,arr2,arr3){
            var result=searchNullChecker(arr1,arr2,arr3);
            return result;
    }





})