<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">


    <head th:fragment="headerFragment(title,active)">
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>triple A</title>
      <link rel="icon" href="/img/logo.ico">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" />
      <link rel="stylesheet" type="text/css" href="/css/common.css">
      <link rel="stylesheet" type="text/css" href="/css/header.css">
      <link rel="stylesheet" type="text/css" href="/css/main.css">
      <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
      <script type="text/javascript" src="/js/common.js"></script>
      <script src="/js/sockjs.min.js"></script>
   	  <script src="/js/stomp.min.js"></script>
      <th:block layout:fragment="html_head"></th:block>
      
      
    <script language='javascript'>
		
    	function changeSiteParseSet(pStatus) {
    		$('#'+pStatus+'_bt').hide();
			$('#'+pStatus+'_wait').show();
			
			$.ajax({
				type : "get", 
				url : "/agent/parseOnOff?pStatus="+pStatus,	
				async : true, 
				dataType : "json", 
				success : function(data) {
					if(data.RES=="SUCCESS"){
	 					alert("처리 완료");
	 					$('#'+pStatus+'_bt').show();
						$('#'+pStatus+'_wait').hide();
					 				
	 				} else {
						$('#'+pStatus+'_bt').show();
						$('#'+pStatus+'_wait').hide();
	 					alert("오류발생");
	 				}
				}
			});
    	}
		
		
		 function userwithdraw(vtype){
					 
					$('#'+vtype+'_bt').hide();
					$('#'+vtype+'_wait').show();
						
					    
			    	 $.ajax({
			 			type : "get",
			 			url : "/user/withdraw?type="+vtype,			 			
			 			async : true,
			 			dataType : "json",
			 			success : function(data) {
			 				if(data.RES=="SUCCESS"){
			 					alert("처리 완료");				 					
			 					$('#'+vtype+'_bt').show();
								$('#'+vtype+'_wait').hide();
							 				
			 				}else{
								$('#'+vtype+'_bt').show();
								$('#'+vtype+'_wait').hide();
			 					alert("오류발생");
			 				}
			 			}
			 		});
			    	 
			     
		    	 
		     }
      

      function comma_inputgeuminputgeum(id,  val) {
          var num = val;
              if (num.length >= 4) {
                  re = /^$|,/g;
                  num = num.replace(re, "");
                  fl=""
              if(isNaN(num)) { alert("문자는 사용할 수 없습니다.");return 0}
              if(num==0) return num
              if(num<0){
                  num=num*(-1)
                  fl="-"
              }
              else{
                  num=num*1 //처음 입력값이 0부터 시작할때 이것을 제거한다.
              }
                  num = new String(num)
                  temp=""
                  co=3
                  num_len=num.length
          while (num_len>0){
              num_len=num_len-co
              if(num_len<0){co=num_len+co;num_len=0}
              temp=","+num.substr(num_len,co)+temp
              }
         	$('#'+id).val(fl+temp.substr(1));
          }
      }


      function num_check() {
          var keyCode = event.keyCode
              if (keyCode < 48 || keyCode > 57){
                  alert("문자는 사용할 수 없습니다."+"["+keyCode+"]")
                  event.returnValue=false
              }
          }
      
      
      
		      function charge(){
		    	  
		    	  if($('#ciCreditAmt').val() =="" ||  $('#ciCreditAmt').val() =="0" ){
		    		  alert("신청 C 를 입력해주세요.");
		    		  return;
		    	  }
		    	 
		    	  
		    	  	var subPoint =0;
		    	  	if($('#pointUseYn').prop("checked")){
		    	  		subPoint = $('#pointAmt').val();		    	  		
		    	  	}
		    	
			    
			    	 $.ajax({
			 			type : "post",
			 			url : "/cash/addProc",
			 			data : {
			 				creditType:"CI",
			 				creditAmt:$('#ciCreditAmt').val().split(",").join(""),
			 				pointAmt:(""+subPoint).split(",").join("")
			 			},
			 			async : true,
			 			dataType : "json",
			 			success : function(data) {
			 				if(data.RES=="SUCCESS"){
			 					alert("완료");		
			 					$('#ciCreditAmt').val("");
			 					
			 				
			 				}else{
			 					alert("오류발생");
			 				
			 				}
			 			}
			 		});
			    	 
			     }
		      
		      
		      function pointUseYnClick(valu){
		    	  
		    	  if(valu){
		    		 
		    		  $('#ciCreditAmt').val($('#pointAmt').val());
		    		  
		    	  }else{
		    		  $('#ciCreditAmt').val("");
		    	  }
		    	  
		    	  
		      }
		      
			function isPointUseYnClick(valu){
		    	
		    	  if(valu){
		    		 
		    		  $('#ciInsureAmt').val($('#isPointAmt').val());
		    		  
		    	  }else{
		    		  $('#ciInsureAmt').val("");
		    	  }
		    	  
		    	  
		      }
		      
		      
 				function chargeInsure(){
		    	  
		    	  if($('#ciInsureAmt').val() ==""  || $('#ciInsureAmt').val() =="0"){
		    		  alert("신청 보험금를 입력해주세요.");
		    		  return;
		    	  }
		    	  
		    
		    	  
		    	  	var subPoint =0;
		    	  	if($('#isPointUseYn').prop("checked")){
		    	  		subPoint = $('#isPointAmt').val();		    	  		
		    	  	}
		    	
			    
			    	 $.ajax({
			 			type : "post",
			 			url : "/insurance/addProc",
			 			data : {
			 				insureType:"TRANIN",
			 				insureAmt:$('#ciInsureAmt').val().split(",").join(""),
			 				insurePointAmt: (""+subPoint).split(",").join("")
			 			},
			 			async : true,
			 			dataType : "json",
			 			success : function(data) {
			 				if(data.RES=="SUCCESS"){
			 					alert("완료");		
			 				//	location.href = location.href; 
			 					$('#ciInsureAmt').val("");
			 				
			 				}else{
			 					alert(data.MSG);
			 				}
			 			}
			 		});
			    	 
			     }
			     
		function exchange() {
			if( $('#coCreditAmt').val() =="" || $('#coCreditAmt').val() > [[${siteCredit}]] ) {
				alert("신청 C를 확인해주세요");
				return;
			}

			$.ajax({
				type : "post",
				url : "/cash/addProc",
				data : {
					creditType:"CO",
					creditAmt:$('#coCreditAmt').val().split(",").join("")
				},
				async : true,
				dataType : "json",
				success : function(data) {
					if(data.RES=="SUCCESS") {
						alert("완료");		
						location.reload();
					} else {
						alert(data.MSG);
					}
				}
			});
		}

		function exchangeInsure() {
			if($('#coInsureAmt').val() =="" || $('#coInsureAmt').val() > [[${insureAmt}]] ) {
				alert("신청 보험금을 확인해주세요");
				return;
			}

			$.ajax({
				type : "post",
				url : "/insurance/addProc",
				data : {
					insureType:"TRANOUT",
					insureAmt:$('#coInsureAmt').val().split(",").join("")
				},
				async : true,
				dataType : "json",
				success : function(data) {
					if(data.RES=="SUCCESS") {
						alert("완료");		
						location.reload();
					} else {
						alert("오류발생");
					}
				}
			});
		}
				 
				 
				 
				 
			var infoSocket = {
					stompClient: null,
					token: null,
					type: null,
					chatId: null
			};
					

						
						
			function connect(){
			
				infoSocket.token = "[[${loginSite.siteIdx}]]";
				infoSocket.type = "info";
				infoSocket.chatId = "1";
				var i_socket = new SockJS('/websocket');
				infoSocket.stompClient = Stomp.over(i_socket);
				infoSocket.stompClient.debug = null;
				infoSocket.stompClient.connect({}, function (frame) {
					
					
					
			        console.log('info Connected: ' + frame);
			       // healththCheck();
			        
			    	
			        infoSocket.stompClient.subscribe('/topic/infoMsg/[[${loginSite.siteIdx}]]', function(obj) {
			        	
			        	var resJson  = JSON.parse(obj.body);
			        	var push = JSON.parse(resJson.content);
			        	console.log(push);
			        	
			        	if(push.ciCnt > 0){
			        		$('.ciCnt').show();
			        		$('.ciCnt').text("("+push.ciCnt+")");
			        	}else{
			        		$('.ciCnt').hide();
			        		$('.ciCnt').text("(0)");
			        	}
			        	
			        	if(push.coCnt > 0){
			        		$('.coCnt').show();
			        		$('.coCnt').text("("+push.coCnt+")");
			        	}else{
			        		$('.coCnt').hide();
			        		$('.coCnt').text("(0)");
			        	}
			        	
			        	if(push.ciCnt + push.coCnt > 0){
			        		$('.cioCnt').show();
			        		
			        	}else{
			        		$('.cioCnt').hide();
			        	
			        	}
			        	

			        	if(push.iiCnt > 0){
			        		$('.iiCnt').show();
			        		$('.iiCnt').text("("+push.iiCnt+")");
			        	}else{
			        		$('.iiCnt').hide();
			        		$('.iiCnt').text("(0)");
			        	}
			        	
			        	if(push.ioCnt > 0){
			        		$('.ioCnt').show();
			        		$('.ioCnt').text("("+push.ioCnt+")");
			        	}else{
			        		$('.ioCnt').hide();
			        		$('.ioCnt').text("(0)");
			        	}
			        	
			        	if(push.iiCnt + push.ioCnt > 0){
			        		$('.iioCnt').show();
			        		
			        	}else{
			        		$('.iioCnt').hide();
			        	
			        	}
			        	
			        	
			        });       
			        
			    });
				
				infoSocket.stompClient.ws.onclose = function() {
					console.log("Websocket connection closed and handled from our app.");
				
					connect();
				};
				
			
			}
				 
			connect();
      </script>
      
    </head>
    <body>
      <div id="wrapper">
        <!--  left -->
        <th:block th:replace="~{admin/include/left::admin_left}"></th:block>
        
        
        <div id="content-wrapper" class="d-flex flex-column">
          <div id="content">
             <!--  head -->
             <th:block th:replace="~{admin/include/top::admin_top}"></th:block>
             
           	 <th:block layout:fragment="content" id="content"></th:block>
            

            

          </div><!-- content -->
          <!--footer class="footer">
            <span>Copyright © AGENT PAGE 2022.</span>
          </footer-->
        </div><!-- top nav -->
      </div>
    </body>
</html>
