﻿/*
 * 새 창 열기
 *
 * [Syntax]
 *   window_open(<url>, <width>, <height>, [option], [target]);
 *
 * [Sample Code]
 *   window_open('popup.htm', 600, 480);
 *   window_open('popup.htm', 600, 480,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
 */
function window_open(u, w, h) {
  var t = (screen.availHeight - h) / 2;
  var l = (screen.availWidth - w) / 2;
  var feature = arguments[3] ? arguments[3] : "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no";
  var target = arguments[4] ? arguments[4] : u.substring(((u.lastIndexOf("/") != -1) ? (u.lastIndexOf("/") + 1) : 0), u.lastIndexOf("."));
  window.open(u, target, 'top=' + t + ',left=' + l + ',width=' + w + ',height=' + h + ',' + feature).focus();
}

/*
 * 로그인 팝업창
 * 2009-03-19, 이철재
 */
function pop_login_open(referer) {
  try {
    window_open("/Member/Pop_login.aspx?returnURL="+referer, 400, 279, "", "poplogin");
  } catch (exception) {
    alert(exception.description);
  }
}

/*
 * 로그인 폼 체크
 * 한진수
 */
function chkForm(objName, idName, pwdName) {
  if (!inputCheck(objName, idName, "required,alphanum,range", "아이디", "1", "15")) { return false; }
  if (!inputCheck(objName, pwdName, "required,range", "비밀번호", "1", "15")) { return false; }
  return true;
}

/*
 * 로그인 항목 검사
 * 한진수
 */
function chkValid(objName, idName, pwdName, chkID, chkSec) {
  if ($(chkID).checked) {
    if (!inputCheck(objName, idName, "required,alphanum,range", "아이디", "1", "15")) {
      $(chkID).checked = false;
      //$(chkSec).checked=false;
      return;
    }
  }
  /*if ($(chkSec).checked) {
      if (!chkForm(objName, idName, pwdName)) { $(chkSec).checked = false; return; }
  }*/
}

/*
 * 네비게이션맵에서 페이지 이동
 * 2009-03-24, 이철재
 */
function gotopage(url) {
  location.href = url;
}

/*
 * 파일 다운로드
 * 2009-03-24, 이철재
 */
function gotodownload(fname, ftype, fdesc) {
  location.href = "/common/filedownload.aspx?fname="+fname+"&ftype="+ftype+"&fdesc="+fdesc;
}

/************************************************************************
함수명			: inputCheckEditor(editorId)
작성목적		: FCKEditor 에 내용입력값 체킹
Parameter		: editorId - 에디터id, itemName-입력항목 타이틀
Return			:
*************************************************************************/
function inputCheckEditor(editorId, itemName)
{
     var oEditor = FCKeditorAPI.GetInstance(editorId) ;
     var content = oEditor.GetXHTML().trim();
     
     if(content == "")
     {
        alert(itemName + "은(는) 필수입력 항목입니다.");
        oEditor.Focus();
        return false;
     }
     else
        return true;
}

/************************************************************************
함수명			: inputCheckEditor(editorId)
작성목적		: FCKEditor 에 내용입력값 지우기
Parameter		: editorId - 에디터id
Return			:
*************************************************************************/
function editorClear(editorId)
{
     var oEditor = FCKeditorAPI.GetInstance(editorId) ;
     oEditor.EditorDocument.body.innerHTML = "";
}

/************************************************************************
함수명			: fn_GetCheckedItems(attrValue)
작성목적		: 해당 Attribute를 갖는 모든 체크박스 중 Check된 항의 배열을 가져온다.
Parameter		:
Return			:
*************************************************************************/
function fn_GetCheckedItems(attrValue)
{
	var oItem;
	var arrReturn;
	var iCnt = 0;
	var idx = 0;
	try
	{
		for ( var i = 0 ; i < document.all.length ; i++ )
		{
			oItem = document.all[i];
			if ( oItem.tagName.toUpperCase() == "INPUT")
				if ( oItem.getAttribute("type").toUpperCase() == "CHECKBOX" )
					if (oItem.getAttribute("chkgrpname") != null )
						if ( oItem.getAttribute("chkgrpname") == attrValue )
							if ( oItem.checked == true )
								iCnt++;
		}
		arrReturn = new Array(iCnt);
		for ( var i = 0 ; i < document.all.length ; i++ )
		{
			oItem = document.all[i];
			if ( oItem.tagName.toUpperCase() == "INPUT")
				if ( oItem.getAttribute("type").toUpperCase() == "CHECKBOX" )
					if (oItem.getAttribute("chkgrpname") != null )
						if ( oItem.getAttribute("chkgrpname") == attrValue )
							if ( oItem.checked == true )
								arrReturn[idx++] = oItem.value;
		}
		return arrReturn;
	}
	catch (exception)
	{
	}
	return null;
}
/************************************************************************
함수명		: fn_OpenDialog
작성목적	: 팝업창을 띠운다.
Parameter :	
				sUrl - 띠울 URL
				sFrame - 띠울 Frame
				sFeature - 창 속성
Return		:

*************************************************************************/
function fn_OpenDialog(sUrl, sFrame, sFeature)
{
    try
    {
	    return window.open(sUrl, sFrame, sFeature);	
	}
	catch(e)
	{
	    alert(e);
	}
}

/************************************************************************
함수명		: fn_OpenModalDialog
작성목적		: 팝업창을 띠운다.
Parameter		:	
					sUrl - 띠울 URL
					sFeature - 창 속성
Return			:
*************************************************************************/
function fn_OpenModalDialog(sUrl, sFeature)
{
	var strReturn = "";
	strReturn = window.showModalDialog( sUrl, sFeature);
	return strReturn;
}

/************************************************************************
함수명		: moveList
작성목적		: 상세화면의 목록으로 페이지이동
Parameter		:	
					sUrl - 띠울 URL
Return			:
*************************************************************************/
function moveList(sUrl)
{
    document.location.replace(sUrl) ;
    
}
// 숫자만 입력받기 (소숫점 처리 없음)
// ex) onKeyDown="fn_comm_checkNumericKey()"
function fn_comm_checkNumericKey()
{
    key = event.keyCode;
    
    if ((key >= 48 && key <= 57) // 키보드 상단 숫자키
       || (key >= 96 && key <= 105) // 키패드 숫자키
       || key == 8  // 백스페이스 키
       || key == 37 // 왼쪽 화살표 키
       || key == 39 // 오른쪽 화살표 키
       || key == 46 // DEL 키
       || key == 13 // 엔터 키
       || key == 9  // Tab 키
       ) 
    {
        event.returnValue = true ;
    } 
    else 
    {
        // alert(key);
        event.returnValue = false ;
    }
} 

// 숫자,대쉬키만 입력받기 (소숫점 처리 없음) 날짜텍스트입력시
// ex) onKeyDown="fn_comm_checkNumericDashKey()"
function fn_comm_checkNumericDashKey()
{
    key = event.keyCode;
    
    if ((key >= 48 && key <= 57) // 키보드 상단 숫자키
       || (key >= 96 && key <= 105) // 키패드 숫자키
       || key == 8  // 백스페이스 키
       || key == 37 // 왼쪽 화살표 키
       || key == 39 // 오른쪽 화살표 키
       || key == 46 // DEL 키
       || key == 13 // 엔터 키
       || key == 9  // Tab 키
       || key == 189  // 상단 -
       || key == 109  // 번호입력 키보드 -
       ) 
    {
        event.returnValue = true ;
    } 
    else 
    {
        // alert(key);
        event.returnValue = false ;
    }
} 
/************************************************************************
함수명		: trim
작성목적		: value의 앞뒤 공백 제거
Parameter		:	
Return			:
*************************************************************************/
function trim(value)
{
	return value.replace(/^|s+|\s+$/g,"");
}

/************************************************************************
함수명		: isValidJuminNumber
작성목적		: 주민번호 체킹
Parameter		:	
Return			:
sample          : isValidJuminNumber('8011111423581')
*************************************************************************/
	function isValidJuminNumber(s) {
		if( s.charAt(6) == 1 || s.charAt(6) == 2 || s.charAt(6) == 3 || s.charAt(6) == 4 )
		{
			if( s.charAt(12) ==
				(( 11 - ((s.charAt(0)*2+s.charAt(1)*3+s.charAt(2)*4
							+s.charAt(3)*5+s.charAt(4)*6+s.charAt(5)*7
							+s.charAt(6)*8+s.charAt(7)*9+s.charAt(8)*2
							+s.charAt(9)*3+s.charAt(10)*4+s.charAt(11)*5)
							% 11)))%10)
				return true;
		}
				alert("주민번호가 올바르지 않습니다. 다시 입력하여 주십시요.");
				return false;
	}
/************************************************************************
함수명		: isValidEmail
작성목적		: 이메일 형식 체킹
Parameter		:	
Return			:
sample          : isValidEmail('aa@naver.com')
*************************************************************************/
function isValidEmail(itemValue)
{
	try
	{
		if (!(/^[\w\.\-]+@[a-z\.]+$/.test(itemValue))) 
		{
			alert("이메일 형식이 올바르지 않습니다.");
			return false;
		}
		else 
		{
			return true;
		}
	} 
	catch (exception)
	{
		//fn_OpenErrorMessage(exception.description);	
		return false;	
	}
}
/************************************************************************
함수명			: fn_GetRadioValue(radioName)
작성목적		: Radion 컨트롤의 이름을 문자열로 전달하면 해당 컨트롤 그룹을 검색하여
					  checked = true인 컨트롤의 value를 리턴한다.
Parameter		:
Return			:
*************************************************************************/
function fn_GetRadioValue(radioName)
{
//	try
//	{
		var iCount;
		var strValue;
		
		var oRGroup = document.all[radioName];
		iCount = oRGroup.length;
		for ( var i = 0 ; i < iCount ; i++ )
		{
			if ( oRGroup[i].checked)
			{
				strValue = oRGroup[i].value;
				break;
			}
		}
		return strValue;
			
//	}
//	catch ( exception )
//	{
//	
//	}	
}

/******************************************************************************************************************
함수명			: freePlayer(mode, value, title, csid, cskey, enc)
작성목적		: 강좌 OT 및 맛보기 학습창 팝업
Parameter		: 
Return			: 
*******************************************************************************************************************/
function freePlayer(mode, value, title, csid, cskey, enc) {
    if (mode == "ot") {
        window.open("/IMGTech/Sungji/Web/popupEduFree.aspx?mode=ot&value="+value+"&title="+title+"&cten="+enc, "freeplayer", "top=0, left=0, width=993, height=566, menubar=no, status=no");
    } else {
        window.open("/IMGTech/Sungji/Web/popupEduFree.aspx?mode="+mode+"&value="+value+"&usid=<%=MemberProc.Login.getENCUSERID %>&csid="+csid+"&csky="+cskey+"&cten="+enc, "freeplayer", "top=0, left=0, width=993, height=566, menubar=no, status=no");
    }
}

/******************************************************************************************************************
함수명			: pop_afternote(bdsn)
작성목적		: 수강후기 팝업
Parameter		: 
Return			: 
*******************************************************************************************************************/
function pop_afternote(bdsn) {
    window_open("/Teacher/Teacher_Lecture_Afternote.aspx?bdsn="+bdsn, 746, 518);
}

/******************************************************************************************************************
함수명			: fnc_tutor_profile_popup(tutorid)
작성목적		: 선생님 약력 팝업
Parameter		: 
Return			: 
*******************************************************************************************************************/
function fnc_tutor_profile_popup(tutorid) {
    switch(tutorid) {
        case "T02": 
            window.open("/Teacher/pop_t02.html", "tutor_profile", "top=0, left=0, width=500, height=350, menubar=no, status=no");
            break;
        case "T03": 
            window.open("/Teacher/pop_t03.html", "tutor_profile", "top=0, left=0, width=500, height=350, menubar=no, status=no");
            break;
        case "T04": 
            window.open("/Teacher/pop_t04.html", "tutor_profile", "top=0, left=0, width=500, height=350, menubar=no, status=no");
            break;
        case "T05": 
            window.open("/Teacher/pop_t05.html", "tutor_profile", "top=0, left=0, width=500, height=350, menubar=no, status=no");
            break;
        default: 
            window.open("/Teacher/pop_t01.html", "tutor_profile", "top=0, left=0, width=500, height=350, menubar=no, status=no");
            break;
    }
}
