// emsurl은 임으로 변경 할 수 없음. arl 파일의 emsurl을 참조하고 있습니다.
var EMSURL = "http://www.homelearn.kr/lecture/result.asp" ;// 위싱웰 홈스터디 결과 전송. // 홈런 실서버
//var EMSURL = "http://elearn.iroonet.com/lecture/result.asp" ;// 위싱웰 홈스터디 결과 전송. // 홈런-테스트서버
//var WSWSTUDY = "http://www77.wishingwell.co.kr" ; // 홈스터디 컨텐츠 위치
var WSWSTUDY = "http://study.iroonet.com" ; // 홈스터디 컨텐츠 위치

var isNav4, isIE4, isMac, isNav6;
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
  isStd = (navigator.appName == "Netscape") ? true : false
  isIE  = (navigator.appName.indexOf("Microsoft") != -1) ? true : false
  isMac = (navigator.platform.indexOf("Mac") != -1) ? true : false
  isPNG = (isIE && ! isMac) ? false : true
}

//비스타 인지 확인하는 스크립트. vista 확인 스크립트
var IS_VISTA="0";
if (navigator.appName == "Microsoft Internet Explorer")
{
	var Agent = navigator.userAgent;
	Agent = Agent.toLowerCase();
	if(Agent.indexOf("nt 6.") > 0) { //비스타
		IS_VISTA="1";
	}
}

// 날짜 형식
function strDate( date, sp )
{
	if (typeof(sp) == "undefined" )
	{
		sp = "-";
	}
	var sDate = Mid(date, 1, 4) ;
		sDate += sp + Mid(date, 5, 2) ;
		sDate += sp + Mid(date, 7, 2) ;
		sDate += sp + Mid(date, 9, 2) ;
		sDate += sp + Mid(date, 11, 2) ;

	return sDate ;
}

// 오늘의 날짜를 String 형식으로 Return '20000901'
function gs_GetDate() {
    current = new Date();

   tmpyear = current.getYear();
   str0 = "";
   str1 = str0.concat(tmpyear);

    tmpmon = current.getMonth() + 1;
    if(tmpmon < 10) {
         str4 = "0";
         str5 = str4.concat(tmpmon);
    }
    else
      str5 = tmpmon;

    tmpday = current.getDate();
   if(tmpday < 10) {
          str6 = "0";
          str7 = str6.concat(tmpday);
    }
   else
       str7 = tmpday;

   str2 = str1.concat(str5);
    str3 = str2.concat(str7);

   return(str3);
}

/* 팝업 띄우기 */
function popupWin(filename,winname,width,height,scroll,left,top)	{
window.open("" + filename + "","" + winname +"","scrollbars=" + scroll + ",toolbar=no,location=no,directories=no,width=" + width + ",height=" + height + ",resizable=no,mebar=no,left=" + left + ",top=" + top + ""); 
}


/* 레이어 보이기_감추기 */
function show(obj) {
	document.getElementById([obj]).style.display ='block';
}
function hide(obj) {
	document.getElementById([obj]).style.display ='none';
}


/* 사이트맵 롤오버 */
function sitemapOn(imgName) {
	document [imgName].src = const_imghost + "/html/images/sitemap/" + imgName + "_on.gif";
}
function sitemapOff(imgName) {
	document [imgName].src = const_imghost + "/html/images/sitemap/" + imgName + ".gif";
}



/* 좌측 메뉴 롤오버 */
function leftOn(imgName) {
	document [imgName].src = const_imghost + "/html/images/common/" + imgName + "_on.gif";
}
function leftOff(imgName) {
	document [imgName].src = const_imghost + "/html/images/common/" + imgName + ".gif";
}



/* 좌측 메뉴 롤오버 및 레이어 */
function bothOn(layerName,imgName) {
	document [imgName].src = const_imghost + "/html/images/common/" + imgName + "_on.gif";
	document.getElementById([layerName]).style.display ='block';
}
function bothOff(layerName,imgName) {
	document [imgName].src = const_imghost + "/html/images/common/" + imgName + ".gif";
	document.getElementById([layerName]).style.display ='none';
}


/* 우측 퀵배너 롤오버 및 레이어 */
function wingOn(layerName,imgBorder) {
			document.getElementById([layerName]).style.display ='block';
			document.getElementById([imgBorder]).style.borderColor='#000000';
}
function wingOff(layerName,imgBorder) {
			document.getElementById([layerName]).style.display ='none';
			document.getElementById([imgBorder]).style.borderColor='#FFFFFF';
}


/* 투명이미지 */ 
 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 '';
    }

//str문자열의 s부터 cnt의 갯수만큼 return
function Mid(str,s,cnt )
{
    s = s - 1;
    return( str.substring( s, s + cnt ) );
}

//	ltrim(str)
function gs_ltrim(str) {
	return (str.replace(/^\s+/g , ''));
}

//	rtrim(str)
function gs_rtrim(str) {
	return (str.replace(/\s+$/g , ''));
}

//	trim(str)
function gs_trim(str) {
	return (str.replace(/^\s+|\s+$/g , ''));
}

// 날짜 형식
function strDate( date, sp )
{
	if (typeof(sp) == "undefined" )
	{
		sp = "-";
	}
	var sDate = Mid(date, 1, 4) ;
		sDate += sp + Mid(date, 5, 2) ;
		sDate += sp + Mid(date, 7, 2) ;


	return sDate ;
}

// 날짜 형식 시간 부까지.
function strDate2( date, sp )
{
	var sDate = Mid(date, 1, 4) ;
		sDate += sp + Mid(date, 5, 2) ;
		sDate += sp + Mid(date, 7, 2) ;
		if ( date.length > 8 )
		{
			sDate += " " + Mid(date, 9, 2) ;
			sDate += ":" + Mid(date, 11, 2) ;
		}

	return sDate ;
}

// 날짜 형식 시간 부까지.
function strDate3( date )
{
	var sDate = Mid(date, 1, 4)  + "-" ;
		sDate +=  Mid(date, 5, 2)  ;

	return sDate ;
}


function FormatNumber(num)
{

  var str = String(num)
  var re = /(-?[0-9]+)([0-9]{3})/;

  while (re.test(str)) {
   str = str.replace(re, "$1,$2");
  }
  return str;
}




/******************************************************************
*  ajax 관련 함수
******************************************************************/
// XMLHttpRequest 생성
function newXMLHttpRequest() {
    var reqHttp;   
    if (window.ActiveXObject) {      // IE
        try {
            reqHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                reqHttp =  new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e1) {               
                reqHttp =  null;
            }
        }
    } else if (window.XMLHttpRequest){  // IE 이외
        try {
            reqHttp =  new XMLHttpRequest();
        } catch (e) {
            reqHttp =  null;
        }
    }
    if (reqHttp == null) errorMessage();   //XMLHttpRequest 생성 실패
    return reqHttp;
}
 
// 지원할 수 없는 브라우저 사용
function errorMessage() {               
    alert("지원할 수 없는 브라우저입니다."); 
}

// readyState와 status 체크 
function openSendStatus(callback, getPost, urlFileAppl, trueFalse, sendData, obj_id) {
    var xmlHttp = newXMLHttpRequest();                 //XMLHttpRequest 생성
    xmlHttp.open(getPost, urlFileAppl, trueFalse);     //전송방법,URL,통신방법
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=euc-kr");
	xmlHttp.send(sendData);                            //서버 처리 데이터
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {                 //서버 처리 완료
             if (xmlHttp.status == 200) {              //파일 수신 성공
				if (typeof(callback) == "function" )
				{
					callback(xmlHttp, obj_id);                  //메인 처리
				}
				else
				{
					return; // 함수 없이 보내면 null
				}
                   
             } else {
                   exceptionControl(xmlHttp, urlFileAppl);          //예외 처리
             }
        }
    }
    
}


// 예외 처리 (status != 200)
function exceptionControl(xmlHttp, dummy) {
    var exceptShow = "상태 코드: " + xmlHttp.status + "";
    exceptShow += "\n비정상으로 종료되었습니다.(" + dummy + ")" ;
	exceptShow += "\n---------------------------------------------------------------";
	exceptShow += "\n" + xmlHttp.responseText + "";
	exceptShow += "\n---------------------------------------------------------------";
    //alert(exceptShow);
}



// $id: 리턴함.
function $id(elementid)
{
	var elements =document.getElementById(elementid);
	return elements;
}

// $name: 리턴함.(배열로 리턴함.)
function $name(elementid)
{
	var elements =document.getElementsByName(elementid);
	return elements;
}

// $name: 리턴함.(배열로 리턴함.)
function $Dom(obj, TagName, idx )
{
	var Doms = obj.getElementsByTagName(TagName)[idx];
	return Doms;
}


/*-----------------------------
* SetCombo: 
--------------------------------*/
function _SetCombo(xmlHttp, obj_id)
{
	if ( typeof( $id(obj_id) ) != "object" ) { return;}

	getDat = xmlHttp.responseText ;
	errgb = Mid(getDat, 1, 1) ;
	data  = getDat.substring(2);

	var combo = new Array();
	if ( errgb == "0" )
	{
		// ex) data => "0;color;;amount;#;red;;1000;#;blue;;2000" ;
		combo = MakeStructArray( data ) ;

		for ( var idx=0;idx<combo.length;idx++)
		{
			var newOpt    = combo[idx].code_nm ; 
			var newOptVal = combo[idx].code_id ; 

			// 추가
			addOption(obj_id, newOpt, newOptVal);
		}
	}
}


/*-----------------------------
* [ Select Box  ] begin
--------------------------------*/

	// SelectBox의 Option을 초기화
	function initOption( selectObjId ){
		var selectObj = document.getElementById( selectObjId );
		if ( selectObj == null ) return; // 객체가 존재하지 않으면 취소

		selectObj.options.length = 0; // 길이를 0으로 하면 초기화
	}


	// Option을 추가
	function addOption( selectObjId, text, value ){
		// SelectBox의 Object
		var selectObj = document.getElementById( selectObjId );    

		// 객체가 존재하지 않으면 취소
		if ( selectObj == null  ) return; 

		// 값이 없으면 추가하지 않음
		if ( !text || !value ) return; 

		// Opeion을 동적 생성
		selectObj.add( createOption( text , value ) ); 
	}

	// Option객체를 생성해서 Return
	function createOption( text, value )
	{
		var oOption = document.createElement("OPTION"); // Option 객체를 생성
		oOption.text = text; // Text(Keyword)를 입력
		oOption.value = value; // Value를 입력
		return oOption;
	}

	// 선택한 SelectBox의 Text변경
	function EditOption( selectObjId, text )
	{
		var selectObj = document.getElementById( selectObjId );
		if ( selectObj == null ) return; // 객체가 존재하지 않으면 취소
		if (selectObj.selectedIndex == -1 ) return; // 값이 없을때 -1

		selectObj.options[selectObj.selectedIndex].text = text; // 텍스트
	}

	// 선택한 SelectBox의 Text변경
	function RemoveOption( selectObjId )
	{
		var selectObj = document.getElementById( selectObjId );
		if ( selectObj == null ) return; // 객체가 존재하지 않으면 취소
		var idx = selectObj.selectedIndex ;
		if (idx == -1 ) return; // 값이 없을때 -1

		selectObj.remove(idx); // 삭제
		if ( selectObj.options.length > 0 )
		{
			selectObj.options[ ( (idx==0)? 0 : idx-1 ) ].selected=true;
		}

	}

	// 선택한 SelectBox의 Text와 Value를 출력
	function getCbo( selectObjId, opt ){
		
		if ( opt.toLowerCase() != "text" && opt.toLowerCase() != "value" ){ return ; }

		var selectObj = document.getElementById( selectObjId );
		if ( selectObj == null ) return; // 객체가 존재하지 않으면 취소
		if (selectObj.selectedIndex == -1 ) return; // 값이 없을때 -1

		var selectedValue = selectObj.options[selectObj.selectedIndex].value; // 값
		var selectedText = selectObj.options[selectObj.selectedIndex].text; // 텍스트
		
		if ( opt.toLowerCase() == "text" )
		{
			return selectedText;
		}
		else
		{
			return selectedValue ;
		}
	}

	// 선택한 SelectBox의 Text값에 해당하는 index 리턴
	function getTextIdx( selectObjId, p_text ){
		
		var selectObj = document.getElementById( selectObjId );
		if ( selectObj == null ) return; // 객체가 존재하지 않으면 취소

		for (var idx=0; idx<selectObj.options.length ; idx++ )
		{
			if ( selectObj.options[idx].text == p_text )
			{
				return idx;
				break;
			}
		}

		return;
	}

	// 선택한 SelectBox의 Value값에 해당하는 index 리턴
	function getValueIdx( selectObjId, p_value ){
		
		var selectObj = document.getElementById( selectObjId );
		if ( selectObj == null ) return; // 객체가 존재하지 않으면 취소

		for (var idx=0; idx<selectObj.options.length ; idx++ )
		{
			if ( selectObj.options[idx].value == p_value )
			{
				return idx;
				break;
			}
		}

		return;
	}

/******************************************************************
*  [iframe에 의한 높이 조절.]
******************************************************************/
function IframeResize( obj, height )
{
	if (isStd)
	{
		eval( "document.getElementById." + obj + ".style.height = height ;" );
	}
	else
	{
		eval( "document.all." + obj + ".style.height = height ;" );
	}
}



/*---------------------------------------------------------------------------
    참조자 Struct 정의
---------------------------------------------------------------------------*/
function MakeStruct(oReference) {
    var Struct = oReference.split(";;");
	for ( var idx=0;idx<Struct.length;idx++)
	{
		var col = Struct[idx].substring(0, Struct[idx].indexOf(":") ) ;
		var val = Struct[idx].substring(Struct[idx].indexOf(":")+1 ) ;
		eval("this."+col.toLowerCase() +"= val ;" );
	}
    return;

}

/***********************************************************************************
*  사용자 객체 배열 만들기
*  argv[0] : ';#;' 로 구분되고, 각 데이타는 ';;'로 구분된 String
*  첫번째 ';#;'로 구분된 정보는 Header 입니다. header 는 모두 소문자로 return합니다.
*  ex) argv[0] = "color;;amount;#;red;;1000;#;blue;;2000"
***********************************************************************************/
	function MakeStructArray(oReference)
	{
		var ObjArray = new Array();
		var Struct = oReference.split(";#;");
		var Head = Struct[0].split(";;");
		
		for ( var row=1;row<Struct.length;row++)
		{
			ObjArray[row - 1] =  new MakeStruct2(Head, Struct[row] );
		}
		return ObjArray;
	}

	/*---------------------------------------------------------------------------
	* 참조자 Struct 정의
	* argv[0] : header Array
	* argv[1] : data   String : ;; 로 구분됨
	---------------------------------------------------------------------------*/
	function MakeStruct2(oHead, oData)
	{
		var Data = oData.split(";;");
		for ( var idx=0;idx<oHead.length;idx++)
		{
			var col = oHead[idx] ;
			var val = Data[idx] ;
			eval("this."+col.toLowerCase() +"= val ;" );
		}
		return;
	}

/******************************************************************
* 첨부파일 프로그래스
******************************************************************/
function ShowProgress( id ) 
{
	var cnt = 0;
	var files = document.getElementsByName("a_filenm1");
	for ( var idx=0; idx<files.length;idx++)
	{
		if( files[idx].value != "" )
		{
			cnt++;
			break;
		}
	}

	if ( cnt > 0 )
	{
		strAppVersion = navigator.appVersion;

		if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
		{
			winstyle = "dialogWidth=400px; dialogHeight:200px; center:yes";
			window.showModelessDialog("/Progress/progress.asp?Progressid="+id,null,winstyle);	  
		}
		else
		{
			winpos = "left=" + ((window.screen.width-380)/2) + ",top=" + ((window.screen.height-110)/2);
			winstyle="width=400,height=200,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,copyhistory=no," + winpos;
			window.open("/Progress/progress.asp?Progressid="+id,null,winstyle);	     
		}
	}

	return true; 
}

/******************************************************************
//  위싱웰 엘리스 플레이어 링크 생성
******************************************************************/
function __MakeWswLink( brn_cd, uniseq, r_god_cd, r_hse_no, r_hse_nm, r_god_nm, cls_cd, iroonet_gb )
{
	var emsurl = EMSURL ;
	var wswStudy = WSWSTUDY ;

	//alert(brn_cd);
	//alert(uniseq);
	//alert(r_hse_no);
	//alert(r_hse_nm);
	//alert(cls_cd);
	//alert(iroonet_gb);


	switch ( Mid(r_god_cd,5,1) ){
		case "1":
		{
			book_name = "Bamboo";
			book_initial = "B";
			break;
		}
		case "2":
		{
			book_name = "Lime";
			book_initial = "L";
			break;
		}
		case "3":
		{
			book_name = "Herb";
			book_initial = "H";
			break;
		}
		case "4":
		{
			book_name = "Almond";
			book_initial = "A";
			break;
		}
		case "5":
		{
			book_name = "Elm";
			book_initial = "E";
			break;
		}
	}

	var book_fnum = Mid(r_god_cd,6,2)*1
	var unit_num =( r_hse_no*1 > 10)?(r_hse_no%10):r_hse_no*1; // 11, 12, 13, 14 가 들어오는 경우 뒤 1,2,3,4값을 취함.
	var arl_name = book_initial +  Mid(r_god_cd,6,2) + unit_num + ".ARL"

	var WSW_URL = "AliceP://possubinfo=" + brn_cd ;
		WSW_URL += "_" + uniseq
		WSW_URL += "_" + book_name + book_fnum
		WSW_URL += "_unit" + unit_num
		WSW_URL += "_" + r_hse_nm
		WSW_URL += "_" + r_god_cd
		WSW_URL += "_" + r_hse_no
		WSW_URL += "_" + cls_cd
		WSW_URL += "_" + iroonet_gb
		WSW_URL += "&&fileurl="+ wswStudy +"/studyzone/" + book_name + book_fnum
		WSW_URL += "/unit" + unit_num
		WSW_URL += "/" + arl_name
		WSW_URL += "&&emsurl=" + emsurl
//alert(WSW_URL);
	return WSW_URL ;
}



/******************************************************************
// 드래그 앤 드롭 스크립트
******************************************************************/
/*var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var x,y;
var dobj;

function movemouse(e)
{
  if (isdrag)
  {
    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    return false;
  }
}

function selectmouse(e)
{
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";

  while (fobj.tagName != topelement && fobj.className != "dragme")
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }

  if (fobj.className=="dragme")
  {
    isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove=movemouse;
    return false;
  }
}

document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");
*/

/******************************************************************
// 객체 내용 보기.
******************************************************************/
function v$Obj( obj, viewObj )
{
	if ( typeof(obj) != "object" )
	{
		alert ( 'typeof is "' + typeof(obj) + '"\n' + obj );
		return;
	}

	var rtn = "";
	for ( var xitem in obj )
	{
		rtn += xitem + ":" + obj[xitem] + "\n";
	}

	if ( typeof(viewObj) == "object" )
	{
		viewObj.style.display = "block";
		viewObj.value = rtn ;
	}
	else
	{
		alert ( rtn );
	}
}


/******************************************************************
// 팝업달력
******************************************************************/
function ln_Calendar(arg,xPosition,yPosition)
{
    var X = event.clientX;
    //var Y = event.clientY + document.body.scrollTop;
	var Y = event.clientY + document.documentElement.scrollTop;

    var mObj = document.getElementById("span_" + arg);
    mObj.style.top = Y;
    mObj.style.left = X;

	if(xPosition=="left" || xPosition=="LEFT")
        mObj.style.left = X-149;
    
	if(yPosition=="top" || yPosition=="TOP")
        mObj.style.top = Y-183;

    if (mObj.style.display == "none")
        mObj.style.display = "" ;
    else
        mObj.style.display = "none" ;
}

// 달력에서 받은 값
function Change_Cal(date, objnm)
{
    var Target = document.getElementById("tbme_"+ objnm)
    Target.value = dFormat(date);
}

//
function dFormat(date)
{
	return date.substr(0,4)+"-"+date.substr(4,2)+"-"+date.substr(6,2)
}



 
 // 강의실 바로가기
function LectureGo()
{
	//uniseq = '<%=gs_UNISEQ%>';
	//brand_gb ='<%=gs_BRN_BRAND%>';
	if ( uniseq != '' )
	{
		if ( brand_gb.indexOf('13') != -1 )
		{
				//location.href = '/lecture/lecture0301.asp'; - 위싱웰 홈스터디 
				location = '/lecture/lecture0101.asp';
		}
		else if ( brand_gb.indexOf('01') != -1 )
		{
				//location.href = '/lecture/lecture04.asp'; - 내신대비동영상강의 
				location = "/lecture/lecture04.asp";
		}
		else if ( brand_gb.indexOf('01') != -1 && hp_gb == 'ATIS' )
		{
				location = '/LC/lecture0801.asp';  //-- 리스닝플러스
		}
		else if ( brand_gb.indexOf('03') != -1 )
		{
			    //location.href = '/lecture/lecture01.asp'; --수 연산 보충학습
				location = "/lecture/lecture04.asp";
		}
	}
}

// 로그인 이미지 보여주기.
function LoginAlert()
{
	div_alt_IMG.style.display = '';
}

