﻿/* roll over-out image */
function menuOver() {
	this.src = this.src.replace(".gif", "_on.gif");
}
function menuOut() {
	this.src = this.src.replace("_on.gif", ".gif");
}

function initImgEffect(ImgEls,SelImg) {

	MenuImg = document.getElementById(ImgEls).getElementsByTagName("img");
	MenuImgLen = MenuImg.length;

	for (i=0; i<MenuImgLen; i++) {
		MenuImg.item(i).onmouseover = menuOver;
		MenuImg.item(i).onmouseout = menuOut;
		if (i == SelImg) {
			MenuImg.item(i).onmouseover();
			MenuImg.item(i).onmouseover = null;
			MenuImg.item(i).onmouseout = null;
		}
	}
}



	/* IE HTML rewrite */
	function IE_HtmlRewrite(objParent) {
		if (window.ActiveXObject && objParent) {
			objParent.innerHTML = objParent.innerHTML;
		}
	}

	/* www.rrl.go.kr submenu */

	function initSubmenu(depth1, depth2, depth3) {
		selectDepth1 = "menu" + depth1 + "-" + depth2;
		selectDepth2 = "menu" + depth1 + "-" + depth2 + "-" + depth3;

		nav = document.getElementById("leftmenu");
		menuEl = nav.getElementsByTagName("li");


		for(i = 0; i < menuEl.length; i++) {
			if (menuEl.item(i).id == selectDepth1 || menuEl.item(i).id == selectDepth2  ) {
				menuEl.item(i).getElementsByTagName("img").item(0).src = menuEl.item(i).getElementsByTagName("img").item(0).src.replace(".gif", "_on.gif");
			} else {
				menuEl.item(i).getElementsByTagName("img").item(0).onmouseover = menuOver;
				menuEl.item(i).getElementsByTagName("img").item(0).onmouseout = menuOut;
				if (menuEl.item(i).getElementsByTagName("div").item(0)) {
					menuEl.item(i).getElementsByTagName("div").item(0).style.display = "none";
				}
			}
		}
	}
















/*function initMoving(target) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = 86;
	obj.initLeft = 920;
	obj.bottomLimit = document.documentElement.scrollHeight - 400;
	obj.topLimit = 84;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;
	obj.style.top = obj.top + "px";
	obj.style.left = obj.left + "px";

	obj.getTop = function() {
		if (document.documentElement.scrollTop) {
			return document.documentElement.scrollTop;
		} else if (window.pageYOffset) {
			return window.pageYOffset;
		} else {
			return 0;
		}
	}
	obj.getHeight = function() {
		if (self.innerHeight) {
			return self.innerHeight;
		} else if(document.documentElement.clientHeight) {
			return document.documentElement.clientHeight;
		} else {
			return 230;
		}
	}
	obj.move = setInterval(function() {
		pos = obj.getTop() + obj.getHeight() / 2 - 15;

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit
		if (pos < obj.topLimit)
			pos = obj.topLimit

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 40)
}*/
function lecOpen() {
	window.open('/utility/lecture.jsp', 'lecture', 'width=718, height=650, scrollbars=yes');
}
function dicOpen() {
	window.open('/utility/dictionary.jsp', 'dictionary', 'width=718, height=650, scrollbars=yes');
}


document.getElementsBySelector = function(selector) {
	// Attempt to fail gracefully in lesser browsers
	if (!document.getElementsByTagName) {
		return new Array();
	}
	// Split selector in to tokens
	var tokens = selector.split(' ');
	var currentContext = new Array(document);
	for (var i = 0; i < tokens.length; i++) {
		token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
		if (token.indexOf('#') > -1) {
			// Token is an ID selector
			var bits = token.split('#');
			var tagName = bits[0];
			var id = bits[1];
			var element = document.getElementById(id);
			if (tagName && element.nodeName.toLowerCase() != tagName) {
				// tag with that ID not found, return false
				return new Array();
			}
			// Set currentContext to contain just this element
			currentContext = new Array(element);
			continue; // Skip to next token
		}
		if (token.indexOf('.') > -1) {
			// Token contains a class selector
			var bits = token.split('.');
			var tagName = bits[0];
			var className = bits[1];
			if (!tagName) {
				tagName = '*';
			}
			// Get elements matching tag, filter them for class selector
			var found = new Array;
			var foundCount = 0;
			for (var h = 0; h < currentContext.length; h++) {
				var elements;
				if (tagName == '*') {
						elements = getAllChildren(currentContext[h]);
				} else {
						elements = currentContext[h].getElementsByTagName(tagName);
				}
				for (var j = 0; j < elements.length; j++) {
					found[foundCount++] = elements[j];
				}
			}
			currentContext = new Array;
			var currentContextIndex = 0;
			for (var k = 0; k < found.length; k++) {
				if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
					currentContext[currentContextIndex++] = found[k];
				}
			}
			continue; // Skip to next token
		}
		// Code to deal with attribute selectors
		if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
			var tagName = RegExp.$1;
			var attrName = RegExp.$2;
			var attrOperator = RegExp.$3;
			var attrValue = RegExp.$4;
			if (!tagName) {
				tagName = '*';
			}
			// Grab all of the tagName elements within current context
			var found = new Array;
			var foundCount = 0;
			for (var h = 0; h < currentContext.length; h++) {
				var elements;
				if (tagName == '*') {
						elements = getAllChildren(currentContext[h]);
				} else {
						elements = currentContext[h].getElementsByTagName(tagName);
				}
				for (var j = 0; j < elements.length; j++) {
					found[foundCount++] = elements[j];
				}
			}
			currentContext = new Array;
			var currentContextIndex = 0;
			var checkFunction; // This function will be used to filter the elements
			switch (attrOperator) {
				case '=': // Equality
					checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
					break;
				case '~': // Match one of space seperated words
					checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
					break;
				case '|': // Match start with value followed by optional hyphen
					checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
					break;
				case '^': // Match starts with value
					checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
					break;
				case '$': // Match ends with value - fails with "Warning" in Opera 7
					checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
					break;
				case '*': // Match ends with value
					checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
					break;
				default :
					// Just test for existence of attribute
					checkFunction = function(e) { return e.getAttribute(attrName); };
			}
			currentContext = new Array;
			var currentContextIndex = 0;
			for (var k = 0; k < found.length; k++) {
				if (checkFunction(found[k])) {
					currentContext[currentContextIndex++] = found[k];
				}
			}
			// alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
			continue; // Skip to next token
		}
		// If we get here, token is JUST an element (not a class or ID selector)
		tagName = token;
		var found = new Array;
		var foundCount = 0;
		for (var h = 0; h < currentContext.length; h++) {
			var elements = currentContext[h].getElementsByTagName(tagName);
			for (var j = 0; j < elements.length; j++) {
				found[foundCount++] = elements[j];
			}
		}
		currentContext = found;
	}
	return currentContext;
}


//quickmenu
// 플로터 - 범위제한
//ex) initMoving("idname",884,500);
function initMoving(id,xleft,ytop) {
 target = document.getElementById(id);
 if (!target) return false;
 var obj = target;
 obj.initLeft = xleft;//절대좌표x
 obj.initTop = ytop;//절대좌표y
 obj.bottomLimit = document.documentElement.scrollHeight - 500;
 obj.topLimit = 20;

 obj.style.position = "absolute";
 obj.top = obj.initTop;
 obj.left = obj.initLeft;
 obj.style.top = obj.top + "px";
 obj.style.left = obj.left + "px";

 obj.getTop = function() {
 if (document.documentElement.scrollTop) {
 return document.documentElement.scrollTop;
 } else if (window.pageYOffset) {
 return window.pageYOffset;
 } else {
 return 0;
 }
 }
 obj.getHeight = function() {
 if (self.innerHeight) {
 return self.innerHeight;
 } else if(document.documentElement.clientHeight) {
 return document.documentElement.clientHeight;
 } else {
 return 500;
 }
 }
 obj.move = setInterval(function() {
 pos = obj.getTop() + obj.getHeight() / 2 - 15;

 if (pos > obj.bottomLimit)
 pos = obj.bottomLimit
 if (pos < obj.topLimit)
 pos = obj.topLimit

 interval = obj.top - pos;
 obj.top = obj.top - interval / 3;
 obj.style.top = obj.top + "px";
 }, 40)
}




function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//select_go
function openWindow(http) {
		window.open(http,"")
	}

function sub_openWindow(http,open_name) {
	var http1,open_name1
		http1 = http;
		open_name1 = open_name;	
		window.open(http1,open_name1)
	}

	function selectLinks(form) {
		var http
			for(i=0;i<form.links.length;i++) {
				if(form.links.options[i].selected == true) {
					http = form.links.options[i].value					
				}
			}

		openWindow(http)
	}
	function selectLinks2(form) {
		var http
			for(i=0;i<form.links2.length;i++) {
				if(form.links2.options[i].selected == true) {
					http = form.links2.options[i].value
				}
			}
		openWindow(http)
	}
//copy link
	function selectLinks3(form) {
		var http
			for(i=0;i<form.links3.length;i++) {
				if(form.links3.options[i].selected == true) {
					http = form.links3.options[i].value
				}
			}
		openWindow(http)
	}
	function selectLinks4(form) {
		var http
			for(i=0;i<form.links4.length;i++) {
				if(form.links4.options[i].selected == true) {
					http = form.links4.options[i].value
				}
			}
		openWindow(http)
	}
	function selectLinks5(form) {
		var http
			for(i=0;i<form.links5.length;i++) {
				if(form.links5.options[i].selected == true) {
					http = form.links5.options[i].value
				}
			}
		openWindow(http)
	}


	function selectLinks10(form) {
		var http
			for(i=0;i<form.links10.length;i++) {
				if(form.links10.options[i].selected == true) {
					http = form.links10.options[i].value
				}
			}
		//openWindow(http)
		sub_openWindow(http,"dept")
	}
	function selectLinks11(form) {
		var http
			for(i=0;i<form.links11.length;i++) {
				if(form.links11.options[i].selected == true) {
					http = form.links11.options[i].value
				}
			}
		openWindow(http)
	}
		function selectLinks12(form) {
		var http
			for(i=0;i<form.links12.length;i++) {
				if(form.links12.options[i].selected == true) {
					http = form.links12.options[i].value
				}
			}
		openWindow(http)
	}



//select_go_self
function gothere(){
    var thebox=document.gameitem
        //if (thebox.windowoption.checked){
        //if (!window.newwindow)
        //    newwindow=window.open("")
        //    newwindow.location=
        //    thebox.item.options[thebox.item.selectedIndex].value
        //}
        //else
            location=
            thebox.item.options[thebox.item.selectedIndex].value
}

//*flash
function flashWrite(url,w,h,id,bg,vars,win){

        var flashStr=
        "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
        "<param name='allowScriptAccess' value='always' />"+
        "<param name='movie' value='"+url+"' />"+
        "<param name='FlashVars' value='"+vars+"' />"+
        "<param name='wmode' value='"+win+"' />"+
        "<param name='menu' value='false' />"+
        "<param name='quality' value='high' />"+
        "<param name='bgcolor' value='"+bg+"' />"+
        "<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
        "</object>";
        document.write(flashStr);

}

/*//FLASH
function ActiveX()
{

}

ActiveX.CreateObject = function( type, 
    id ,
    width,
    height,
    name,
    transparent )
{
    switch( type )
    {
        case "Flash":
            Flash.CreateObject( id, 
                width, 
                height, 
                name,
                transparent );
            break;
    }
}

// JScript 파일
function Flash()
{
    this.ID = null;
    this.Width = 0;
    this.Height = 0;
    this.Name = null;
    this.IsTransparent = false;
}

Flash.createParam = function( name, value )
{
    document.write( "<param name=\"" + name + "\"" );
    document.writeln( " value=\"" + value + "\" />" ) 
}

Flash.CreateObject = function( id, 
    width, 
    height, 
    name, 
    transparent )
    
{    
    document.write( "<object" );
    document.write( " width=\"" + width + "\"" );
    document.write( " height=\"" + height + "\"" );
    document.write( " id=\"" + id + "\"" );
    
    if( window.navigator.appName == "Netscape" )
    {
        document.write( " type=\"application/x-shockwave-flash\"" );
        document.write( " data=\"" + name + "\"" );
    }
    else
    {
        document.write( " classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"" );    
    }
    
    document.writeln( " align=\"top\">" );
    
    Flash.createParam( "allowScriptAccess", "sameDomain" );
    Flash.createParam( "movie", name );
    Flash.createParam( "quality", "high" );
    Flash.createParam( "movie", name );
    
    if( transparent == true )
        Flash.createParam( "wmode", "transparent" );
 
    document.writeln( "</object>" ); 
}
*/

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() { //v3.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; }
}
//input background
function
	clrImg(obj) {
		obj.style.backgroundImage="";obj.onkeydown=obj.onmousedown=null;
}


//확대 축소
 function chgWindow(d,v) {


   if(v == "1.0") {    /* 초기화 */
       mZoom = readCookie("cZoom");
       d.body.style.zoom = mZoom;
   } else if(d.body.style.zoom == '' ){
    if (v > 1) {
     d.body.style.zoom = v ;
    }
   } else {
    var fSize = parseFloat(d.body.style.zoom);

    if (fSize > 2.0 ) {
     if (v < 1) {
      d.body.style.zoom *= v;
     }
 //    d.body.style.zoom = 2.0; // 이이상은 작동 않하게
    } else if ( fSize < 1 ) {
     if (v > 1) {
      d.body.style.zoom = 1 ;
     }
 //    d.body.style.zoom = 1;  // 이이하는 작동 않하게
    } else {
     d.body.style.zoom *= v;
    }
  
   }
  

 }




/*
 * 제   목 :	새창 열기 onkeypress  대체 스크립트
 * 기   존  :	<a href="http://www.naver.com" onclick="window.open(this.href); retun false;" onkeypress="window.open(this.href); retun false;"  
 * 사용법 :	<a href="http://www.naver.com" onclick="window.open(this.href); retun false; onkeypress="return window_open(event, this.href);" 
 */
/*
function window_open(event, uri){
	if(allowOnkeypress(event)){
		window.open(uri);
		return false;
	}else{
		return true;
	}
} 
*/
function window_open(event, uri, pop_id, option){
	if(allowOnkeypress(event)){
		if(option){
			window.open(uri, pop_id,option);
		}else{
			window.open(uri);			
		}
		return false;
	}else{
		return true;
	}
} 
/*
 * 제   목 : onkeypress  허용 가능 판단
 * 사용법 : allowOnkeypress(event);"
 */
function allowOnkeypress(event){
	var evCode = (window.netscape) ? event.which : event.keyCode;
	var clickCode = (window.netscape) ? 1 : 0;

	// 코드 (클릭), 13(엔터), 
	if(evCode==clickCode || evCode==13 ){
		return true;
	}else{
		return false;
	}
}
