var display_option;

// ¸Þ´º ÀÚµ¿ »ç¶óÁüÀ» À§ÇØ Ãß°¡ÇÔ (2005-12-02 °­À§¼ö)
var menuTimeout;

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_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
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; 
		}
}

// ¸Þ´º ÀÚµ¿ »ç¶óÁüÀ» À§ÇØ Ãß°¡ÇÔ (2005-12-02 °­À§¼ö)
function clearMenu() {
	// ¸ðµç ¸Þ´º ·¹ÀÌ¾î¸¦ ¾ø¾Ú
	MM_showHideLayers('Layer1','','hide','Layer2','','hide','Layer3','','hide','Layer4','','hide','Layer5','','hide');
	menuTimeout = null;
	return;
}

// ¸Þ´º ÀÚµ¿ »ç¶óÁüÀ» À§ÇØ Ãß°¡ÇÔ (2005-12-02 °­À§¼ö)
function clearMenuTimeout() {
	if (menuTimeout != null) {
		clearTimeout(menuTimeout);
		menuTimeout = null;
	}
	return;
}

// ¸Þ´º ÀÚµ¿ »ç¶óÁüÀ» À§ÇØ Ãß°¡ÇÔ (2005-12-02 °­À§¼ö)
function setMenuTimeout() {
	menuTimeout = setTimeout("clearMenu()", 500);
	return;
}

function toggleRightUnderMenu(i, o) {
	var apply_flag = 0;
	
	var rc = setButton(i, display_option);
	if (rc == -1) {
		setButton(right_option, display_option);
		alert('Áö¿øµÇÁö ¾Ê´Â ±â´ÉÀÔ´Ï´Ù.');
		return;
	}

        if (MM_findObj('RightUnderMenu_1') == null) {
                location.href='/?ro='+i;
                return;
        }

	right_option2 = i;
	if (i == 7) right_option2 = 6;

        for (j=1;j<7;j++) {
                if (j == right_option2) {
                        if (o == 0) {
                                MM_showHideLayers('RightUnderMenu_'+j,'','show');
                                if (right_option2 != j) {
                                        eval('document.rm_'+right_option2+'.item('+convItemLoc(item_option, right_option)+').checked = false;');
				} else {
                                        right_option = j;
                                        item_option = 1;
                                        eval('document.rm_'+right_option2+'.item('+convItemLoc(item_option, right_option)+').checked = true;');
                                        apply_flag = 1;
                                }
                        } else {
                                MM_showHideLayers('RightUnderMenu_'+j,'','show');
				eval('document.rm_'+right_option2+'.item('+o+').checked = true;');
                        }
                } else {
			MM_showHideLayers('RightUnderMenu_'+j,'','hide');
                }
        }
        if (apply_flag == 1) loadingMap(MAP_X1, MAP_Y1, MAP_X2, MAP_Y2);

	if (display_option == 'map') {
		document.Legend.src = '/img/legend_'+i+'_'+item_option+'.gif';
	}
}

function toggleSubmenu(i, o) {
	clearLeftSubmenuTimeout();

	for (j=1;j<5+1;j++) {
		if (j == i) {
			if (o == 0) {
				MM_showHideLayers('SubMenu_'+j,'','show');
			} else {
				MM_showHideLayers('SubMenu_'+j,'','hide');
			}
		} else {
			if (o == 0) {
				MM_showHideLayers('SubMenu_'+j,'','hide');
			} else {
				MM_showHideLayers('SubMenu_'+j,'','show');
			}
		}
	}
}

function validateEmail(email) {
	var atLoc = email.indexOf("@",1);
	var dotLoc = email.indexOf(".",atLoc+2);
	var len = email.length;

	if (!(atLoc > 0 && dotLoc > 0 && len > dotLoc+2)) {
		return false;
	}
	return true;
}

function isNumber(value) {
	var i = 0;
	for (i=0;i<value.length;i++) {
		temp = value.substring(i, i+1);
		if (!(temp >= '0' && temp <= '9' || temp == '.' || (temp == '-' && i == 0))) return false;
	}                       
	return true;
}     
function isNumberwithoutPoint(value) {
	var i = 0;
	for (i=0;i<value.length;i++) {
		temp = value.substring(i, i+1);
		if (!(temp >= '0' && temp <= '9')) return false;
	}                       
	return true;
}     

function checkAll(form, name, cnt) {
	var chk;
	var i;
	eval('if (form.'+name+'_1.checked == true) chk = false; else chk = true;');
	for (i=1;i<=cnt;i++)
		eval('form.'+name+'_'+i+'.checked = chk;');
}
function checkNumberExist(data) {
	for (i=0;i<data.length;i++) 
		if (data.charCodeAt(i) > 47 && data.charCodeAt(i) < 59) return true;
	return false;

}

function checkSpecialCharExist(data) {
	for (i=0;i<data.length;i++) 
		if ((data.charCodeAt(i) > 32 && data.charCodeAt(i) < 48) || (data.charCodeAt(i) > 57 && data.charCodeAt(i) < 63)) return true; 
	return false; 
} 

function checkName(data) { // ÇÑ±Û°ú ¿µ¹®¸¸Çã¿ë 
	for (i=0;i<data.length;i++) if ((data.charCodeAt(i) < 65 ) || (data.charCodeAt(i) > 90 && data.charCodeAt(i) <97) || (data.charCodeAt(i) > 122 && data.charCodeAt(i) < 128)) return true; 
	return false; 
} 
function checkValue(data) { // ¼ýÀÚ¿Í ¿µ¹® ¼Ò¹®ÀÚ ¸¸ Çã¿ë ¾ÆÀÌµð¿Í ºñ¹Ð¹øÈ£ Ã¼Å©½Ã »ç¿ë.
	for(i=0;i<data.length;i++) 
		if(!((data.charCodeAt(i) > 47 && data.charCodeAt(i) < 59)||(data.charCodeAt(i) > 96 && data.charCodeAt(i)< 123))) return true;
	return false;
}

function checkLen(check,highlength,lowlength) { 
	var len = check.length; 
	if (!(len >= lowlength && len <= highlength)) { return false; } 
	return true; 
}

function openWin(name, file, width, height,addoption) { 
	window.open(file, name,'status=0,resizable=no,scrollbars=yes ,width='+width+', height='+height+addoption); 
}

function checkOnlyEnglish(data) { 
	for (i=0;i<data.length;i++) 
		if (data.charCodeAt(i) > 255) return false; 
	return true; 
}

function checkSsn(ssn1,ssn2){//Àß¸øµÈ °æ¿ì¿¡ true ¸®ÅÏÇÑ´Ù.

	var ssn = ssn1+ssn2;

	// ÁÖ¹Îµî·Ï¹øÈ£ÀÇ ÇüÅÂ¿Í 7¹øÂ° ÀÚ¸®ÀÇ À¯È¿¼º °Ë»ç
	fmt = /^\d{6}[1234]\d{6}$/; if (!fmt.test(ssn)){ return true; }

	// ³¯Â¥ À¯È¿¼º °Ë»ç
	birthYear = (ssn.charAt(6) <= "2") ? "19" : "20"; birthYear += ssn.substr(0,2); 
	birthMonth = ssn.substr(2,2)-1; 
	birthDate = ssn.substr(4,2);
	birth = new Date(birthYear, birthMonth, birthDate);

	if (birth.getYear() % 100 != ssn.substr(0,2) || birth.getMonth() != birthMonth || birth.getDate() != birthDate) return true;

	// ÀÌ»óÀÌ ¾øÀ» °æ¿ì falseÃâ·Â
	return false; 
}

function getMapName(category, item) { 
	switch(category) { 
		case "disease": 
			return;
		case "pest":
			break;
		case "pheromon": 
			return "pher"; 
			break; 
		case "predict": 
			if (item == 'scab' || item == 'wrot') { return "hf"; } else { return "df"; } 
			break; 
	} 
}

function resizeSelfIFrame(toHeight, toWidth, iframe_name) { 
	if (!iframe_name) {
		iframe_name = 'table'; 
	} 
	eval("var target = parent.document.all."+iframe_name+";"); 
	if (target) { 
		target.height = toHeight;
		if (toWidth > 0) { target.width = toWidth; } else { target.width = 639; } 
	} 
}

// ¸Þ´º ÀÚµ¿ »ç¶óÁüÀ» À§ÇÑ º¯¼ö
var leftSubmenuTimeout = null; 
var rightMapmenuTimeout = null; 
var rightMapmenuFocused = false;
var mouseOverRightMapmenu = false;
var optionChanged = false;

function clearLeftSubmenuTimeout() { 
	if (leftSubmenuTimeout) clearTimeout(leftSubmenuTimeout); 
	leftSubmenuTimeout = null; 
	return; 
}

function setLeftSubmenuTimeout() { 
	clearLeftSubmenuTimeout();
	leftSubmenuTimeout = setTimeout("eraseLeftSubmenu()",500); 
	return; 
} 

function eraseLeftSubmenu() { 
	toggleSubmenu(0,0); 
	leftSubmenuTimeout = null;
	return; 
}

function setRightMapmenuFocus() { 
	rightMapmenuFocused = true; 
}

function clearRightMapmenuFocus() { 
	rightMapmenuFocused = false; 
	if (!mouseOverRightMapmenu) setRightMapmenuTimeout(); 
}

function onMouseOverRightMapmenu() { 
	mouseOverRightMapmenu = true;
	clearRightMapmenuTimeout(); 
}

function onMouseOutRightMapmenu() { 
	mouseOverRightMapmenu = false;
	setRightMapmenuTimeout(); 
}

function clearRightMapmenuTimeout() { 
	if (rightMapmenuTimeout) clearTimeout(rightMapmenuTimeout); 
	rightMapmenuTimeout = null; 
	return; 
}

function setRightMapmenuTimeout() { 
	if (!optionChanged && !rightMapmenuFocused) { 
		clearRightMapmenuTimeout(); 
		rightMapmenuTimeout = setTimeout("eraseRightMapmenu()",500);
	}
	return; 
}

function eraseRightMapmenu() { 
	toggleRightMenu(0,0); 
	rightMapmenuTimeout = null; 
	return; 
}

function convItemLoc(i, r) { if (r == 7) return (i+2-1); else return (i-1); }

function setButton(r,d) { 
	switch (r) { 
		case 1:
			BUTTON_MAP = 1; 
			BUTTON_GRAPH =1; 
			BUTTON_TABLE = 1; 
			break; 
		case 2: 
			BUTTON_MAP = 1; 
			BUTTON_GRAPH = 1;
			BUTTON_TABLE = 1; 
			break; 
		case 3: 
			BUTTON_MAP = 1; 
			BUTTON_GRAPH = 1; 
			BUTTON_TABLE= 1; 
			break; 
		case 4: 
			BUTTON_MAP = 1; 
			BUTTON_GRAPH = 1; 
			BUTTON_TABLE = 1; 
			break;
		case 5: 
			BUTTON_MAP = 1; 
			BUTTON_GRAPH = 1; 
			BUTTON_TABLE = 1; 
			break; 
		case 6: 
		case 7: 
			BUTTON_MAP = 1; 
			BUTTON_GRAPH = 1; 
			BUTTON_TABLE = 1; 
			break; 
	}

	switch (display_option) { 
		case 'map': 
			if (!BUTTON_MAP) { return -1; }
			break; 
		case 'graph': 
			if (!BUTTON_GRAPH) { return -1; } 
			break; 
		case 'table': 
			if (!BUTTON_TABLE) { return -1; }
			break; 
	} 
	return 0; 
}

function showBigImage2(id) { 
	window.open('/bigimage.php?id='+id, 'BIG_IMAGE','status=no,resizable=no, width=400, height=400'); 
}

function abs(a) {
	if (a < 0) {
		return a * -1;
	} else {
		return a;
	}
}

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 ""; 
}

