var Index = {
	init : function(){
		this.loginBox = Ext.get('kma-loginbox'); 
		this.logoutBox = Ext.get('kma-logoutbox');
		
		if(Global.Session.isLogin()){
			//회원사로그인 로그아웃			
			//window.location="http://old.kma.or.kr/new06_kma/member/session_logout.asp";

			this.logoutBox.child('.kma-logout-btn').on('click', this.onLogout, this);
			this.loginBox.setStyle("display", "none");
			this.logoutBox.setStyle("display", "block");
			this.fillLoginInfo();			
		}			
		else if(Global.Session.isMemberLogin())
		{
			//this.onLogout();
			
			this.loginForm = new Mys.Login("kma-login-form", this.login, this);
			this.loginBox.setStyle("display", "block");
			this.logoutBox.setStyle("display", "none");
			//this.loginBox.child('.login-corp-btn').on('click', this.onCorpLogout, this); 
			var btn = this.loginBox.child('.login-corp-btn');
			btn.on('click', this.onGoCorp, this);
			btn.dom.src= "/images/main/btn_coinfo.gif";
			
		}else{
			this.loginForm = new Mys.Login("kma-login-form", this.login, this);
			this.loginBox.setStyle("display", "block");
			this.logoutBox.setStyle("display", "none");
			
			if(window.sessionData && sessionData.response && sessionData.response.saved_email){
				this.loginForm.fillId(sessionData.response.saved_email);
			}
		}

	}
	,login : function(recvData){
		if(recvData&&recvData.response){
			this.data = recvData.response;
		}
		window.location.reload();
	}
	,fillLoginInfo : function(){
		this.logoutBox.child('.name').dom.innerHTML = Global.Session.getNick();
		var promotion = this.logoutBox.child('.promotion');
		promotion.dom.innerHTML = Global.Session.getPromotionTitle();
		promotion.dom.setAttribute("href", Global.Session.getPromotionUrl());
		promotion.dom.setAttribute("target", Global.Session.getPromotionTarget()==true ? "_blank" : "_self" );
	}
	,onManageUserInfo : function(){
		alert('사용자 정보 관리 페이지');
	}
	,onLogout : function(){
		window.location="/api/index.php?model=session&mode=logout&view=script&complete_url="+window.location;
	}
	,onGoCorp : function() {
		window.location="/member/companyinfo.htm";
	}

};
Index.init();