var is_gecko  = navigator.userAgent.toLowerCase().indexOf("gecko") != -1;
var is_ie     = navigator.userAgent.toLowerCase().indexOf("msie") != -1;

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_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_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() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  with (document) if (getElementById && ((obj=getElementById(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 MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_jumpMenu_blank(selObj,restore){ //v3.0
  eval("window.open='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function setPng24(obj) {
  obj.width=obj.height=1;
  obj.className=obj.className.replace(/\bpng24\b/i,'');
  obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
  obj.src='';
  return '';
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// 컨텐츠 더보기
var tid;
var pos = -220;

function initMenu(flag) {
	if(flag) {
		pos = -220;
		tid = setInterval("showMenu()", 10);
	} else {
		pos = 0;
		tid = setInterval("hiddenMenu()", 10);
	}
}

function showMenu() {
	if(pos < 0) { pos += 10; document.getElementById('content').style.bottom = pos; }
	else { clearInterval(tid); }
}

function hiddenMenu() {
	if(pos > -220) { pos -= 10; document.getElementById('content').style.bottom = pos; }
	else clearInterval(tid);
}

// 퀙메뉴
String.prototype.toInteger = function() {
	return this.replace(/[^0-9]/g, '') * 1;
}

function followBanner(div_id, origin_top, limit_top, margin_top){
	var d, t, s, g, target_height;
	origin_top *= 1;
	limit_top *= 1;
	margin_top *= 1;

	d = document.getElementById(div_id);
	s = document.documentElement.scrollTop + "";

	target_height = s.toInteger() + margin_top;
	if(target_height < limit_top) {
		target_height = origin_top;
	}

	t = d.style.top.toInteger();

	if(t != target_height) {
		g = Math.ceil((t - target_height) / 5);
		if(g > 50) {
			g = 50;
		} else if (g < -50) {
			g = -50;
		}
		d.style.top = (t - g) + "px";
	}
	setTimeout("followBanner('"+div_id+"', '"+origin_top+"', '"+limit_top+"', '"+margin_top+"');", 1);
}

/* 검색박스 배경처리 */
function hideBG(f){
	f.style.backgroundImage = "";
}

function showBG(f){
	if(f.value == ""){
		f.style.backgroundImage = "url(/ecologic/images/main/bg_input.gif)";
	}
}

// 글숫자 검사
function check_byte(content, target)
{
		var i = 0;
		var cnt = 0;
		var ch = '';
		var cont = document.getElementById(content).value;

		for (i=0; i<cont.length; i++) {
				ch = cont.charAt(i);
				if (escape(ch).length > 4) {
						cnt += 2;
				} else {
						cnt += 1;
				}
		}
		// 숫자를 출력
		document.getElementById(target).innerHTML = cnt;

		return cnt;
}

// 삭제 검사 확인
function del(href)
{
	if(confirm("한번 삭제한 자료는 복구할 방법이 없습니다.\n\n정말 삭제하시겠습니까?"))
	{
		document.location.href = href;
	}
}

// a 태그에서 onclick 이벤트를 사용하지 않기 위해
function win_open(url, name, option)
{
	var popup = window.open(url, name, option);
	popup.focus();
}

function win_zip(frm_name, frm_zip1, frm_zip2, frm_addr1, frm_addr2)
{
	window.open('/resource/bbs/zip.php?frm_name='+frm_name+'&frm_zip1='+frm_zip1+'&frm_zip2='+frm_zip2+'&frm_addr1='+frm_addr1+'&frm_addr2='+frm_addr2,'win_zip','width=444,height=500,top=50,left=100');
}

function win_pop()
{
	window.open('http://210.90.121.101/libmate.php','lib_win','toolbar=no,location=no,directory=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=1020,height=650,left=0,top=0');
}

function image_window(img)
{
	var w = img.tmp_width;
	var h = img.tmp_height;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/3;

	if (w >= screen.width) {
			winl = 0;
			h = (parseInt)(w * (h / w));
	}

	if (h >= screen.height) {
			wint = 0;
			w = (parseInt)(h * (w / h));
	}

	var js_url = "<script language='JavaScript1.2'> \n";
			js_url += "<!-- \n";
			js_url += "var ie=document.all; \n";
			js_url += "var nn6=document.getElementById&&!document.all; \n";
			js_url += "var isdrag=false; \n";
			js_url += "var x,y; \n";
			js_url += "var dobj; \n";
			js_url += "function movemouse(e) \n";
			js_url += "{ \n";
			js_url += "  if (isdrag) \n";
			js_url += "  { \n";
			js_url += "    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x; \n";
			js_url += "    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y; \n";
			js_url += "    return false; \n";
			js_url += "  } \n";
			js_url += "} \n";
			js_url += "function selectmouse(e) \n";
			js_url += "{ \n";
			js_url += "  var fobj      = nn6 ? e.target : event.srcElement; \n";
			js_url += "  var topelement = nn6 ? 'HTML' : 'BODY'; \n";
			js_url += "  while (fobj.tagName != topelement && fobj.className != 'dragme') \n";
			js_url += "  { \n";
			js_url += "    fobj = nn6 ? fobj.parentNode : fobj.parentElement; \n";
			js_url += "  } \n";
			js_url += "  if (fobj.className=='dragme') \n";
			js_url += "  { \n";
			js_url += "    isdrag = true; \n";
			js_url += "    dobj = fobj; \n";
			js_url += "    tx = parseInt(dobj.style.left+0); \n";
			js_url += "    ty = parseInt(dobj.style.top+0); \n";
			js_url += "    x = nn6 ? e.clientX : event.clientX; \n";
			js_url += "    y = nn6 ? e.clientY : event.clientY; \n";
			js_url += "    document.onmousemove=movemouse; \n";
			js_url += "    return false; \n";
			js_url += "  } \n";
			js_url += "} \n";
			js_url += "document.onmousedown=selectmouse; \n";
			js_url += "document.onmouseup=new Function('isdrag=false'); \n";
			js_url += "//--> \n";
			js_url += "</"+"script> \n";

	var settings;

	if (is_gecko) {
			settings  ='width='+(w+10)+',';
			settings +='height='+(h+10)+',';
	} else {
			settings  ='width='+w+',';
			settings +='height='+h+',';
	}
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars=no,';
	settings +='resizable=yes,';
	settings +='status=no';


	win=window.open("","image_window",settings);
	win.document.open();
	win.document.write ("<html><head> \n<meta http-equiv='imagetoolbar' CONTENT='no'> \n<meta http-equiv='content-type' content='text/html; charset=utf-8'>\n");
	var size = "이미지 사이즈 : "+w+" x "+h;
	win.document.write ("<title>"+size+"</title> \n");
	if(w >= screen.width || h >= screen.height) {
			win.document.write (js_url);
			var click = "ondblclick='window.close();' style='cursor:move' title=' "+size+" \n\n 이미지 사이즈가 화면보다 큽니다. \n 왼쪽 버튼을 클릭한 후 마우스를 움직여서 보세요. \n\n 더블 클릭하면 닫혀요. '";
	}
	else
			var click = "onclick='window.close();' style='cursor:pointer' title=' "+size+" \n\n 클릭하면 닫혀요. '";
	win.document.write ("<style>.dragme{position:relative;}</style> \n");
	win.document.write ("</head> \n\n");
	win.document.write ("<body leftmargin=0 topmargin=0 bgcolor=#dddddd style='cursor:arrow;'> \n");
	win.document.write ("<table width=100% height=100% cellpadding=0 cellspacing=0><tr><td align=center valign=middle><img src='"+img.src+"' width='"+w+"' height='"+h+"' border=0 class='dragme' "+click+"></td></tr></table>");
	win.document.write ("</body></html>");
	win.document.close();

	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}