//아래 소스는 인스티즈(instiz.net)가 직접 제작한 스크립트입니다. 무단도용을 절대 금합니다.
//Copyright By instiz.net(인스티즈), All rights reserved.

//전체새글
var updatem, udtnow;
function update(){
if(!udtnow)udtnow=0;
var u1=document.getElementById('u1');
var u2=document.getElementById('u2');
var u3=document.getElementById('u3');
var u3b=document.getElementById('u3b');
var uc=document.getElementById('update_con');
var a='../cached/iframe_side';
if(updatem){
uc.innerHTML=ajaxload(a+eval(1+udtnow)+'.php',1);
u3b.className='btnu3';
u3.title='(1/2)';
updatem='';
}else{
uc.innerHTML=ajaxload(a+eval(2+udtnow)+'.php',1);
u3b.className='btnu3o';
u3.title='(2/2)';
updatem=1;
}
if(udtnow==0){
u1.className='btnu1o';
u2.className='btnu2';
}else{
u1.className='btnu1';
u2.className='btnu2o';
}}
function update_go(){
if(GetCookie('updatego')){ udtnow=eval(GetCookie('updatego')); updatem=1; update(); }else document.getElementById('update_con').innerHTML=ajaxload('../cached/iframe_side1.php',1);
}
function udt(no){
if(no==1)udtnow=0; else udtnow=2;
var ExpDate=new Date();
ExpDate.setTime(ExpDate.getTime()+1000*3600*24*7);
SetCookie('updatego',udtnow,ExpDate);
updatem=1;
update();
}

//쇼탭
function showtab(lim,number){
for(var i=1;i<=lim;i++){
var conname="body"+i;
if(i==number){
document.getElementById('tb'+i).className='current';
document.getElementById(conname).style.display="block";
}else{
document.getElementById('tb'+i).className='';
document.getElementById(conname).style.display="none";
}}
return false;
}

//공지
function notice(no){
var m=confirm('다른 공지가 뜰때까지 이 공지를 숨겨두시겠습니까?');
if(m){
var ExpDate=new Date();
ExpDate.setTime(ExpDate.getTime()+1000*3600*24*3); SetCookie(no,1,ExpDate);
document.getElementById('notice').style.display='none';
}}

//선택형embed
function showembed(no){
document.getElementById('embedmark'+no).style.display='none';
document.getElementById('embed'+no).style.display='block';
}

//onload 합치기
function addEvent(obj, type, fn){
if(obj.addEventListener)
obj.addEventListener(type, fn, false);
else if(obj.attachEvent){
obj['e'+type+fn]=fn;
obj[type+fn]=function(){ obj['e'+type+fn]( window.event );}
obj.attachEvent('on'+type, obj[type+fn]);
}}

function checkLength(name,limit){
var re=/\r\n/g;
var note=document.getElementById(name);
var newlineCount=0;

newlineCount=calcNewLine(note.value);
if(note.value.length+newlineCount > limit){
	alert('내용은 '+limit+'자 까지 입력이 가능합니다');
	document.getElementById(name).value = note.value.substring(0,limit-newlineCount);
	newlineCount = calcNewLine(document.getElementById(name).value);
}
document.getElementById('lengths').value=(note.value.length+newlineCount)+'/'+limit;
}
function calcNewLine(str){
var re= /\r\n/g;
var note = str;
var newlineCount = 0;

if(!(re.test(note))){
	var noteReplace = note.replace(/\n/g,'');
	newlineCount = noteReplace.length;
	newlineCount = note.length - newlineCount;
}
return newlineCount;
}

function submenu(mode){
var tg=document.getElementById('subparent');
if(mode==1) tg.style.display='block'; else tg.style.display='none';
}

function op(url,name,width,height,option){
addiction='';
if(width) addiction+='width='+width;
if(height) addiction+=', height='+height;

LeftPosition=(screen.width)?(screen.width-width)/2:0;
TopPosition=(screen.height)?(screen.height-height)/2:0;
if(width||height)addiction+=',';
addiction+='top='+(TopPosition-30)+',left='+(LeftPosition-30);

if(option){ if(width||height)addiction+=','; addiction+=option; }
if(!addiction) addiction='';
if(!name) name='';
window.open(url,name,addiction);
}

function delete_all(id,no){
frm=document.getElementById('list');
if(frm){
gowin=op('about:blank','goadmin',290,330);
if(!no)no='';
frm.action='select_list_all.php?id='+id+'&no='+no;
frm.target='goadmin';
frm.submit();
}else{
gowin=op('../bbs/select_list_all.php?id='+id+'&no='+no,'goadmin',290,330);
}
}

function reverse(){
var i;
for(i=0;i<document.list.length;i++){
if(document.list[i].type=='checkbox'){
if(document.list[i].checked){document.list[i].checked=false;}else{document.list[i].checked=true;}
}}}


//복사
var AutoSourcing = {
  div      : null,
  id       : "",
  timer    : null,
  regex    : null,
  strings  : [],
  skip     : false,
  handlers : {},
  init : function(format, enable) {
    var t = this;
    var n = navigator;
    var is_safari = (n.userAgent.indexOf("WebKit") > -1);
    this.div = document.createElement("div");
    this.div.className = (((/MSIE/.test(n.userAgent)&&!/MSIE 8/.test(n.userAgent))||/Gecko/.test(n.userAgent))&&!is_safari)?"autosourcing-stub":"autosourcing-stub-extra";
    // 임시 아이디 부여
    this.id = "autosourcing_tmp_"+(Math.random()*100000);
    // 형식을 정규식으로 만든다. 일단은 특수문자 처리 생략
    this.regex = new RegExp(format.replace("%id%", "(\\d+)"));
    // bind functions
    this.handlers.copy     = function(){ t.copy() };
    this.handlers.keydown  = function(evt){ t.keydown(evt) };
    this.handlers.keypress = function(evt){ t.keypress(evt) };
    // enable
    if(typeof enable == "undefined") enable = true;
    this.setEnable(enable);
  },
  setEnable : function(bool) {
    if (bool) {
      if (typeof document.body.oncopy != "undefined") {
        // Internet Explorer, Safari
        this.addEvent(document.body, "copy", this.handlers.copy);
      } else {
        this.addEvent(document, "keydown", this.handlers.keydown);
        this.addEvent(document, "keypress", this.handlers.keypress);
        this.addEvent(document, "contextmenu", this.handlers.copy);
      }
    } else {
      if (typeof document.body.oncopy != "undefined") {
        // Internet Explorer, Safari
        this.removeEvent(document.body, "copy", this.handlers.copy);
      } else {
        this.removeEvent(document, "keydown", this.handlers.keydown);
        this.removeEvent(document, "keypress", this.handlers.keypress);
        this.removeEvent(document, "contextmenu", this.handlers.copy);
      }
    }
  },
  getId : function(rng) {
    var range_s, range_e, par, id;
    // 시작노드에 대해서
    range_s = this.cloneRange(rng)
    range_s.collapse(true); // collapse to start point
    par = this.getParentElement(range_s);
    while(par && par.parentNode) {
      if (par.nodeType == 1 && this.regex.test(par.id)) {
        id = parseInt(RegExp.$1);
        return isNaN(id)?0:id;
      }
      par = par.parentNode;
    }
    // 시작노드에 없어? 그럼 끝노드에 대해서
    range_e = this.cloneRange(rng)
    range_e.collapse(false); // collapse to end point
    par = this.getParentElement(range_e);
    while(par && par.parentNode) {
      if (par.nodeType == 1 && this.regex.test(par.id)) {
        id = parseInt(RegExp.$1);
        return isNaN(id)?0:id;
      }
      par = par.parentNode;
    }
    return 0;
  },
  getSelection : function() {
    if (window.getSelection) {
      return window.getSelection();
    } else {
      return document.selection;
    }
  },
  getRange : function(selection) {
    selection = selection || this.getSelection();
    if (selection.getRangeAt) {
      return selection.getRangeAt(0);
    } else {
      return selection.createRange();
    }
  },
  cloneRange : function(rng) {
    rng = rng || this.getRange();
    if (rng.duplicate) {
      return rng.duplicate();
    } else {
      return rng.cloneRange();
    }
  },
  getParentElement : function(range) {
    var par = range.parentElement?range.parentElement():range.commonAncestorContainer;
    if (!par) return null;
    while(par.nodeType != 1) {
      par = par.parentNode;
    }
    return par;
  },
  setString : function(id, sTitle, sName, sLink) {
    var data = { name : sName, link : sLink, title : sTitle };
    this.strings[id] = this._template.replace(/\{(\w+)\}/g,function(m0,m1){
      return data[m1]?data[m1]:"";
    });
  },
  copy : function(evt) {
    var evt    = evt || window.event;
    var self   = this;
    var sel    = this.getSelection();
    var rng    = this.getRange(sel);
    var rngtmp = this.cloneRange(rng);
    var regcopy= /(?:p|<div)[^<>]+class\s*=\s*"?autosourcing\-stub(?:\-extra)?\-saved(?:\b|")/i;
    var regtag = /textarea|input/i;
    var id     = this.getId(rng);
    var node_rng;
    this.skip = false;
    clearTimeout(this.timer);
    if (id == 0) {
      try { this.div.parentNode.removeChild(this.div) }catch(e){};
      return;
    }
    if (evt && evt.srcElement && evt.srcElement.tagName.toUpperCase() == "A") return;
    if(!this.div.innerHTML) this.div.innerHTML = this.strings[id];
    if (window.getSelection) {
      var html = (window.XMLSerializer)?new XMLSerializer().serializeToString(rng.cloneContents()):"";
      if (regcopy.test(html) || regtag.test(rng.commonAncestorContainer.tagName)) {
        this.skip = true;
        return;
      }
      rngtmp.collapse(false);
      rngtmp.insertNode(this.div);
      if (this.div.nextSibling) {
        rng.setEndBefore(this.div.nextSibling);
      } else {
        rng.setEndAfter(this.div);
      }
      sel.removeAllRanges();
      sel.addRange(rng);
    } else if (document.selection) {
      var body = document.body || document.getElementsByTagName("body")[0];
      var div  = document.createElement("div");
      var span = document.createElement("span");
      span.id = this.id;
      if (regcopy.test(rng.htmlText) || regtag.test(rng.parentElement().tagName)) {
        this.skip = true;
        return;
      }
      rngtmp.collapse(false);
      rngtmp.pasteHTML(span.outerHTML+'&nbsp;<a></a>'); // <a>는 노드를 나누기 위해 삽입
      //rngtmp.pasteHTML(span.outerHTML);
      span = document.getElementById(this.id);
      (span || rngtmp.parentElement()).insertAdjacentElement("afterEnd",this.div);
      if(!/MSIE 8/.test(navigator.userAgent)) {
        do {
          rng.moveEnd("character", 1);
          (rngtmp = rng.duplicate()).collapse(false);
        } while(rngtmp.offsetLeft == 0);
      }
      else {
        rng.moveEnd("character", this.div.innerHTML.replace(/<[^>]*>/g, '').replace(/^\s\s*/, '').replace(/\s\s*$/, '').length);
        rngtmp = this.cloneRange(rng);
        rngtmp.collapse(false);
      }
      try { rng.select(); } catch(e){}
      // 블로그를 위한 패치 - 이래도 되는건가...
      if (span && span.parentNode) {
        if(!span.nextSibling.nextSibling) return false;
        span.parentNode.removeChild(span.nextSibling.nextSibling);
        span.parentNode.removeChild(span.nextSibling.nextSibling);
        span.parentNode.removeChild(span);
      }
      if (div.parentNode) {
        div.parentNode.removeChild(div);
      }
    }
    if (typeof document.body.oncopy != "undefined") {
      this.timer = setTimeout(function(){ self.aftercopy(rng); }, 0);
    }
  },
  aftercopy : function(rng) {
    if (this.skip) return;
    try {
      this.div.parentNode.removeChild(this.div);
      if (/WebKit/.test(navigator.userAgent)) {
        var sel = this.getSelection();
        sel.removeAllRanges();
        sel.addRange(rng);
      }
    } catch(e) { }
  },
  keydown : function(e) {
    if ((e.ctrlKey || e.metaKey) && e.keyCode == 67) {
      this.copy();
    }
  },
  keypress : function(e) {
    if ((e.ctrlKey || e.metaKey) && e.keyCode == 67) {
      var t = this;
      this.timer = setTimeout(function(){ t.aftercopy(); }, 10);
    }
    },
  mousedown : function(e) {
  },
  setTemplate : function(html) {
    this._template = html;
  },
  addEvent : function(obj, sEvent, pFunc) {
    function addEventIE(obj, sEvent, pFunc) {
      obj.attachEvent("on"+sEvent, pFunc);
    }
    function addEventFF(obj, sEvent, pFunc) {
      obj.addEventListener(sEvent, pFunc, false);
    }
    if (obj.attachEvent) this.addEvent = addEventIE;
    else this.addEvent = addEventFF;
    this.addEvent(obj, sEvent, pFunc);
  },
  removeEvent : function(obj, sEvent, pFunc) {
    function removeEventIE(obj, sEvent, pFunc) {
      obj.detachEvent("on"+sEvent, pFunc);
    }
    function removeEventFF(obj, sEvent, pFunc) {
      obj.removeEventListener(sEvent, pFunc, false);
    }
    if (obj.detachEvent) this.removeEvent = removeEventIE;
    else this.removeEvent = removeEventFF;
  }
}

//이미지띄우기
function ie(img){ if(img.src.indexOf('sw.php')<0&&img.src.indexOf('/cached')<0&&img.src.indexOf('tistory.com')<0&&img.already!=1){ img.already=1; img.src=imgurl+'&url='+encodeURIComponent(img.src); img.alt=img.title='loading'; img.onload=function(){ img.alt=img.title=img.old=img.already=''; }}}
function link(address){//링크
var m=true;var js=false;
if(address.indexOf("http")>-1&&address.indexOf("instiz.net")<0&&address.indexOf("cached")<0&&address.indexOf("news.naver.com")<0){
var m=confirm("인스티즈 외부 사이트로 이동합니다, 안전하지 않을 수 있습니다\n계속 하시겠습니까?\n\n("+address+")");
}if(address.indexOf("javascript")>-1){ js=true; return true; }
if(m&&!js)window.open("../go_link.php?url="+encodeURIComponent(address));
return false;}

//(function(){var s=function(){__flash__removeCallback=function(i,n){if(i)i[n]=null;};window.setTimeout(s,10);};s();})();//임베드소스 버그패치
function imgupload(mb){ if(mb!=1)mb=''; op("../../popup_upload.htm?mb="+mb,'upload',417,531);}
function joininti(){op('http://www.instiz.net/popup_join.htm','join',333,324);}//가입창
function hide(){document.getElementById('layer_loginok').style.display='none';}
function emailverify(){op('../popup_email.htm','em',510,240);}//이메일인증
function signout(){op('../popup_logout.htm','logout',336,338);}
function login(){op("../popup_login.htm","loginpopup",367,181);}//로그인팝업
function modify(){op('../popup_thome.htm?modify=1','thome',384,535);}
function autoenter(memo,normal){ p=memo.split('\n');document.getElementById('memo').style.height=normal+(p.length-1)*10+'px'; } //textarea자동높이
function realout(){clearTimeout(settime); document.getElementById('reallayer1').style.display='none'; }//실시간 레이어 끄기
function rulelist(){alert(ajaxload("../popup_thome_rulelist.htm").replace(/##enter##/gi,'\n')); }
function support(){op('../popup_support.htm','support',353,514);}
function twitter(){op('../popup_realtime.htm','realtime',710,593);}
function mini(title,alert){ if(!alert){alert='';} op('../popup_minimemo.htm?title='+encodeURIComponent(title)+'&alert='+encodeURIComponent(alert),'minimemo',570,500); }
function lv(lv){op("popup_buy_level.htm?level="+lv,"lv",250,120);}
function mailto(mode){if(!mode)mode=''; op('../popup_contact.htm?mode='+mode,'',570,500); }
function police(id,no){op('../popup_police.htm?sid='+id+'&no='+no,"police",667,528);}//악플 신고
function ccl(id,no){op('../popup_ccl.htm?id='+id+'&no='+no,'ccl',517,330);}//ccl
function clearbg(id){document.getElementById(id).style.backgroundImage="none";}//인풋배경삭제
function message(mode){ var get=''; if(!mode)mode=''; else if(mode=='_read') get='?mode=get'; op('../popup_message'+mode+'.htm'+get,'thome',615,535); }
function mystar(){op('../popup_mystar.htm','mystar',230,437);}//연인잡담
function myfriend(){op('../popup_chat.htm','chat',250,437);}
function openchat(id,no,friend){ if(!friend){ friend=''; } op('../popup_chatting.htm?id='+id+'&no='+no+'&friend='+friend,'',490,550,'resizable=yes');}
function myimg(){op('../popup_thome.htm?myimg=1',"thome",384,535);}//대표 사진
function friend(){op('../popup_thome.htm?myfriend=1',"thome",384,535);}//친구
function maketag(){op('../popup_thome.htm?maketag=1',"thome",384,535);}//댓글꾸미기 버튼
function jtrans(){op("http://jpdic.naver.com/trans.nhn","jtrans",555,480);}//번역기
function jdic(){op("http://m.jpdic.naver.com/main.nhn","jdic",530,600);}//일본어사전
function voting(){op('','popup_vote',780,450);document.getElementById('vote').submit();}//투표
function result(no){address="../iframe_makevote.htm?no="+no+"&layout=popup&view=1";op(address,'popup_vote',400,486,'scrollbars=yes,resizable=yes');}
function setting(){op('../popup_setting.htm','setting',360,215);}//옵션
function nowmember(){op('http://www.instiz.net/popup_nowmember.htm','nowmember',300,511);}//동접자
function drawing(){op("../../popup_drawing.htm?id="+document.getElementById('id').value,"drawing",550,490);}//그리기 첨부
function ads(){op('../popup_ad.htm','ad',740,550);}//광고
function rule(mode){op('http://www.instiz.net/popup_rule.htm?mode='+mode,'rule',740,550);}//이용규칙
function repmod(id,parent,no){op("../popup_comment_modify.htm?id="+id+"&parent="+parent+"&no="+no,'cm',610,350);}//댓글수정
function repdel(id,parent,no){var m=confirm('이 댓글을 삭제하시겠습니까?');if(!m) return; else document.getElementById('ajax').src="../../iframe_comment_delete.htm?id="+id+"&parent="+parent+"&no="+no;}//댓글삭제
function hideandseek(){ tbid=ajaxdate(); var sHTML='<br><table class="hide_con"><tr><td class="hide_btnname" onclick="hideopen(\'hide'+tbid+'\');">더보기</td></tr><tr><td id="hide'+tbid+'" class="hide_btncon"><p>감춰둘 내용을 여기에 입력하세요.</p></td></tr></table>'; oEditors.getById["ir1"].exec("PASTE_HTML",[sHTML]); }
function hideopen(obj){ obj=document.getElementById(obj); obj.className=(obj.className=='hide_btncon')?'none':'hide_btncon'; }
function showpic(src){window.open('../../popup_showpic.htm?url='+encodeURIComponent(src),'origin','width=200,height=200,left=0,top=0,toolbars=no,resizable=yes,scrollbars=yes');}
function admore(){ document.getElementById('adfoot').innerHTML='<iframe width="728" height="90" src="../ad72890.htm" frameborder="0" scrolling="no"></iframe>'; }

function nowno(){
if(no){
n=document.getElementById(no);
g=document.getElementById('g'+no.substring(1));
if(n){
	n.innerHTML='─';
	if(no.substring(0,1)=='g')n.className='listno';
}else if(g){
	g.innerHTML='─';
	g.className='listno';
}}

function blockwin(m){
if(m.outerWidth==0||m==null||!m||m.closed||typeof m.closed=='undefined')return true;
else return false;
}}

function rudel(cmt){
ment='';
if(cmt>4)ment='\n또, 댓글이 5개 이상인 글(현재 '+cmt+'개)을 삭제하면 얻은 포인트의 3배가 차감됩니다.';
var m=confirm('이 글을 삭제하시겠습니까?\n\n내 글에 달린 댓글이나 글 이동은 신고기능을 이용해 삭제/이동 요청 할 수 있습니다.'+ment);
if(!m)return false;
}

var sclayer, scid, scno, scsub;
function scrap(id,no,subject,e){
scid=id;
scno=no;
scsub=encodeURIComponent(subject);

var topscroll=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
var e=(!window.event)?e:window.event; //IE:Moz
var x, y;
x=(e.clientX+75<document.body.scrollWidth)?e.clientX:e.clientX-100;
if(e.clientY-topscroll<200&&e.clientY>topscroll) topscroll=0; //아이폰등에서 마우스Y값과 스크롤값이 일치하는문제로 (터치기기엔 스크롤이없으므로)
y=(topscroll+e.clientY+70<document.body.scrollHeight)?topscroll+e.clientY:e.clientY+topscroll-70;
if(!sclayer)sclayer='<div id="scraplayer" onmouseover="this.style.display=\'block\';" onmouseout="this.style.display=\'none\';" style="display:none;position:absolute;left:'+x+'px;top:'+(y-10)+'px;z-index:100;display:block;"><table class="memberlayer" style="width:290px"><tr><td><b><a href="javascript:op(\'../popup_thome.htm?scrap=1&id='+id+'&no='+no+'&subject='+subject.replace('\'','\\\'')+'\',\'thome\',384,535)">나의T홈</a></b><span class="tb_spr2">l</span><a href="javascript:scrapgo(1)">미투</a><span class="tb_spr2">l</span><a href="javascript:scrapgo(5)">요즘</a><span class="tb_spr2">l</span><a href="javascript:scrapgo(3)">트위터</a><span class="tb_spr2">l</span><a href="javascript:scrapgo(4)">페북</a><span class="tb_spr2">l</span><a href="javascript:scrapgo(2)">네북</a><span class="tb_spr2">l</span><a href="javascript:scrapgo(6)">구북</a><span class="tb_spr2">l</span><a href="javascript:print()">프린트</a></td></tr></table></div>';
pa=document.body.appendChild(document.createElement('div'));
pa.style.display='block';
pa.innerHTML=sclayer;
}

function scrapgo(mode){
if(mode==1){ //미투데이
window.open('http://me2day.net/posts/new?new_post[body]=http://www.instiz.net/'+scid+'/'+scno+'&new_post[tags]=인스티즈');
}else if(mode==2){//네이버
window.open('http://bookmark.naver.com/post?ns=1&amp;title='+scsub+'&amp;url=http://www.instiz.net/'+scid+'/'+scno);
}else if(mode==3){//트위터
window.open('http://twitter.com/home?status='+scsub+' http://www.instiz.net/'+scid+'/'+scno);
}else if(mode==4){//페이스북
window.open('http://www.facebook.com/sharer.php?u=http://www.instiz.net/'+scid+'/'+scno+'&t='+scsub);
}else if(mode==5){//다음요즘
window.open('http://yozm.daum.net/api/popup/prePost?link=http%3A%2F%2Fwww.instiz.net%2F'+scid+'%2F'+scno+'&prefix='+scsub+'&parameter=인스티즈');
}else if(mode==6){//구글북마크
window.open('http://www.google.com/bookmarks/mark?op=add&amp;title='+scsub+'&amp;bkmk=http://www.instiz.net/'+scid+'/'+scno);
}}

//검색
function searchs(){ keyword=document.getElementById('k').value; document.getElementById('search').submit(); return false; }
function searchreset(){ kwd=document.getElementById('k'); if(kwd.value=='게­시판 검색'||kwd.value=='상품 검색'){ kwd.value=''; kwd.focus(); }}
function typeop(mode){
kwd=document.getElementById('k');
st=document.getElementById('stype');
st.value=mode;
for(i=1;i<=5;i++){
why=(mode==i)?' kstypeon':'';
if(document.getElementById('ks'+i)) document.getElementById('ks'+i).className='kstype kstype'+i+why;
}
kwd=document.getElementById('k');
if(kwd.value=='게­시판 검색'||kwd.value=='상품 검색')kwd.value='';
if((st.value==1||st.value==2||st.value==4||st.value==5)&&kwd.value=='') kwd.focus(); else searchs();
}

//자동완성
var db, mainpage='';
function ffkeyword(id,e){
if(navigator.userAgent.indexOf("MSIE")<0){ if(e.keyCode)var code=e.keyCode; else var code=e.charCode; }
k=document.getElementById('k');
if(db!=k.value){
if(navigator.userAgent.indexOf("Firefox")>-1||navigator.userAgent.indexOf("Chrome")>-1||navigator.userAgent.indexOf("Safari")>-1){
if(code!=40&&code!=38&&code!=13)keyword_check(k.value,id,e);
} db=k.value; }
setTimeout(function(){ ffkeyword(id,e); },10);
}

function keyword_check(keyword,id,e){
if(e.keyCode==40||e.keyCode==38){ return false; }else if(e.keyCode==13){ return false; }else{ i=1;key=0; data=''; ddo=document.getElementById('dd');
if(keyword){
page=(id=='intistore')?'sg_it':'sg';
data=ajaxload('../'+page+'.htm?k='+encodeURIComponent(keyword)+'&id='+id);
}
if(data==''){
if(!keyword&&document.location.host!='m.instiz.net'&&!GetCookie('mobile')){ kwd.style.width='123px'; if(mainpage)document.getElementById('msubse').style.display='block'; }
ddo.style.display='none';
}else{
document.body.onfocus=function(){ document.getElementById('dd').style.display='none'; }
if(keyword&&document.location.host!='m.instiz.net'&&!GetCookie('mobile')){	kwd.style.width='253px'; if(mainpage)document.getElementById('msubse').style.display='none'; }
data=data.replace(/<td/gi,'<td onmouseover="this.style.backgroundColor=\'#efefef\'" onmouseout="this.style.backgroundColor=\'\'" ');
data='<table id="tbs">'+data+'<tr><td class="minitext2 subottom" onclick="document.getElementById(\'dd\').style.display=\'none\';document.getElementById(\'no\').value=\'\'">× 닫기</td></tr></table>';
ddo.style.display='block';
}
ddo.innerHTML=data;
}}

//테이블
var i=1;
var key=0;
function tableshow(e){
var names=e.keyCode;
k=document.getElementById('k');
n=document.getElementById('no');
if(names=="38"){
	if(key==1)i=i-2;
	trname="tr"+i;
	var val=document.getElementById(trname);
	if(val){
	for(s=0;s<20;s++){
		colorset="tr"+s;
		if(document.getElementById(colorset))document.getElementById(colorset).style.backgroundColor='';
	}
	val.style.backgroundColor='#dbffaa';
	k.value=val.getAttribute('auto');
	k.focus();
	n.value=val.getAttribute('searchno');
	i=i-1;
	key=2;
	}		
}else if(names=="40"){
	if(key==2)i=i+2;
	trname="tr"+i;
	var val=document.getElementById(trname);
	if(val){
	for(s=0;s<20;s++){
		colorset="tr"+s;
		if(document.getElementById(colorset))document.getElementById(colorset).style.backgroundColor='';
	}
	val.style.backgroundColor='#dbffaa';
	k.value=val.getAttribute('auto');
	k.focus();
	n.value=val.getAttribute('searchno');
	i=i+1;
	key=1;
	}		
}}
function keywordshow(){
var ds=document.getElementById('dd');
if(ds.innerHTML) ds.style.display='block';
}

//인티뮤직
function preview_ban(){
for(var s=0; s<4; s++){
if(s==0)var embeds=document.getElementsByTagName('embed');
else if(s==1)var embeds=document.getElementsByTagName('object');
else if(s==2)var embeds=document.getElementsByTagName('EMBED');
else if(s==3)var embeds=document.getElementsByTagName('OBJECT');
for(var i=0; i<embeds.length; i++){
	embeds[i].src='';
	embeds[i].stop();
	embeds[i].style.display='none';
}}
pretimer=0;
clearTimeout('times');
document.getElementById('memo_content').innerHTML='<br /><br /><br />';
document.getElementById('preview_notice').innerHTML='미리듣기 1분이 초과하여 음성/영상 자료가 자동 제거 되었습니다.';
}
function preview_timer(){if(pretimer>0){pretimer=pretimer-1;setTimeout('preview_timer()',1000);document.getElementById('preview').innerHTML=pretimer;}else{preview_ban();}}
function load_con(no){
var URL="../bbs/include_content.php?no="+no;
document.getElementById('memo_content').innerHTML=ajaxload(URL);
}

//스타일시트 재반영
var restyle_font, new_restyle_font;
var nowwebfont='', fonts='';
function restyle(font){
if(!usewebfont){
if(!font)font='';
if(nowwebfont&&font)nowwebfont=nowwebfont+',';
restyle_fonts=nowwebfont+font;
if(restyle_font!=restyle_fonts){
href='../style_webfont.php?font='+restyle_fonts;
var el = document.createElement("link");
el.setAttribute("type", "text/css");
el.setAttribute("rel", "stylesheet");
el.setAttribute("href", href);
document.getElementsByTagName("head")[0].appendChild(el);
restyle_font=restyle_fonts;
}}}

//AJAX 스크립트 구현
function get_outerHTML(element){
if(element.outerHTML)
return element.outerHTML;
if(element.nodeType != 1)
return null;
var tagName=element.nodeName.toLowerCase();
var tag=" a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol optgroup option p param pre q s samp script select small span strike strong style sub sup table tbody td textarea tfoot th thead title tr tt u ul var ";
if(tag.indexOf(" "+tagName+" ")==-1)
return null;
var attr_arr=new Array();
var attributes=element.attributes;
var attr_len=attributes.length;
for(var i=0;i<attr_len;i++){
var attr_prop=attributes[i].nodeName;
var attr_value=attributes[i].nodeValue;
if(attr_value.indexOf("\"") != -1)
attr_value="'"+attr_value+"'";
else
attr_value="\""+attr_value+"\"";
attr_arr[i]=attr_prop+"="+attr_value;
}
var attr_text=attr_len?(" "+attr_arr.join(" ")):"";
var lower=" area base basefont br col frame hr img input isindex link meta param ";
if(lower.indexOf(" "+tagName+" ") != -1)
return "<"+tagName+attr_text+" />";
else
return "<"+tagName+attr_text+">"+element.innerHTML+"</"+tagName+">";
}
function set_outerHTML(element,html){
if(element.outerHTML) {
element.outerHTML=html;
return;
}
var temp=document.createElement("div");
temp.innerHTML=html;
var parent=element.parentNode;
while(temp.firstChild) { parent.insertBefore(temp.firstChild,element); }
parent.removeChild(element);
temp=null;
}

//댓글+답글+답답글 기능
var cellname, setname, nofocus;
function reple(num,parent,original){
if(document.getElementById('memo')){
setname=(parent)?'답답글':'답글';
document.getElementById('m'+num).innerHTML='';
if(document.getElementById('replemode').value) replemodecancle();
document.getElementById('replemode').value=num;
if(document.getElementById('memo').style.width=='192px'){ document.getElementById('memo').style.width='127px'; }
else if(document.getElementById('memo').style.width=='875px'){ document.getElementById('memo').style.width='833px'; }
document.getElementById('replemodetext').innerHTML='　<a href="javascript:replemodecancle();"><span style="color:#009e25">'+setname+'취소</span></a>';
if(document.getElementById('replemodetextarea').innerHTML){
cellname='replemode'+original;
document.getElementById(cellname).innerHTML=document.getElementById('replemodetextarea').innerHTML;
}else{
cellnames='replemode'+original;
document.getElementById(cellnames).innerHTML=document.getElementById(cellname).innerHTML;
cellname=cellnames;
}
document.getElementById('replemodetextarea').innerHTML='';
setTimeout(function(){ document.getElementById('memo').focus(); },300);
}else alert('로그인 후 이용해주세요');
}

function replemodecancle(){
memo=document.getElementById('memo');
if(memo.value) var m=confirm(setname+' 달기를 취소하면 입력한 내용이 사라집니다.\n\n정말 취소하시겠습니까?');
if(!memo.value||m){
c=document.getElementById(cellname);
if(memo.style.width=='127px') memo.style.width='192px';
else if(memo.style.width=='833px') memo.style.width='875px';
rm=document.getElementById('replemode');
document.getElementById('m'+rm.value).innerHTML=setname;
memo.value=rm.value=document.getElementById('replemodetext').innerHTML='';
if(cellname){ document.getElementById('replemodetextarea').innerHTML=c.innerHTML; c.innerHTML=''; }
cellname='';
}}

function innerHTMLJS(obj,content){
obj=(typeof obj=='string')?document.getElementById(obj):obj;
content='<body>'+content.replace(/<\/?head>/gi, '')
.replace(/<\/?html>/gi, '')
.replace(/<body/gi, '<div')
.replace(/<\/body/gi, '</div')+'</body>';
obj.innerHTML=content;
var scripts=obj.getElementsByTagName('script');
if(scripts == false) return true;
for(var i=0; i<scripts.length; i++) {
var scriptclone=document.createElement('script');
if(scripts[i].attributes.length > 0) {
for(var j in scripts[i].attributes) {
if(typeof(scripts[i].attributes[j])!='undefined'&&typeof(scripts[i].attributes[j].nodeName)!='undefined'&& scripts[i].attributes[j].nodeValue!=null&& scripts[i].attributes[j].nodeValue!=''){
scriptclone.setAttribute(scripts[i].attributes[j].nodeName, scripts[i].attributes[j].nodeValue);}
}}
scriptclone.text=scripts[i].text;
if (navigator.userAgent.indexOf("Opera")>0) { return; }
scripts[i].parentNode.replaceChild(scriptclone, scripts[i]);
}
return true;
}

var sm;
function reple_refresh(id,parent){
clearTimeout(sm);
document.getElementById('refresh').innerHTML='</a><img src="http://cfile21.uf.tistory.com/image/142D23564E21262F0753F1" width="16" height="5" alt="" /> 로딩';
sm=setTimeout(function(){ ajax_c(id,parent); document.getElementById('refresh').innerHTML='새로고침'; },1000);
}

function ajax_c(id,parent,xp,xb){
if(!cellname){
if(!xp)xp=''; if(!xb)xb='';
var url="view_comment.php?id="+id+"&no="+parent+"&xp="+xp+"&xb="+xb;
var cont=ajaxload(url);
innerHTMLJS('ajax_comment',cont);
}}

function ajax_chat(id,parent){
var url='../cached_chat/'+id+'/'+id+'_'+parent+'.php';
cont=ajaxload(url,1);
if(!cont)cont=1;

if(lastloading!=''&&lastloading!=undefined&&lastloading!=cont){
if(cont.length==3) ajax_c(id,parent); else{ document.getElementById('replemodetextarea').style.display='none'; document.getElementById('ajax_comment').innerHTML=''; document.getElementById('memo_content').innerHTML='<br><br><p align="center">Hㅏ... 글을 읽는 동안 이 글이 삭제되었습니다</p><br><br>'; }
}
lastloading=cont;
}

//풍선도움말
function msgposit_list(e){ hb=document.getElementById('helpbox'); if(hb){ var topscroll=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;hb.style.left=e.clientX+13+document.body.scrollLeft+"px"; hb.style.top=e.clientY+18+topscroll+"px"; }}
function msgset_list(str){ hb=document.getElementById('helpbox'); if(hb){ var text; hb.innerHTML=str; hb.style.display='block'; }}
function msghide_list(){ hb=document.getElementById('helpbox'); if(hb)hb.style.display='none'; }

//미니팝업
var popnow;
function minipopup(mode){
if(popnow!=mode){
var minipopup=document.getElementById('minipop');
if(mode=='on') minipopup.style.display='block';
else if(mode=='off'){ document.getElementById('messnum').innerHTML='나의T홈'; minipopup.style.display='none'; }
}
popnow=mode;
}

//새쪽지 알림
function newmemo(no,sound,message,icon){
if(!aninow){
if(message){ if(no>=100)noshort=99; else noshort=no; document.getElementById('messnum').innerHTML='쪽지 '+noshort; messing=message; }else messing=no+'개의 쪽지가 있습니다';
if(sound==1) var soundtext="<object type='application/x-shockwave-flash' width='0' height='0'><param name='movie' value='http://myhome.qook.co.kr/~a3246072/msg.swf'><embed type='application/x-shockwave-flash' src='http://myhome.qook.co.kr/~a3246072/msg.swf' width='0' height='0'></embed></object>"; else var soundtext='';
subdomain=ajaxload('../_ip.php?show=1');
document.getElementById('messaging_icon').src='../si.php?no='+icon;
document.getElementById('messaging').innerHTML=soundtext+messing;
newmemo_animate();
minipopup('on');
}}

//새쪽지 애니메이션
var ani, animode, aninow, animate;
function newmemo_animate(){
var toasts=document.getElementById('toast');
aninow=1;
if(!ani){
ani=75;
toasts.style.display='block';
toasts.style.top=ani+"px";
}
if(!animode||animode==1){//올라가는
	if(ani>6){
	ani=ani-1;
	toasts.style.top=ani+"px";
	animate=setTimeout('newmemo_animate()',1);
	}else if(ani==6){
	animode=2;
	animate=setTimeout('newmemo_animate()',5000);
	}
}else{
	if(ani<75){//내려오는
	ani=ani+1;
	toasts.style.top=ani+"px";
	animate=setTimeout('newmemo_animate()',1);
	}else if(ani==75){
	toasts.style.display='none';
	ani=aninow=animode='';
	clearTimeout(animate);
	}
}
}
function newmemo_reup(){ document.getElementById('toast').style.top='6px'; clearTimeout(animate); animode=1; ani=7; newmemo_animate(); }

//아이프레임 사이즈조절
function resizeFrame(names,paddings){
if(!paddings) paddings=0;
var doc=document.getElementById("content");
if(doc.offsetHeight!=0){
pageheight=doc.offsetHeight+paddings;
parent.document.getElementById(names).height=pageheight+"px";
parent.scrollTo(0,0);
}}

//실시간 레이어 작동
var ro;
function realon(date){
var rl=document.getElementById('reallayer1');
if(!ro){ rl.innerHTML=ajaxload('../cached_now/realchart/content_'+date+'.php',1); SetOpacity(document.getElementById('reallayer_bg'),80); ro=1; }
rl.style.display='block';
rl.style.visibility='visible';
}

//자스 쿠키
function getCookieVal(offset){ var endstr=document.cookie.indexOf (";", offset); if (endstr == -1) endstr=document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); }
function GetCookie(name){ var arg=name+"="; var alen=arg.length; var clen=document.cookie.length; var i=0; while (i < clen){ //while open
var j=i+alen; if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i=document.cookie.indexOf(" ", i)+1; if (i == 0) break; } //while close
return ''; } function SetCookie(name, value){ var argv=SetCookie.arguments; var argc=SetCookie.arguments.length; var expires=(2 < argc) ? argv[2] : null; var path=(3 < argc) ? argv[3] : null; var domain=(4 < argc) ? argv[4] : null; var secure=(5 < argc) ? argv[5] : false; document.cookie=name+"="+escape (value)+((expires == null) ? "" : ("; expires="+expires.toGMTString()))+((path == null) ? "" : ("; path="+path))+((domain == null) ? "" : ("; domain="+domain))+((secure == true) ? "; secure" : ""); } 

var mode;
var randnews=Math.floor(Math.random()*2);
var nownews=randnews;

//ajax
function ajaxload(url,mode){
var xmlhttp=null;
var responseText;
if(window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); else if (window.ActiveXObject) xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if(typeof(xmlhttp.onprogress)=='object'){//ff버그
xmlhttp.onload = xmlhttp.onerror = xmlhttp.onabort = function(){responseText=xmlhttp.responseText;}
}else{
xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&xmlhttp.status==200&&xmlhttp.statusText=='OK')responseText=xmlhttp.responseText;}
}
if(mode) mode='POST'; else mode='GET';
xmlhttp.open(mode,url,false);
xmlhttp.send(null);
return responseText;
}

//날짜
function ajaxdate(){var m=Math.round(new Date().getTime()/1000);return m;}

//리얼박스 로딩
news=new Array();
newsno=new Array();
newsid=new Array();
var realbox;
var nore=0;

function reload_now(){
document.getElementById('connection').innerHTML=ajaxload('include_conn.php',1);
var now=ajaxload('cached_now/update_now.php',1);
if(realbox!=now){
realbox=now;
if(memno){
icon=ajaxload('cached_now/'+memno+'.php',1);
if(icon){
icon=icon.split('/');
if(eval(icon[1])>0) newmemo(icon[1],memsound,'새 쪽지가 도착했습니다',icon[0]);
}}
var cont=ajaxload('include_now.php',1);
if(cont){
cont=cont.split('\|\|');
contlen=cont.length-1;
for(i=0;i<contlen;i++){
var tempcont=cont[i].split('\|');
news[i]=tempcont[0];
newsid[i]=tempcont[1];
newsno[i]=tempcont[2];
}
ms=document.getElementById('menu_sub');
randnews=Math.floor(Math.random()*contlen);
	if(newsno[randnews]!='0'){
		if(newsid[randnews]!='x')ms.innerHTML='<a href="../'+newsid[randnews]+'/'+newsno[randnews]+'" target="_blank">'+news[randnews]+'</a>';
		else ms.innerHTML=news[randnews].replace('★now★',document.getElementById('connection').innerHTML);
	}else ms.innerHTML='<a href="../realtime">'+news[randnews]+'</a>';
if(randnews!=nownews)nownews=randnews;
}
}
if(nore<60){
setTimeout("reload_now()",120000);
nore=nore+1;
}}

//상단 실시간 뉴스 more기능
function nextnews(){
nownews=(nownews>=news.length-1)?0:nownews+1;
ms=document.getElementById('menu_sub');
if(newsno[nownews]!='0'){
	if(newsid[nownews]!='x')ms.innerHTML='<a href="../'+newsid[nownews]+'/'+newsno[nownews]+'" target="_blank">'+news[nownews]+'</a>';
	else ms.innerHTML=news[nownews].replace('★now★',document.getElementById('connection').innerHTML);
}else ms.innerHTML='<a href="../realtime">'+news[nownews]+'</a>';
}
function nextnews_auto(){ nextnews(); setTimeout(function(){ nextnews_auto(); },20000); }

//멤버 레이어
var no,ss,add,pl,nos;
function prlayer_print(no,e){
var topscroll=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
var e=(!window.event)?e:window.event; //IE:Moz
if(!no||no==0) alert('비회원이거나 비공개 상태입니다'); else{
var x, y;
nos=no;
if(e.clientX+75<document.body.scrollWidth) x=e.clientX; else x=e.clientX-100;
if(e.clientY-topscroll<200&&e.clientY>topscroll) topscroll=0; //아이폰등에서 마우스Y값과 스크롤값이 일치하는문제로 (터치기기엔 스크롤이없으므로)
if(topscroll+e.clientY+70<document.body.scrollHeight) y=topscroll+e.clientY; else y=e.clientY+topscroll-70;
if(!pl)prlayer_inner();
pr=document.getElementById("prlayer");
data=ajaxload('../include_mc.php?no='+nos,1);
if(data==0) text='상태 비공개'; else if(data==1) text='<span style="color:#009e25">현재 접속중</span>'; else text='미접속';
document.getElementById("memconn").innerHTML='<span class="minitext">'+text+'</span>';
document.getElementById("memicon").src='../si.php?no='+nos;
pr.style.display='block';
pr.style.left=(x-5)+'px';
pr.style.top=(y-10)+'px';
}}

//기능 바로 작동
function prlayer_go(ss,no,option){
q='';
if(!no&&!nos) alert('비회원이거나 비공개 상태입니다'); else{
if(!no) no=nos;
if(ss==1){//T홈 가기
if(option==1) opt='&mythome=1'; else if(option==2) opt='&scrap=1'; else opt='';
if(option==3) add='popup_thome_rand.htm'; else add='popup_thome.htm?member_no='+no+opt;
w=384; h=535; n='thome'; 
}else if(ss==2){add='popup_message_write.htm?member_no='+no; w=615; h=535; n='thome'; //쪽지 보내기
}else if(ss==3){add='popup_friend_add.htm?friendno='+no; w=300; h=162; n='add'; //친구 등록
}else if(ss==4){add='popup_chatting.htm?friend='+no; w=490; h=550; n=''; q='resizable=yes'; }//1:1대화
op('http://www.instiz.net/'+add,n,w,h,q);
}}

//멤버레이어 넣기
function prlayer_inner(){
var prlayer_body='<div id="prlayer" onmouseover="this.style.display=\'block\';" onmouseout="this.style.display=\'none\';" style="width:95px; position:absolute;left:0; top:0; z-index:100;display:none;"><table class="memberlayer"><tr><td valign="top" align="center" height="58"><a href="javascript:void(0);" onclick="prlayer_go(\'1\')"><img id="memicon" width="48" height="48" alt="" style="padding:7px 0 0 0;" /></a></td></tr><tr><td id="memconn"></td></tr><tr><td><a href="javascript:void(0);" onclick="prlayer_go(\'1\')">T홈</a><span class="tb_spr2">l</span><a href="javascript:void(0);" onclick="prlayer_go(\'3\')">친구</a></td></tr><tr><td><a href="javascript:void(0);" onclick="prlayer_go(\'2\')">쪽지</a><span class="tb_spr2">l</span><a href="javascript:void(0);" onclick="prlayer_go(\'4\')">1:1</a></td></tr></table></div>';
pl=document.body.appendChild(document.createElement('div'));
pl.innerHTML=prlayer_body;
}

function gb(id,no,frame){
if(no&&no>0)no='/'+no; else no='';
if(document.location.host=='m.instiz.net') front='http://www.instiz.net/'; else front='../';
add=front+id+no;
if(frame==1)parent.frames.location=add; else if(frame==2) op(add); else location=add;
}

function imgresize(){
obj=document.getElementById('memo_content');
if(obj){
if(typeof(imglimit)==undefined||imglimit==''){ if(window.innerWidth){ mywidth=window.innerWidth; }else{ mywidth=document.documentElement.clientWidth; } imglim=(mywidth)-30; my=1; }else imglim=imglimit;
imgr=obj.getElementsByTagName('img');
ilength=imgr.length;
for(var i=0;i<ilength;i++){
width=imgr[i].width;
if(!imgr[i].origin_width) imgr[i].origin_width=width; else width=imgr[i].origin_width;
if(width>imglim){
	var imgs=document.createElement('img');
	imgs.src=imgr[i].src;
	document.body.appendChild(imgs);
	per=Math.ceil(imgs.height/(imgs.width/imglim));
	imgr[i].width=imglim; imgr[i].style.width=imglim+'px';
	document.body.removeChild(imgs);
	if(per){ imgr[i].height=per; imgr[i].style.height=per+'px'; }
}}
}}

//댓글사진
function toggle_img(no,mode,small){
if(small==1) imlimit=160; else imlimit=700; 
that='img'+no;
img=document.getElementById(that);
address=document.getElementById(that).src;
if(mode==1){
img.style.border='2px dotted #777';
img.style.width=img.style.height='auto';
img.removeAttribute('width');
img.removeAttribute('height');
address=address.replace('/upload_thumb/','/upload/');
img.onclick=function(){ toggle_img(no,2,small); }
img.title="이미지를 클릭하면 축소됩니다";
img.src=address;
img.onload=function(){ if(img.width>imlimit){ img.style.width=imlimit+'px'; }}
}else{
img.style.border='1px solid #ccc';
img.title="이미지를 클릭하면 확대됩니다";
address=address.replace('/upload/','/upload_thumb/');
img.src=address;
img.onclick=function(){ toggle_img(no,1,small); }
img.style.width='80px';
}
}

var imglimit,fcookie,preview,popup,usewebfont,key;
var songid=1;

//로딩 완료시 실행되는 구문
window.onresize=function(){ imgresize(); }
window.onload=function(){
if(GetCookie('mobile')&&window.pageYOffset==0)window.scrollTo(0, 1);//모바일 주소창 없애기
imgresize();
}
