/****************************************************************************************************
제목 : 잉그벨 웹 사이트에서 사용되는 기본적인 JavaScript 함수
----------------------------------------------------------------------------------------------------
목적 :
----------------------------------------------------------------------------------------------------
주의 :
----------------------------------------------------------------------------------------------------
POST
----------------------------------------------------------------------------------------------------
GET
----------------------------------------------------------------------------------------------------
REQUEST
----------------------------------------------------------------------------------------------------
작성자 : 고광진 (akanaka)
작성일 : 2009년 06월 22일
수정일 : 2009년 07월 30일	// QnA24 파일을 잉그벨 리뉴엘에 맞게 수정 함. ( 주석 이외 수정 사항 없음 )
연락처 : akanaka@hanmail.net
****************************************************************************************************/


/**************************************************
이미지 프리로드 변수 선언
--------------------------------------------------
**************************************************/
var imagePreLoad	= new Array () ;


/**************************************************
비 정상적인 접근을 제어한다.
--------------------------------------------------
**************************************************/
$( document ).ready( function(){
	if ( parent.frames.length == 2 )
		return false ;
	if ( confirm ( '정상적인 경로를 통해 접근하여 주십시오.\n\n서비스 메인 페이지로 접근 하시겠습니까?' ) )
		top.location.href	= 'http://' + window.location.host ;
}) ;


/**************************************************
페이지 이동 ( osFrame 구조에서만 사용 가능 )
--------------------------------------------------
pageName	: loadPage 변수에 전달 할 값
parameter	: GET 파라메터 ( key=value&key=value )
reset		: 기존 URL 유지 여부 ( true :
**************************************************/
function loadPage ( pageName , parameter , reset )
{
	var url = '' , loadFrame = '' , loadPagePattern = /(\?|\&)?loadPage\=([a-zA-Z0-9\_\-\^]*)/gi , loadFramePattern = /(\?|\&)?loadFrame\=([a-zA-Z0-9\_\-\^]*)/gi ;
	if ( ! pageName )
	{
		if ( ! loadPagePattern.test ( location.search ) )
			return alert ( '웹 페이지 접근 경로를 찾을 수 없습니다.' ) ;
		pageName	= RegExp.$2 ;
	}
	if ( reset == false )
	{
		var query	= '' ;
		if ( location.search != '?' )
			query	= location.search.substr ( 1 , location.search.length - 1 ).replace ( /(\?|\&)?loadPage\=[a-zA-Z0-9\_\-\^]*/gi , '' ) ;
		url		= location.pathname + '?' + 'loadPage=' + pageName + ( ( query.substr ( 0 , 1 ) == '&' ) ? query : '&' + query )
	}
	else
		url	= location.pathname + '?loadPage=' + pageName ;
	if ( parameter )
		url	+= '&' + parameter ;
	if ( loadFramePattern.test ( location.search ) )
		url	+= '&loadFrame=' + RegExp.$2 ;
	if ( reset == false )
		url += location.hash ;
	location.href = url ;
}


/**************************************************
메뉴 On
--------------------------------------------------
id		: id Attribute 속성에서 숫자를 제외한 이름
number	: id Attribute 속성에서 이름을 제외한 숫자
**************************************************/
function menuOn ( idPrefix , number )
{
	if ( $('#' + idPrefix + number).size() == 0 )
		return false ;
	$('#' + idPrefix + number)
		.attr('src',$('#' + idPrefix + number).attr('src').replace(/Off\.gif$/,'On.gif'))
		.attr('toggle','none');
}


/**************************************************
회원에 한하여 제공되는 서비스 안내 : 회원 가입 유도
--------------------------------------------------
url	: 현재 페이지 값 ( LoadPage URL 형식 )
**************************************************/
function onlyMemberForJoin ( url )
{
	if ( ! url )
		url	= escape ( location.href ) ;
	if ( confirm ( '비회원은 서비스 이용이 불가능합니다.\n\n회원 가입을 하시겠습니까?' ) )
		loadPage ( 'memberService^joinAgreement' , 'backPage=' + url ) ;
	else if ( ! document.readyState || document.readyState == 'interactive' )
		window.history.back () ;
}


/**************************************************
회원에 한하여 제공되는 서비스 안내 : 로그인 유도
--------------------------------------------------
url	: 현재 페이지 값 ( LoadPage URL 형식 )
**************************************************/
function onlyMemberForLogin ( url )
{
	if ( ! url )
		url	= escape ( location.href ) ;
	alert ( '회원에 한하여 이용이 가능한 서비스입니다.\n\n로그인 후, 이용하여 주십시오.' ) ;
	window.history.back () ;
//	loadPage ( 'memberService^login' , 'backPage=' + url ) ;
}


/**************************************************
로그인
--------------------------------------------------
form	: 폼 객체
key		: 로그인 Key
**************************************************/
function login ( form , key )
{
	if ( ! FORM.check ( form ) )
		return false ;
	var result	= UTIL.ajax.send
	(
		'/addOn/process/user/login.php?'
			+ 'id=' + MD5 ( form.id.value )
			+ '&password=' + MD5 ( key + MD5 ( form.password.value ) + key )
			+ ( ( UTIL.get.type ( form.save ) == 'object' && form.save.checked == true ) ? '&save=Y' : '' )
		, 'GET'
		, 'TEXT'
		, false
	).split ( '|' ) ;
	if ( result[0] == 'MOVE' )
	{
		alert ( result[1] ) ;
		top.location.href = 'http://' + result[2] ;
	}
	else if ( result[0] == 'ERROR' )
	{
		form.id.value		= '' ;
		form.password.value	= '' ;
		FORM.failure ( result[1] ) ;
		form.id.focus () ;
	}
	else if ( result[0] == 'OK' )
	{
		//alert ( result[1] ) ;	// 안내 문구 출력 제거
		var backPage	= form.getAttribute ( 'backPage' ) ;
		if ( backPage.length > 0 )
			if ( backPage.substr ( 0 , 7 ).toUpperCase () == 'HTTP://' || backPage.substr ( 0 , 1 ) == '/' )
				location.href	= backPage ;
			else
				loadPage ( backPage ) ;
		else if ( form.action && form.action.length > 0 )
			window.location.href	= form.action ;
		else
			window.location.reload () ;
	}
	else
		alert ( '프로그램 처리에 오류가 발생되어, 정상적으로 로그인 할 수 없습니다.\n\n시스템 관리자에게 문의하여 주십시오.' ) ;
	return false ;
}


/**************************************************
로그아웃
--------------------------------------------------
form	: 폼 객체
**************************************************/
function logout ()
{
	var result	= UTIL.ajax.send ( '/addOn/process/user/logout.php' , 'GET' , 'TEXT' , false ).split ( '|' ) ;
	if ( result[0] == 'ERROR' )
		alert ( result[1] ) ;
	else if ( result[0] == 'OK' )
	{
		//alert ( result[1] ) ;	// 안내 문구 출력 제거
		window.location.reload () ;
	}
}


/**************************************************
사용자 레코드 삭제
--------------------------------------------------
table		: 삭제 대상 Table ( 실제 Table 명이 아님을 주의 할 것 )
idx			: 삭제 대상 Record 고유번호
pageName	: loadPage 변수에 전달 할 값
parameter	: GET 파라메터 ( key=value&key=value )
**************************************************/
function recordDelete ( table , idx , pageName , parameter )
{
	var result	= UTIL.ajax.send ( '/addOn/process/user/deleteRecord.php?table=' + table + '&idx=' + idx , 'GET' , 'TEXT' , false ).split ( '|' ) ;
	if ( result[0] == 'ERROR' )
	{
		alert ( result[1] ) ;
		return false ;
	}
	else if ( result[0] == 'OK' )
	{
		alert ( result[1] ) ;
		loadPage ( pageName , parameter ) ;
	}
}


/**************************************************
동영상 강의 팝업
--------------------------------------------------
classNumber		: 강좌 고유번호
lectureNumber	: 강의 고유번호
width			: 팝업 가로 넓이
height			: 팝업 세로 높이
**************************************************/
function popupLecture ( classNumber , lectureNumber , width , height )
{
	UTIL.window.popup ( '/?loadPage=movieService^moviePopup&class=' + classNumber + '&lecture=' + lectureNumber , width , height , null , 'lecturePopup' ) ;
}


/**************************************************
이벤트 팝업 닫기
--------------------------------------------------
**************************************************/
function closeLayerPopup ( name , value , second )
{
	var obj ;
	if ( obj = UTIL.get.obj ( name ) )
		obj.style.display	= 'none' ;
	if ( value )
		UTIL.cookie.set ( name , value , second ) ;
}


/**************************************************
미리보기를 위한 페이지 레이어 출력
--------------------------------------------------
**************************************************/
function showPreviewLayer ()
{
	UTIL.create.tag
	(
		'div'
		, 'title=현재 페이지는 미리 보기 페이지입니다.'
		, 'position:absolute;top:0px;left:0px;z-index:999;width:100%;height:' + $( '#areaAll' ).height() + 'px'
			+ ';background:silver;filter:alpha(opacity=0);opacity:0.0;-moz-opacity:0.0;'
		, ''
		, true
	) ;
}


/**************************************************
음원 재생
--------------------------------------------------
url	: 음원 경로
**************************************************/
function studyRecordPlay ( url )
{
	UTIL.get.obj ( 'wmp' ).Filename	= url ;
}


/**************************************************
음원 다운로드
--------------------------------------------------
path	: 폴더 이름 + '/' + 파일 이름
**************************************************/
function studyRecordDownload ( path )
{
	var temp	= path.split ( '/' ) ;
	UTIL.window.popup ( 'http://202.72.124.46/download.php?seq1=' + temp[0] + '&seq2=' + temp[1] + '.mp3' , 100 , 100 ) ;
}