
/* browser */

var browser = {
  detect:function(){
    var UA = navigator.userAgent;
    this.isGecko = (/Gecko/.test(UA) && !this.isKHTML);
    this.isOpera = /Opera/.test(UA);
    this.isMSIE  = (/MSIE/.test(UA) && !this.isOpera);
  }
}

browser.detect();

if (browser.isGecko)
{
	var _emptyTags = {
	   "IMG":   true,
	   "BR":    true,
	   "INPUT": true,
	   "META":  true,
	   "LINK":  true,
	   "PARAM": true,
	   "HR":    true
	};

	HTMLElement.prototype.__defineGetter__("outerHTML", function () {
	   var attrs = this.attributes;
	   var str = "<" + this.tagName;
	   for (var i = 0; i < attrs.length; i++)
		  str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";

	   if (_emptyTags[this.tagName])
		  return str + ">";

	   return str + ">" + this.innerHTML + "</" + this.tagName + ">";
	});

	HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
	   var r = this.ownerDocument.createRange();
	   r.setStartBefore(this);
	   var df = r.createContextualFragment(sHTML);
	   this.parentNode.replaceChild(df, this);
	});
}

/* cookie */

function getCookie( cookieName )
 {
  var search = cookieName + "=";
  var cookie = document.cookie;

  if( cookie.length > 0 )
  {
   startIndex = cookie.indexOf( cookieName );
   
   if( startIndex != -1 )
   {
    startIndex += cookieName.length;    
    endIndex = cookie.indexOf( ";", startIndex );
   
    if( endIndex == -1) endIndex = cookie.length;

    return unescape( cookie.substring( startIndex + 1, endIndex ) );
   }
   else
   {

    return false;
   }
  }
  else
  {
   return false;
  }
 }

 function setCookie( cookieName, cookieValue )
 {
	 var expiredays = 365;
	 var exdate=new Date() ;
     exdate.setDate(exdate.getDate()+expiredays);


	 document.cookie = cookieName + "=" + escape( cookieValue ) + "; path=/; expires=" + exdate.toGMTString() + ";" 
 }

 function deleteCookie( cookieName )
 {
	var expireDate = new Date();
  
	expireDate.setDate( expireDate.getDate() - 1 );
	document.cookie = cookieName + "= " + "; expires=" + expireDate.toGMTString() + "; path=/";  
 }


/* function list */
function trim( str )
{
	return str.replace(/(^ *)|( *$)/g, "");
}

function fncom_chk_strlength_cut(vn_maxlength, vn_str)
{
 var vn_sumlength=0;
 var vn_restr='';
 for(var i= 0;i < vn_str.length; i++)
 {
  if( escape(vn_str.charAt(i)).length > 3 ) { vn_length = 2; }
  else if (vn_str.charAt(i) == '<' || vn_str.charAt(i) == '>') { vn_length = 4; }
  else { vn_length = 1 ; }
  if ( vn_maxlength < (vn_sumlength + vn_length) ) { break; }
  vn_sumlength += vn_length;
  vn_restr += vn_str.charAt(i);
 }
 return (vn_restr);
}

function shortcut_write( v , length ) {


	var  newtext = fncom_chk_strlength_cut( length, v );

	if ( newtext.length < v.length)
	{
		newtext = newtext  + '..';
	}
	else
	{
		newtext = newtext;
	}

	return newtext;
}


function toggle_div( clickobj, objid ) {
	var obj = document.getElementById( objid );

	if (obj.style.display == "none")
	{
		clickobj.title = "정보 접기";
		obj.style.display = "block";

		setCookie( "cookie_" + objid , "1" );
	}
	else
	{
		clickobj.title = "정보 펼치기";
		obj.style.display = "none";

		setCookie( "cookie_" + objid , "2" );
	}
}

function sidebar_title_getCookie( wrap_name ) {
	var cookie = getCookie("cookie_"+wrap_name);
	var obj = document.getElementById( wrap_name );

	if ( cookie != false )
	{
		if (cookie == "1")
		{
			obj.style.display = "";
		}
		else
		{
			obj.style.display = "none";
		}
	}

}

write_calender = function ( timedata ) {
		timedata += " ";

		var s_arr = timedata.split(" ");
		var y_arr = s_arr[0].split("/");

		var month = "";
		var day = y_arr[2];

		switch(y_arr[1])
		{
			case "01": month = "JAN";
				break;
			case "02": month = "FEB";
				break;
			case "03": month = "MAR";
				break;
			case "04": month = "APR";
				break;
			case "05": month = "MAY";
				break;
			case "06": month = "JUN";
				break;
			case "07": month = "JUL";
				break;
			case "08": month = "AUG";
				break;
			case "09": month = "SEP";
				break;
			case "10": month = "OCT";
				break;
			case "11": month = "NOV";
				break;
			case "12": month = "DEC";
				break;
		}

		document.write("<div class='entry_title_calender_month'>" + month + "</div>");
		document.write("<div class='entry_title_calender_day'>" + day + "</div>");
}

function autoTimeString( str )
{
	if (str < 10)
	{
		str = "0"+str;
	}

	return str;
}

function showNowTime( id )
{	
	var obj = document.getElementById(id);

	var mydate=new Date();

	var year=mydate.getYear();

	if (year < 1000)
		year+=1900;

	var day=mydate.getDay();
	var month=autoTimeString(mydate.getMonth()+1);

	var daym=autoTimeString(mydate.getDate());

	var hours = autoTimeString(mydate.getHours());

	var min =  autoTimeString(mydate.getMinutes());

	var sec = autoTimeString(mydate.getSeconds());

	obj.innerHTML = year+"."+month+"."+daym+" <span class='gray_font'>"+hours+":"+min+":"+sec+"</span>";
	
		
}

function showNowTime_realTime( id )
{
	showNowTime(id);
	setInterval( "showNowTime('"+id+"')" ,  1000 );
}


function swf(src,w,h){
	html = '';
	html += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="param" width="'+w+'" height="'+h+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#ffffff">';
	html += '<param name="swliveconnect" value="true">';
	html += '<param name="wmode" value="transparent">';
	html += '<embed src="'+src+'" quality=high bgcolor="#ffffff" width="'+w+'" height="'+h+'" swliveconnect="true" id="param" name="param" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	html += '<\/object>';
	document.write(html);
}

function swfwrite(id,src,w,h){
	html = '';
	html += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="param" width="'+w+'" height="'+h+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#ffffff">';
	html += '<param name="swliveconnect" value="true">';
	html += '<param name="wmode" value="transparent">';
	html += '<embed src="'+src+'" quality=high bgcolor="#ffffff" width="'+w+'" height="'+h+'" swliveconnect="true" id="param" name="param" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	html += '<\/object>';
	document.getElementById(id).innerHTML = html;
}