
// ************************************
// 서비스 안내
// ************************************
function maintenanceNotice()
{
	alert('시스템 점검 관계로 당분간 서비스를 중지합니다.\n\n이용에 불편을 드려 죄송합니다.');
}

function preparationNotice()
{
	alert('준비 중인 서비스입니다.\n\n이용에 불편을 드려 죄송합니다.');
}

function createDivConfirm(oSelf, innerHTML, posX, posY, nWidth, nHeight, bAutoClose, color)
{
	if (posX == undefined)		var posX = 0;
	if (posY == undefined)		var posY = 0;
	if (nWidth == undefined)	var nWidth = 0;
	if (nHeight == undefined)	var nHeight = 0;
	if (bAutoClose == undefined) var bAutoClose = false;
	if (color == undefined)		var color = "blue";

	if (createDivConfirm.mouseIn == undefined)
		createDivConfirm.mouseIn	= false;

	if (createDivConfirm.mouseOut == undefined)
		createDivConfirm.mouseOut	= false;

	var oColorMap = {
		blue	: {bg:'bg_arrow_up.gif',border: '#687381', bodyBg: '#F1F5F8' },
		yellow	: {bg:'bg_arrow_up_yellow.gif',border: '#E9A900', bodyBg: '#FFF6EA' }
	};

	oSelf.style.position = 'relative';

	cancelDivConfirm();

	var oDiv = document.createElement("<div>");

	oDiv.id = "divConfirm";

	with (oDiv.style)
	{
		position = 'absolute';
		left = oSelf.offsetLeft + posX;
		top = oSelf.offsetTop + 20 + posY;
		zIndex = 100000;
	}

	if (nWidth > 0)
		oDiv.style.width = nWidth + "px";
	if (nHeight > 0)
		oDiv.style.height = nHeight + "px";

	if (bAutoClose)
	{

		oDiv.onmouseout = function()
		{
			hitTestDivConfirm();
		};
	}

	var output = "";
	
	output += "<div style='width:100%;padding-top:7px;background:url(" + gImg_root + "/" + oColorMap[color].bg + ") no-repeat top center;'>";

	output += "<div style='text-align:center;padding:15px;border:2px solid " + oColorMap[color].border + ";border-top:none;background-color:" + oColorMap[color].bodyBg + ";'>";
	output += (innerHTML || "내용 없음") + "</div></div>";

	oDiv.innerHTML = output;

	document.body.appendChild(oDiv);

	g('divConfirm').style.left = parseInt(g('divConfirm').style.left) - g('divConfirm').offsetWidth/2 + 6;
}

function hitTestDivConfirm(posX, posY)
{
	setTimeout(function()
	{
		var oDiv = g('divConfirm');

		if (!oDiv)
			return ;

		if (oDiv.offsetTop <= Mouse._y && Mouse._y <= (oDiv.offsetTop + oDiv.offsetHeight) &&
			oDiv.offsetLeft <= Mouse._x && Mouse._x <= (oDiv.offsetLeft + oDiv.offsetWidth))
		{
			hitTestDivConfirm();
			return ;
		}

		cancelDivConfirm();
	}, 1000);

}

function cancelDivConfirm()
{
	if (g('divConfirm'))
		g('divConfirm').removeNode(true);
}

// 장바구니에 담기
function addMyCart(cshop_package_id, contentsUrl)
{
	if (!isLogined)
	{
		if (confirm("로그인 후, 구매하실 수 있습니다.\n\n지금 로그인하시겠습니까?") == false)
			return ;
		else
			location.href = gURL_root + gSitePath + "/front/error.php?action=Needed&url=" + escape(gURL_root + gSelf + "?" + gQueryString);
		return ;
	}

	var oForm = new AnonymForm({
		action:contentsUrl || gSelf,
		method:"POST"
	});

	oForm.setValue('action', 'AddMyCart');
	oForm.setValue('cshop_package_id', cshop_package_id);
	oForm.setValue('returnURL', gURL_root + gSelf + '?' + gQueryString);
	oForm.submit();
}

// 맛보기 강의 띄우기
function showSampleLesson(package_id, width, height, resizable)
{
	showPopup(gSelf + "?action=ShowSampleLesson&package_id=" + package_id, "lectureWnd", width, height, false, resizable);
}

// 액션 보카 실행
function doRunActionVoca(voca_id, unit_no, actVocaUrl, study_mode)
{
	if (!gHasActionVocaToken)
	{
		alert('[Action! VOCA 학습하기]는 이용권 신청 후, 이용 가능합니다.');
		return ;
	}

	// 무료 이용권 이용자는 10회차까지만 이용 가능
	if (gHasActVocaFreeToken && unit_no > gMaxActVocaUnitNoForFreeUser)
	{
		alert("Action VOCA 무료 이용권으로는 각 단어장별로 " + gMaxActVocaUnitNoForFreeUser + "회차까지만 이용하실 수 있습니다.\n\n" + unit_no + "회차 학습을 하시려면, 이용권을 구입하셔야 합니다.");
		return ;
	}

	if (study_mode == undefined)
		var study_mode = "study";

	var url = (actVocaUrl || gSelf) + "?action=ShowActionVoca&voca_id=" + voca_id + "&unit_no=" + unit_no + "&study_mode=" + study_mode;
	showPopup(url, "actVocaWnd", 900, 660, false, false);
}

// 액션 딕테이션 실행
function doRunActionSen(sen_id, unit_no, actSenUrl, study_mode)
{
	if (study_mode == undefined)
		var study_mode = "study";

	if (!gHasActionSenToken)
	{
		alert('[Action! DICTATION 학습하기]는 이용권 신청 후, 이용 가능합니다.');
		return ;
	}

	// 무료 이용권 이용자는 10회차까지만 이용 가능
	if (gHasActSenFreeToken && unit_no > gMaxActSenUnitNoForFreeUser)
	{
		alert("Action DICTATION 무료 이용권으로는 각 단어장별로 " + gMaxActSenUnitNoForFreeUser + "회차까지만 이용하실 수 있습니다.\n\n" + unit_no + "회차 학습을 하시려면, 이용권을 구입하셔야 합니다.");
		return ;
	}

	var url = (actSenUrl || gSelf) + "?action=ShowActionSen&sen_id=" + sen_id + "&unit_no=" + unit_no + "&study_mode=" + study_mode;
	showPopup(url, "actSenWnd", 700, 600, false, false);
}


// 스크랩 단어로 액션 보카 실행
function doRunActionVocaForScrap(voca_scrap_group_id, actVocaUrl)
{
	if (!gHasActionVocaToken)
	{
		alert('[Action! VOCA 학습하기]는 이용권 신청 후, 이용 가능합니다.');
		return ;
	}

	var url = (actVocaUrl || gSelf) + "?action=ShowActionVoca&voca_scrap_group_id=" + voca_scrap_group_id;
	showPopup(url, "actVocaWnd", 900, 660, false, false);
}

// 스크랩 단어로 액션 딕테이션 실행
function doRunActionSenForScrap(sen_scrap_group_id, actSenUrl, study_mode)
{
	if (study_mode == undefined)
		var study_mode = "study";

	if (!gHasActionSenToken)
	{
		alert('[Action! DICTATION 학습하기]는 이용권 신청 후, 이용 가능합니다.');
		return ;
	}

	var url = (actSenUrl || gSelf) + "?action=ShowActionSen&sen_scrap_group_id=" + sen_scrap_group_id + "&study_mode=" + study_mode;
	showPopup(url, "actSenWnd", 700, 600, false, false);
}

/* dashboard, bookmark 에서.. */
function showChildVocaList(id)
{
	$('#__list_' + id).slideToggle('fast');
}

function showChildSenList(id)
{
	$('#__list_' + id).slideToggle('fast');
}


/* 레이어 띄우기 */
function showMsgBox(title, body, box_width, box_height, footer, oOption)
{
	with ($('#overlay'))
	{
		css('position','absolute');
		css('top','0');
		css('left','0');
		css('width','100%');
		css('height',$('body').height());
		show();
	}

	if(box_width == undefined)
		box_width = 456;

	if(box_height == undefined)
		box_height = 91;

	with ($('#divMsgBox'))
	{
		width(box_width+63);
		css('z-index', '99999');
		fadeIn();
	}

	with ($('#divMsgBox>div.body'))
	{
		width(box_width);
		height(box_height);
	}

	if(g(body))
	{
		$('#'+body).hide();
		var bodyStr = $('#'+body).html().toString().replace(" _id="," id=");
	}
	else
	{
		var bodyStr = body;
	}

	$('#divMsgBox>div.title>h3').html(title);
	$('#divMsgBox>div.body').html(bodyStr);

	if (!jQuery($('#divMsgBox>div.close'))[0].orgHtml)
		jQuery($('#divMsgBox>div.close'))[0].orgHtml = $('#divMsgBox>div.close').html();

	if (footer == undefined)
		var footer = "";

	if (footer != "")
		$('#divMsgBox>div.close').html(footer + jQuery($('#divMsgBox>div.close'))[0].orgHtml);
	
	if (oOption != undefined)
	{
		if (typeof oOption.onClose == "function")
			$('#divMsgBox>div.close>button.btn:last').click(oOption.onClose);

		if (typeof oOption.lblClose == "string")
			$('#divMsgBox>div.close>button.btn:last>span>b').html(oOption.lblClose);
	}
	else
	{
		$('#divMsgBox>div.close>button.btn:last').click(hideMsgBox);
	}
	
	g('body').scrollIntoView(true);
}

function hideMsgBox()
{
	// bookMark 일 경우 reload가 필요할 경우.
	if (g('divBookmarkSetup') &&
		$('#divBookmarkSetup').html() != null && getLayerCloseAfterReload())
	{
		location.reload();
	}
	else
	{
		if ($('#overlay'))
			$('#overlay').hide();

		if ($('#divMsgBox'))
			$('#divMsgBox').fadeOut();
	}
}

function showPlacementTest()
{
	showPopup("/themes/eoneodotcom/html/voca_CAT.html", "levelTest", 700, 400, false, false);
}

function showGrammarSample()
{
	showPopup("/themes/eoneodotcom/html/movie.html", "grammarSample", 780, 393, false, false);
}

// 쿠폰 등록 레이어 띄우기
function showCouponBox()
{
	var pWidth = 400;
	var pHeight = 240;

	var obj = document.getElementById("expansionBox");	

	obj.style.zIndex = 999;
	
	if (navigator.appName == 'Netscape')
		var scrollTop = document.body.scrollTop ;
	else 
		var scrollTop = document.documentElement.scrollTop ;

	obj.style.marginLeft = pWidth/2*-1 + 'px';
	obj.style.top = ((document.documentElement.clientHeight - 400) / 2)  + scrollTop  + 'px';

	obj.style.width = pWidth + 'px';
	obj.style.height = pHeight + 'px';

	var output = "";

	output += "<form name='couponForm' method='post'>";
	output += "<div class='coupon-container'>";
	output += "<div class='coupon-box-top'>";
	output += "<div style='float:left;width:198px;'>";
	output += "<img src='" + gURL_root + '/themes/eoneodotcom/img/img_coupon.png' + "' style='float:left;'/><span class ='coupon-title'><b>쿠폰등록</b></span>";
	output += "</div>";
	output += "<div style='float:right;width:198px;'>";
	output += "<a href='javascript:closeCouponBox();' onfocus='this.blur();'><img src='" + gURL_root + '/themes/eoneodotcom/img/img_close.png' + "' style='float:right;border:none;'/></a>";
	output += "</div>";
	output += "<div class='coupon-txt'>";
	output += "<span>지금 갖고 있는 쿠폰이 있으신가요?</span><br/>";
	output += "<span>쿠폰을 등록하시고, 다양한 학습 콘텐츠를 이용해 보세요~</span><br/>";
	output += "</div>";
	output += "<div style='width:396px;text-align:center;'>";
	output += "<input type='text' name='coupon_no1' id='coupon_no1' class='coupon-input' size='5' maxlength='4' onkeydown=\"autoNext(this.form, this, '', 'coupon_no2', 4);\"/>&#160;-&#160;";
	output += "<input type='text' name='coupon_no2' id='coupon_no2' class='coupon-input' size='5' maxlength='4' onkeydown=\"autoNext(this.form, this, '', 'coupon_no3', 4);\"/>&#160;-&#160;";
	output += "<input type='text' name='coupon_no3' id='coupon_no3' class='coupon-input' size='5' maxlength='4' onkeydown=\"autoNext(this.form, this, '', 'coupon_no4', 4);\"/>&#160;-&#160;";
	output += "<input type='text' name='coupon_no4' id='coupon_no4' class='coupon-input' size='5' maxlength='4'/>";
	output += "</div>";
	output += "<div style='font-size:9pt;padding-left:25px;'>";
	output += "<span style='color:#777777;font-size:8pt;line-height:16px;'>* 언어닷컴 쿠폰은 언어닷컴에서만 등록 및 사용 가능합니다.</span><br />";
	output += "<span style='color:#777777;font-size:8pt;line-height:16px;'>* 등록한 쿠폰은 <b><a href='/sites/front.php/mystudy/couponbox'>MY STUDY &gt; 내 쿠폰함</a></b>에서 확인하실 수 있습니다.</span>";
	output += "</div>";
	output += "<div class='coupon-btn-container'>";
	output += "<button class='btn' onclick='javascript:checkCouponInfo();' onfocus='this.blur();' title='쿠폰 등록하기'><span><b>쿠폰 등록하기</b></span></button>";
	output += "</div>";

	output += "</div>";
	output += "</div>";
	output += "</form>";	

	obj.innerHTML = output;

	obj.style.display = 'block';
}

// 쿠폰 등록 레이어 닫기
function closeCouponBox()
{
	var obj = document.getElementById("expansionBox");

	obj.style.display = 'none';
	
}

function showbookPreView(package_id)
{
	switch (package_id)
	{
		case '89' : 
			url = gURL_root + "/themes/eoneodotcom/html/innerbook/middle_1/index.html";
			break;
		case '94' : 
			url = gURL_root + "/themes/eoneodotcom/html/innerbook/middle_2/index.html";
			break;
		case '99' : 
			url = gURL_root + "/themes/eoneodotcom/html/innerbook/middle_3/index.html";
			break;
		case '102' : 
			url = gURL_root + "/themes/eoneodotcom/html/innerbook/north_europe/index.html";	
			break;
	}
	showPopup(url, "bookPreView", 940, 690, false, false);
}
