CheckListPageManager = Class.create();
CheckListPageManager.prototype = {
  //cfg 파라미터의 changePage 속성이 넘어왔을때 페이지 이동시 호출함수 설정
  //값이 없을때 default으로 changePage 함수로 설정 
  initialize: function(cfg){
	 this.current = '1',
	 this.first = '',
	 this.end = '',
	 this.next = '',
	 this.prev = '',
	 this.ipp = '10',
	 this.totalItem = '';

	 // 페이지 이동 시 호출되는 Function 이름
	 this.changePageFunction = (cfg != undefined && cfg.changePage != undefined)? cfg.changePage :'changePage';

	 // 이미지 경로 저장 변수
	 this.firstImagePath = '/images/user/common/btn/btn_first.gif';
	 this.prevImagePath = '/images/user/common/btn/btn_prev.gif';
	 this.nextImagePath = '/images/user/common/btn/btn_next.gif';
	 this.endImagePath = '/images/user/common/btn/btn_last.gif';

  },
  calcPaging : function() {
	 // ipp, current, totalItem을 입력하면 paging 계산
	 this.ipp = (this.ipp==0) ? 10 : this.ipp;
	 if ( this.totalItem != 0 ) {
		this.end = parseInt(this.totalItem/this.ipp) + (((this.totalItem%this.ipp)==0)?0:1);
		this.next = parseInt(Math.ceil( (this.current/10.0) )*10);
		this.prev = this.next - 9;
		this.next =  ( this.next > this.end)?this.end:this.next;
		this.first = 1;
	 } else {
		this.clear();
	 }
  },
  clear : function() {
	 // pageCondtion 를 초기화한다.
	 this.current = '1',
	 this.first = '',
	 this.end = '',
	 this.next = '',
	 this.prev = '',
	 this.ipp = '10',
	 this.totalItem = '';
  },
  getPaging: function(){
	 // 승인자 페이징 데이터를 리턴한다.
	 var pageHTML = '';
	 if (this.first != 0) {
		if (this.prev != this.first) {
		  pageHTML += "<a href=\"#\" onkeypress=\"\" onclick=\"" + this.changePageFunction + "(" + Number(this.first) + "); return false;\"><img src='" + this.firstImagePath + "' alt=\"첫페이지\" title=\"첫페이지\" /></a>";
		  pageHTML += "<a href=\"#\" onkeypress=\"\" onclick=\"" + this.changePageFunction + "(" + Number(this.prev - 1) + "); return false;\"><img src='" + this.prevImagePath + "' alt=\"이전페이지\" title=\"이전페이지\" /></a>";
		}
		
		for (var i = this.prev; i <= this.next; i++) {
			var lnk = "";
		  if (i == this.current) {
			  lnk += '<strong>' + i + '</strong>';
		  } else {
			  lnk += '<a href="#" onkeypress="" onclick="' + this.changePageFunction + '(' + i + ');" class="item">' + i + '</a>';
		  }
		  
		  if (i == this.prev) {
			  pageHTML += '<span class="first">' + lnk + '</span>';
		  } else if (i == this.next) {
			  pageHTML += '<span class="last">' + lnk + '</span>';
		  } else {
			  pageHTML += '<span>' + lnk + '</span>';
		  }
		}

		if (this.next != this.end) {
		  pageHTML += "<a href=\"#\" onkeypress=\"\" onclick=\"" + this.changePageFunction + "(" + Number(this.next + 1) + ");\"><img src='" + this.nextImagePath + "' alt=\"다음 페이지\" title=\"다음 페이지\" /></a>";
		  pageHTML += "<a href=\"#\" onkeypress=\"\" onclick=\"" + this.changePageFunction + "(" + Number(this.end) + ");\"><img src='" + this.endImagePath + "' alt=\"마지막 페이지\" title=\"마지막 페이지\" /></a>";
		}
	 }
	 return pageHTML;
  }
};
/*
	 ICT_checkManager USER결과목록조회 클래스
	 dependency: prototype.js, scriptaculous.js, effect.js
				 DWR(engine,CommonManager interface)
	 Author: hyhy81
	 Date:2009/03/23
*/
var pageManager = new CheckListPageManager ();

var changePage = function (page) {
	pageManager.current = page;
	g_checkMgr.loadList();
};

var ICT_checkManager = Class.create({
	initialize : function(){
		
	},
	
	/**
	 * 순번
	 * @param 
	 * @return 
	 */
	getNum : function() {
		return (pageManager.totalItem - ( (pageManager.current -1) * pageManager.ipp));
	},
	
	/**
	 * 결과목록 리스트
	 * @param 
	 * @return 
	 */
	loadList : function() {	
		var innerHtml = "";
		var map = {};
		map['sql_id']='Ict_check.getTstResultListCnt_ict';	
		map['u_id']=u_id;
		pageManager.totalItem = doit_Manager('CommonManager.get', map);
		var num = pageManager.totalItem - this.getNum() + 1;
		
		map['sql_id']='Ict_check.getTstResultList_ict';
		map['ipp'] = pageManager.ipp;
		map['current'] = pageManager.current;
		var result = doit_Manager('CommonManager.getList', map);
		
		if(result && result.length > 0){
			var goImg = '';
			var resultLength = result.length;
			for(var i=0; i< resultLength; i++){
					
				result[i].apply_sec = this.parseHour(result[i].apply_sec);
				innerHtml += "<tr>"
							+ "	<td>"+(num++)+"</td>";
				
				if (result[i].evalstt_nm == "완료") {
					innerHtml += "	<td><img src=\"/images/user/common/btn/btn_comfirm05.gif\" alt=\"완료\"></td>";
					goImg = '<a href="#" onkeypress="" onclick="g_checkMgr.openReport('+result[i].tst_idx+'); return false;" ><img src="/images/user/common/btn/btn_view.gif" alt="보기"/></a>';
				} else {
					innerHtml += "	<td><img src=\"/images/user/common/btn/btn_tempo.gif\" alt=\"임시\"></td>";
					goImg = '&nbsp;';
				}
				
				innerHtml += "	<td>"+result[i].apply_st_tm+"</td>"
							+ "	<td>"+result[i].apply_sec+"</td>"
							+ "	<td>"+this.pointNumerFormat(result[i].rs,1)+"</td>"
							+ "	<td>"+result[i].on_cd+"</td>"
							+ "	<td>"+goImg+"</td>"
							+ "</tr>"; 
			}
		}else{
			innerHtml = '<tr height="28" align="center"><td colspan="7" bgcolor="#FFFFFF" nowrap>진단 결과가 없습니다.</td></tr>';
		}	
		$('content').update(innerHtml);
		pageManager.calcPaging();
		$('paging').update(pageManager.getPaging());	
	},
	
	/**
	 * 초를 시간/분/초로 변환.
	 * @param stuSec (초)
	 * @return 
	 */
	parseHour : function(stuSec){
		var viewStuSec = '';
	 	if(stuSec < 60){
	  		viewStuSec = stuSec + '초'; 
	 	}else if(60<=stuSec && stuSec<3600){
	  		var minutes = 0;
	  		var sec = 0;
	  		minutes = Math.floor(stuSec/60);
	  		for(var i=0;i<minutes;i++){
	   			stuSec -= 60;
	  		}
	  		sec = stuSec;
	  
	  		if(sec != 0){
	   			viewStuSec = minutes+"분 "+sec+"초";
	  		}else{
	   			viewStuSec = minutes+"분 ";
	  		}
	   
	 	}else if(stuSec>=3600){
	  		var hour = 0;
	  		var minutes = 0;
	  		var sec = 0;
	  
	  		hour = Math.floor(stuSec/3600);
	  		for(var i=0;i<hour;i++){
	   			stuSec -= 3600;
	  		}
	  		if(stuSec > 60){
	  			minutes = Math.floor(stuSec/60);
	   			for(var i=0;i<minutes;i++){
	    			stuSec -= 60;
	   			}
	   			sec = stuSec;
	  		}
	  
	  		if(minutes != 0 && sec != 0){
	   			viewStuSec = hour + "시간 " + minutes + "분 " + sec + "초";
	  		}else if(minutes == 0 && sec != 0){
				viewStuSec = hour + "시간 "  + sec + "초";
			}else if(minutes != 0 && sec == 0){
				viewStuSec = hour + "시간 "  + minutes + "분 "; 
			}else if(minutes == 0 && sec == 0){
				viewStuSec = hour + "시간 ";
			}
		}
		return viewStuSec;
	},
	
	/**
	 * 성적표 창띄우기
	 * @param tst_idx
	 * @return 
	 */
	openReport : function(tst_idx){
		popWindow('reportWin', '/jsp/ICT/user/check/Ict_popReport.jsp?idx='+tst_idx+'&u_id='+u_id, 687, 700, 'no', 'yes', 'no');	
	},
	
	/**
	 * 성적표 용어보기
	 * @param
	 * @return 
	 */
	popWordView : function(){
		popWindow('wordWin', '/jsp/ICT/user/check/Ict_popWordView.jsp', 588, 710, 'no', 'yes', 'no');	
	},
	
	/**
	 * 소수점 뒤 자리수 맞춰주는 함수
	 * @param value(숫자값), scale(소수점 자릿수) 모자를경우 뒤에0을 붙여주고 남는경우는 버린다.
	 * @return value (소수점자리에 해당하는..), 문자형으로 리턴
	 */
	pointNumerFormat : function(value, scale){
		value = value+"";
		var idx = value.indexOf(".")+1;
		var strLen = value.length;
		var backStrLen = strLen - idx;
		if(idx == 0) backStrLen=0;

		if(backStrLen < scale){
			if(idx == 0){
				value += ".";
				for(var i=backStrLen; i < scale; i++){
					value += "0";
				}
			}else{
				for(var i=backStrLen; i < scale; i++){
					value += "0";
				}
			}
		}else if(backStrLen > scale){
			value = value.substring(0,strLen - (backStrLen-scale));
		}
		return value;
	}
	
});

