function showFlash(flaFile, widths, heights, btrans) { 
  var strings = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="' + widths + '"  height="' + heights + '"><param name="movie" value="' + flaFile + '"> <param name="quality" value="high"> '; 
  if (btrans == 'y') { 
    strings += '<param name="wmode" value="transparent">'; 
  } 
  strings += '<embed src="' + flaFile + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + widths + '" height="' + heights + '"> </embed> </object>'; 
  document.write(strings); 
  return; 
}

function getObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {	
		return document.getElementById(objectId); // check W3C DOM
	}
	else if (document.all && document.all(objectID)) {	
		return document.all(objectID); // IE4
	}
	else if (document.layers && document.layers[objectID]) {	
		return document.layer[objectID]; // NN4
	}
	else {
		return false;
	}
}

function divCls(comeon)
{
	
	if(comeon == 'close') {
		getObject('message').style.display="none";
	}
}  

    
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_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_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; }
}


function menuclick(srcID, pos, totalCnt) {	
	for(i=0; i<totalCnt; i++) {
   		// Tab ¸Þ´º ¼±ÅÃ Ç¥½Ã
   		var sub_srcID = srcID + i;

	   	if (i == pos) {
				getObject(sub_srcID).style.display = "block";
	    } else {
				getObject(sub_srcID).style.display = "none";
	    }
	}
}


/* ¹æ »ó¼¼Á¤º¸ */
function win_roomInfo(URL) {
  downwin=window.open(URL,'win_roomInfo','scrollbars=yes,width=800,height=600')
  downwin.focus();
}


//°ø¹éÃ¼Å©(null, space)
function isEmpty(str) {
	for (var i=0; i<str.length; i++) {
		if (str.substring(i, i+1) != " ") return false;
	}

	return true;
}


//±ÛÀÚÅ©±â º¯°æ
var zoomRate = 10;  // È®´ë/Ãà¼Ò½Ã Áõ°¨·ü
var maxRate = 150;  //ÃÖ´ëÈ®´ë·ü
var minRate = 70;  //ÃÖ¼ÒÃà¼Ò·ü

function zoomIn(contentid, how) {
    if(GetCookie("zoomVal") != null && GetCookie("zoomVal") != ""){
        document.all[contentid].style.zoom = GetCookie("zoomVal");
        currZoom=GetCookie("zoomVal");
    } else {
        document.all[contentid].style.zoom = '100%'; 
        currZoom = '100%';
    }

    if (((how == "in") && (parseInt(currZoom) >= maxRate)) || ((how == "out") && (parseInt(currZoom) <= minRate)) ) {
        return; 
    }

    if (how == "in") {
        document.all[contentid].style.zoom = parseInt(document.all[contentid].style.zoom)+zoomRate+'%'
    } else {
        document.all[contentid].style.zoom = parseInt(document.all[contentid].style.zoom)-zoomRate+'%'
    }

    SetCookie("zoomVal",document.all[contentid].style.zoom);
}

function zoomOut(contentid, how) {
    if (GetCookie("zoomVal") != null && GetCookie("zoomVal") != "") {
        document.all[contentid].style.zoom = GetCookie("zoomVal");
        currZoom=GetCookie("zoomVal");
    } else {
        document.all[contentid].style.zoom = '100%'; 
        currZoom = '100%';
    }

    if (((how == "in") && (parseInt(currZoom) >= maxRate)) || ((how == "out") && (parseInt(currZoom) <= minRate)) ) {
        return; 
    }

    if (how == "in") {
        document.all[contentid].style.zoom = parseInt(document.all[contentid].style.zoom)+zoomRate+'%'
    } else {
        document.all[contentid].style.zoom = parseInt(document.all[contentid].style.zoom)-zoomRate+'%'
    }

    SetCookie("zoomVal",document.all[contentid].style.zoom);
}

function zoomReset(contentid, how) {
    document.all[contentid].style.zoom = '100%'; 
    currZoom = '100%';
    SetCookie("zoomVal",document.all[contentid].style.zoom);
}

function SetCookie(name,value){
  document.cookie = name + "=" + escape (value)+";domain=forest.go.kr";
 }

function SetCookie(name,value){
    document.cookie = name + "=" + escape (value)+";domain=forest.go.kr";
}

function GetCookie(name){
    if (document.cookie != "") {
        zoomc = document.cookie.split("; ");

        for (var i=0; i < zoomc.length; i++) {
            zoomv = zoomc[i].split("="); 

            if (zoomv[0] == name) {
                return  unescape(zoomv[1]);
            }
        }        
    } else {
        return "";
    }
}

function GoZoom(contentid){
    if (GetCookie("zoomVal") != null && GetCookie("zoomVal") != "") {
        document.all[contentid].style.zoom = GetCookie("zoomVal");
        currZoom=GetCookie("zoomVal");
    } else {
        document.all[contentid].style.zoom = '100%'; 
        currZoom = '100%';
    }
}


/**
 * ÇÁ¸°ÅÍ Ã³¸®.
 */
function contentPrint() {
    var windowLeft = (screen.width-640)/2;
	var windowTop = (screen.height-480)/2;

    var printURL = "/templates/user/common/forPrint.vm";

    window.open(printURL,"print",'width=700, height=550, menubar=no, scrollbars=yes,status=no,resizable=yes,top=' + windowTop + ',left=' + windowLeft + '');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function Moves() {
	var myindex = SiteGo.selectedIndex;
	urls = SiteGo.options[myindex].value;
	window.open(urls);
}

//ÈÞ¾ç¸² ¼Ò°³ - µ¿¿µ»ó º¸±â ¸µÅ©
function JsIntroVodLink(url) {
	if (url == "#") {
		alert("¸µÅ© Á¤º¸°¡ ¾ø½À´Ï´Ù.");
	} else {
		window.open(url, 'popup_forest_mv');
	}
}

//ÀÌ¹ÌÁö ¸®»çÀÌÁî
function JsImgResize(img) {
	// ¿øº» ÀÌ¹ÌÁö »çÀÌÁî ÀúÀå
	var width = img.width;
	var height = img.height; 

	// °¡·Î, ¼¼·Î ÃÖ´ë »çÀÌÁî ¼³Á¤
	var maxWidth = 500;   // ¿øÇÏ´Â´ë·Î ¼³Á¤. ÇÈ¼¿·Î ÇÏ·Á¸é maxWidth = 100  ÀÌ·± ½ÄÀ¸·Î ÀÔ·Â
	var maxHeight = height * 0.5;   // ¿ø·¡ »çÀÌÁî * 0.5 = 50%

	// °¡·Î³ª ¼¼·ÎÀÇ ±æÀÌ°¡ ÃÖ´ë »çÀÌÁîº¸´Ù Å©¸é ½ÇÇà  
	if (width > maxWidth) {  // °¡·Î°¡ ¼¼·Îº¸´Ù Å©¸é °¡·Î´Â ÃÖ´ë»çÀÌÁî·Î, ¼¼·Î´Â ºñÀ² ¸ÂÃç ¸®»çÀÌÁî
		resizeWidth = maxWidth;
//		resizeHeight = Math.Round((height * resizeWidth) / width);
	} else {  // ÃÖ´ë»çÀÌÁîº¸´Ù ÀÛÀ¸¸é ¿øº» ±×´ë·Î
		resizeWidth = width;
		resizeHeight = height;
	}

	// ¸®»çÀÌÁîÇÑ Å©±â·Î ÀÌ¹ÌÁö Å©±â ´Ù½Ã ÁöÁ¤
	img.width = resizeWidth;
//	img.height = resizeHeight;
}

/**
 *  ÁÖ¹Îµî·Ï¹øÈ£ÀÇ À¯È¿¼ºÀ» Ã¼Å©ÇÑ´Ù.
 */
function isValidJuminNo(juminno) {
  if(juminno=="" || juminno==null || juminno.length!=13) {
    alert("ÁÖ¹Îµî·Ï¹øÈ£¸¦ Àû¾îÁÖ¼¼¿ä.");
    return false;
  }
  
  var jumin1 = juminno.substr(0,6);
  var jumin2 = juminno.substr(6,7);
  var yy     = jumin1.substr(0,2);        // ³âµµ
  var mm     = jumin1.substr(2,2);        // ¿ù
  var dd     = jumin1.substr(4,2);        // ÀÏ
  var genda  = jumin2.substr(0,1);        // ¼ºº°
  var msg, ss, cc;

  // ¼ýÀÚ°¡ ¾Æ´Ñ °ÍÀ» ÀÔ·ÂÇÑ °æ¿ì
  if (!isNumeric(jumin1)) {
    alert("ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ¼ýÀÚ·Î ÀÔ·ÂÇÏ¼¼¿ä.");
    return false;
  }
  
  // ±æÀÌ°¡ 6ÀÌ ¾Æ´Ñ °æ¿ì
  if (jumin1.length != 6) {
    alert("ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
    return false;
  }
  
  // Ã¹¹øÂ° ÀÚ·á¿¡¼­ ¿¬¿ùÀÏ(YYMMDD) Çü½Ä Áß ±âº» ±¸¼º °Ë»ç
  if (yy < "00" 
      || yy > "99" 
      || mm < "01" 
      || mm > "12" 
      || dd < "01" 
      || dd > "31") {
    alert("ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
    return false;
  }
  
  // ¼ýÀÚ°¡ ¾Æ´Ñ °ÍÀ» ÀÔ·ÂÇÑ °æ¿ì
  if (!isNumeric(jumin2)) {
    alert("ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®¸¦ ¼ýÀÚ·Î ÀÔ·ÂÇÏ¼¼¿ä.");
    return false;
  }

  // ±æÀÌ°¡ 7ÀÌ ¾Æ´Ñ °æ¿ì
  if (jumin2.length != 7) {
    alert("ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
    return false;
  }
  
  // ¼ºº°ºÎºÐÀÌ 1 ~ 4 °¡ ¾Æ´Ñ °æ¿ì
  if (genda < "1" || genda > "4") {
    alert("ÁÖ¹Îµî·Ï¹øÈ£ µÞÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
    return false;
  }
 
  // ¿¬µµ °è»ê - 1 ¶Ç´Â 2: 1900³â´ë, 3 ¶Ç´Â 4: 2000³â´ë
  cc = (genda == "1" || genda == "2") ? "19" : "20";
  // Ã¹¹øÂ° ÀÚ·á¿¡¼­ ¿¬¿ùÀÏ(YYMMDD) Çü½Ä Áß ³¯Â¥ Çü½Ä °Ë»ç
  if (isValidDate(cc+yy+mm+dd) == false) {
    alert("ÁÖ¹Îµî·Ï¹øÈ£ ¾ÕÀÚ¸®¸¦ ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
    return false;
  }
  
  // Check Digit °Ë»ç
  if (!isSSN(jumin1, jumin2)) {
    alert("ÀÔ·ÂÇÑ ÁÖ¹Îµî·Ï¹øÈ£¸¦ °ËÅäÇÑ ÈÄ, ´Ù½Ã ÀÔ·ÂÇÏ¼¼¿ä.");
    return false;
  }
  return true;
}

function isValidDate(iDate) {
  if( iDate.length != 8 ) {
    return false;
  }
   
  oDate = new Date();
  oDate.setFullYear(iDate.substring(0, 4));
  oDate.setMonth(parseInt(iDate.substring(4, 6)) - 1);
  oDate.setDate(iDate.substring(6));

  if( oDate.getFullYear()     != iDate.substring(0, 4) 
      || oDate.getMonth() + 1 != iDate.substring(4, 6) 
      || oDate.getDate()      != iDate.substring(6) ){
     
    return false;
  }
    
  return true;
}

 

function isNumeric(s) { 
  for (i=0; i<s.length; i++) { 
    c = s.substr(i, 1); 
    if (c < "0" || c > "9") return false; 
  } 
  return true; 
}

 

function isSSN(s1, s2) {
  n = 2;
  sum = 0;
  for (i=0; i<s1.length; i++)
    sum += parseInt(s1.substr(i, 1)) * n++;
  for (i=0; i<s2.length-1; i++) {
    sum += parseInt(s2.substr(i, 1)) * n++;
    if (n == 10) n = 2;
  }
  
  c = 11 - sum % 11;
  if (c == 11) c = 1;
  if (c == 10) c = 0;
  if (c != parseInt(s2.substr(6, 1))) return false;
  else return true;
}


/**
 *  »ç¾÷ÀÚµî·Ï¹øÈ£ÀÇ À¯È¿¼ºÀ» Ã¼Å©ÇÑ´Ù.
 */

function isValidCsnNo(csn) {
    var strNumb = csn;
    if (strNumb.length != 10) {
        alert("»ç¾÷ÀÚµî·Ï¹øÈ£°¡ Àß¸øµÇ¾ú½À´Ï´Ù.");
        return false;
    }
    
        sumMod  =   0;
        sumMod  +=  parseInt(strNumb.substring(0,1));
        sumMod  +=  parseInt(strNumb.substring(1,2)) * 3 % 10;
        sumMod  +=  parseInt(strNumb.substring(2,3)) * 7 % 10;
        sumMod  +=  parseInt(strNumb.substring(3,4)) * 1 % 10;
        sumMod  +=  parseInt(strNumb.substring(4,5)) * 3 % 10;
        sumMod  +=  parseInt(strNumb.substring(5,6)) * 7 % 10;
        sumMod  +=  parseInt(strNumb.substring(6,7)) * 1 % 10;
        sumMod  +=  parseInt(strNumb.substring(7,8)) * 3 % 10;
        sumMod  +=  Math.floor(parseInt(strNumb.substring(8,9)) * 5 / 10);
        sumMod  +=  parseInt(strNumb.substring(8,9)) * 5 % 10;
        sumMod  +=  parseInt(strNumb.substring(9,10));
    
    if (sumMod % 10  !=  0) {
        alert("»ç¾÷ÀÚµî·Ï¹øÈ£°¡ Àß¸øµÇ¾ú½À´Ï´Ù.");
        return false;
    }
	return true;
}

function jsSearchEngine() {
	
	//ÅëÇÕ°Ë»ö º¯°æ
	var word = document.getElementById('searchEValue').value;
	var url = encodeURI("http://www.forest.go.kr/kfsweb/search2/index.jsp?kwd=" + word + "&pageNum=1&tagFlg=&category=");
	//alert(url);
	window.open( url );


}


//###############################################
//## go Top
//###############################################

// scrolling layer
function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof(window.pageYOffset) == "number") {
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof(document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return document.documentElement.scrollTop;
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}

	if (self.innerHeight) {
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if(document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 560;
		}
	}

	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//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 / 7;
		obj.style.top = obj.top + "px";
	}, 20)
}
//scrolling layer end
function goTop(){  //alert("gotop");
	location.href="#bodyArea";
}


function list_over(obj,startN) { /* Table List Over*/
	var list_row = obj.getElementsByTagName("tr");
	for (i=startN; i<list_row.length; i++) {
		list_row[i].onmouseover = function() {
			this.className = 'over';
		}
		list_row[i].onmouseout = function() {
			this.className = '';
		}
	}
}

//¼ýÀÚ¿¡ ÄÞ¸¶³Ö±â
function AddComma(strValue)
{
	var sum_data="", j=0;
	// strValue°¡ NumberÇüÀ¸·Î µé¾î¿Ã ¼ö ÀÖ±â¶§¹®¿¡ ¹®ÀÚÇüÀ¸·Î Ä¡È¯ÇÑ º¯¼ö»ç¿ë(¹ö±×ÀÇ ¿øÀÎÀÌ¾úÀ½)
	var rawData = ""+strValue;

	if ((rawData == null) || (rawData == "NaN") || (rawData.length <= 3)) return strValue;
	if (rawData.indexOf(",") >= 0) rawData = DelComma(strValue);

	// ¼Ò¼öÁ¡ Ã¼Å© (¼Ò¼öÁ¡ÀÌ ¾øÀ¸¸é ¹®ÀÚ¿­ÀÇ ±æÀÌ)
    var pos = rawData.indexOf(".");
    var pointPos = (pos < 0) ? rawData.length : pos;
    
	for (var i=rawData.length-1; i>=0 ; i--) {
		if (i < pointPos) {
			var ch = rawData.substring(i, i+1);
			// ¼Ò¼öÁ¡ À§ÀÇ °æ¿ì
			if (j == 3) {
				j = 0;
				if ((ch != "-") && (ch != "+")) sum_data = "," + sum_data;
			}
			sum_data = ch + sum_data;
			// ºÎÈ£(+/-)¸é ÁßÁö
			if ((ch == "-") || (ch == "+")) break;
			j++;
		}
		else {
			// ¼Ò¼öÁ¡ ¾Æ·¡ÀÇ °æ¿ì
			sum_data = rawData.substring(i, i+1) + sum_data;
		}
	}
	return sum_data;
}
