/* *******UTIL */
function getCookie(name){
	var nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length )
	{
	        var y = (x+nameOfCookie.length);
	        if ( document.cookie.substring( x, y ) == nameOfCookie ) {
	                if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
	                        endOfCookie = document.cookie.length;
	                return unescape( document.cookie.substring( y, endOfCookie ) );
	        }
	        x = document.cookie.indexOf( " ", x ) + 1;
	        if ( x == 0 ) break;
	}
	return "";
}

function setCookie( name, value, expiredays ){
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

/* // */

/* 네비 */
var NAVI;
function naviAction(wrapId, startDepth, actions){
	this.wrapId = wrapId;
	this.startDepth = startDepth; //1차,2차,3차 시작 점에 따른 현재 페이지 활성화 처리 위해 필요.
	
	this.actions = actions;
	this.isActive = false;
	this.inEnter = false;
	
	this.navi = $(this.wrapId).down('ul');
	menus = this.navi.childElements('li');
	for (var i=0; i < menus.length; i++){
		var my = this;
		menus[i].down('a').observe('mouseover', function(event){my.focusEvent(event)}.bind(my));
		menus[i].down('a').observe('focus', function(event){my.focusEvent(event)}.bind(my));
		//menus[i].down('a').observe('mouseout', function(event){my.blurEvent(event)}.bind(this));
	}
}

naviAction.prototype ={
	focusEvent:function(e, menu){
		if(!this.isActive){
			this.navi = $(this.wrapId).down('ul');
			var menus = this.navi.childElements('li');
			if(!menu) {	
				var menu = (window.event ? event.srcElement : e.target)
				if(menu.tagName!="A") menu = menu.parentNode;//IE 저질 이벤트..
				if(menu.tagName=="LI") menu = menu.down('a');//IE 저질 이벤트..
			}
			else {
				var menu = menu;
			}
			for (var i=0; i < menus.length; i++){
				//alert(menus[i].tagName + menu.tagName);
				if(menus[i].down('a')==menu || menus[i]==menu){				
					if(menu.down('img')) menu.down('img').src = menu.down('img').src.replace("Off.gif", "On.gif");
					menu.addClassName('on');
					//alert(menu.next());
					if (this.actions == 'visibility' && menu.next('ul')) {
						menu.next('ul').style.visibility = 'visible';
					}
					else if(this.actions == 'display' && menu.next('ul')) {
						menu.next('ul').show();
					}
					if (this.actions == 'visibility' && menu.next('div')) {
						menu.next('div').style.visibility = 'visible';
					}
					else if(this.actions == 'display' && menu.next('div')) {
						menu.next('div').show();
					}
					if(this.startDepth == 4 && menu.next('div')) {
						menu.next('div').down('ul').style.minWidth = (menu.up('li').offsetWidth < 75 ? 75 : menu.up('li').offsetWidth) + "px";
						//menu.next('ul').style.width = menu.up('li').offsetWidth + "px";
					}
					inEnter=true;
				}
				else {
					var my = this;
					my.reset(menus[i].down('a'));
				}
				
			}
		}
	},
	blurEvent:function(e){
		if(!this.isActive){
			this.navi = $(this.wrapId).down('ul');
			var menus = this.navi.childElements('li');
			//if(childMenu.hasClassName('focus')) return false;
			//else {
				menu = (window.event ? event.srcElement : e.target);
				if(menu.down('img')) menu.down('img').src = menu.down('img').src.replace("On.gif", "Off.gif");
				//removeClassName("focus");	
				if (this.actions == 'visibility') {
					menu.next('ul').style.visibility = 'hidden';
				}
				else if(this.actions == 'display') {
					menu.next('ul').hide();
				}
				
			//}
		}
	},
	reset:function(menu){
		if(menu.down('img')) menu.down('img').src = menu.down('img').src.replace("On.gif", "Off.gif");
		menu.removeClassName('on');
		if (this.actions == 'visibility' && menu.next('ul')) {
			menu.next('ul').style.visibility = 'hidden';
		}
		else if(this.actions == 'display' && menu.next('ul')) {
			menu.next('ul').hide();
		}
		if (this.actions == 'visibility' && menu.next('div')) {
			menu.next('div').style.visibility = 'hidden';
		}
		else if(this.actions == 'display' && menu.next('div')) {
			menu.next('div').hide();
		}
	}
};

/* 현제 페이지 활성화 */ 
function menuActivation(){
	var nav = document.getElementById('nav');
	for (var i=0; nav.getElementsByTagName('li').length > i; i++){
		if(nav.getElementsByTagName('li')[i].className == 'on') {
			NAVI.focusEvent(this, nav.getElementsByTagName('li')[i].parentNode.parentNode.getElementsByTagName('a')[0]);
		} 
	}
	
	
}
function sideMenu(){
	
	var strHref = window.location.href;

	temp = strHref.split("://");

	if(temp[1].indexOf("www") < 0) strHref = "www." + temp[1];

    //if (strHref != "http://www.ddm.go.kr/" && strHref != "http://www.ddm.go.kr/main.jsp" && strHref != "http://ddm.go.kr/" &&strHref != "http://ddm.go.kr/main.jsp" ) {
	if(
		(strHref.indexOf("/civil") > -1 || 
		strHref.indexOf("/join") > -1 || 
		strHref.indexOf("/education") > -1 || 
		strHref.indexOf("/life") > -1 || 
		strHref.indexOf("/info") > -1 || 
		strHref.indexOf("/ddm") > -1 || 
		strHref.indexOf("/etc") > -1 ) && strHref.indexOf("pageAlert") < 1 
	){
		var div = document.getElementById("pageNavi") ;	// > 로 연결된 상단 네비게이션
	
		var x = div.title;
		var y = "";
		
		var level1 = "";
		var level2 = "";
		var level3 = "";
		var level4 = "";
		var level5 = "";
	
		if(x.match(">") != null) {	//잘라서..
			y = x.split(">");
			
			if(y != null && y != ""){
				level1 = y[1];
				level2 = y[2];
				level3 = y[3];
				level4 = y[4];
				level5 = y[5];
			}
		}
		
		var li = document.getElementById('bodyLeft').getElementsByTagName("li");	//li 태그 모두 긇어옴
		
		var urlParam = window.location.search //파라메터
		
		for(var i = 0; i < li.length; i++ ){
			var x = li[i];
			if(x.id != null && x.id != ""){	//id 값없는 놈은 제외..
	
				if(level2 != "" && level2 != null){
					if(x.id.replace(/^\s*|\s*$/g, '').replace('_HC', '') == level2.replace(/^\s*|\s*$/g, '')){
						//li[i].style.backgroundColor="skyblue";
						li[i].className ="on";
					}
				}
			
				if(level3 != "" && level3 != null){
					
					if(x.id.replace(/^\s*|\s*$/g, '').replace('_HC', '') == level3.replace(/^\s*|\s*$/g, '')){
						
						if(urlParam == "?gubun1=2"){	//파라메터 구분이 안되서 이런 삽질을 했습니다.. 무념..
							document.getElementById("공공기관").innerHTML="<b>공공기관</b>";
						}else{
							li[i].innerHTML="<strong>" + x.id + "</strong>";
						}
					}
				}
			}
		}
		var navLi = document.getElementById('nav').getElementsByTagName("li");	//li 태그 모두 긇어옴
		
		
		for(var i = 0; i < navLi.length; i++ ){
			var x = navLi[i];
			if(x.id != null && x.id != ""){	//id 값없는 놈은 제외..
	
				if(level2 != "" && level2 != null){
					if(x.id.replace(/^\s*|\s*$/g, '').replace('_HC', '') == level2.replace(/^\s*|\s*$/g, '')){
						navLi[i].className ="on";
					}
				}
			}
		}
    }
};

//교육기간 관내 기간에 파라메터 구분이 있어서 만듬.... 에이쓰....

function get_url_parameter(strParamName) {	//해당 URL의 파라메터 값만 건져옴
    var strReturn = "";
    var strHref = window.location.href;
    if (strHref.indexOf("?") > -1) {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1) {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }    
    return unescape(strReturn);
}

Event.observe(window, 'load', function(){
	NAVI = new naviAction('nav', 1 , 'visibility'); //메뉴 감싼 개체 ID, 글로벌 depth, 서브메뉴 출력타입
	sideMenu();
	menuActivation();
});

Event.observe(window, 'load', function() {
	if($('tabMenu4Dep')){
		var tabMenu;
		tabMenu = new naviAction('tabMenu4Dep', 4 , 'visibility'); //메뉴 감싼 개체 ID, 글로벌 depth, 서브메뉴 출력타입
	}
});
/* / / */

/* 스킵 메뉴활성화  ::  수정 필요 */
Event.observe(window, 'load', function(){
	LI = $$('.easymenu a');
	for (i=0; i<LI.length; i++)	{
		LI[i].onfocus = function(){
			this.up('.easymenu').style.zIndex = 10;
		};
		LI[i].onblur = function(){
			this.up('.easymenu').style.zIndex = -10;
		};
	}
});

/* 새창  ::  수정 필요  */
Event.observe(window, 'load', function(){
	newWindow = document.getElementsByClassName('newWin');
	for (i=0; i<newWindow.length; i++)	{
		newWindow[i].onclick = function(){
			window.open(this.href);
			return false;
		};
	}
	blankA = document.getElementsByClassName('blank');
	for (i=0; i<blankA.length; i++)	{
		blankA[i].onclick = function(){
			window.open(this.href);
			return false;
		};
	}
});

/* 탭메뉴 */
function useTab(wrapId, btnTag, contTag){
	this.wrapId = wrapId;
	this.btnTag = (!btnTag ? 'h2' : btnTag);
	this.contTag = (!contTag ? 'ul' : contTag);
	$(this.wrapId).addClassName('script');
	this.menus = $$("#"+this.wrapId+" "+this.btnTag);
	for (var i=0; i < this.menus.length; i++){
		var my = this;	
		this.menus[i].down('a').observe('mouseover', function(event){my.focusEvent(event)});
		if(i==0) this.menus[i].next(this.contTag).addClassName('block');
		else this.menus[i].next(this.contTag).addClassName('none');
	}
}


useTab.prototype = {
	focusEvent:function(e){
		this.menus = $(this.wrapId).getElementsByTagName(this.btnTag);	
		var menu = (window.event ? event.srcElement : e.target);
		if(menu.tagName!="A") menu = menu.parentNode;//IE 저질 이벤트..
		if(menu.tagName==this.btnTag) menu = menu.down('a');//IE 저질 이벤트..
		for (var i=0; i < this.menus.length; i++){
			//alert(menus[i].tagName + menu.tagName);
			if(this.menus[i].down('a')==menu || this.menus[i]==menu){				
				if(menu.down('img')) menu.down('img').src = menu.down('img').src.replace("Off.gif", "On.gif");
				menu.parentNode.style.zIndex = 2; //index 버튼 겹치
				menu.addClassName('on');
				menu.parentNode.next(this.contTag).removeClassName('none');//스크린리더에 읽히게.. class로 우회
				menu.parentNode.next(this.contTag).addClassName('block');
			}
			else {
				var my = this;
				my.reset(this.menus[i].down('a'));
			}
		}
	},
	reset:function(menu){
		if(menu.down('img')) menu.down('img').src = menu.down('img').src.replace("On.gif", "Off.gif");
		menu.parentNode.style.zIndex = 0;
		menu.removeClassName('on');
		menu.parentNode.next(this.contTag).addClassName('block');
		menu.parentNode.next(this.contTag).addClassName('none');
	}
}

/* 약시자 전환 화면 */
function amblyopia(){
	var BODY = document.body;
	
	if ($('amblyopiaScreen').checked){
		var imgs = $$('#headArea img');
		var alts = new Array();
		for (var i=0; i < imgs.length; i++)	{
			if (imgs[i].getAttribute("alt")){
				alts[i] = imgs[i].alt;
				imgs[i].replace(alts[i]);
			}		
		}
		var imgs = $$('#footArea img');
		var alts = new Array();
		for (var i=0; i < imgs.length; i++)	{
			if (imgs[i].getAttribute("alt")){
				alts[i] = imgs[i].alt;
				imgs[i].replace(alts[i]);
			}		
		}
		/*
		var imgs = $$('#quickArea img');
		var alts = new Array();
		for (var i=0; i < imgs.length; i++)	{
			if (imgs[i].getAttribute("alt")){
				alts[i] = imgs[i].alt;
				imgs[i].replace(alts[i]);
			}		
		}
		*/
		BODY.addClassName("amblyopia");
		setCookie("amblyopiaChecked", "chk", 1);
	}
	else {
		if(BODY.hasClassName("amblyopia")) BODY.removeClassName("amblyopia");	
		setCookie("amblyopiaChecked", "unchk", 1);	
	}
	//return false;
}
Event.observe(window, 'load', function(){
	if(getCookie("amblyopiaChecked")=="chk") {
		$('amblyopiaScreen').checked = "checked";
		amblyopia();
	}
});


var fSize = '0.9em';
function fontSize(state){
	//fSize = getStyle(document.body, 'fontSize');
	fSize = fSize.split('em')[0];
	fSize = parseFloat(fSize);
	if (state =='up' && fSize <= parseFloat(1.7)){
		fSize = fSize + 0.2;
	} else if (state =='down' && fSize >= parseFloat(0.5)){
		fSize = fSize - 0.2;
	} else if (state == 'default'){
		fSize = 0.9;
	}else {
		alert('최대값입니다.');
	}
	fSize = fSize + 'em';
	document.body.style.fontSize = fSize;
	return false;
}

/* 키워드 검색 값 초기화 */
function inputReset(key){var oldKey = key.value; key.value = ''; key.onblur = function(){if(this.value==oldKey||this.value==''){this.value = oldKey}}}


/* 4depth tab menu */
function depth4menu(){
	if (!$('tabMenu4Dep')) return false;
	var menus = $('tabMenu4Dep');
	var menu = menus.getElementsByTagName('a');
	for(var i=0; i < menu.length; i++){
		menu[i].onmouseover = function(){
			if(this.nextSibling.nextSibling){
				this.nextSibling.nextSibling.style.visibility = 'visible';
			}
		}
		menu[i].onfocus = function(){
			if(this.nextSibling.nextSibling){
				this.nextSibling.nextSibling.style.visibility = 'visible';
			}
		}
		menu[i].onmouseout = function(){
			//if(this.next('ul')){
			//	this.next('ul').style.visibility = 'hidden';
			//}
		}
		menu[i].onblur = function(){
			//if(this.next('ul')){
			//	this.next('ul').style.visibility = 'hidden';
			//}
		}
	}
}
//Event.observe(window, 'dom:loaded', depth4menu);

function imgOpen(oHref, title){
  	(!title ? title="동대문 이미지 뷰어" : title=title);
  	var str="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
  	str+="<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ko\" lang=\"ko\">\n<head>";
  	str+="<title>" + title + "</title>\n<style type=\"text/css\">html,body{padding:0; margin:0;}</style></head>\n";
  	str+="<body onload=\"width1=document.getElementById('tImg').width;if(width1>1024)width1=1024;height1=document.getElementById('tImg').height;if(height1>768)height1=768;top.window.resizeTo(width1,height1);\">\n";
  	str+="<img src=\"" + oHref + "\" alt=\"이미지\" onclick=\"top.window.close()\" id=\"tImg\" title=\"클릭하면 창이 닫힙니다.\" style=\"cursor:pointer;\" />\n";
  	str+="</body>\n</html>";
  	
  	imgWin=window.open('','imgViewer','toolbar=no, width=0,height=0');
  	imgWin.document.open();
  	imgWin.document.write(str);
  	imgWin.document.close();
  	imgWin.focus();
	return false;
}

var banners;
function initBanner(objId) {
	document.getElementById(objId).parentNode.style.position = "relative";
	document.getElementById(objId).parentNode.style.overflow = "hidden";
	document.getElementById(objId).style.position = "absolute";
	banners = new scrolling(objId,1000,1,1); // objId,delay,sec2,speed,height
	document.getElementById("bannersCtrl").onmouseover = function() {
		banners.div.isover=true;
	}
	document.getElementById("bannersCtrl").onmouseout = function() {
		if( banners.div.controlPlay == true ) {
			banners.div.isover=false;
		}else{
			banners.div.isover=true;
		}
	}
	document.getElementById("bannersCtrl").onfocus = function() {
		banners.div.isover=true;
	}
	document.getElementById("bannersCtrl").onblur = function() {
		banners.div.isover=false;
	}
}

function scrolling(objId,sec1,sec2,speed,Width){
	this.objId=objId;
	this.sec1=sec1;
	this.sec2=sec2;
	this.speed=speed;
	this.h=0;
	this.div=document.getElementById(this.objId);
	this.width = (!Width ? Width : this.div.childNodes[1].offsetWidth);
	this.div.style.width = this.div.childNodes[1].offsetWidth * this.div.getElementsByTagName('li').length * 2 + 1 +  "px";
	this.htmltxt=this.div.innerHTML;
	this.div.innerHTML=this.htmltxt+this.htmltxt;
	this.div.isover=false;
	this.div.controlPlay = true;
	this.div.onmouseover=function(){this.isover=true;}
	this.div.onmouseout=function(){this.isover=false;}
	var aTags = this.div.getElementsByTagName('a');
	for (var i=0; i<aTags.length; i++){
		aTags[i].onfocus==function(){this.isover=true;}
		aTags[i].onblur==function(){this.isover=false;}
	}
	var self=this;
	this.div.style.left=0;
	window.setTimeout(function(){self.run()},this.sec1);
} 
scrolling.prototype={
	run:function(){
		var self=this;
		this.width= this.div.childNodes[1].offsetWidth;
		if(!this.div.isover){
			this.h+=this.speed;
			if(this.div.offsetLeft<-this.div.scrollWidth/2-1){
				this.div.style.left = 0 + 'px';
				this.h = 0;
			}else{
				if(this.h%this.width==0){
					window.setTimeout(function(){self.run()},this.sec1);
					return;
				}
				this.div.style.left = -this.h-1 + 'px';
			}
		}
		window.setTimeout(function(){self.run()},this.sec2);
	},
	prev:function(){
		if(this.div.offsetLeft<-this.div.scrollWidth/2) this.div.style.left = - this.div.scrollWidth/2 + px;
		if ( this.h != 0 ) {
			this.h = this.h - this.width;
			this.div.style.left = -this.h-1 + 'px';
		} else {
			this.div.style.left = 0 + 'px';
		}
	},
	next:function(){
		if(this.div.offsetLeft<-this.div.scrollWidth/2) this.div.style.left =0;
		if ( this.h < this.div.scrollWidth-this.width*2 ) {
			this.h = this.h + this.width;
			this.div.style.left = -this.h-1 + 'px';
		} else {
			this.h = 0;
			this.div.style.left = 0 + 'px';
		}
	},
	play:function(){
		this.div.controlPlay = true;
		this.div.isover = false;
	},
	pause:function(){
		this.div.controlPlay = false;
		this.div.isover = true;
	}
};

function submitOpenSite(obj){
	var uri = obj.getElementsByTagName('select')[0].value;
	if(uri.indexOf("http://") != -1) window.open(uri);
	else alert("이동 할 곳을 선택하여주세요");
}

/* 서울 GIS 연결 */
function ff_Open(){
	Param = "http://gis.seoul.go.kr/SubMap/index.jsp?Mode=0&OfficeName=동대문구&ImgDir=1&SecTorYN=N";
	Options = "status=yes, resizable=yes, width=1015, height=695";

	window.open(Param, "", Options);
}

/* 
	프론트페이지 주소찾기(우편번호).
	인자값 
	formName = 폼이름
	postNo1 = 첫번째 우편번호의 폼 이름
	postNo2 = 두번째 우편번호의 폼 이름
	addrInput = 첫번째 주소의 폼 이름 
*/
function fnFindZip(formName, postNo1, postNo2, addrInput) {
	var url = "/common/include/findZipcode.jsp?formName="+formName+"&postNo1="+postNo1+"&postNo2="+postNo2+"&addrInput="+addrInput;
	window.open(url,"FIND_ZIP","width=400 , height=280 , scrollbars=yes ");
	return;
}

/* 설문조사사 */
function PopWin2(tmpUrl, w, h, scroll) {
		// 새창 화면 중앙에 띄우기
		winToTop	= (screen.height)	? (screen.height-h)/2 : 0;
		winToLeft	= (screen.width)	? (screen.width-w)/2 : 0;
		making = 'width=' + w + ', height=' + h + ', top=' + winToTop + ', left=' + winToLeft + ', scrollbars=' + scroll + ', resizable=no, titlebar=no, status=no'
		window.open(tmpUrl,"seol",making);
	}
