var allNewsValues = [
	{key : "notice", name : "공지사항", url : "/pages/sub.jsp?menuIdx=101"}, 
	{key : "public", name : "고시/공고", url : "/pages/sub.jsp?menuIdx=102"}, 
	{key : "ipchal", name : "입찰정보", url : "/pages/sub.jsp?menuIdx=233"}, 
	{key : "ipchalresult", name : "입찰결과", url : "/pages/sub.jsp?menuIdx=234"}, 
	{key : "alrim", name : "발주계획", url : "/pages/sub.jsp?menuIdx=235"}, 
	{key : "suwi", name : "수의계약내역", url : "/pages/sub.jsp?menuIdx=236"}, 
	{key : "lawmaking", name : "입법예고", url : "/pages/sub.jsp?menuIdx=104"}, 
	{key : "speech_news", name : "보도자료", url : "/pages/sub.jsp?menuIdx=105"}, 
	{key : "test_news", name : "시험정보", url : "/pages/sub.jsp?menuIdx=106"}, 
	{key : "moonwha", name : "문화예술", url : "/pages/sub.jsp?menuIdx=238"}, 
	{key : "information", name : "주요일정", url : "/pages/sub.jsp?menuIdx=107"}, 
	{key : "soil_air", name : "토양대기수질", url : "/pages/sub.jsp?menuIdx=111"}, 
	{key : "apartment", name : "공동주택현황", url : "/pages/sub.jsp?menuIdx=113"}, 
	{key : "sanitaion", name : "위생민원", url : "/pages/sub.jsp?menuIdx=114"}, 
	{key : "environment", name : "환경소식", url : "/pages/sub.jsp?menuIdx=115"}
];
var defaultNewsValues = [
	"notice", "public", "ipchal", "lawmaking", "speech_news"
];
var monthExpires = new Date();
// 1달
monthExpires.setTime(monthExpires.getTime() + 24 * 60 * 60 * 30 * 1000);

// 뉴스 세팅 화면을 보여주는 함수.
function showNewsAjaxDialog() {
	var newsValue = getCookie("newsTab");

	// 체크한 항목이 있을 경우
	if (newsValue != "none") {
		var newsValues = $w(newsValue);

		allNewsValues.each(function (newsValue) {
			try { $(newsValue.key + "NewsTab").checked = false; } catch (ex) { }
		});

		if (newsValues != null && newsValues.length > 0) {
			newsValues.each(function (newsValue) {
				try { $(newsValue + "NewsTab").checked = true; } catch (ex) { }
			});
		}
	}

	$("newsAjax").show();
}

// 뉴스 세팅 화면을 닫는 함수.
function hideNewsAjaxDialog() {
	$("newsAjax").hide();
}

// 해당 뉴스항목을 체크했을 때 호출되는 함수.
function checkNewsTab(obj) {
	if (obj.value == "notice") {
		alert("공지사항은 기본항목입니다.");
		obj.checked = true;
	}

	// 체크 갯수가 5개를 초과하면...
	if ($CF("newsTab").length > 5) {
		alert("5개 이하로 선택해주세요.");
		obj.checked = false;
	}
}

// 선택한 뉴스항목을 저장하는 함수.
function saveNewsTab() {
	var newsValues = $CF("newsTab");

	// 선택된 뉴스 항목이 있을 경우
	if (newsValues != null && newsValues.length > 0) {
		var values = "";

		for (var i = 0; i < newsValues.length; i++) {
			values += newsValues[i] + " ";
		}

		//setCookie("newsTab", values, monthExpires, "/");
		setCookie("newsTab", values, 1, "/");

		changeNewsTab(newsValues);
	}
	// 뉴스 항목을 선택하지 않은 경우
	else {
		//setCookie("newsTab", "none", monthExpires, "/");
		setCookie("newsTab", "none", 1, "/");
	}

	hideNewsAjaxDialog();
}

// 뉴스 항목을 변경한다.
function changeNewsTab(newsValues) {
	allNewsValues.each(function (newsValue) {
		$$("li." + newsValue.key + "Li").each(Element.hide);
	});

	if (newsValues != null && newsValues.length > 0) {
		newsValues.each(function (newsValue) {
			$$("li." + newsValue + "Li").each(Element.show);
		});
	}
}

// 뉴스 탭을 생성하는 함수.
function writeNewsTab_new() {
	var tabSource = "";

		tabSource += "	<ul>";

	for (var i = 0; i < allNewsValues.length; i++) {
		if (i != 0) {
			//tabSource += "	<li class=\"floatleft " + allNewsValues[i].key + "Li\"	></li>";
		}
		
		if(i==0){
			tabSource += "		<li class=\"floatleft " + allNewsValues[i].key + "Li on\" id=\"" + allNewsValues[i].key + "Title\"><a onmouseover=\"showNews_new('" + allNewsValues[i].key + "')\" onclick=\"document.location.href='" + allNewsValues[i].url + "';\">" + allNewsValues[i].name + "<img src=\"/images/main_n/ico_newsArrow.gif\" width=\"9\" height=\"6\" alt=\"arrow\" id=\"" + allNewsValues[i].key + "Img\" style=\"display:\" /></a></li>";
		}else{
			tabSource += "		<li class=\"floatleft " + allNewsValues[i].key + "Li\" id=\"" + allNewsValues[i].key + "Title\"><a onmouseover=\"showNews_new('" + allNewsValues[i].key + "')\" onclick=\"document.location.href='" + allNewsValues[i].url + "';\">" + allNewsValues[i].name + "<img src=\"/images/main_n/ico_newsArrow.gif\" width=\"9\" height=\"6\" alt=\"arrow\" id=\"" + allNewsValues[i].key + "Img\" style=\"display:none\" /></a></li>";
		}
	}
	//tabSource += "	<li class=\"floatright\"><a href=\"javascript:showNewsAjaxDialog();\" title=\"메인 게시판 설정창을 엽니다.\"><img src=\"/images/main/btn_establish.gif\" alt=\"설정\" width=\"27\" height=\"16\" /></a></li>";
	tabSource += "	</ul>";

	document.write(tabSource);

	var newsValue = getCookie("newsTab");
	var newsValues = null;

	// 쿠키값이 없을 경우 기본 세팅
	if (newsValue == null || newsValue == "") {
		newsValues = defaultNewsValues;
		setCookie("newsTab", newsValues.join(" "), monthExpires, "/");
	}
	// 값이 none 이 아닐 경우
	else if (newsValue != "none") {
		newsValues = $w(newsValue);
	}
	
	changeNewsTab(newsValues);
}

// 뉴스 탭을 생성하는 함수.
function writeNewsTab() {
	var tabSource = "";

		tabSource += "	<ul class=\"ul_none f11\">";

	for (var i = 0; i < allNewsValues.length; i++) {
		if (i != 0) {
			tabSource += "	<li class=\"floatleft " + allNewsValues[i].key + "Li\"><img src=\"/images/main/i_news_div.gif\" alt=\"\" width=\"11\" height=\"10\" class=\"pad_t2\" /></li>";
		}

		tabSource += "	<li class=\"floatleft " + allNewsValues[i].key + "Li\"><span id=\"" + allNewsValues[i].key + "Title\" class=\"abtn\" onmouseover=\"showNews('" + allNewsValues[i].key + "')\" onclick=\"document.location.href='" + allNewsValues[i].url + "';\">" + allNewsValues[i].name + "</span></li>";
	}
	tabSource += "		<li class=\"floatright\"><a href=\"javascript:showNewsAjaxDialog();\" title=\"메인 게시판 설정창을 엽니다.\"><img src=\"/images/main/btn_establish.gif\" alt=\"설정\" width=\"27\" height=\"16\" /></a></li>";
	tabSource += "	</ul>";

	document.write(tabSource);

	var newsValue = getCookie("newsTab");
	var newsValues = null;

	// 쿠키값이 없을 경우 기본 세팅
	if (newsValue == null || newsValue == "") {
		newsValues = defaultNewsValues;
		setCookie("newsTab", newsValues.join(" "), monthExpires, "/");
	}
	// 값이 none 이 아닐 경우
	else if (newsValue != "none") {
		newsValues = $w(newsValue);
	}
	
	changeNewsTab(newsValues);
}

// 해당 뉴스를 활성화하는 함수.
function showNews_new(type) {
	allNewsValues.each(function (newsValue) {
		try {
			$(newsValue.key + "Title").className = "";
			$(newsValue.key + "Img").style.display = "none";
			$(newsValue.key).hide();
		} catch (ex) {
			//alert(newsValue.key);
		}
	});

	$(type+"Title").className = "on";
	$(type + "Img").style.display = "";
	$(type).show();
}

// 해당 뉴스를 활성화하는 함수.
function showNews(type) {
	allNewsValues.each(function (newsValue) {
		try {
			$(newsValue.key + "Title").className = "";
			$(newsValue.key).hide();
		} catch (ex) {
			//alert(newsValue.key);
		}
	});

	$(type+"Title").className = "on";
	$(type).show();
}

// 설문조사/자유제안방을 활성화하는 함수.
function showPoll(type) {
	if(type == "pollBody1") {
		$("pollBody1_img").src = "/images/main/ti_forum_on.gif";
		$("pollBody2_img").src = "/images/main/ti_forum2_off.gif";
	} else {
		$("pollBody1_img").src = "/images/main/ti_forum_off.gif";
		$("pollBody2_img").src = "/images/main/ti_forum2_on.gif";
	}

	$("pollBody1").hide();
	$("pollBody2").hide();

	$(type).show();
}

// 서비스 항목을 변경한다.
function changeServiceTab(service) {
	if (service == "oneClick") {
		$("oneClickServiceImg").src = "/images/main/btn_tab_on.gif";
		$("favoriteServiceImg").src = "/images/main/btn_tab02_off.gif";
		$("civil01").show();
		$("civil02").hide();
	} else {
		$("oneClickServiceImg").src = "/images/main/btn_tab_off.gif";
		$("favoriteServiceImg").src = "/images/main/btn_tab02_on.gif";
		$("civil01").hide();
		$("civil02").show();
	}
}

// 즐겨찾는 서비스 항목을 변경한다.
function changeFavoriteService(division) {
	$("eCivilAffairFavoriteImg").src = "/images/main/btn_eCivilAffair_off.gif";
	$("governmentFavoriteImg").src = "/images/main/btn_government_off.gif";
	$("participationFavoriteImg").src = "/images/main/btn_participation_off.gif";
	$("lifeFavoriteImg").src = "/images/main/btn_life_off.gif";
	$("economyFavoriteImg").src = "/images/main/btn_economy_off.gif";
	
	$(division + "FavoriteImg").src = "/images/main/btn_" + division + "_on.gif";
	
	$("eCivilAffairFavoriteDiv").hide();
	$("governmentFavoriteDiv").hide();
	$("participationFavoriteDiv").hide();
	$("lifeFavoriteDiv").hide();
	$("economyFavoriteDiv").hide();
	
	$(division + "FavoriteDiv").show();
}

/*
 * 쿠키 값을 얻습니다.
 * getCookie(쿠키명); 형식으로 사용합니다.
 */
function getCookie(name) {
	var value=null, search=name+"=";

	if (document.cookie.length > 0) {
		var offset = document.cookie.indexOf(search);

		if (offset != -1) {
			offset += search.length;
			var end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			value = unescape(document.cookie.substring(offset, end));
		}
	}

	return value;
}

/*
 * 쿠키를 생성합니다.
 * setCookie(쿠키명,값[,시간[,경로]]); 형식으로 사용합니다.
 */
function setCookie(name, value, expire, path) {
	document.cookie = name + "=" + escape(value) + ((!expire) ? "" : ("; expires=" + expire.toGMTString())) + "; path=" + ((!path) ? "" : path);
}

/*
 * 쿠키를 삭제합니다.
 * deleteCookie(쿠키명); 형식으로 사용합니다.
 */
function deleteCookie(name, path) {
	if(getCookie(name)) {
		document.cookie = name + "=" + "; path=" + ((!path) ? "/" : path) + "; expires=" + new Date(0).toGMTString();
	}
}


// 3뎁스
function showHistory(viewObj,chkNum,onImg) {//보일Obj ID/Obj 갯수/
	if(viewObj!=null) {//선택 레이어 보임
		document.getElementById(viewObj).style.display="block";
		if((chkNum!=null) && (!isNaN(chkNum))) {//대신 숨길 레이어가 있다면 숨김
			var hideObj = new String;
			var selObjNum = parseInt(viewObj.substring(viewObj.length-1,viewObj.length));
			hideObj = viewObj.substr(0,viewObj.length-1);

			for(var i=1;i<=chkNum;i++)	{
				if(i!=selObjNum)	{
					hideObj = hideObj.concat(i);
					document.getElementById(hideObj).style.display="none";
					hideObj = viewObj.substr(0,viewObj.length-1);
				}
			}
			
			if (onImg!=null) {//마우스over/out시 이미지on/of 수정
				document.getElementById(onImg).src = document.getElementById(onImg).src.replace("off.gif", "on.gif");
				var offImg	= new String;
				var selImgNum = parseInt(onImg.substring(onImg.length-1,onImg.length));
				offImg = onImg.substr(0,onImg.length-1);

				for(var i=1;i<=chkNum;i++)	{
					if(i!=selImgNum)	{
						offImg = offImg.concat(i);
						document.getElementById(offImg).src = document.getElementById(offImg).src.replace("on.gif", "off.gif");
						offImg = onImg.substr(0,onImg.length-1);
					}
				}
			}
		}
	}
}


// 탭메뉴 스크립트
function tabNavigation(seq) {
	tabnav = document.getElementById("tabmenu");
	tabnav.tabmenu = new Array();
	tabnav.tabcurrent = null;
	tabnav.tabmenuseq = 0;
	tabnavLen = tabnav.childNodes.length;
	
	taballA = tabnav.getElementsByTagName("a")
	for(k = 0; k < taballA.length; k++) {
		taballA.item(k).onclick = taballA.item(k).onfocus = function () {
			tabnav.isOver = true;
		}
		taballA.item(k).onmouseout = taballA.item(k).onblur = function () {
			tabnav.isOver = false;
			setTimeout(function () {
				if (tabnav.isOver == false) {
					if (tabnav.tabmenu[seq])
						tabnav.tabmenu[seq].onclick();
					else if(tabnav.current) {
						tabmenuImg = tabnav.tabcurrent.childNodes.item(0);
						tabmenuImg.src = tabmenuImg.src.replace("_over.gif", ".gif");
						if (tabnav.tabcurrent.tabsubmenu)
							tabnav.tabcurrent.tabsubmenu.style.display = "none";
						tabnav.tabcurrent = null;
					}
				}
			}, 300000);//300초뒤에 선택한 타겟활성화
		}
	}

	for (i = 0; i < tabnavLen; i++) {
		tabnavItem = tabnav.childNodes.item(i);
		if (tabnavItem.tagName != "LI")
			continue;

		tabnavAnchor = tabnavItem.getElementsByTagName("a").item(0);
		tabnavAnchor.tabsubmenu = tabnavItem.getElementsByTagName("ul").item(0);
		
		tabnavAnchor.onclick = tabnavAnchor.onfocus = function () {
			if (tabnav.tabcurrent) {
				tabmenuImg = tabnav.tabcurrent.childNodes.item(0);
				tabmenuImg.src = tabmenuImg.src.replace("_over.gif", ".gif");
				if (tabnav.tabcurrent.tabsubmenu)
					tabnav.tabcurrent.tabsubmenu.style.display = "none";
				tabnav.tabcurrent = null;
			}
			if (tabnav.tabcurrent != this) {
				tabmenuImg = this.childNodes.item(0);
				tabmenuImg.src = tabmenuImg.src.replace(".gif", "_over.gif");
				if (this.tabsubmenu)
					this.tabsubmenu.style.display = "block";					
				tabnav.tabcurrent = this;
			}
			tabnav.isOver = true;
		}
		tabnav.tabmenuseq++;
		tabnav.tabmenu[tabnav.tabmenuseq] = tabnavAnchor;
	}
	if (tabnav.tabmenu[seq])
		tabnav.tabmenu[seq].onclick();
}
