/* 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("sub");
	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("ul").item(0)) {
				menuEl.item(i).getElementsByTagName("ul").item(0).style.display = "none";
			}
		}
	}
}
function applyScriptCss(linkCss) {
	document.write(linkCss);
}


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;
}

/*quick*/
function A2YSlide(name,id,range,sec,tb,margin){ //객체명,레이어id,이동값,이동초,상하위치(false)?t:b,계산된 상하 위치에서 떨어질 범위
	//속성
	this.name = name;
	this.obj = document.getElementById(id);
	this.range = range;
	this.sec = sec;
	this.tb = tb;
	this.margin = margin;
	
	this.Timer();
}
/*━━━━━━━━━━━private 메소드 함수 선언부━━━━━━━━━━━━━━*/
A2YSlide.prototype.Move = function A2YSlide_Move(fix_y){
	objY = parseInt(this.obj.style.top);	
	objscrH	= parseInt(document.documentElement.scrollHeight);
	objqrH = parseInt(document.getElementById('rQuick').scrollHeight);

	//alert(objscrH);
	
	if(objY != fix_y){ //무한 스크롤링 제어 KYC Insert
		if	(objY <= (objscrH - 328) ){
			this.obj.style.top = (objY + this.GetMoveValue(objY,fix_y)) + 'px';
		}	
		else if	(fix_y <= (objscrH - 328)) {
			this.obj.style.top = (objY + this.GetMoveValue(objY,fix_y)) + 'px';	
		}

	//alert	(this.obj.style.top )

	}
	this.Timer();

}

A2YSlide.prototype.GetMoveValue = function A2YSlide_GetMoveValue(start, end){ //현재 위치와 이동할 위치에 따른 이동거리를 리턴한다.

	return (end - start) * this.range;

}

A2YSlide.prototype.GetDocTnB = function A2YSlide_GetDocTnB(bTB){ //문서의 상단or하단 픽셀값을 반환한다. (!bTB) ? Top : Bottom
	return ((bTB)?document.documentElement.clientHeight:0) + document.documentElement.scrollTop;
}

A2YSlide.prototype.Timer = function A2YSlide_Timer(){
	setTimeout(this.name + '.Move('+(this.GetDocTnB(this.tb)+this.margin)+')',this.sec);
}

/*━━━━━━━━━━━외부 마법사 코드━━━━━━━━━━━━━━*/
function A2Wzd_YSlide(id,range,sec,tb,margin){ //A2YSlide의 생성을 도와준다.
	eval('C'+id+" = new A2YSlide('C"+id+"','"+id+"',"+range+","+sec+","+tb+","+margin+');');
	//실행예 - CSMenu = new A2YSlide('CSMenu','SMenu',0.2,10,0,50); => var을 사용하지 않은 전역변수를 생성한다.
}
/*quick*/




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)
	}

//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);

}


//메인 배너 롤링
function mainrollingbanner(){
	var obj=document.getElementById('brinside');
	var moveobj=obj.getElementsByTagName('ul')[0];
	var banners=obj.getElementsByTagName('li');
	obj.style.width='318px';
	obj.style.height='30px';
	moveobj.style.marginLeft='0px';
	moveobj.style.display='block';

	this.canimove=true;
	
	var temp,nowm,speed=80,onew=-105;
	var rolling=function(){
		nowm=parseInt(moveobj.style.marginLeft);
		if(onew<nowm){
			setm(nowm+(Math.floor((onew-nowm)/speed)));
			moveobj.action=setTimeout(rolling,5);
		}else if(onew>nowm || onew==nowm){
			setm(0);
			items=moveobj.getElementsByTagName('li');
			temp=items[0].cloneNode(true);
			moveobj.removeChild(items[0]);
			moveobj.appendChild(temp);
			autorolling();
		}
	}
	
	var autorollingtime=1000;
	var autorollingtimer=0;
	var autorollingtimerid;
	var autorolling=function(){
		clearTimeout(autorollingtimerid);
		if(!mainrolling.canimove){
			autorollingtimer=0;
		}else{
			if(autorollingtime>autorollingtimer){
				autorollingtimer+=100;
				autorollingtimerid=setTimeout(autorolling,100);
			}else if(autorollingtime<=autorollingtimer){
				clearTimeout(autorollingtimerid);
				autorollingtimer=0;
				rolling();
			}
		}
	}
	this.restart=function(){
		autorolling();
	}

	var setm=function(newm){
		moveobj.style.marginLeft=newm+'px';
	}

	obj.onmouseover=function(){
		mainrolling.canimove=false;
	}
	obj.onmouseout=function(){
		mainrolling.canimove=true;
		mainrolling.restart();
	}

	var vabtn=document.getElementById('brviewallbtn');
	vabtn.style.display='none';
	vabtn.onclick=function(){mainrolling.viewallbanners();	}

	this.viewallbanners=function(hide){
		if(!hide){
			obj.style.height='';
			vabtn.onclick=function(){mainrolling.viewallbanners(true);}
			mainrolling.canimove=false;
			obj.onmouseout=null;
		}else{
			obj.style.height='35px';
			vabtn.onclick=function(){mainrolling.viewallbanners();}
			mainrolling.canimove=true;
			obj.onmouseout=function(){
				mainrolling.canimove=true;
				mainrolling.restart();
			}
			mainrolling.restart();
		}
	}

	rolling();

}

//메인 배너 롤링
function mainrollingbanner_eng(){
	var obj=document.getElementById('brinside');
	var moveobj=obj.getElementsByTagName('ul')[0];
	var banners=obj.getElementsByTagName('li');

	obj.style.width='318px';
	obj.style.height='30px';
	moveobj.style.marginLeft='0px';
	moveobj.style.display='block';

	this.canimove=true;
	
	var temp,nowm,speed=80,onew=-105;
	var rolling=function(){
		nowm=parseInt(moveobj.style.marginLeft);
		if(onew<nowm){
			setm(nowm+(Math.floor((onew-nowm)/speed)));
			moveobj.action=setTimeout(rolling,5);
		}else if(onew>nowm || onew==nowm){
			setm(0);
			items=moveobj.getElementsByTagName('li');
			temp=items[0].cloneNode(true);
			moveobj.removeChild(items[0]);
			moveobj.appendChild(temp);
			autorolling();
		}
	}
	
	var autorollingtime=1000;
	var autorollingtimer=0;
	var autorollingtimerid;
	var autorolling=function(){
		clearTimeout(autorollingtimerid);
		if(!mainrolling.canimove){
			autorollingtimer=0;
		}else{
			if(autorollingtime>autorollingtimer){
				autorollingtimer+=100;
				autorollingtimerid=setTimeout(autorolling,100);
			}else if(autorollingtime<=autorollingtimer){
				clearTimeout(autorollingtimerid);
				autorollingtimer=0;
				rolling();
			}
		}
	}
	this.restart=function(){
		autorolling();
	}

	var setm=function(newm){
		moveobj.style.marginLeft=newm+'px';
	}

//마우스 오버일때....
	obj.onmouseover=function(){
		//alert(moveobj);
		mainrolling.canimove=false;
		initImgEffect("bannersr");
		
	}
	obj.onmouseout=function(){
		mainrolling.canimove=true;
		mainrolling.restart();
	}

	var vabtn=document.getElementById('brviewallbtn');
	vabtn.style.display='none';
	vabtn.onclick=function(){mainrolling.viewallbanners();	}

	this.viewallbanners=function(hide){
		if(!hide){
			obj.style.height='';
			vabtn.onclick=function(){mainrolling.viewallbanners(true);}
			mainrolling.canimove=false;
			obj.onmouseout=null;
		}else{
			obj.style.height='35px';
			vabtn.onclick=function(){mainrolling.viewallbanners();}
			mainrolling.canimove=true;
			obj.onmouseout=function(){
				mainrolling.canimove=true;
				mainrolling.restart();
			}
			mainrolling.restart();
		}
	}

	rolling();

}

function goBanner(url, target){
	if(target == "Y"){
		location.href = url;
	}else{
		window.open(url);
	}
}

function goBanner_eng(url, target){
	if(target == "Y"){
		location.href = url;
	}else{
		window.open(url);
	}
	initImgEffect_over("bannersr");
}
function imgchange(imgobj){
	if(imgobj.src.indexOf('on.gif')==-1){
		imgobj.src=imgobj.src.replace('.gif','on.gif');
		imgobj.onmouseout=function(){if(this.src.indexOf('on.gif')!=-1) this.src=this.src.replace('on.gif','.gif');}
	}
}


//인쇄하기
var strObj = "";
           

function funcPrint(obj){                                 
	if(obj != undefined){
		strObj = obj;
		strObj.style.display = "none";
	}
	window.open("/include/preview.asp","winPrint","width=660,height=660,top=10,left=10,scrollbars=yes");
}

 function funcReturnState(state){
	if(strObj != ""){                 
		strObj.style.display = state;
	}
}
