/* UI.js :: ver20071126 */
var UI={
	_browser : null
};
Object.extend=function(a, b){
  for (var property in b) a[property] = b[property];
  return a;
};

UI.$=function(s) { return document.getElementById(s) };
UI.trim=function(s) {return s.replace(/(^\s*)|(\s*$)/g, "") };
UI.toogle=function(id) { UI.$(id).style.display=(UI.getStyle(UI.$(id),'display')=='none') ? 'block':'none' };
UI.getEl=function(e){var E=UI.getE(e);return E.target || E.srcElement}
UI.getE=function(e){return e || window.event}
UI.random=function(min, max){ return Math.floor(Math.random() * (max - min + 1) + min) };
UI.addEvent=function(object, type, listener) {	
	if(object.addEventListener) {if(type=='mousewheel')type='DOMMouseScroll'; object.addEventListener(type, listener, false)}
	else { object.attachEvent("on"+type, listener); }
};
UI.delEvent=function(object, type, listener){
	if (object.removeEventListener) {if(type=='mousewheel')type='DOMMouseScroll'; object.removeEventListener(type, listener, false)}
	else object.detachEvent('on'+type, listener);
};
UI.stopEvent=function(event) {
	var e=event || window.event;
	if(e.preventDefault) {e.preventDefault(); e.stopPropagation(); }
	else {e.returnValue = false; e.cancelBubble = true;}
};
UI.getEventWheel=function(e){
	var delta=0;
	if(e.wheelDelta) delta=e.wheelDelta/120;
	else if(e.detail) delta=-e.detail/3;
	return delta;
};
UI.getBrowser=function(){
	var ua=navigator.userAgent.toLowerCase();
	var opera=/opera/.test(ua)
	UI._browser={
		ie:!opera && /msie/.test(ua),
		ie_ver: parseFloat(((ua.split('; '))[1].split(' '))[1]),
		opera:opera,
		ff:/firefox/.test(ua),
		gecko:/gecko/.test(ua)		
	};
	return UI._browser;
};
UI.resizeIframe=function(iframe_id) {
	var h = (self.innerHeight) ? document.documentElement.offsetHeight : document.body.scrollHeight;
	try{parent.document.getElementById(iframe_id).style.height = h+"px";}catch(e){}
};
UI.rollOver=function(s) {
	var img=(typeof(s)=="string") ? img=UI.$(s):s;
	img.onmouseover=function() { UI.rollOver.over(img) }
	img.onmouseout=function() { UI.rollOver.out(img) }
}
UI.rollOver.over=function(img){ var src=img.src; img.src=src.replace("_off.","_on."); }
UI.rollOver.out=function(img){ var src=img.src; img.src=src.replace("_on.","_off."); };

UI.popUp=function(url,name,w,h,scroll,resize,status,center){
	if(!scroll) scroll=0;
	if(!resize) resize=0;
	if(!status) status=1;
	if(center)	
	{
		var x = (screen.width - w) / 2;
		var y = (screen.height - h) / 2;
		center = ",top="+y+",left="+x;
	}
	return window.open(url,name,"width="+w+",height="+h+",status="+status+",resizable="+resize+",scrollbars="+scroll+center);
};
UI.setCookie=function(name,value,expires){
	var d = new Date();	var day="";
	if(expires)
	{
		d.setDate(d.getDate()+expires);
		day = "expires="+d.toGMTString()+";";
	}
	document.cookie = name+"="+escape(value)+"; path=/;"+day;
};
UI.getCookie=function(name){
	name += "=";
	cookie = document.cookie + ";";
	start = cookie.indexOf(name);
	if (start != -1)
	{
		end = cookie.indexOf(";",start);
		return unescape(cookie.substring(start + name.length, end));
	}
	return "";
};
UI.embedSWF=function(f,w,h,options){
	var param={	id:"UIswf_"+f,quality:'high',bgcolor:'#ffffff',allowScriptAccess:'always'}
	Object.extend(param, options);

	var id='id="'+param.id+'"';
	var name = 'name="'+param.id+'"';
	var p='',e='';	

	for(i in param) 
	{
		if(i=='id')continue;
		p+='<param name="'+i+'" value="'+param[i]+'">\n';
		e+=i+'="'+param[i]+'" ';
	}

	var s='<object '+id+' width="'+w+'" height="'+h+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">';
	s+='<param name="movie" value="'+f+'">'+ p;	
	s+='<embed '+name+' src="'+f+'" width="'+w+'" height="'+h+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" '+e+'/>';
	s+='</object>';
	document.write(s);
	return s;
};
UI.embedWMP=function(f,w,h,options){
	var param={	id:"UIwmp_"+f,autostart:'1',showstatusbar:'-1',transparentatstart:'1',displaybackcolor:'0',uimode:'full'}
	Object.extend(param, options);

	var id='id="'+param.id+'" name="'+param.id+'"';
	var p='',e='';
	for(i in param) 
	{
		if(i=='id')continue;
		p+='<param name="'+i+'" value="'+param[i]+'">\n';
		e+=i+'="'+param[i]+'" ';
	}
	var s='<object '+id+' width="'+w+'" height="'+h+'" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" style="filter:gray();">';
	s+='<param name="filename" value="'+f+'">'+ p;
	s+='<embed '+id+' src="'+f+'" width="'+w+'" height="'+h+'" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaplayer/" '+e+' />';
	s+='</object>';
	document.write(s);
};
UI.getStyle=function(el, style) {
	var value = el.style[style];
	if(!value)
	{
		if(document.defaultView && document.defaultView.getComputedStyle) 
		{
			var css = document.defaultView.getComputedStyle(el, null);
			value = css ? css[style] : null;
		} 
		else if (el.currentStyle) value = el.currentStyle[style];
	}
	return value == 'auto' ? null : value;
};
UI.getPosition=function(el)
{
	var left=0,top=0;
	while(el)
	{
		left+=el.offsetLeft || 0;
		top+=el.offsetTop || 0;
		el=el.offsetParent;
	}
	return {'x': left, 'y': top}
};
UI.getScroll=function () {
	if(document.all && typeof document.body.scrollTop != "undefined")
	{
		var cont=document.compatMode!="CSS1Compat"?document.body:document.documentElement;
		return {left:cont.scrollLeft, top:cont.scrollTop, width:cont.clientWidth, height:cont.clientHeight}
	}
	else 
		return {left:window.pageXOffset, top:window.pageYOffset, width:window.innerWidth, height:window.innerHeight}
};
UI.submit=function(f) { 
	var form=UI.$(f)||document.forms[f];	
	if(form.onsubmit && !form.onsubmit()) return;
	form.submit();
};
UI.focus=function(n) { 
	var s=null;
	s = UI.$(n)||document.getElementsByName(n)[0];
	s.focus();
};
UI.$F=function(n) {
	var s=null;
	s = UI.$(n)||document.getElementsByName(n)[0];
	if(s.type=="checkbox")
	{
		var c=[];
		var r=document.getElementsByName(n);
		for(var i=0;i<r.length; i++) if(r[i].checked) c.push(r[i].value);
		return (c.length>0)?c:"";
	}
	else if(s.type=="radio")
	{
		var r=document.getElementsByName(n);
		for(var i=0;i<r.length; i++) if(r[i].checked) return r[i].value;
		return "";
	}
	return s.value;
};
UI.length=function(str,len,tail){
	if(!tail) tail="";
	str=UI.html2str(str);
	var l=0, c=0, l2=0, u="", s="";
	if(len>0) l2=len;	
	for(var i=0;u=str.charCodeAt(i);i++)
	{
		if (u>127) l+=2;
		else l++;
		if(l2) {
			s+=str.charAt(i); 
			if(l>=l2)
			{
				if(l>l2) s=s.substring(0,l2-1);
				return s+tail;
			}
		}		
	}
	return l2 ? s:l;
};
UI.html2str=function(s,m){
	var s1=["&amp;","&#39;","&quot;","&lt;","&gt;"];
	var s2=["&","'","\"","<",">"];
	var s3=[];
	if(m) {s3=s1;s1=s2;s2=s3;}
	for(var i in s1) s=s.replace(new RegExp(s1[i],"g"), s2[i]);
	return s;
};
UI.setOpacity=function(el,value){
	el.style.filter="alpha(opacity="+value+")";
	el.style.opacity=(value/100);
	el.style.MozOpacity=(value/100);
	el.style.KhtmlOpacity=(value/100);
};
UI.indexOf=function(arr,s){
	for(var i=0;i<arr.length; i++) if(arr[i]==s) return i;
	return -1;
};
UI.resizeImage=function(img,w,h){
	var t = new Image();
	t.src=img.src;	
	if(t.width==0 || t.height==0) return;
	if(t.width>w || t.height >h)
	{
		img.width=w;img.height=h;
		if((t.width/w) > (t.height/h) )	img.height=Math.round(t.height * (w / t.width));
		else img.width = Math.round(t.width *  (h / t.height));
	}
	else
	{
		img.width=t.width;
		img.height=t.height;
	}
	if(img.width==0 || img.height==0) setTimeout(function(){UI.resizeImage(img,w,h)},500);
};
UI.StringBuffer=function(){this.buffer=new Array()}
UI.StringBuffer.prototype={append:function(s){this.buffer.push(s)},toString:function(){return this.buffer.join("")}};
UI.parseQuery=function(){
	var r=[],t=[];
	var a=location.search.substr(1).split('&');
	for(i=0;i<a.length;i++){t=a[i].split("=");r[t[0]] = t[1];}
	return r;
};

/* UI.toolTip : 2008-02-11 :: modify by ezsharp  */
UI.toolTip=function(event, options) {
	var e=event || window.event;
	var el= e.target || e.srcElement;

	el.options={
		className:'UItoolTip',
		mousemove:UI.toolTip.mousemove
	};
	Object.extend(el.options, options);

	if(!el.UItoolTip) 
	{
		el.stitle = el.alt || el.title || el.stitle;
		el.title = el.alt = "";
		if(!el.stitle) return;
		
		var d = document.createElement("DIV");		
		d.className = el.options.className;
		d.style.position="absolute";	
		UI.$('JESToolTip').appendChild(d);
		
		el.UItoolTip=d;
		el.UItoolTip.innerHTML=el.stitle;
	}
	var scroll = UI.getScroll();

  if(el.options.layerFixed) {
    if(el.options.isvsRight) //Type = vs
      var x = getAbsoluteLeft(el) - 298 + "px";
    else
      var x = getAbsoluteLeft(el) + "px";
    var y = getAbsoluteTop(el) + el.offsetHeight + 8 + "px";
  } else {
  	var x = (e.clientX+scroll.left+10) + "px";
    var y = (e.clientY+scroll.top+10) + "px";
  }

	
	el.UItoolTip.style.left = x;
	el.UItoolTip.style.top =  y;
	el.UItoolTip.style.visibility="visible";

	UI.addEvent(el,'mouseout',UI.toolTip.mouseout);
	if(el.options.mousemove) UI.addEvent(document, "mousemove", el.options.mousemove);
}

document.write('<div id="JESToolTip"></div>');
UI.toolTip.seq = 1;
UI.toolTip.mousemove=function(event){
	var e=event || window.event; var el= e.target || e.srcElement;
	var scroll = UI.getScroll();
	el.UItoolTip.style.left=(e.clientX+scroll.left)+"px";
	el.UItoolTip.style.top=(e.clientY+scroll.top+20)+"px";
};
UI.toolTip.mouseout=function(event){
	var e=event || window.event; var el= e.target || e.srcElement;
	if(!el.UItoolTip) return;
	el.UItoolTip.style.visibility="hidden";
	if(el.options.mousemove) UI.delEvent(document, "mousemove",  el.options.mousemove);	
};

/* UI.ByteChecker.js */
UI.ByteChecker=function(id,len){
	this.input = UI.$(id);
	this.cid=id;
	this.len=len;
	var self=this;
	UI.addEvent(this.input,'keyup', function(){self.check()})
}
UI.ByteChecker.prototype={
	check:function(){		
		var el=this.input;
		var len = UI.length(el.value);
		if(len > this.len)
		{
			alert("최대 "+this.len+"Bytes까지 가능합니다. 초과된 내용은 자동으로 삭제됩니다.");
			this.input.focus();
			el.value=UI.length(el.value, this.len -1);
			len=this.len;
		}
		UI.$(this.cid+"_byteinfo").innerHTML = len;		
	}
}


/* netucc Function */
function goTop() {
	parent.window.scrollTo(0,0);
}

function clearbg(id){
	document.getElementById(id).style.backgroundImage='none';
}

function searchSubmitForm(formEl) {
	var errorMessage = null;
	var objFocus = null;
	if (formEl.searchInput.value.length == 0 || UI.trim(formEl.searchInput.value)=="") {
		errorMessage = "검색어를 넣어주세요.";
		objFocus = formEl.searchInput;
	}
	if(errorMessage != null) {
		alert(errorMessage);
		objFocus.focus();
		return false;
	}
	topUrl = parent.document.location.href;

	if(topUrl.indexOf("&allComment=T") > 0)
		topUrl = topUrl.substring(0,topUrl.indexOf("&allComment=T"));
	topUrl = removeIfUrlText(topUrl,"&cSearchKey=");
	topUrl = removeIfUrlText(topUrl,"&cSearchValue=");
	topUrl = removeIfUrlText(topUrl,"&cSearchName=");
	topUrl = removeIfUrlText(topUrl,"&cSortKey=");
	parent.document.location.href = topUrl+"&allComment=T&cPageIndex=1&cSearchKey="+formEl.cSearchKey.value+"&cSearchValue="+encodeURIComponent(formEl.cSearchValue.value)+"&cSearch=search";
	return false;
}

function pop_self(){ //본인클릭시
  alert("본인의 글은 추천할 수 없습니다")
}

// 댓글 쓰기
function writeCommentSubmit(formEl, vsYN) {
	var errorMessage = null;
	var objFocus = null;
	var cmtTitle = document.getElementById("cmtTitle");
	var cmtText = document.getElementById("cmtText");

  if (cmtTitle.value.length == 0 || UI.trim(cmtTitle.value)=="") {
      errorMessage = "제목을 넣어주세요.";
      objFocus = cmtTitle;
  }else if (cmtText.value.length == 0 || UI.trim(cmtText.value)=="") {
    errorMessage = "내용을 넣어주세요.";
    objFocus = cmtText;
  }
  if(vsYN) {
	var cmtRadio1 = document.getElementById("objCate1");
	var cmtRadio2 = document.getElementById("objCate2");
   
   if (cmtRadio1.checked == false && cmtRadio2.checked == false) {
    errorMessage = "대결선택해주세요.";
    objFocus = cmtRadio1;
    }
  }

  if(errorMessage != null) {
    alert(errorMessage);
    objFocus.focus();
    return false;
  }	
	return true;
}
//WebMan
var webManCode = "D_WEBMAN_MEDIA";
function startpage() {
    try {
        document.domain = 'daum.net';
        if (typeof __webmanFrame !== 'undefined' && typeof __webmanFrame.setDaumHome === 'function') {
             __webmanFrame.setDaumHome(webManCode); // default 'webman' 
        }
    } catch(e) {  }
}
function setWebManCode(code){
	webManCode = code;
}

function toggleCmtOpt (urlInfo) {
	location.href=urlInfo
}

function commentListResize(){
if(parent.document.getElementById('netUCC100')) {
	var pBody = parent.document.body;
	var oBody = document.body;
	oBody.style.top='0';
	var height, width;
	if (navigator.userAgent.indexOf("MSIE") == -1) {
		height=oBody.scrollHeight;
	} else {
		height=oBody.scrollHeight+oBody.offsetHeight-oBody.clientHeight;
	}
	parent.document.getElementById('netUCC100').height=height;
}
}

function removeIfUrlText(fullurl,findtext,replace) {
  if(fullurl.indexOf(findtext) > 0) {
    temp1 = fullurl.substring(0,fullurl.indexOf(findtext))
    temp2 = fullurl.substring(fullurl.indexOf(findtext),fullurl.length)
    if(temp2.indexOf("&") == 0) {
      amp = true;
      temp2 = temp2.substring(1,temp2.length);
    }       
    if(temp2.indexOf("&") > 0) {
      fullfindtext = temp2.substring(0,temp2.indexOf("&"));
    }else{
      fullfindtext = temp2.substring(0,temp2.length);
    }
    if(amp==true)
    fullfindtext = "&"+fullfindtext;

    if(replace) {
      if(fullfindtext.indexOf("=")>0) {
      findtextValue = fullfindtext.substring(fullfindtext.indexOf("=")+1,fullfindtext.length);
      fullurl = fullurl.replace(fullfindtext,findtext+replace);
      }
    } else
    fullurl = fullurl.replace(fullfindtext,"");
  }
    return fullurl;
}
/*
goList = function(listPageIndex) {
  topUrl = parent.location.href;
  if(topUrl.indexOf("&cView")>0){
    topUrl = removeIfUrlText(topUrl,"&cView=");
    topUrl = removeIfUrlText(topUrl,"&listPageIndex=");
    topUrl = removeIfUrlText(topUrl,"&cPageIndex=");
	if(listPageIndex)  topUrl = topUrl + "&cPageIndex="+listPageIndex;
    top.location.href="topUrl";
  }
}*/

paging = function(replaceNum) {
	topUrl = parent.document.location.href;
	if(topUrl.indexOf("?")<0)
		topUrl = topUrl + "?";
	if(topUrl.indexOf("&cPageIndex=")>0){
		topUrl = removeIfUrlText(topUrl,"&cPageIndex=",replaceNum);
	}else
		topUrl = topUrl + "&cPageIndex=" + replaceNum;
	top.location = topUrl;

}

/* NetUcc>>>Textarea Resizing */
UI.TextareaResize=function(id,min,max){
  this.input = UI.$(id);
  var self=this;
  if (navigator.userAgent.indexOf("MSIE") == -1) {
	this.input.style.overflowY = "auto";	
  }else{
	UI.addEvent(this.input,'keyup', function(){ self.resize(min,max) })
  }  
}
UI.TextareaResize.prototype={
  resize:function(min,max){
      textarea = this.input;
      scrollheight = textarea.scrollHeight;  
      if(scrollheight<min) {
        textarea.style.height = min;
        textarea.style.overflowY = "hidden";
      }else if(scrollheight>max){
        textarea.style.height = max;
        textarea.style.overflowY = "auto";	
      }else{
        textarea.style.height = scrollheight + 2;
        textarea.style.overflowY = "hidden";
		topUrl = parent.document.location.href;
		if(topUrl.indexOf("rhea") < 0) commentListResize();
      }
  }
}


/* show Name Layer */
var Browser = new Object();
var clickAreaCheck = false;

//Browser.isMozilla = (typeof doc-ument.implementation != 'undefined') && (typeof doc-ument.implementation.createnull != 'undefined') && (typeof HTMLnull!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);

function showNameLayer(curObj, link1, pos) {
  clickAreaCheck = true;
  url = "http://media.daum.net/netizen/myreply/index.html?pageIndex=1" + link1
  var str = "<div class='nLayer' onMouseOver=this.style.backgroundColor='#f1f1f1' onMouseOut=this.style.backgroundColor='#ffffff'><a href="+url+" target='_parent'>다른 글 보기</a></div>";
  setLayersPosition(curObj, str, "nameLayer", pos);
}

function daum_paging_rollover(obj, img, type) {
	var imgurl = "http://image.hanmail.net/hanmail/2006_ui/";
	var tmp
	if (type == "on") {
		obj.src = imgurl + img + "_over.gif";
	} else {
		obj.src = imgurl + img + ".gif";
	}
}	

function setLayersPosition(curObj, str , layername, pos) {
  var name = layername;
  if (!document.getElementById(name)) {
	var cElement = document.createElement("DIV");
	cElement.id = name;
	cElement.style.position = 'absolute';
	cElement.style.zIndex = 50;
	document.body.appendChild(cElement);
  }
  document.getElementById(name).style.top = getAbsoluteTop(curObj) + curObj.offsetHeight + 2 + "px";
  if(pos == "r")
   document.getElementById(name).style.left = getAbsoluteLeft(curObj) + "px";
  else if(pos == "s")
   document.getElementById(name).style.left = getAbsoluteLeft(curObj)-44 + "px";
  else if(pos == "p")
   document.getElementById(name).style.left = getAbsoluteLeft(curObj) + "px";
  else
   document.getElementById(name).style.left = getAbsoluteLeft(curObj)+17 + "px";
  
  document.getElementById(name).innerHTML = str;
  divDisplay(name, 'block');
}

function divDisplay(objId, act) {		
  if (document.getElementById(objId)) {
	document.getElementById(objId).style.display = act;
  }
}

document.onclick = function() {
  if (!clickAreaCheck) {
	if(document.getElementById("nameLayer")) {
	  divDisplay ("nameLayer", 'none');
	}
  } else clickAreaCheck = false;
}

// 절대 높이 계산
function getAbsoluteTop(oNode){
  var oCurrentNode=oNode;
  var iTop=0;
  while(oCurrentNode.tagName!="BODY"){
	if(oCurrentNode.tagName=="HTML")break;
	iTop+=oCurrentNode.offsetTop;
	oCurrentNode=oCurrentNode.offsetParent;
  }
  return iTop;
}
// 절대 좌측 계산
function getAbsoluteLeft(oNode){
  var oCurrentNode=oNode;
  var iLeft=0;
  while(oCurrentNode.tagName!="BODY"){
	if(oCurrentNode.tagName=="HTML")break;
	iLeft+=oCurrentNode.offsetLeft;
	oCurrentNode=oCurrentNode.offsetParent;
  }
  return iLeft;
}