﻿/*
 * CjMenuUtil 객체
 * 
 * 모든페이지에서 필수로 인클루드 해야하는 JS
 * 각 페이지들에서 메뉴와 관련된 기능을 사용하려면 본 파일을 필수로 포함해야함.
 * 
 * Lee Won-Gyoon <richscript@gmail.com>, <@richscript>, <www.richscript.net>
 * e-motion Corp.
*******************************************************************************/

var CjMenuUtil = {
	instanceName : "CjMenuUtil",
	menuInstanceName : "CjMenu",
	menuFrame : null,
	
	/**
	* CjMenuUtil 객체가 생성되었는지 여부를 알려준다.
	* 프레임을 잘못찾거나 객체가없으면 Exception을 발생시킨다.
	* @return boolean
	*/
	isExist : function() {
		return true;
	},
	
	/**
	* CjMenu 객체를 가져온다.
	* @return CjMenu 객체
	*/
	getMenuInstance : function() {
		return eval(this.menuFrame+"."+this.menuInstanceName);
	},
	
	/**
	* 현재 메뉴 코드를 가져온다.
	* 파악하지 못할 경우 공백을 리턴한다.
	* @return String
	*/
	getCurrentMenuCode : function() {
		var menuCode = "";
		if (this.getMenuInstance().isExistUI()) {
			menuCode = this.getMenuInstance().getUI().currentMenu.menuCode;
		}
		if (menuCode=="") {
			menuCode = $js.request.get("menuCode");
		}
		return menuCode;
	},
	
	/**
	* 해당 메뉴로 이동한다.
	* @param _menuCode 메뉴코드
	* @param _option 예외처리할 파라미터
	* @return Void
	*/
	openMenuFromMenuCode : function(_menuCode, _option) {
		this.getMenuInstance().openMenuFromMenuCode(_menuCode, _option);
	},
	
	/**
	* 해당 메뉴로 이동한다.
	* @param _skinCode 메뉴코드
	* @param _option 예외처리할 파라미터
	* @return Void
	*/
	openMenuFromSkinCode : function(_skinCode, _option) {
		this.getMenuInstance().openMenuFromSkinCode(_skinCode, _option);
	},
	
	/**
	* 사용자 정보를 셋팅한다.
	* @param _loginYN 로그인여부
	* @return Void
	*/
	updateUserSession : function(_loginYN) {
		try {
			this.getMenuInstance().updateUserSession(_loginYN);
		} catch(e) {}
	},
	
	/**
	* 초기화
	* @return void
	*/
	initialize : function() {
		
		/* 메뉴 Data를 포함한 Frame을 찾는다. */
		try {
			if (parent[this.menuInstanceName].isExist()) {
				this.menuFrame = "parent";
			}
		} catch(e1) {
			try {
				if (parent.parent[this.menuInstanceName].isExist()) {
					this.menuFrame = "parent.parent";
				}
			} catch(e2) {
				try {
					if (parent.parent.parent[this.menuInstanceName].isExist()) {
						this.menuFrame = "parent.parent.parent";
					}
				} catch(e3) {
					try {
						if (parent.parent.parent.parent[this.menuInstanceName].isExist()) {
							this.menuFrame = "parent.parent.parent.parent";
						}
					} catch(e4) {
						this.menuFrame = "self";
						try {
							window[this.menuInstanceName].isExist();
						} catch(e) {
							out.print('<scr'+'ipt type="text/javascr'+'ipt" src="/js/lib/richscript/richscript.cj.menu.js"></scr'+'ipt>');
							out.print('<scr'+'ipt type="text/javascr'+'ipt" src="/js/lib/richscript/richscript.cj.menu.data.js"></scr'+'ipt>');
						}
					}
				}
			}
		}
		out.print('<scr'+'ipt type="text/javascr'+'ipt" src="/login/update.session.asp?_temp='+(new Date()).getTime()+'"></scr'+'ipt>');
	}
};

CjMenuUtil.initialize();



/**
* 해당 메뉴로 이동한다.
* @param _menuCode 메뉴코드
* @param _option 예외처리할 파라미터
* @return Void
*/
function openMenu(_menuCode, _option) {
	openMenuFromMenuCode(_menuCode, _option);
}

/**
* 해당 메뉴로 이동한다.
* @param _menuCode 메뉴코드
* @param _option 예외처리할 파라미터
* @return Void
*/
function openMenuFromMenuCode(_menuCode, _option) {
	CjMenuUtil.openMenuFromMenuCode(_menuCode, _option);
}

/**
* 해당 메뉴로 이동한다.
* @param _skinCode 메뉴코드
* @param _option 예외처리할 파라미터
* @return Void
*/
function openMenuFromSkinCode(_skinCode, _option) {
	CjMenuUtil.openMenuFromSkinCode(_skinCode, _option);
}

/**
* window.open의 리턴값으로 인해 화면에
* [object]라고 출력되는 것을 방지해준다.
* 사용법 및 기능은 window.open과 동일하다.
* @param _url URL
* @param _target 타겟
* @param _option 옵션
* @return Void
*/
function openWindow(_url, _target, _option) {
	if (_target==undefined) _target = "_self";
	if (_option==undefined) _option = "";
	var win = open(_url, _target, _option);
	try {
		win.focus();
	} catch(e) { }
}

/**
* 로그인 후 현재 메뉴로 돌아올때 사용
* @param _option 로그인 관련 옵션을 설정한다. Param Array 로 아래의 속성을 사용한다.
*                - RETURN_MENU_URL : 로그인 후 돌아갈 URL 임의 지정
*                - RETURN_MENU_CODE : 로그인 후 돌아갈 메뉴코드 임의 지정
*                (_option 값을 String 문자열로 넘겨주면 자동으로 RETURN_MENU_URL로 사용된다.)
* @return Void
*/
function openLoginMenu(_option) {
	var param = [];
	var menuCode = CjMenuUtil.getCurrentMenuCode();
	if (menuCode==CjMenuUtil.getMenuInstance().menuCode.login||menuCode==CjMenuUtil.getMenuInstance().menuCode.home) {
		menuCode = "";
	}
	if (_option==undefined||_option==null) {
		param.push("RETURN_MENU_CODE="+menuCode);
	} else if (typeof(_option)=="string"&&_option.indexOf("/")==0) {
		param.push("RETURN_MENU_CODE="+menuCode);
		param.push("RETURN_MENU_URL="+_option);
	} else if (typeof(_option)=="object"&&_option.length) {
		param = _option;
	}
	openMenu(CjMenuUtil.getMenuInstance().menuCode.login, param);
}
function openLogin() {
	var contentsFrame = null;
	try {
		if (window.name.indexOf("F1")==0) {
			contentsFrame = self;
		} else {
			if (parent.window.name.indexOf("F1")==0) {
				contentsFrame = parent;
			} else {
				if (parent.parent.window.name.indexOf("F1")==0) {
					contentsFrame = parent.parent;
				} else {
					if (parent.parent.parent.window.name.indexOf("F1")==0) {
						contentsFrame = parent.parent.parent;
					}
				}
			}
		}
	} catch(e) { }
	if (contentsFrame!=null) {
		var url = "https://www.cj.co.kr/login/login.asp";
		contentsFrame.location.replace(url.appendParameter("RETURN_MENU_URL="+contentsFrame.location.href));
		contentsFrame = null;
	} else {
		openLoginMenu();
	}
}
function confirmLogin() {
	var msg = "";
	msg += "로그인이 필요합니다.";
	msg += "\n로그인 페이지로 이동하시겠습니까?";
	if (confirm(msg)) {
		openLogin();
	}
}

/**
* 로그아웃
* @return Void
*/
function openLogout() {
	openMenu(CjMenuUtil.getMenuInstance().menuCode.logout);
}

/**
* 회원가입
* @return Void
*/
function openJoin() {
	openMenu(CjMenuUtil.getMenuInstance().menuCode.join);
}

/**
* 맴버쉽
* @return Void
*/
function openMembership() {
	openMenu(CjMenuUtil.getMenuInstance().menuCode.userInfo);
}

/**
* Home 으로 이동한다.
* @return Void
*/
function openHome() {
	CjMenuUtil.getMenuInstance().openHome();
}

/**
* 최상위 프레임을 해당 URL로 이동시킨다.
* @param _url
* @return Void
*/
function openTop(_url) {
	try {
		top.location.href = _url;
	} catch(e) {
		open(_url, "_top", "");
	}
}

/**
* 영문 사이트로 이동한다.
* @return Void
*/
function openCjEnglish() {
	//alert("CJ제일제당 글로벌 사이트는 오픈 준비중 입니다.");
	openTop("http://eng.cjcheiljedang.com/");
}

/**
* 일문 사이트로 이동한다.
* @return Void
*/
function openCjJapanese() {
	//alert("CJ제일제당 글로벌 사이트는 오픈 준비중 입니다.");
	openTop("http://jp.cjcheiljedang.com/");
}

/**
* 중문 사이트로 이동한다.
* @return Void
*/
function openCjChinese() {
	//alert("CJ제일제당 글로벌 사이트는 오픈 준비중 입니다.");
	openTop("http://cn.cjcheiljedang.com/");
}

/**
* 국문 사이트로 이동한다.
* @return Void
*/
function openCjKorean() {
	openHome();
}



var $loading = {
	getL : function() {
		var s = '';
		s += '<div style="';
		s += '	width:71px;';
		s += '	height:70px;';
		s += '	background:url(/img/richscript/ui/template/loading.large.bg.png) transparent;';
		s += '	_background-image:none;';
		s += '	_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/img/richscript/ui/template/loading.large.bg.png, sizingMethod=scale);';
		s += '	background-repeat:no-repeat;';
		s += '">';
		s += '<div style="padding:11px 1px 0 0;">';
		s += '<img src="/img/richscript/ui/template/loading.large.gif" width="48" height="48" border="0" />';
		s += '</div>';
		s += '</div>';
		return s;
	},
	getS : function() {
		var s = '';
		s += '<div style="';
		s += '	width:48px;';
		s += '	height:48px;';
		s += '	background:url(/img/richscript/ui/template/loading.small.bg.png) transparent;';
		s += '	_background-image:none;';
		s += '	_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/img/richscript/ui/template/loading.small.bg.png, sizingMethod=scale);';
		s += '	background-repeat:no-repeat;';
		s += '">';
		s += '<div style="padding:12px 0 0 0;">';
		s += '<img src="/img/richscript/ui/template/loading.small.gif" width="24" height="24" border="0" />';
		s += '</div>';
		s += '</div>';
		return s;
	},
	printL : function() {
		document.write(this.getL());	
	},
	printS : function() {
		document.write(this.getS());	
	}
};


/**
* CJ주문배송정보 팝업
* @return Void
*/
function openCjOrder() {
	openWindow("http://www.cjgls.co.kr/cjgroup/cjorders.asp", "cjOrder", "toolbar=0,menubar=0,scrollbars=no,resizable=yes,left=0,top=0,width=820,height=900");
}

/**
* CJ 사이버투어
*/
function openCyberTour(){
   openWindow("/brand/cyber_tour.html", "cjCyber", "toolbar=0,menubar=0,scrollbars=no,resizable=no,left=0,top=0,width=960,height=720");
}

/**
* CJ e카달로그 2011 구정
*/
function openECatalog(){
   openWindow("/etc/e-catalog/201101/main.html", "cjECatalog", "toolbar=0,menubar=0,scrollbars=no,resizable=no,left=0,top=0,width=1024,height=761");
}

/**
* CJ e카달로그 2011 추석
*/
function openECatalog2(){
   openWindow("/etc/e-catalog/201108/main.html", "cjECatalog", "toolbar=0,menubar=0,scrollbars=no,resizable=no,left=0,top=0,width=1024,height=740");
}

/**
* CJ e카달로그 2012 신정
*/
function openECatalog3(){
   openWindow("/etc/e-catalog/201201/main.html", "cjECatalog", "toolbar=0,menubar=0,scrollbars=no,resizable=no,left=0,top=0,width=1024,height=740");
}


/**
* 미스터리쇼퍼
* @return Void
*/
function openShopper() {
	//openWindow("/u-monitour/mistory/pop_shopper01.asp", "pop_shopper", "toolbar=0,menubar=0,scrollbars=no,resizable=yes,left=0,top=0,width=456,height=330");
	alert("다음 미스터리쇼퍼 준비중입니다.");
}

/**
* 유모니투어 활동결과
* @return Void
*/
function openUmonitourAct() {
	//alert("컨텐츠 준비중입니다.");
	//openWindow("/u-monitour/active/pop_active.asp", "pop_active", "toolbar=0,menubar=0,scrollbars=no,resizable=yes,left=0,top=0,width=850,height=606");
}


