﻿// 전메뉴 공통적인 스크립트
// 레이어 관련 스크립트
/*
	@ author	김선호 (likesun@hanmail.net)
	@ date 	2004.2.15
	@ modify	2004.2.28 - 메인검색 스크립트 추가
	@ ver	1.1	
	@ range	공통 스크립트
	@ detail	레이어 관련, 메뉴, 새창띄우기, 롤이미지
*/

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function searchMain(form) {
	if(!form.words.value) {
		alert("검색할 단어를 입력해주세요");
		return;
	}
	
	if(form.words.value.length < 2){
		alert("2글자 이상의 단어를 입력해 주세요");
		return;
	}
	form.submit();
}

function inCell(cell, newcolor) {
			if (!cell.contains(event.fromElement)) {
				cell.bgColor = newcolor;
			}
		}

function outCell(cell, newcolor) {
			if (!cell.contains(event.toElement)) {
				cell.bgColor = newcolor;
			}
		}

function changeCss(obj, css)
{
	obj.className = css;
}


/*
 * IE의 새로운 ActiveX정책에 의해 Object는 document.write스크립트를 활용하여야 한다.
 * 작성자 : 2006.04.18 현준아빠
 * 
 * String src : 플래쉬 주소 [필수]
 * int w : 플래쉬 폭 [필수]
 * int h : 플래쉬 높이 [필수]
 * wmode : [선택]
 * menu : [선택]
 */
function writeFlash(src,width,height,wmode,menu) {
	html = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	html = html + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ width + '" height="' + height + '">';
	html = html + '<param name="movie" value="' + src + '">';
	if(wmode != null) {	html = html + '<param name="wmode" value="' + wmode + '">';	}
	if(menu != null) {	html = html + '<param name="menu" value="' + menu+ '">';	}
	html = html + '<param name="quality" value="high">';
	html = html + '<embed src="' + src + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>';
	html = html + '</object>';

	document.write(html);		 
}

/*
 * IE의 새로운 ActiveX정책에 의해 Object는 document.write스크립트를 활용하여야 한다.
 * 작성자 : 2006.04.18 현준아빠
 * 
 * String classid : 태그프리 ID [필수]
 * String version : 태그프리 버전[필수]
 */
function writeTagfree(classid, version) {
	html = '<object classid="' + classid + '" id="twe"  ';
	html = html + 'style="position:absolute" width="100%" height="100%" ';
	html = html + 'codebase="/assist/tagfree/tweditor.cab#version=' + version + '" >';
	html = html + '<param name="InitFile" value="/assist/tagfree/env.xml">';
	html = html + '<param name="ApplyInitData" value="1"><param name="Mode" value="0">';
	html = html + '</object>';

	document.write(html);		
}

/*
 * IE의 새로운 ActiveX정책에 의해 Object는 document.write스크립트를 활용하여야 한다.
 * 작성자 : 2006.04.18 현준아빠
 * 
 * String html : 소스
 */
function writeObject(html) {
	document.write(html);		
}


/*
 * 새로운 팝업창을 띄웁니다.
 * String url : 팝업문서의 경로 [필수]
 * String name : 팝업창의 이름 [default:"nWin"]
 * int w : 팝업창의 폭 [default:300]
 * int h : 팝업창의 높이 [default:300]
 * int x : 팝업창의 좌측 상단의 x좌표 [default:10]
 * int y : 팝업창의 좌측 상단의 y좌표 [default:10]
 * String s : 팝업창에 스클로바 표시여부('no' : 표시안함, 'yes' : 표시함, [default:"no"])
 */
function popup(url, name, w, h, x, y, s) {
	if(url == null) return;
	_name = arguments[1] != null ? arguments[1] : "nWin";
	_w = arguments[2] != null ? arguments[2] : "300";
	_h = arguments[3] != null ? arguments[3] : "300";
	_x = arguments[4] != null ? arguments[4] : "10";
	_y = arguments[5] != null ? arguments[5] : "10";
	_s = arguments[6] != "yes" ? "no" : "yes";
	var opt = ',menubar=0,status=0,resizable=0,directories=0,toolbar=0,location=0,';
	p_win = window.open(url, _name,
			'width=' + _w + ',height=' + _h + ',left=' + _x + ',top=' + _y + ',scrollbars=' + _s + opt);
	p_win.focus();
	this.name = 'cnedu';
	return p_win;
}

/*
 * 화면의 중앙에 팝업창을 띄웁니다.
 *
 * String url : 팝업문서의 경로 [필수]
 * String name : 팝업창의 이름 [default:"nWin"]
 * int w : 팝업창의 폭 [default:300]
 * int h : 팝업창의 높이 [default:300]
 * String s : 팝업창에 스클로바 표시여부('no' : 표시안함, 'yes' : 표시함, [default:"no"])
 */
function popupCenter(url, name, w, h, s) {
	if(url == null) return;
	_name = arguments[1] != null ? arguments[1] : "nWin";
	_w = arguments[2] != null ? arguments[2] : "300";
	_h = arguments[3] != null ? arguments[3] : "300";
	_x = (screen.width / 2) - (_w / 2);
	_y = (screen.height / 2) - (_h / 2);
	_s = arguments[4] == "yes" ? "yes" : "no";
	var opt = ',menubar=no,status=no,resizable=no,directories=0,toolbar=0,location=0,';
	p_win = window.open(url, _name,
			'width=' + _w + ',height=' + _h + ',left=' + _x + ',top=' + _y + ',scrollbars=' + _s + opt);
	p_win.focus();
	this.name = 'cnedu';
	return p_win;
}

/*
 * 새로운 윈도우를 띄웁니다.
 */
function openWin(url, name) {
	if(url == null) return;
	_name = arguments[1] != null ? arguments[1] : "nWin";
	p_win = window.open(url, _name);
	p_win.focus();
	this.name = 'cnedu';
	return p_win;
}


/*

  쿠키의 존재여부에 따라 popup창을 띄웁니다.
  String c_name : 쿠키명
  String url : 팝업문서의 경로
  String name : 팝업창의 이름
  int w : 팝업창을 폭
  int h : 팝업창의 높이
  int x : 팝업창의 좌측 상단의 x좌표
  int y : 팝업창의 좌측 상단의 y표표
  String s : 팝업창에 스클로바 표시여부('no' : 표시안함, 'yes' : 표시함)

  #2003.11.18 silver_star
  String s_date : 시작일시
  String e_date : 종료일시

  시작일시 <= 게시일 < 종료일시
*/
function popupByCookie(c_name, url, name, w, h, x, y, s,s_date,e_date) {
	var cookie = getCookie(c_name);

	if(s_date != null && e_date != null) {
		var day = new Date();
		year = day.getYear();
		month = day.getMonth() + 1;
		date = day.getDate();
		hour = day.getHours();
		if(month < 10) month = "0" + month;
		if(date < 10) date = "0" + date;
		if(hour < 10) hour = "0" + hour;

		var c_date = year + "" + month + "" + date + "" + hour;

		c_date = parseInt(c_date);
		s_date = parseInt(s_date);
		e_date = parseInt(e_date);

		if((c_date >= s_date) && (c_date < e_date)) {
			if(!cookie) popup(url, name, w, h, x, y, s);
		}
	} else {
		if(!cookie) popup(url, name, w, h, x, y, s);
	}
}

/*
  쿠키 생성 함수
  String name : 쿠키명
  String value : 쿠키 값
  int day : 쿠키만료 기간(일 단위)
*/
function setCookie(name, value, day) {
	if(day != null) {
	    var expDays = day;                // 만료 날짜 셋팅
    	var exp = new Date();
    	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
    	var expire_date = new Date(exp);
	    //document.cookie = name + "=" + value + "; domain=.chungnam.net ; expires=" + expire_date.toGMTString()+ "; path=/";
	    document.cookie = name + "=" + value + " ; expires=" + expire_date.toGMTString()+ "; path=/";
	} else {
		//document.cookie = name + "=" + value + "; domain=.chungnam.net ; path=/";
		document.cookie = name + "=" + value + "; path=/";
	}
}

/*
  쿠키 소멸 함수
  String name : 소멸시킬 쿠키명
*/
function clearCookie(name) {
    var today = new Date()
    //어제 날짜를 쿠키 소멸 날짜로 설정한다.
    var expire_date = new Date(today.getTime() - 60*60*24*1000)
    //document.cookie = name + "= " + "; expires=" + expire_date.toGMTString() + "; path=/";
    //document.cookie = name + "= " + "; domain=.chungnam.net ; path=/";
    document.cookie = name + "= " + "; path=/";
}

/*
  쿠키를 가져오는 함수
  String name : 쿠키명
*/
function getCookie(name) {
   var from_idx = document.cookie.indexOf(name+'=');
   if (from_idx != -1) {
      from_idx += name.length + 1
      to_idx = document.cookie.indexOf(';', from_idx)

      if (to_idx == -1) {
            to_idx = document.cookie.length
      }
      return unescape(document.cookie.substring(from_idx, to_idx))
   }
}

/*
  체크 상태에 따라 쿠키 생성과 소멸을 제어하는 함수
  checkbox의 Event Handler인 onClick이벤트에 등록해서 사용합니다.
  ex) <input type="checkbox" onClick="controlCookie(this, 'cName')">
  Form.checkbox frmObj : input type이 'checkbox'인 Form Object
  ex) checkbox를 사용하지 않는경우 use에 값을 부여한다.
*/
function controlCookie(frmObj, name, day,use) {
	  if ((frmObj.checked) || (use != null)) {
        //체크 박스를 선택했을 경우 쿠키 생성 함수 호출
        setCookie(name,"true", day);
        self.close();
    }
    else {
        //체크 박스를 해제했을 경우 쿠키 소멸 함수 호출
        clearCookie(name);
    } 
    return
}


/*
 즐겨찾기 추가
*/
 function Bookmark(){
  if (document.all){
	  url="http://cnedu/";
	  title = "충남교육청";
		window.external.AddFavorite(url ,title);
	}
}

/*
 달력
*/
function openCal(pName) {
	popupCenter("/assist/comn/calendar.jsp?pName=" + pName, "nCal", 200, 213, "no");
}
/*
 달력
*/
function openCal01(pName) {
	popupCenter("/assist/comn/calendar01.jsp?pName=" + pName, "nCal", 200, 213, "no");
}

/*
 부서선택
*/
function openDeptCd() {
	popupCenter("/assist/comn/dept.select.html", "nDeptCd", 400, 400, "no");
}

/*
 인쇄 기능
*/
function popPrint() {
	//pUrl = getPostPathString(document.location.pathname + document.location.search, 2);
	//popupCenter("/ctnt/prnt." + pUrl.substring(1, pUrl.length), "nWin", 685, 600, "yes");
	
	pUrl = getPostPathString(document.location.pathname, 2);
  var frm = document.all.frmPrintMail;
  if(frm != null) {
      popupCenter("", "wPrintWindow", 685, 600, "yes");
      frm.target = "wPrintWindow";
      frm.action = "/ctnt/prnt." + pUrl.substring(1, pUrl.length);
      frm.submit();
  }
}

// iframe 리사이징
function iframeAutoresize(obj)
{
	obj.height = eval(obj.name + ".document.body.scrollHeight");
}

