var selMenu = 0;
var dateToday = new Date();
window.name = '_borlandforum';

// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
// Usage: include this code segment at the beginning of your document
// before any other Javascript contents.

if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
{
  //http://www.browserland.org/scripts/htmlelement/

  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);
  });

  HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
  {
    switch (where)
    {
    case 'beforeBegin':
      this.parentNode.insertBefore(parsedNode,this)
      break;
    case 'afterBegin':
      this.insertBefore(parsedNode,this.firstChild);
      break;
    case 'beforeEnd':
      this.appendChild(parsedNode);
      break;
    case 'afterEnd':
      if (this.nextSibling) 
        this.parentNode.insertBefore(parsedNode,this.nextSibling);
      else 
        this.parentNode.appendChild(parsedNode);
      break;
    }
  }

  HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
  {
    var r = this.ownerDocument.createRange();
    r.setStartBefore(this);
    var parsedHTML = r.createContextualFragment(htmlStr);
    this.insertAdjacentElement(where,parsedHTML)
  }


  HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
  {
    var parsedText = document.createTextNode(txtStr)
    this.insertAdjacentElement(where,parsedText)
  }
}


function IsIE()
{
  return (navigator.appName=='Microsoft Internet Explorer');
}

function docAll(elementId)
{
  if(document.all) 
    return document.all[elementId];
  else
  	return document.getElementById(elementId);
}

function docAllWin(winObj, elementId)
{
	if(!winObj) return null;
  if(document.all) 
  	return winObj.document.all[elementId];
  else
  	return winObj.document.getElementById(elementId);
}

function loginCheck(theForm)
{
    if(theForm.UserID.value.length == 0)
    {
        alert("¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
        theForm.UserID.focus();
        return false;
    }
    if(theForm.UserPass.value.length == 0)
    {
        alert("ÆÐ½º¿öµå¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
        theForm.UserPass.focus();
        return false;
    }
    theForm.BackUrl.value = location.href;
    return true;
}

function writeLoginForm()
{
  var UserID = getCookie('bforum-ID');
  if(UserID.length>0)
  {
    document.write(unescape(getCookie('bforum-UserName')) + ' ´Ô (ÀÏ¹Ý È¸¿ø)');
    document.write(' <a href="/impboard/impuser.dll?action=logout"><img src="http://img.borlandforum.com/images/btn_logout.gif" align="absmiddle"></a> <a href="/impboard/impuser.dll?action=modifyuser"><img src="http://img.borlandforum.com/images/btn_modifyuser.gif" align="absmiddle"></a>&nbsp;');
  }
  else
  {
    document.write('<a href="/impboard/signup.html"><img src="http://img.borlandforum.com/images/btn_signup.gif" align="absmiddle"></a> <a href="javascript:openFindPassword()"><img src="http://img.borlandforum.com/images/btn_findpass.gif" align="absmiddle"></a> | <input type="hidden" name="BackUrl">');
    document.write('<form method="POST" action="/impboard/impuser.dll?action=login"><b>¾ÆÀÌµð</b><input type=text name=UserID class=boxline size=10> <b>ºñ¹Ð¹øÈ£</b><input type=password name=UserPass class=boxline size=10><input type=hidden name=BackUrl value="' + location.href + '">');
    document.write('<label for="savecookie" style="vertical-align:middle"><input type="checkbox" name="savecookie" id="savecookie" style="border:0px;" value="1">ÀúÀå</label> <input type="image" src="http://img.borlandforum.com/images/btn_login.gif" align="absmiddle"></form>&nbsp;');
  }
}

function ShowSubMenu(newSel)
{
  selMenu = newSel;
  for(var i=1; i<=8; i++)
    docAll('SubMenu'+i).style.display = "none";
  docAll('SubMenu'+selMenu).style.display = "";
}




function setCookie(sName, sValue)
{
  var strExpires = "";
  expireDate = new Date();
  expireDate.setDate(expireDate.getDate() + 365);
  strExpires = "expires=" + expireDate.toGMTString();
  document.cookie = sName + "=" + sValue + ";" + strExpires + ";path=/;domain=" + getGroupDomainAddr();
}

function getCookie(sName)
{
  var value = "";
  var aCookie = document.cookie.split("; ");
  for(var i=0; i<aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if(aCrumb.length>1 && sName==aCrumb[0])
      value = unescape(aCrumb[1].replace(/&&/g, "%"));
  }
  if(value=='undefined') value = "";
  return value;
}

function getQuery(sName)
{
  var value = location.search.substr(1, 10000);
  var aQuery = value.split("&");
  for(var i=0; i<aQuery.length; i++)
  {
    var aCrumb = aQuery[i].split("=");
    if(aCrumb.length>1 && sName==aCrumb[0])
      value = unescape(aCrumb[1].replace(/&&/g, "%"));
  }
  if(value=='undefined') value = "";
  return value;
}

function getGroupDomainAddr()
{
    var strDomain = location.hostname.toLowerCase();
    var DotPos = strDomain.indexOf(".");
    if(DotPos >= 0)
    {
        var part1 = strDomain.substr(0, DotPos);
        if(part1 != parseInt(part1))
            return strDomain.substr(DotPos+1, 1000);
    }
    return strDomain;
}

function getTodayString()
{
  Now = new Date();
  month = (Now.getMonth()+1) + '-';
  if(month.length == 2) month = '0' + month;
  day = Now.getDate();
  if(day.toString().length == 1) day = '0' + day;
  return Now.getFullYear() + '-' + month + day;
}


function writeReplyImage(indent)
{
  if(indent > 0) document.write('<img src="http://img.borlandforum.com/impboard/images/remark.gif">');
}

function dayDiffFromToday(WrDate)
{
  var dateWrDate = new Date(WrDate);
  return Math.ceil((dateToday - dateWrDate) / 1000 / 24 / 60 / 60); 
} 

function writeNewImage(WrDate, AttachCount, CommentCount)
{
  if(AttachCount>0) document.write('<font color=#666666>[<img src="http://img.borlandforum.com/impboard/images/clip.gif" height=11>' + AttachCount + ']</font>');
  if(CommentCount>0) document.write('<font color=#666666>[<img src="http://img.borlandforum.com/impboard/images/comment.gif" height=11>' + CommentCount + ']</font>');
  var DayInterval = dayDiffFromToday(WrDate);
  if(DayInterval<=1) document.write('&nbsp;<img src="http://img.borlandforum.com/impboard/images/new!.gif" height=10>');
  else if(DayInterval==2) document.write('&nbsp;<img src="http://img.borlandforum.com/impboard/images/new!2.gif" height=10>');
}


function initReadPage(no)
{
  focus();
}

function viewUser(UserID)
{
  window.open("/impboard/impuser.dll?action=viewuser&userid=" + UserID, "ViewUser", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width=440,height=125");
}

function openHtmlWrite(BoardID)
{
  window.open('/impboard/impboard.dll?action=write&db=' + BoardID + '&tpl=html', 'ViewUser', 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no,width=700,height=650');
}

function modifyArticle(aDB, aNo)
{
  if(bLogedIn!=true)
    window.open("InputPassword.htm?action=modify&db="+aDB+"&no="+aNo, "InputPasswordModifyArticle", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width=300,height=130");
  else
    location.href = "impboard.dll?action=modify&db="+aDB+"&no="+aNo;
}

function deleteArticle(aDB, aNo)
{
  if(confirm("Á¤¸»·Î »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")==false) return;
  if(bLogedIn!=true)
    window.open("InputPassword.htm?action=delete&db="+aDB+"&no="+aNo, "InputPasswordDeleteArticle", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width=300,height=130");
  else
    location.href = "impboard.dll?action=delete&db="+aDB+"&no="+aNo;
}

function openListSendTrackback(SN)
{
  window.open("/impboard/impboard.dll?action=listsendtrackback&sn=" + SN, "ListSendTrackback", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width=660,height=480");
}

function openFindPassword()
{
    window.open("/impboard/FindPassword.htm", "FindPassword", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width=300,height=140");
}

function openChangePassword()
{
  window.open("/impboard/ChangePassword.htm", "ChangePassword", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width=300,height=157");
}

function openSignOff()
{
  if(confirm("Á¤¸»·Î º¼·£µåÆ÷·³¿¡¼­ Å»Åð ÇÏ½Ã°Ú½À´Ï±î?")==false) return;
  window.open("/impboard/InputPassword.htm?action=signoff", "InputPasswordSignOff", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,width=300,height=125");
}

function deleteComment(Db, no, cno)
{
  if(confirm("Á¤¸»·Î »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?"))
    location.href="impboard.dll?action=deletecomment&db=" + Db + "&no=" + no + "&cno=" + cno + "&backurl=javascript:history.back()";
}


function getExt(URL)
{
  var DotPos = URL.lastIndexOf(".");
  if(DotPos >= 0) return URL.substr(DotPos+1, 1000).toLowerCase();
  return '';
}

function getFilename(URL)
{
  var SlashPos = URL.lastIndexOf("/");
  if(SlashPos >= 0) return URL.substr(SlashPos+1, 1000).toLowerCase();
  return '';
}

var preparedExt = 'txt|log|cgl|ace|arc|asf|avi|bmp|swf|bpg|bpk|bpr|cbproj|chm|cpp|c|hpp|h|dfm|divx|doc|dot|dpk|dpr|dproj|emf|eml|fon|gif|groupproj|gz|hwp|hlp|htm|html|inf|ini|jpe|jpeg|jpg|js|lha|mdb|mht|mhtl|mid|midi|mov|mp3|mpeg|mpg|msg|msi|msp|pas|pcx|pdf|png|ppt|pps|pot|qt|ra|ram|rar|rm|rtf|tif|tiff|url|wav|wmf|xfm|xls|xlt|xml|xsl|z|zip|tbz|tgz|exe|bat|dll|bpl|reg|wmv|wma|rpm|hxs|hxi|hxt|cs|ocx|sys|drv|cpl|scr|bdsproj|';
var imgExt = 'bmp|gif|jpg|png';
var movieExt = 'wmv|mpg|mpeg|asf|asx|avi|mov|wma';
var musicExt = 'mp3|mid|wav';

function showFileIcon(attachLink)
{
	var attachLinkObj = docAll(attachLink);
	if(!attachLinkObj) return;
  ext = getExt(attachLinkObj.href);

  if(imgExt.indexOf(ext)>=0)
  {
  	attachLinkObj.className = 'thickbox';
  	//attachLinkObj.rel = 'attach_images';
  }
  else if(ext=='swf')
  {
  	attachLinkObj.className = 'thickbox';
  	attachLinkObj.href = attachLinkObj.href + '?keepThis=true&TB_iframe=true&width=640&height=480';
  }
  else if(movieExt.indexOf(ext)>=0)
  {
  	attachLinkObj.className = 'thickbox';
  	attachLinkObj.href = '/impboard/ShowMedia.htm?mediafile=' + attachLinkObj.href + '&keepThis=true&TB_iframe=true&width=640&height=524';
  }
  else if(musicExt.indexOf(ext)>=0)
  {
  	attachLinkObj.className = 'thickbox';
  	attachLinkObj.href = '/impboard/ShowMedia.htm?mediafile=' + attachLinkObj.href + '&keepThis=true&TB_iframe=true&width=640&height=33';
  }

  if(preparedExt.indexOf(ext)<0) ext = 'undefined';
	attachLinkObj.parentNode.style.backgroundImage = 'url(/impboard/images/ext/ext_'+ext+'.gif)';
}

function getFileIconImgStr(FileUrl)
{
}

function showFileEmbed(attOrder, fileUrl)
{
  var ext = getExt(fileUrl);
  if(imgExt.indexOf(ext)>=0 || ext=='swf' || movieExt.indexOf(ext)>=0 || musicExt.indexOf(ext)>=0)
  {
    filename = getFilename(fileUrl);
    var checkButtonId = 'check' + attOrder;
    document.write('<input type=button id="' + checkButtonId + '" class=viewCheckButton onclick="viewAttach(this, \'AttView_' + attOrder + '\', \'' + fileUrl + '\')" checked=false value=º¸±â>');
    docAll(checkButtonId).checked = false;
  }
}

function viewAttach(checkButton, AttViewId, fileUrl)
{
  checkButton.checked = !checkButton.checked;
  var ext = getExt(fileUrl);
  var AttViewObj = docAll(AttViewId);
  if(!checkButton.checked)
  {
    AttViewObj.innerHTML = '';
    AttViewObj.style.display = 'none';
    checkButton.value = 'º¸±â';
  }
  else
 	{
	  AttViewObj.style.display = 'block';
	  checkButton.value = '¼û±â±â';
	  if(imgExt.indexOf(ext)>=0)
    	AttViewObj.innerHTML = '<img src="' + fileUrl + '" border=0>';
  	else if(ext=='swf')
	    AttViewObj.innerHTML = '<embed src="' + fileUrl + '" width=100% height=650 type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
	  else if(movieExt.indexOf(ext)>=0)
	    AttViewObj.innerHTML = '<embed src="' + fileUrl + '" width=100% height=576 type="application/x-mplayer2" pluginspage="http://www.microsoft.com/korea/windows/windowsmedia/download/default.asp"></embed>';
	  else if(musicExt.indexOf(ext)>=0)
	    AttViewObj.innerHTML = '<embed src="' + fileUrl + '" width=100% height=74 type="application/x-mplayer2" pluginspage="http://www.microsoft.com/korea/windows/windowsmedia/download/default.asp"></embed>';
	}
}

function popupViewImage(fileUrl)
{
  window.open(fileUrl, "ViewImage", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=640,height=480");
}


function preCommentSubmitCheck(theForm)
{
  if(getCookie('bforum-ID')=="")
  {
    alert("´ñ±Û ¾²±â´Â ·Î±×ÀÎ ÈÄ¿¡¸¸ »ç¿ë °¡´ÉÇÕ´Ï´Ù.");
    return false;
  }
  if(theForm.Content.value.length == 0)
  {
    alert("´ñ±Û ³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä.");
    theForm.Content.focus();
    return false;
  }
  theForm.BackUrl.value = location.href;
  return true;
}

function commentContentCheck()
{
	if(bLogedIn==true) return;
	var inputCommentContent = docAll('inputCommentContent');
	inputCommentContent.innerHTML = '·Î±×ÀÎ ÈÄ¿¡ ´ñ±ÛÀ» ³²±æ ¼ö ÀÖ½À´Ï´Ù.';
	inputCommentContent.readOnly = true;
	inputCommentContent.style.color = 'gray';
	docAll('submitComment').disabled = true;
}

function addBookmark(boardId, no)
{
  if(bLogedIn != true)
  {
    alert('ºÏ¸¶Å© ±â´ÉÀº ·Î±×ÀÎÇÑ ÈÄ¿¡¸¸ »ç¿ë°¡´ÉÇÕ´Ï´Ù.');
    return;
  }
  location.href = 'impboard.dll?action=addbookmark&db=' + boardId + '&no=' + no;
}

function sendMail()
{
  alert('¾ÆÁ÷ ¿Ï¼ºµÇÁö ¾ÊÀº ±â´ÉÀÔ´Ï´Ù.');
}

function doPrint()
{
  window.open(location.href + "&tpl=print", "print", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=764,height=520");
}


function getStrLen(str)
{
  return str.length+(escape(str)+"%u").match(/%u/g).length-1;
}

function setStrLen(str, newLen)
{
  var newStr = '';
  len = 0;
  for(var i=0; i<str.length; i++)
  {
     ch = str.charAt(i);
     len += (escape(ch).length>1 && ch!=' ' ? 2 : 1);
     if(len>newLen) break;
     newStr = newStr + str.charAt(i);
  }
  return newStr;
}

function limitLength()
{
  /*theInput = event.srcElement;
  str = theInput.value;
  //if(event.type=='paste')
  //  str = str + clipboardData.getData('Text');
  var strLen = str.length+(escape(str)+"%u").match(/%u/g).length-1;
  if(strLen >= theInput.maxLength)
  {
     alert(theInput.name + 'ÀÇ ÃÖ´ëÄ¡´Â ' + theInput.maxLength + ' ¹®ÀÚ±îÁöÀÔ´Ï´Ù.');
     return false;
  }*/
  return true;
}

function disableInput(input, enabled)
{
  input.readOnly = "true";
  input.style.color = "gray";
  input.style.backgroundColor = "#f0f0f0";
}

function addFileInput(fileInput)
{
  if(event.propertyName!='value') return;
  if(fileInput.value.length==0) return;

  docAll('attachCell').insertAdjacentHTML("beforeEnd", strNewAttach);
  fileCount++;
  fileInput.onpropertychange = null;
  fileInput.onchange = null;
}

function simpleEncrypt(theText)
{
  output = new String;
  Temp = new Array();
  Temp2 = new Array();
  TextSize = theText.length;
  for (i = 0; i < TextSize; i++)
  {
    rnd = Math.round(Math.random() * 122) + 68;
    Temp[i] = theText.charCodeAt(i) + rnd;
    Temp2[i] = rnd;
  }
  for(i=0; i<TextSize; i++)
  output += String.fromCharCode(Temp[i], Temp2[i]);
  return output;
}

function simpleDecrypt(theText)
{
  output = new String;
  Temp = new Array();
  Temp2 = new Array();
  TextSize = theText.length;
  for (i = 0; i < TextSize; i++)
  {
    Temp[i] = theText.charCodeAt(i);
    Temp2[i] = theText.charCodeAt(i + 1);
  }
  for (i = 0; i < TextSize; i = i+2)
  output += String.fromCharCode(Temp[i] - Temp2[i]);
  return output;
}

function EncodeToNum(in_str)
{
  var result = "";
  in_str = escape(in_str);
  for(i = 0; i < in_str.length; i++)
    result += in_str.charCodeAt(i) - 23;
  return result;
}

function DecodeFromNum(str)
{
  var num_in, str_out = "";
  for(i = 0; i < str.length; i += 2)
  {
    num_in = parseInt(str.substr(i,[2])) + 23;
    num_in = unescape('%' + num_in.toString(16));
    str_out += num_in;
  }
  return unescape(str_out);
}

function checkSearchForm(theForm)
{
  if(theForm.keyword.value.length==0 || (theForm.insubject.checked==false && theForm.incontent.checked==false && theForm.inwriter.checked==false))
  {
    alert("°Ë»ö Á¶°ÇÀ» ÁöÁ¤ÇÏ¼¼¿ä.");
    theForm.keyword.focus();
    return false;
  }
  return true;
}

function checkGoNoForm(theForm)
{
  if(theForm.no.value.length==0 || isNaN(theForm.no.value))
  {
    alert("±Û ¹øÈ£¸¦ ÀÔ·ÂÇÏÁö ¾Ê¾Ò°Å³ª ¼ýÀÚ°¡ ¾Æ´Õ´Ï´Ù.");
    theForm.no.focus();
    return false;
  }
  return true;
}

function searchCheckClick(check)
{
  if(check.checked && check==docAll('inwriter'))
  {
    docAll('insubject').checked = false;
    docAll('incontent').checked = false;
  }
}

function sethomepage(aObj)
{
  if (document.all)
  {
    aObj.style.behavior='url(#default#homepage)';
    aObj.setHomePage(location.href);
  }
  else window.alert('IE¿¡¼­¸¸ »ç¿ë °¡´ÉÇÕ´Ï´Ù.');
}

function addfavorites()
{
  if (document.all) window.external.AddFavorite(location.href, document.title)
  else window.alert('IE¿¡¼­¸¸ »ç¿ë °¡´ÉÇÕ´Ï´Ù.');
}

function adddesktop()
{
  if (document.all) window.external.AddDesktopComponent(location.href, 'website', 1024, 0, 920, 2000);
  else window.alert('IE¿¡¼­¸¸ »ç¿ë °¡´ÉÇÕ´Ï´Ù.');
}


function openPopup(popupname, url, width, height, scrollbars)
{
    var cookies = document.cookie.split("; ");
    var openwin = "yes";
    var checkedCookieStr = popupname + "=checked";
    for (i=0; i<cookies.length; i++)
        if(cookies[i] == checkedCookieStr)
            openwin = "no";
    var left = screen.width - width - 9;
    //914;
    if(openwin=="yes")
        window.open(url, popupname,'width='+width+',height='+height+',scrollbars='+scrollbars+',toolbar=no,location=no,directories=no,status=no,resizable=no,menubar=no,top=0,left='+left);
}

function onClosePopupClick(popupname, checked, days)
{
    if(checked == true)
    {
      var strExpires = "";
      if(days > 0)
      {
          expireDate = new Date();
          expireDate.setDate(expireDate.getDate() + days);
          strExpires = "expires=" + expireDate.toGMTString();
      }
        document.cookie = popupname + "=checked;path=/;" + strExpires + ";domain=borlandforum.com;";
    }
    window.close();
}

function getDocName(url)
{
    var parts = url.split("/");
    return parts[parts.length-1];
}

function copyTrackbackUrl()
{
	copyToClipBoard(docAll('trackbackUrl').innerHTML);
}

var clipb = 0;

function copyToClipBoard(text2copy)
{
  if (window.clipboardData) 
    window.clipboardData.setData("Text", text2copy);
  else 
  {
    var flashcopier = 'flashcopier' + clipb;

    if(!document.getElementById(flashcopier)) 
    {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="http://img.borlandforum.com/impBoard/clipboard.swf" FlashVars="clipboard='+encodeURIComponent(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
  clipb++;

  alert('Å¬¸³º¸µå·Î º¹»çµÇ¾ú½À´Ï´Ù.');
}
