// Àü¿ª º¯¼ö
var errmsg = "";
var errfld;  

// ÇÊµå °Ë»ç
function check_field(fld, msg) 
{
    if ((fld.value = trim(fld.value)) == "") 			   
        error_field(fld, msg);
    else
        clear_field(fld);
    return;
}

// ÇÊµå ¿À·ù Ç¥½Ã
function error_field(fld, msg) 
{
    if (msg != "")
        errmsg += msg + "\n";
    if (!errfld) errfld = fld;
    fld.style.background = "#BDDEF7";
}

// ÇÊµå¸¦ ±ú²ýÇÏ°Ô
function clear_field(fld) 
{
    fld.style.background = "#FFFFFF";
}

function trim(s)
{
	var t = "";
	var from_pos = to_pos = 0;

	for (i=0; i<s.length; i++)
	{
		if (s.charAt(i) == ' ')
			continue;
		else 
		{
			from_pos = i;
			break;
		}
	}

	for (i=s.length; i>=0; i--)
	{
		if (s.charAt(i-1) == ' ')
			continue;
		else 
		{
			to_pos = i;
			break;
		}
	}	

	t = s.substring(from_pos, to_pos);
	//				alert(from_pos + ',' + to_pos + ',' + t+'.');
	return t;
}

// ÆùÆ® Å©°Ô
function font_add(){
	font += 1;
	if(font > 30){
		font = 30;
	}

	if(document.all.news_article){
		document.all.news_article.style.fontSize=font;
	}				
}
// ÆùÆ® ÀÛ°Ô
function font_minus(){
	font -= 1;

	if(font<12){
		font = 12;
	}
	
	if(document.all.news_article){
		document.all.news_article.style.fontSize=font;
	}	
}

// ÀÚ¹Ù½ºÅ©¸³Æ®·Î PHPÀÇ number_format Èä³»¸¦ ³¿
// ¼ýÀÚ¿¡ , ¸¦ Ãâ·Â
function number_format(data) 
{
	
    var tmp = '';
    var number = '';
    var cutlen = 3;
    var comma = ',';
    var i;
   
    len = data.length;
    mod = (len % cutlen);
    k = cutlen - mod;
    for (i=0; i<data.length; i++) 
	{
        number = number + data.charAt(i);
		
        if (i < data.length - 1) 
		{
            k++;
            if ((k % cutlen) == 0) 
			{
                number = number + comma;
                k = 0;
			}
        }
    }

    return number;
}

// »õ Ã¢
function popup_window(url, winname, opt)
{
    window.open(url, winname, opt);
}


// Æû¸ÞÀÏ Ã¢
function popup_formmail(url)
{
	opt = 'scrollbars=yes,width=417,height=385,top=10,left=20';
	popup_window(url, "wformmail", opt);
}

// Å«ÀÌ¹ÌÁö Ã¢
function popup_large_image(it_id, img, width, height, cart_dir)
{
	var top = 10;
	var left = 10;
	url = "./?doc="+cart_dir+"/largeimage.php&it_id=" + it_id + "&img=" + img;
	width = width + 50;
	height = height + 70;
	opt = 'scrollbars=yes,width='+width+',height='+height+',top='+top+',left='+left;
	popup_window(url, "largeimage", opt);
}

// , ¸¦ ¾ø¾Ø´Ù.
function no_comma(data)
{
	var tmp = '';
    var comma = ',';
    var i;

	for (i=0; i<data.length; i++)
	{
		if (data.charAt(i) != comma)
		    tmp += data.charAt(i);
	}
	return tmp;
}

// »èÁ¦ °Ë»ç È®ÀÎ
function del(href) 
{
    if(confirm("ÇÑ¹ø »èÁ¦ÇÑ ÀÚ·á´Â º¹±¸ÇÒ ¹æ¹ýÀÌ ¾ø½À´Ï´Ù.\n\nÁ¤¸» »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) 
        document.location.href = href;
}

// ÄíÅ° ÀÔ·Â
function set_cookie(name, value, expirehours) 
{
	var today = new Date();
	today.setTime(today.getTime() + (60*60*1000*expirehours));
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
}

// ÄíÅ° ¾òÀ½
function get_cookie(name) 
{
    var find_sw = false;
    var start, end;
    var i = 0;

	for (i=0; i<= document.cookie.length; i++)
	{
		start = i;
		end = start + name.length;

		if(document.cookie.substring(start, end) == name) 
		{
			find_sw = true
			break
		}
	}

    if (find_sw == true) 
	{
        start = end + 1;
        end = document.cookie.indexOf(";", start);

        if(end < start)
            end = document.cookie.length;

        return document.cookie.substring(start, end);
    }
    return "";
}

// ÄíÅ° Áö¿ò
function delete_cookie(name) 
{
	var today = new Date();

	today.setTime(today.getTime() - 1);
	var value = getCookie(name);
	if(value != "")
		document.cookie = name + "=" + value + "; path=/; expires=" + today.toGMTString();
}

// ¿ìÆí¹øÈ£ Ã¢
function popup_zip(frm_name, frm_zip1, frm_zip2, frm_addr1, frm_addr2, dir, top, left)
{
    url = './?doc='+dir+'/mbzip.php&frm_name='+frm_name+'&frm_zip1='+frm_zip1+'&frm_zip2='+frm_zip2+'&frm_addr1='+frm_addr1+'&frm_addr2='+frm_addr2;
    opt = 'scrollbars=yes,width=417,height=250,top='+top+',left='+left;
    window.open(url, "mbzip", opt);
}

// a ÅÂ±×¿¡¼­ onclick ÀÌº¥Æ®¸¦ »ç¿ëÇÏÁö ¾Ê±â À§ÇØ
function winopen(url, name, option)
{
    window.open(url, name, option);
    return ;
}

// TEXTAREA »çÀÌÁî º¯°æ
function textarea_size(fld, size)
{
	var rows = parseInt(fld.rows);

	rows += parseInt(size);
	if (rows > 0) {
		fld.rows = rows;
	}
}

var old='';
function menu(name){

	submenu=eval(name+".style");

	if (old!=submenu)
	{
		if(old!='')
		{
			old.display='none';
		}
		submenu.display='block';
		old=submenu;
	}
	else
	{
		submenu.display='none';
		old='';
	}
}

// 3.36
function image_window(img, w, h)
{
    var tmp_w = w;
    var tmp_h = h;
    winl = (screen.width-w)/2;
    wint = (screen.height-h)/3;

    if (w >= screen.width) {
        winl = 0;
        w = screen.width - 10;
        h = (parseInt)(w * (h / w));
    }

    if (h >= screen.height) {
        wint = 0;
        h = screen.height - 80;
        w = (parseInt)(h * (w / h));
    }

    var settings  ='width='+w+',';
        settings +='height='+h+',';
        settings +='top='+wint+',';
        settings +='left='+winl+',';
        settings +='scrollbars=no,';
        settings +='resizable=no,';
        settings +='status=no';

    win=window.open("","newWindow",settings);
    win.document.open();
    win.document.write ("<html><head><meta http-equiv='content-type' content='text/html; charset=euc-kr'>");
    win.document.write ("<title>ÀÌ¹ÌÁö º¸±â</title></head>");
    win.document.write ("<body leftmargin=0 topmargin=0>");
    //win.document.write ("<img src='"+img+"' width='"+w+"' height='"+h+"'border=0 onclick='window.close();' style='cursor:hand' title='ÇØ»óµµ ("+tmp_w+"x"+tmp_h+")\nÅ¬¸¯ÇÏ¸é ´ÝÇô¿ä'>");
    win.document.write ("<img src='"+img+"' width='"+w+"' height='"+h+"'border=0 onclick='window.close();' style='cursor:hand'>");
    win.document.write ("</body></html>");
    win.document.close();

    if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function updateChar(length_limit)
{
	var cmt_content='';
	cmt_content = eval("document.cmtform.cmt_content");
	var form = document.cmtform;
	var length = calculate_msglen(cmt_content.value);
	document.getElementById("textlimit").innerHTML = length;
	if (length > length_limit) {
		alert("ÃÖ´ë " + length_limit + "byteÀÌ¹Ç·Î ÃÊ°úµÈ ±ÛÀÚ¼ö´Â ÀÚµ¿À¸·Î »èÁ¦µË´Ï´Ù.");
		cmt_content.value = cmt_content.value.replace(/\r\n$/, "");
		cmt_content.value = assert_msglen(cmt_content.value, length_limit, 1);
	}
}
function re_updateChar(length_limit, formname)
{
	var cmt_content='';
	cmt_content = eval("formname.cmt_content");
	var length = calculate_msglen(cmt_content.value);
	if (length > length_limit) {
		alert("ÃÖ´ë " + length_limit + "byteÀÌ¹Ç·Î ÃÊ°úµÈ ±ÛÀÚ¼ö´Â ÀÚµ¿À¸·Î »èÁ¦µË´Ï´Ù.");
		cmt_content.value = cmt_content.value.replace(/\r\n$/, "");
		cmt_content.value = assert_msglen(cmt_content.value, length_limit, 0);
	}
}
function calculate_msglen(message)
{
	var nbytes = 0;

	for (i=0; i<message.length; i++) {
		var ch = message.charAt(i);
		if(escape(ch).length > 4) {
			nbytes += 2;
		} else if (ch == '\n') {
			if (message.charAt(i-1) != '\r') {
				nbytes += 1;
			}
		} else if (ch == '<' || ch == '>') {
			nbytes += 4;
		} else {
			nbytes += 1;
		}
	}

	return nbytes;
}
function assert_msglen(message, maximum, print_msg)
{
	var inc = 0;
	var nbytes = 0;
	var msg = "";
	var msglen = message.length;

	for (i=0; i<msglen; i++) {
		var ch = message.charAt(i);
		if (escape(ch).length > 4) {
			inc = 2;
		} else if (ch == '\n') {
			if (message.charAt(i-1) != '\r') {
				inc = 1;
			}
		} else if (ch == '<' || ch == '>') {
			inc = 4;
		} else {
			inc = 1;
		}
		if ((nbytes + inc) > maximum) {
			break;
		}
		nbytes += inc;
		msg += ch;
	}
	if(print_msg) {
    	document.getElementById("textlimit").innerHTML = nbytes;
	}
	return msg;
}

function hideComment(hideobj,hideimg)
{
    var ho = eval('document.getElementById(\''+hideobj+'\')');
	var himg = eval('document.getElementById(\''+hideimg+'\')');
	if (ho.style.display == "none")
	{
	    ho.style.display = "block";
		himg.src = "http://img.empas.com/ni/comment/reply_comment_hide.gif";
	}
	else
	{
	    ho.style.display = "none";
		himg.src = "http://img.empas.com/ni/comment/reply_comment_view.gif";
	}
}

function ShowContents(obj,idx)
{
    var showobj = obj+idx;
	var ho = eval('document.getElementById(\''+showobj+'\')');
	if (ho.style.display == "none")
	{
	    ho.style.display = "block";
		//Á¦¸ñ boldÃ³¸®
		if ( obj == "commentlayer" ) {
		    Sobj = "summary"+idx
			var sho = eval('document.getElementById(\''+Sobj+'\')');
			sho.style.fontWeight="bold"
		}
	} 
	else {
	    ho.style.display = "none";
		if ( obj == "commentlayer" ) {
		Sobj = "summary"+idx
		var sho = eval('document.getElementById(\''+Sobj+'\')');
		sho.style.fontWeight="normal"
		}
	}
	//Á¦¸ñ ´ÝÀ»¶§ ´ä±Û Ã¢µµ °°ÀÌ ´ÝÀ½
	if (showobj.indexOf('commentlayer') != -1) {
	    showobj = "Relayer"+idx
		var ho = eval('document.getElementById(\''+showobj+'\')');
		if (ho.style.display != "none") {
    		ho.style.display = "none";
		}
	}
}

function ShowReply(obj) 
{
    var showobj = obj;
	var ho = eval('document.getElementById(\''+showobj+'\')'); 
	if (ho.style.display == "none") 
	{
	    ho.style.display = "block"; 
	} 
	else 
	{   
	    ho.style.display = "none"; 
	}
	try {
	    parent.syncHeight("showBody");
	} 
	catch ( err ) 
	{
	}
}  
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();
}
MM_reloadPage(true);

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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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];}
}
    // ÀÌ¹ÌÁö¸¦ º¸´Â ½ºÅ©¸³Æ® ÀÏÁ¤½Ã°£ÀÌ Áö³ª¸é ÀÌ¹ÌÁö°¡ »ç¶óÁü
    var timeinterval = 3; // ÃÊ 
    var IE = document.all?true:false;
    if (!IE) document.captureEvents(Event.MOUSEMOVE)
    document.onmousemove = getMouseXY;
    var tempX = 0;
    var tempY = 0;
    var prevdiv = null;
    var timerID = null;
    
    function getMouseXY(e)
    {
        if (IE) { // grab the x-y pos.s if browser is IE
            tempX = event.clientX + document.body.scrollLeft;
            tempY = event.clientY + document.body.scrollTop;
        } else {  // grab the x-y pos.s if browser is NS
            tempX = e.pageX;
            tempY = e.pageY;
        }   
        
        if (tempX < 0) {tempX = 0;}
        if (tempY < 0) {tempY = 0;}
        
        return true;
    }   
    
    function imageview(name, w, h)
    {
    
        menu(name);
        
        submenu = eval(name+".style");
        submenu.posLeft = tempX - ( w + 11 );
        submenu.posTop  = tempY - ( h / 2 );
    }   
    
    function help(name, left, top)
    {
        menu(name);

        submenu = eval(name+".style");
        submenu.posLeft = tempX - 50 + left;
        submenu.posTop  = tempY + 15 + top;
    }

function setCookie(name,value,expires) { 
    document.cookie=name + "=" + escape(value) + ((expires == null)? "" : (" ; expires=" + expires.toGMTString())); 
}

function getCookie(name) { 
    var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 

	while(i< clen) { 
	    var j = i + alen; 
		if(document.cookie.substring(i,j)==arg) { 
		  var end = document.cookie.indexOf(";",j); 

		  if(end == -1) end = document.cookie.length;
		    return unescape(document.cookie.substring(j,end));
		} 
		i=document.cookie.indexOf(" ",i)+1; 
		
		if (i==0) break; 
	} 
	return null; 
}

var fontSize = parseInt(getFontCookie());

function getFontCookie() { 
    var cookie = getCookie("news_font_size"); 
	if ( cookie == null ) return 12; 
	if ( cookie.length ) return cookie; 
	else return 12; 
}

function scaleFont(val) {
    var content, lineHeight; 
	content = document.getElementById("news_content"); 
	if (val > 0) {
	    if (fontSize <= 24) { 
		  fontSize = fontSize + val; 
		  lineHeight = fontSize+Math.round(1.1*fontSize); 
		  news_content.style.fontSize = fontSize + "px";
		} 
	} 
	else { 
	    if (fontSize > 8) {
		  fontSize = fontSize + val; 
		  lineHeight = fontSize+Math.round(1.1*fontSize); 
		  news_content.style.fontSize = fontSize + "px"; 
		}
	} 
	var mydate = new Date; 
	mydate.setDate(mydate.getDate()+1000); 
	setCookie("news_font_size", fontSize, mydate);
}

function flash_tag(f_name, f_id, f_width, f_height, wmode) {
        document.write("<OBJECT id='"+f_id+"' codeBase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0 height='"+f_height+"' width='"+f_width+"' align=middle classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000>");
		document.write("<PARAM NAME='allowScriptAccess' VALUE='always'>");
		document.write("<PARAM NAME='movie' VALUE='"+f_name+"'>");
		document.write("<PARAM NAME='wmode' VALUE='"+wmode+"'>");
		document.write("<PARAM NAME='quality' VALUE='high'>");
		document.write("<PARAM NAME='bgcolor' VALUE='#ffffff'>");
		document.write("</OBJECT>");
}

function flash_weather() {
        document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' WIDTH='120' HEIGHT='55' id='naver' ALIGN=''>");
		document.write("<PARAM NAME=movie VALUE='http://weather.naver.com/newsnaver.swf?Data_File=http://weather.naver.com/newsnaver_data.txt'>");
		document.write("<PARAM NAME=quality VALUE=high>"); 
		document.write("<EMBED src='http://weather.naver.com/newsnaver.swf' quality=high bgcolor=#FFFFFF  WIDTH='120' HEIGHT='55' NAME='naver' ALIGN='' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED>"); 
		document.write("</OBJECT>");
}