/**
 * 플래쉬에서 호출되는 함수, 특정 자원의 도감페이지로 이동합니다.
 * @param idx
 * @return
 */
function goIlstrFromMainTopFlash(idx){
	var spcsArr = [
	    null,
		{spcsDiv:"P",btncCd:"807"},
		{spcsDiv:"P",btncCd:"6197"},
		{spcsDiv:"P",btncCd:"6259"},
		{spcsDiv:"P",btncCd:"14157"},
		{spcsDiv:"P",btncCd:"12423"},
		{spcsDiv:"P",btncCd:"9292"},
		{spcsDiv:"I",ilstrNo:"ZOBL0003"},
		{spcsDiv:"I",ilstrNo:"ZOEC0011"},
		{spcsDiv:"I",ilstrNo:"ZOEJ0031"},
		{spcsDiv:"I",ilstrNo:"ZRED0002"},
		{spcsDiv:"I",ilstrNo:"ZREP0016"},
	];
	
	var spcsItem = spcsArr[idx];
	if(spcsItem.spcsDiv=="P"){
		//식물도감을 호출
		var url = "/wkbik1/wkbik1343.leaf?plntBtncCd="+spcsItem.btncCd;
	}else if(spcsItem.spcsDiv="I"){
		//곤충도감을 호출
		var url = "/wkbik2/wkbik2333.leaf?isctIlstrNo="+spcsItem.ilstrNo;
	}
	
	window.location.href = url;
}

/**
 * swf 에서 호출됨
 * @param idx
 * @return
 */
function selKinList(idx){
	//1-식물, 2-곤충, 3-균류
	var url = "";
	if(idx==1) url = "/wkbik1/wkbik1531.leaf";
	else if(idx==2) url = "/wkbik2/wkbik2521.leaf";
	else if(idx==3) url = "/wkbik3/wkbik3411.leaf";
	
	window.location.href = url;
}

/**
 * swf에서 호출됨
 * @param idx
 * @return
 */
function bannerCall(idx){
	//1-기준표본정보, 2-지식나눔터, 3-어린이생물교식
	var url = "";
	if(idx==1) url = "/wkbik1/wkbik1441t1.leaf";
	else if(idx==2) url = "/wkbik5/wkbik5111.leaf";
	else if(idx==3) url = "/wkbik6/wkbik6111.leaf";
	
	window.location.href = url;
}
 
function topMenuFormSearch(cd1, cd2){
	var url = "";
	if(cd1=="plant"){
		if(cd2=="guide") url = "/wkbik1/wkbik1311t1.leaf";
		else if(cd2=="spcm") url = "/wkbik1/wkbik1411t1.leaf";
	}else if(cd1=="insect"){
		if(cd2=="guide") url = "/wkbik2/wkbik2311t1.leaf";
		else if(cd2=="spcm") url = "/wkbik2/wkbik2421t1.leaf";
	}else if(cd1=="fungi"){
		if(cd2=="guide") url = "/wkbik3/wkbik3311t1.leaf";
	}else if(cd1=="animal"){
		if(cd2=="guide") url = "/wkbik4/wkbik4321t1.leaf";
		else if(cd2=="spcm") url = "/wkbik4/wkbik4321t1.leaf";
	}else if(cd1=="bird"){
		if(cd2=="guide") url = "/wkbik4/wkbik4611t1.leaf";
		else if(cd2=="spcm") url = "/wkbik4/wkbik4611t1.leaf";
	}
	
	window.location.href = url;
}

function goTotalSearch() {
	var form = document.searchForm;
	if (!edu_IsEmpty(form.keyword.value)){
		if(form.searchKey.value == "1") {
			form.target = "_self";
			form.action = "/wkbik0/wkbik0601_1.leaf";
		} else {
			form.target = "_blank";
			form.action = "/wkbik0/wkbik0601_2.leaf";
		}
		return true;
	}else{
		alert("검색어를 입력하세요.");
		return false;
	}
}
function fnEnter() {
	if(event.keyCode == "13") {
		goTotalSearch();
	}else{
		return ;
	}
}

function clickshow(num){
	var layerID = document.getElementsByName('layerId');
	if (layerID) {
		for (var i = 0; i < layerID.length; i++) 
			layerID[i].style.display = "none";
		
		if (layerID[num]) {
			layerID[num].style.display = "";
		}
	}
	var tabmenuimg = document.getElementsByName('tabmenuimg');
	if (tabmenuimg) {
		for (var i = 0; i < tabmenuimg.length; i++) 
			tabmenuimg[i].src = "/images/main/tab_0" + (i + 1) + ".gif"
		if (tabmenuimg[num]) {
			tabmenuimg[num].src = "/images/main/tab_0" + (num + 1) + "_select.gif";
		}
	}
}


var searchTxt0 = new Array("국명","학명");
var searchTxt1 = new Array("통합검색","뉴스/공지","휴양/등산","산림지식","이미지/동영상","고객센터","자료실","웹문서","포털뉴스");

function changeSelect(item){
    var temp, i=0, j=0;
    var cnt, value, text;

    temp = document.searchForm.nameType;

    for (i=(temp.options.length-1) ; i>0 ; i--){ temp.options[i] = null; }
    eval('cnt = searchTxt' + item + '.length');
    for (j=0 ; j<cnt ; j++) {
        eval('text = searchTxt' + item + '[' + j + '];');
        if( item[j] == "국명" )	eval('value = 1 ;');
        else if( item[j] == "학명" )	eval('value = 3 ;');
        else eval('value = ' + j + ';');
        
        temp.options[j]= new Option(text,value);
    }
    temp.options[0].selected=true;
    return true;
}

function setRecomKeyword(keyword){
	document.searchForm.keyword.value=keyword;
}

// ------------------------------
var stmnLEFT = 930; // 왼쪽 여백  
var stmnGAP1 = 100; // 위쪽 여백 
var stmnGAP2 = 10; // 스크롤시 브라우저 위쪽과 떨어지는 거리
var stmnBASE = 150; // 스크롤 시작위치
var stmnActivateSpeed = 200;
var stmnScrollSpeed = 10;

var stmnTimer;

function RefreshStaticMenu(){
	var stmnStartPoint;
	var stmnEndPoint;
	var stmnRefreshTimer;
	stmnStartPoint = parseInt(QUICKMENU.style.top, 10);
	stmnEndPoint = document.body.scrollTop + stmnGAP2;
	if (stmnEndPoint < stmnGAP1) stmnEndPoint = stmnGAP1;
	stmnRefreshTimer = stmnActivateSpeed;
	if ( stmnStartPoint != stmnEndPoint ) {
		stmnScrollAmount = Math.ceil( Math.abs( stmnEndPoint - stmnStartPoint ) / 15 );
		QUICKMENU.style.top = parseInt(QUICKMENU.style.top, 10) + ( ( stmnEndPoint<stmnStartPoint ) ? -stmnScrollAmount : stmnScrollAmount );
		stmnRefreshTimer = stmnScrollSpeed;
	}
	
	stmnTimer = setTimeout ("RefreshStaticMenu();", stmnRefreshTimer);
}

function InitializeStaticMenu(){
	QUICKMENU.style.left = stmnLEFT;
	QUICKMENU.style.top = document.body.scrollTop + stmnBASE;
	RefreshStaticMenu();
} 


/* 통합 검색 셀렉트 박스 _ 테이블 및 div로 대체로 인한 추가 시작 */
function searchKeyOption(set){
    document.getElementById("optionDiv1").style.display = set;
}
function ChgBgcolor(id){
    eval("document.getElementById('"+ id +"').style.backgroundColor = \"#F0F7FF\";");
}
function NoBgcolor(id){
    eval("document.getElementById('"+ id +"').style.backgroundColor = \"\";");
}

function setSearchKey(num){
	if( num == '1' ){
		document.getElementById("searchKeyText1").innerHTML = "생물DB 통합 검색";
		document.getElementById("searchKeyText2").innerHTML = "국명";
		document.searchForm.nameType.value="1";		
	}
	if( num == '2' ){
		document.getElementById("searchKeyText1").innerHTML = "산림청 통합 검색";
		document.getElementById("searchKeyText2").innerHTML = "통합검색";
		document.searchForm.nameType.value="0";
	}
	document.searchForm.searchKey.value=num;
	searchKeyOption('none');
}
function setNameType(num){
	document.searchForm.nameType.value=num;
	var searchKey = document.searchForm.searchKey.value;
	if( searchKey == "1" ){
		if( num == "1" ) document.getElementById("searchKeyText2").innerHTML = "국명";
		if( num == "3" ) document.getElementById("searchKeyText2").innerHTML = "학명";
	}
	if( searchKey == "2" ){
		if( num == "0" ) document.getElementById("searchKeyText2").innerHTML = "통합검색";
		if( num == "1" ) document.getElementById("searchKeyText2").innerHTML = "뉴스/공지";
		if( num == "2" ) document.getElementById("searchKeyText2").innerHTML = "휴양/등산";
		if( num == "3" ) document.getElementById("searchKeyText2").innerHTML = "산림지식";
		if( num == "4" ) document.getElementById("searchKeyText2").innerHTML = "이미지/동영상";
		if( num == "5" ) document.getElementById("searchKeyText2").innerHTML = "고객센터";
		if( num == "6" ) document.getElementById("searchKeyText2").innerHTML = "자료실";
		if( num == "7" ) document.getElementById("searchKeyText2").innerHTML = "웹문서";
		if( num == "8" ) document.getElementById("searchKeyText2").innerHTML = "포털뉴스";
	}
	natypeOption('none');
}
function natypeOption(set){
	var searchKey = document.searchForm.searchKey.value;
	if( searchKey == "1" ){
		if( set == "block" )
			document.getElementById("optionDiv2").style.display = "block";
		else
			document.getElementById("optionDiv2").style.display = "none";
	}
	if( searchKey == "2" ){
		if( set == "block" )
			document.getElementById("optionDiv3").style.display = "block";
		else
			document.getElementById("optionDiv3").style.display = "none";
	}
}
/* 통합 검색 셀렉트 박스 _ 테이블 및 div로 대체로 인한 추가 끝 */



function openPop(pageName, width, height, left, top, popSeq, popFileNm, popSbjt)
{
	var sFeatures;
	var popWin;
	var url = "/wkbik0/wkbik0003p1.leaf?popSeq="+popSeq;
	//첨부파일이 html인경우 첨부된 html파일을 팝업으로 보여진다
	if( popFileNm.indexOf("html")>=0 || popFileNm.indexOf("HTML")>=0) url = "/fileUpload/popup/"+popFileNm;
	sFeatures = "status=yes,width="+ width + ",height=" + height + ",left="+left+",top="+top+",resizable=no,help:no,scrollbars=yes";
	//alert(url);
	//alert(pageName);
	//alert(sFeatures);
	popWin = window.open(url, popSbjt+popSeq, sFeatures);

	return popWin;
}
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 "";
}

/*
* 메인페이지 사이트 배너 boyoung 추가 
*/

function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != "function"){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		};
	}
}

var slidespeed = "3";
var leftrightslide = new Array();
var finalslide = "";

leftrightslide[0] = '<span style="margin-right:5px;"><a href="http://www.forest.go.kr/" target="_blank"><img src="/img/logo/banner_all_forest5.gif" alt="산림청"/></a></span>';
leftrightslide[1] = '<span style="margin-right:5px;"><a href="http://blog.daum.net/kfs4079" target="_blank"><img src="/img/logo/banner_all_forestblog8.gif" alt="푸르미의산림이야기" /></a></span>';
leftrightslide[2] = '<span style="margin-right:5px;"><a href="http://www.foreston.go.kr/" target="_blank"><img src="/img/logo/banner_all_foreston7.gif" alt="숲에ON" /></a></span>';
leftrightslide[3] = '<span style="margin-right:5px;"><a href="http://www.gbif.org/" target="_blank"><img  src="/img/logo/banner_all_gbif4.gif" alt="GBIF"/></a></span>';	
leftrightslide[4] = '<span style="margin-right:5px;"><a href="http://www.kna.go.kr/" target="_blank"><img src="/img/logo/banner_all_kna6.gif" alt="국립수목원"/></a></span>';		
leftrightslide[5] = '<span style="margin-right:5px;"><a href="https://www.knowledge.go.kr/main.jsp" target="_blank"><img src="/img/logo/banner_all_knowledge2.gif" alt="국가지식포털" /></a></span>';			
leftrightslide[6] = '<span style="margin-right:5px;"><a href="http://www.mopas.go.kr/" target="_blank"><img src="/img/logo/banner_all_mopas1.gif" alt="행정안전부" /></a></span>';	
leftrightslide[7] = '<span style="margin-right:5px;"><a href="http://www.nia.or.kr/" target="_blank"><img src="/img/logo/banner_all_nia3.gif" alt="한국정보화진흥원"/></a></span>';	

var imagegap = ""
var slideshowgap = 0

var copyspeed = slidespeed;
leftrightslide = "<nobr>" + leftrightslide.join(imagegap) + "</nobr>";
var iedom = document.all || document.getElementById;
if (iedom) {
	document.write('<span id="temp" style="visibility:hidden;height:41px;overflow-y:hidden;position:absolute;top:-100;left:-1000">' + leftrightslide + '</span>')
}

var actualwidth = "";
var cross_slide, ns_slide;
var righttime, lefttime;

function fillup() {
	if (iedom) {
		cross_slide = document.getElementById ? document.getElementById("banner") : document.all.banner;
		cross_slide2 = document.getElementById ? document.getElementById("banner2") : document.all.banner2;
		cross_slide.innerHTML = cross_slide2.innerHTML = leftrightslide;
		actualwidth = document.all ? cross_slide.offsetWidth : document.getElementById("temp").offsetWidth;
		cross_slide2.style.left = actualwidth + slideshowgap + "px";
	} else if (document.layers) {
		ns_slide = document.ns_slidemenu.document.ns_slidemenuorange;
		ns_slide2 = document.ns_slidemenu.document.ns_slidemenu3;
		ns_slide.document.write(leftrightslide);
		ns_slide.document.close();
		actualwidth = ns_slide.document.width;
		ns_slide2.left = actualwidth + slideshowgap;
		ns_slide2.document.write(leftrightslide);
		ns_slide2.document.close();
	}
	lefttime = setInterval("slideleft()", 80);
}

function slideleft() {
	if (iedom) {
		if (parseInt(cross_slide.style.left) > (actualwidth * (-1) + 8))
			cross_slide.style.left = parseInt(cross_slide.style.left) - copyspeed + "px";
		else
			cross_slide.style.left = parseInt(cross_slide2.style.left) + actualwidth + slideshowgap + "px";

		if (parseInt(cross_slide2.style.left) > (actualwidth * (-1) + 8))
			cross_slide2.style.left = parseInt(cross_slide2.style.left)	- copyspeed + "px";
		else
			cross_slide2.style.left = parseInt(cross_slide.style.left) + actualwidth + slideshowgap + "px";
	} else if (document.layers) {
		if (ns_slide.left > (actualwidth * (-1) + 8))
			ns_slide.left -= copyspeed;
		else
			ns_slide.left = ns_slide2.left + actualwidth + actualwidth + 30;

		if (ns_slide2.left > (actualwidth * (-1) + 8))
			ns_slide2.left -= copyspeed;
		else
			ns_slide2.left = ns_slide.left + actualwidth + actualwidth + 30;
	}
}

function slideright() {
	if (iedom) {
		if (parseInt(cross_slide.style.left) < (actualwidth + 8))
			cross_slide.style.left = parseInt(cross_slide.style.left)+ copyspeed + "px";
		else
			cross_slide.style.left = parseInt(cross_slide2.style.left) + actualwidth * (-1) + slideshowgap + "px";

		if (parseInt(cross_slide2.style.left) < (actualwidth + 8))
			cross_slide2.style.left = parseInt(cross_slide2.style.left)	+ copyspeed + "px";
		else
			cross_slide2.style.left = parseInt(cross_slide.style.left) + actualwidth * (-1) + slideshowgap + "px";
	} else if (document.layers) {
		if (ns_slide.left > (actualwidth * (-1) + 8))
			ns_slide.left -= copyspeed;
		else
			ns_slide.left = ns_slide2.left + actualwidth + slideshowgap;

		if (ns_slide2.left > (actualwidth * (-1) + 8))
			ns_slide2.left -= copyspeed;
		else
			ns_slide2.left = ns_slide.left + actualwidth + slideshowgap;
	}
}

function right() {
	if (lefttime) {
		clearInterval(lefttime);
		clearInterval(righttime);
		righttime = setInterval("slideright()", 80);
	}
}

function left() {
	if (righttime) {
		clearInterval(lefttime);
		clearInterval(righttime);
		lefttime = setInterval("slideleft()", 80);
	}
}
