/**
* @projectDescription MainPage's javacript
* @author ATTO Information Technology Corp. eWork R&D Team
* @version 1.0
* @sdoc ../../../sdoc/MainPage.sdoc
* ----------------------------------------------------------------------------------------------------
* Modification Information
* Date            	Developer        		Content
* ----------       ------------   	---------------------------
* 2009.09.16		KimKS			V2 구현
*/
  
/********************************************************************************
 * Global Variable : 화면 기준 전역변수 정의 
 ********************************************************************************/

var mintHelperTimer;
var mintHelperTimeout = 2000;
var mintCurrentHelper = 0;

/********************************************************************************
 * Event : prototype.js를 통해 제공되어지는 오브젝트별 이벤트 정의
 ********************************************************************************/
Event.observe(window, 'load', function() {
	//오브젝트별 이벤트 정의
	MainPage.observe();

	//화면초기화
	MainPage.initData();			//화면 로드시 데이터초기화
	MainPage.initDesign();			//화면 로드시 디자인 초기화
});



/**
 * 클래스
 * 
 * @alias MainPage
 * @classDescription : 메인페이지 처리 스크립트
 * @memberOf observe 
 * @memberOf initDesign
 * @memberOf initData
 */
var MainPage = {

/********************************************************************************
 * Event Object : 이벤트에서 오브젝트 선언 그룹 
 ********************************************************************************/
	observe:function(){
		//오브젝트별 이벤트 정의
		if ($("btnLogout"))		{Event.observe('btnLogout', 'click', this.eventControl); }
		if ($("btnGoMyeWork"))	{Event.observe('btnGoMyeWork', 'click', this.eventControl); }
	
	},



/********************************************************************************
 * Event Function : 이벤트에서 호출하는 함수그룹 
 ********************************************************************************/
	eventControl:function(event){
		try{
			var objElement = SCObjectControl.getObject(event);
			switch(objElement.id){
				case "btnLogout" 		: SCWindowControl.showWindow("srcweb/zz/login/DoLogout.jsp", "_self", 0, 0, ""); break;
				case "btnGoMyeWork" 	: CMCMControl.pageLink("MYPORTAL","",""); break;
			}
		} catch(ex){
			SCErrorControl.doErrorRtn(ex, "eventControl");	
		}
	},

		
/********************************************************************************
 * Init Function : 화면초기화 및 화면디자인 함수 그룹
 ********************************************************************************/	
	/**
	 * 화면 디자인 초기화
	 */
	initDesign:function(){
		
		//변경된 약관의 상태와 동의여부를 이용하여 팝업으로 경고를 하거나, 약관동의화면으로 모든행위를 막는다
		MainPage.setAgreement();

		// 약관 확인창을 이동할 수 있도록 하려면 주석을 해제
		//new Draggable('dvAgreementLayer',{scroll:window,handle:'handle1',revert:function(element){return ($('dvAgreementLayer').checked)}});
		
	},
	
	/**
	 * 데이터 초기화
	 */
	initData:function(){
		//공지사항, 이워크뉴스 조회
		MainPage.actionRtn("GET_ANNOUNCE_NEWS_LIST");

		//읽지 않은 메시지 숫자 조회
		if ($("spMsgCount")) {
			MainPage.actionRtn("GET_MSG_COUNT", "aaa");
		}
		
		mintCurrentHelper = 0;
		MainPage.setNextHelperTimer();
		
		// 공통 팝업 호출 
		CMCMControl.showMainPopup("CMCM");
		
		//campuslife통해들어오면 FAQ보여줌
		if($F(txtADD_POP)=="Y"){CMCMControl.showFAQPopup("CCQA2009032013021103981");}

		//최근중요정보표시(과외정보)
		//MainPage.actionRtn("GET_EDU_LIST");			

	},
	
	
/********************************************************************************
 * Control Function : 처리함수 그룹  
 ********************************************************************************/	
	/**
	 * ActionControl 처리
	 * @param {String} strCase 처리구분
	 * @param {String} strParam1 GET_FILE_ENTRY일 경우 TreeNode의 값(Path 값)
	 */
	actionRtn:function(strCase, strParam1){
		try{
			SCActionControl.initAction();
			switch(strCase){
				case "GET_ANNOUNCE_NEWS_LIST" : //공지사항, 이워크뉴스
					$("dvAnnounceNewsList").innerHTML =$("dvSectionLoadingSmall").innerHTML;

					SCActionControl.CALL_ID = "MainPage.GET_ANNOUNCE_NEWS_LIST";					
					SCActionControl.addResultURL ("success", "/srcweb/zz/main/AnnounceNewsListLI.jsp");

					SCAjaxControl.options.onSuccess = MainPage.processAjaxResult_AnnounceNewsList;
					SCAjaxControl.RESULT_TYPE = SCAjaxControl.resultTypes.PAGE;

					SCAjaxControl.ajaxActionRequest ();
					break;

				case "GET_CHANGED_AGREE":
					SCActionControl.CALL_ID = "MainPage.SELECTCHANGED";					
					SCActionControl.addResultURL ("success", "/srcweb/zz/main/ChangedAgreemmentI.jsp");
					SCAjaxControl.options.onSuccess = MainPage.processAjaxResult_ChangedAgree;
					SCAjaxControl.options.parameters = "";

					SCAjaxControl.ajaxActionRequest ();					
					break;


				case "GET_MSG_COUNT" :
					SCAjaxControl.options.onSuccess = MainPage.processAjaxResult_MsgCount;
					SCAjaxControl.RESULT_TYPE = SCAjaxControl.resultTypes.JSON;
					SCActionControl.CALL_ID = "MainPage.GET_MSG_COUNT";
					
					SCAjaxControl.ajaxActionRequest ();
					break;
					

				case "GET_EDU_LIST" :	//최근중요정보(과외 등)
					SCActionControl.CALL_ID = "MainPage.GET_EDU_LIST";					
					SCActionControl.addResultURL ("success", "/srcweb/zz/main/NewEduListLI.jsp");

					SCAjaxControl.options.onSuccess = MainPage.processAjaxResult_NewEduList;
					SCAjaxControl.RESULT_TYPE = SCAjaxControl.resultTypes.PAGE;

					SCAjaxControl.ajaxActionRequest ();
					break;

			}
		} catch(ex){
			SCErrorControl.doErrorRtn(ex, "actionRtn");	
		}
	},	

	processAjaxResult_AnnounceNewsList:function(xmlHttp) {
		var returnData = xmlHttp.responseText;

		$("dvAnnounceNewsList").innerHTML = returnData;
	},

	processAjaxResult_ChangedAgree:function(xmlHttp) {
		var returnData = xmlHttp.responseText;

		$("dvChanagedAgree").innerHTML = returnData;
	},	

	processAjaxResult_MsgCount:function(xmlHttp) {
		if ($("spMsgCount")) {
			//Return값 반환
			var returnData = SCAjaxControl.responseJson(xmlHttp);

		    var strCount = returnData.resultSet.MSG.UNREAD_CNT;
			$("spMsgCount").innerHTML = strCount ;
		}
	},	
	
	/**
	 * 최근 중요정보(과외)를 해당 영역에 설정한다.
	 * @param {Object} xmlHttp
	 */		   
	processAjaxResult_NewEduList:function(xmlHttp) {
		var returnData = xmlHttp.responseText;

		$("dvInterestList").innerHTML = returnData;
		
		//최근중요건수가 있을 경우 레이어를 보여준다.
		if($("txtEduCnt")){
			if($F("txtEduCnt") > 0){
				//쿠키에 설정되어 있지 않을 경우 보여준다.
				var strSATE = SCCookieControl.getCookie(UserConst.EWORKLAND,'INTER_LAYER');
				if(strSATE === ""){$("dvInterestList").className = "View";} 
			}
		}
		
	},		

	 
	/**
	 * 최근 중요 영역 숨기기
	 * @param {Object} strCase
	 */
	setLayerHidden:function(strCase){

		switch(strCase){
			case "01" :
			try{
				var expdate = new Date();
				expdate.setTime(expdate.getTime() + 1000 * 3600 * 24); // 1일
				SCCookieControl.setCookie(UserConst.EWORKLAND, "INTER_LAYER", "true", expdate);
			} catch (ex) {
				SCErrorControl.doErrorRtn(ex, "setLayerHidden");	
			}
			$("dvInterestList").className = "Hidden";
			break;
		}		
	},

	//Slide Timer 제어	
	setNextHelperTimer: function() {
		MainPage.showHelperImage(mintCurrentHelper + 1);
	},
	
	showHelperImage: function(iIndex) {
		if ($("imgInfo" + mintCurrentHelper)) {
			$("imgInfo" + mintCurrentHelper).className = "hidden";
			$("imgPageBtn" + mintCurrentHelper).src = gRootWebImages01 + "/imgBoxNum"+mintCurrentHelper+"Off.gif";
		}
		
		mintCurrentHelper = ((iIndex - 1) % 5) + 1;
		
		if ($("imgInfo" + mintCurrentHelper)) {
			$("imgInfo" + mintCurrentHelper).className = "view";
			$("imgPageBtn" + mintCurrentHelper).src = gRootWebImages01 + "/imgBoxNum"+mintCurrentHelper+"On.gif";
		}

		MainPage.clearHelperTimer();
		MainPage.startHelperTimer();
	},
	
	clearHelperTimer: function() {
		clearTimeout(mintHelperTimer);
	},
	
	startHelperTimer: function() {
		mintHelperTimer = window.setTimeout("MainPage.setNextHelperTimer()", mintHelperTimeout);
	},
	
	/*변경된 약관의 상태와 동의여부를 이용하여 팝업으로 경고를 하거나, 약관동의화면으로 모든행위를 막는다
	 */
	setAgreement: function() {
		switch($F("txtAGREE")){
			case "POPUP" 		: MBMMControl.pageLink("CHANGED_AGREE"); break;
//			case "BLOCKING" 	: this.actionRtn("GET_CHANGED_AGREE"); 				//약관미동의시 로그인금지 정책이 바뀌어서 주석처리
//								//레이어를 보여줌 
//								SCViewControl.showCenterLayer($("dvChanagedAgree"),0,0);
//								break;
		}
	}, 
	
	
	setBlocking: function(){
		this.actionRtn("GET_CHANGED_AGREE"); 
		SCViewControl.showCenterLayer($("dvChanagedAgree"),0,0);
	}
	
};

	
