/* -----------------------------------------------------------------
	Global variable
	created date: 2010.04.09
//----------------------------------------------------------------*/

//var G_HOST_NAME			= "smile.littlefox.co.kr";
//var G_URL				= 'http://smile.littlefox.co.kr:8088';
//var G_IMG_URL			= 'http://smile.littlefox.co.kr:8088/static/img';
////var G_IMG_URL			= 'http://littlefox.nefficient.co.kr/littlefox/nwa/smile';
//var G_CONTENTS_IMG_URL	= 'http://littlefox.nefficient.co.kr/littlefox/nwa/little/static/cont_img';

// Email노출 by pink, 2010.03.19

var swfId	= "foxP";


function mailto_link(sId, sHost)
{
	// IE6
	var browser=navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		self.event.returnValue = false;
	}
	location.href = 'mailto:' + sId + '@' + sHost;
}

function login(url)
{
	frm				= document.forms['loginfo'];
	frm.url.value	= url;
	frm.submit();
}

function login_process()
{
	frm				= document.forms['login'];

	if( frm.loginid.value == '아이디' || frm.loginid.value == '' )
	{
		alert( '아이디를 입력하세요.' );
		frm.loginid.focus();
		return false;
	}

	if( frm.loginpw.value == '비밀번호' || frm.loginpw.value == '' )
	{
		alert( '비밀번호를 입력하세요.' );
		frm.loginpw.focus();
		return false;
	}

	frm.submit();
}

function Get_Cookie( check_name )
{
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Delete_Cookie( name, path, domain )
{
	if (Get_Cookie( name )) document.cookie = name + "=" +
					( ( path ) ? ";path=" + path : "") +
					( ( domain ) ? ";domain=" + domain : "" ) +
					";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function foxLogout()
{
	Delete_Cookie( 'fx0', '/', G_HOST_NAME );
	Delete_Cookie( 'fx1', '/', G_HOST_NAME );
	Delete_Cookie( 'fx2', '/', G_HOST_NAME );
	Delete_Cookie( 'fx3', '/', G_HOST_NAME );
	Delete_Cookie( 'fx4', '/', G_HOST_NAME );
	Delete_Cookie( 'fx5', '/', G_HOST_NAME );
	Delete_Cookie( 'fx6', '/', G_HOST_NAME );
	Delete_Cookie( 'fx7', '/', G_HOST_NAME );
	Delete_Cookie( 'fx8', '/', G_HOST_NAME );
	Delete_Cookie( 'fx9', '/', G_HOST_NAME );
	Delete_Cookie( 'fxa', '/', G_HOST_NAME );
	Delete_Cookie( 'fxb', '/', G_HOST_NAME );
	Delete_Cookie( 'fxc', '/', G_HOST_NAME );
	Delete_Cookie( 'fxu', '/', G_HOST_NAME );

	/* 사용 안함 */
	Delete_Cookie( 'fx10', '/', G_HOST_NAME );
	Delete_Cookie( 'fx11', '/', G_HOST_NAME );

	window.location.href="/";
}

function Vocabulary( fcid , free )
{
	//alert("free => (" + free + ")");
	if ( free != 'Y' )
	{
		if ( Login.need() === false ) {return;}
	}

	var url			= "/vocabulary/main/"+fcid;

	var win		= window.open( url, 'Vocabulary', "width=730,height=690,top=0,left=200,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=1,copyhistory=0" );

	if( win.focus )
	{
		win.focus();
	}
	else
	{
		try {
			getSwf(swfId).openWindowFromSwf(url);
		} catch (e) {
			if (e instanceof RangeError) return '...';
			throw e;
		}
	}
}

function ViewQuiz( fcid , free )
{
	//alert("free => (" + free + ")");
	if ( free != 'Y' )
	{
		if ( Login.need() === false ) {return;}
	}

	var url		= "/quiz/main/"+fcid;

	var win		= window.open( url, 'FoxQuiz', "width=700,height=528,top=50,left=100" );

	if( win.focus )
	{
		win.focus();
	}
	else
	{
		try {
			getSwf(swfId).openWindowFromSwf(url);
		} catch (e) {
			if (e instanceof RangeError) return '...';
			throw e;
		}
	}
}

function Quiz(M)
{
    document.write("<OBJECT id='Player' CLASSID='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' CODEBASE='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+G_FLASH_VERSION+"' WIDTH='150' HEIGHT='98' ALIGN='middle'> <PARAM NAME='MOVIE' VALUE='"+M+"'> <PARAM NAME='QUALITY' VALUE='HIGH'> <PARAM NAME='SCALE' VALUE='EXACTFIT'> <PARAM NAME='WMODE' VALUE='TRANSPARENT'> <PARAM NAME='PLAY' VALUE='FALSE'> </OBJECT>");
}

function PrintQuiz( fcid, frid )
{
	if ( Login.need() === false ) {return;}

	var win	= window.open( "/quiz/quizprint/"+fcid+"/"+frid, 'FoxQuiz', "width=680,height=750,top=50,left=100,scrollbars=yes" );
	if( win.focus ) win.focus();
}


function getSwf(id)
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		alert( window[id] );
		return window[id];
	} 
	else
	{
		alert( document[id] );
		return document[id];
	}
} 







// by pink 2009.10.22
function goUrl(gUrl)
{
	/* IE6 */
	var browser=navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		self.event.returnValue = false;
	}
	window.location.href=gUrl;
}

function autoResize(obj)
{
    var iframeHeight = obj.contentWindow.document.body.scrollHeight;
    obj.height = iframeHeight + 20;
}

function new_win( theURL, winName, features )
{
	window.open( theURL, winName, features );
}





/* ----- Main Publishing Script : Only Use in Main Page ---------------------------------------------------- */

function showNext( order, from )
{
	if( order == 'NEXT' )
	{
		newNum		= ( newNum < 4 ) ? newNum+1 : 0;
	}
	else
	{
		newNum		= ( newNum > 0 ) ? newNum-1 : 4;
	}

	newStory( newNum );

	if( from )
	{
		clearTimeout( tid );
		tid		= window.setTimeout("showNext('NEXT')", 2200);
	}
	else
	{
		tid		= window.setTimeout("showNext('NEXT')", 2200);
	}
}

function newStory( num )
{
//	var news		= decodeURIComponent(articles[num]).replace(/\+/gi,' ');
	var news		= decodeURI(articles[num]);

	var img_str		= '<a href="javascript:Player.title( \''+story_list[num]+'\', \''+key_list[num]+'\' );"><img src="'+G_CONTENTS_IMG_URL+'/'+story_list[num]+'_m.png" alt="" /></a>';
	var date_str	= date_list[num];
	var cont_str	= '<a href="javascript:Player.title( \''+story_list[num]+'\', \''+key_list[num]+'\' );">새동화: ' + title_list[num] + '</a>';
	var news_str	= '<a href="/board/view/LB007/1/'+article_nums[num]+'">새소식: ' + news.substr(0,25) + '</a>';

	document.getElementById("new_st_img").innerHTML		= img_str;
	document.getElementById("new_st_date").innerHTML	= date_str;
	document.getElementById("today_story").innerHTML	= cont_str;
	document.getElementById("today_news").innerHTML		= news_str;
}

function todayStory()
{
	document.getElementById("total_story").innerHTML	= story_cnt;
//	document.getElementById("total_pb").innerHTML		= pb_cnt;

	document.getElementById("month_title").innerHTML	= '<a href="javascript:Content.detail(\'' + month_fcid + '\');" title="상세보기">' + month_story + '</a>';

	var fame_list	= '<ul>';
	
	for( i=0; i<3; i++ )
	{
		fame_list	+= '<li>' + fame_nick[i] + '<span>' + fame_date[i] + '</span></li>'
	}

	fame_list		+= '</ul>';

	document.getElementById("hall_of_fame").innerHTML	= fame_list;
}

function onloaded()
{
//	newStory( newNum );
	todayStory();
//	showNext('NEXT');
}

/* png 파일 ie6에서 투명하게 */ 
function setPng24(obj) { 
    obj.width=obj.height=1; 
    obj.className=obj.className.replace(/\bpng24\b/i,''); 
    obj.style.filter = 
    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');" 
    obj.src=''; 
    return ''; 
}


/* //----- Main Publishing Script : Only Use in Main Page ---------------------------------------------------- */



/* ----- Help Popup Script : URL 수정 필요 ---------------------------------------------------- */

function fox_help()
{
	new_win( '/html/fox_info','fox_help','width=740,height=600,scrollbars=yes');
}

function ecash_help()
{
	new_win( '/html/ecash_info','ecash_help','width=740,height=600,scrollbars=yes');
}

/* //----- Help Popup Script : URL 수정 필요 ---------------------------------------------------- */






















//===============================================================================================
// Ajax Request
//===============================================================================================
var isIE	= (document.all)?true:false;
var req		= "";

function getAjaxRequest(sUrl, sParam)
{
	if( isIE )
	{
		req	= new ActiveXObject('Msxml2.XMLHTTP');
	}
	else
	{
		req	= new XMLHttpRequest();
	}

	if( req )
	{
		req.onreadystatechange = setAjaxResponse;
		req.open("POST", sUrl, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(sParam);
	}
	else
	{
		alert("전송요청 오류!");
	}
}

//===============================================================================================
// Ajax 호출 후 진행바 보이기/숨기기
//===============================================================================================
function goWaiting( arg )
{
	var oIng	= document.getElementById("oProgress");
	var nLen	= arguments.length;

	if( nLen > 1 )
	{
		var sName	= arguments[1];

		if( sName != "Mouse" )			// oMsg가 아닌 다른 Object를 중심으로 Bar를 표현하고자 할 경우
		{
			var obj			= document.getElementById(arguments[1]);
			oIng.style.left	= getXPos(obj) + 250;
			oIng.style.top	= getYPos(obj) - 30;
		}
		else							// 마우스를 중심으로 Progress Bar를 표현하고자 할 경우
		{
			oIng.style.left	= event.clientX + document.documentElement.scrollLeft - 70;
			oIng.style.top	= event.clientY + document.documentElement.scrollTop + 20;
		}
	}
	else								// 디폴트 위치(oMsg)를 중심으로 위치 지정
	{
		var obj			= document.getElementById("oMsg");
		oIng.style.left	= getXPos(obj) + 250;
		oIng.style.top	= getYPos(obj) - 25;
	}

	if( arg == 1 )
	{
		oIng.style.visibility	= "visible";
	}
	else
	{
		oIng.style.visibility	= "hidden";
	}
}


//===============================================================================================
// Browser Version Check
//===============================================================================================
function getVersion()
{
	var appName	= navigator.appName;
	var appVer	= navigator.appVersion;

	if( appName.indexOf("Internet Explorer") > 0 )
	{
		var arrVer	= appVer.split(";");
		var tmpVer	= arrVer[1].substring(6, 7);
		return tmpVer;
	}
	else
	{
		return 9;
	}
}

//===============================================================================================
// Object 위치 (X, Y)
//===============================================================================================
function getXPos(obj)
{
	if(obj == null) return 0;

	var nLeft = 0;

	while( obj != document.body )
	{
		nLeft	= nLeft + obj.offsetLeft;
		obj		= obj.offsetParent;

		if(obj == null) break;
	}

	if( getVersion() < 8 )				// IE 8 버전 미만인 경우
	{
		nLeft = nLeft - 10;
	}

	return nLeft;
}

function getYPos(obj)
{
	if(obj == null) return 0;

	var nTop = 0;

	while(obj != document.body)
	{
		nTop	= nTop + obj.offsetTop;
		obj		= obj.offsetParent;

		if(obj == null) break;
	}
	return nTop;
}

//===============================================================================================
// 리스트 하단 페이징 처리
//===============================================================================================
function setListPage( page )
{
	var nStartPage	= 1;
	var nEndPage	= 1;
	var sPageStr	= "";
	var i			= 0;

	if( page == "" || page < 1 || page > gnTotalPage )
	{
		page	= 1;
	}

	if( gnTotalPage == 0 || gnPageSize == 0 )
	{
		page	= 0;
	}

	nStartPage	= 1 + parseInt((page-1)/gnPageSize)*gnPageSize;
	nEndPage	= nStartPage + gnPageSize;
	i			= nStartPage;

	sPageStr	= "<div class='paginate'>";

	if( nStartPage > 1 )
	{
		sPageStr += "<a href='javascript:getAjaxData(1);'><img src='/Student/lesson/eLib/img/btn_nprv_b.gif' align='absmiddle' border=0></a>\n";
	}

	if(i > gnPageSize) sPageStr += "<a href='javascript:getAjaxData(" + (nStartPage-1) + ");'><img src='/Student/lesson/eLib/img/btn_prv_b.gif' hspace='2' align='absmiddle' border=0></a>\n";

	while(i <= gnTotalPage){
		if(i == nStartPage){
			if(i == page)
				sPageStr += "<strong>" + i + "</strong>\n";
			else
				sPageStr += "<a href='javascript:getAjaxData(" + i + ");'>" + i + "</a>\n";
		}
		else {
			if(i == page)
				sPageStr += "<strong>" + i + "</strong>\n";
			else
				sPageStr += "<a href='javascript:getAjaxData(" + i + ");'>" + i + "</a>\n";
		}

		i++;
		if(i == nEndPage) break;
	}

	if(nStartPage+gnPageSize <= gnTotalPage) sPageStr += " <a href='javascript:getAjaxData(" + eval(nStartPage+gnPageSize) + ")'><img src='/Student/lesson/eLib/img/btn_next_b.gif' align='absmiddle' border=0></a>";

	if(nEndPage <= gnTotalPage) sPageStr += "<a href='javascript:getAjaxData(" + gnTotalPage + ")'><img src='/Student/lesson/eLib/img/btn_nnext_b.gif' align='absmiddle' border=0></a>";

	sPageStr += "</div>";
	
	//alert(sPageStr);
	if(document.getElementById("oPage")){
		document.getElementById("oPage").rows[0].cells[0].innerHTML = sPageStr;
		document.getElementById("oPage").style.display = "";
	}
}
