function resizeImage(targetImg)
{
  widthvalue = targetImg.width;
  heightvalue = targetImg.height;
  if( widthvalue > 660 )
  {
    targetImg.width = 660;
    targetImg.height = heightvalue - (heightvalue * (widthvalue-660)/widthvalue);
  }
}

function tbsRegulateSubmit(f){
  var c=0;
  for(var i=0; i<f.action.length; i++){
    if(f.action[i].checked){
      c++;
      break;
    }
  }
  if(c>0){
    if(confirm("Á¤¸»·Î ½ÇÇàÇÏ°Ú½À´Ï±î?")) return true;
    else return false;
  }
  else{
    alert("¼±ÅÃ");
    return false;
  }
}

function tbsRegulateCheck(c){
  var obj=document.getElementById("divRegulateMove");
  if(c.checked){
    if(c.value=="move") obj.style.visibility="visible";
    else obj.style.visibility="hidden";
  }else{
    obj.style.visibility="hidden";
  }
}




function changeSfield(v,skin){
  if(v=="nick"){
    document.all("imgSearchName").src = "./skin/"+skin+"/search_name_on.gif";
	document.all("imgSearchSubject").src = "./skin/"+skin+"/search_subject_off.gif";
	document.all("imgSearchContent").src = "./skin/"+skin+"/search_content_off.gif";
  }
  else if(v=="content"){
    document.all("imgSearchName").src = "./skin/"+skin+"/search_name_off.gif";
	document.all("imgSearchSubject").src = "./skin/"+skin+"/search_subject_off.gif";
	document.all("imgSearchContent").src = "./skin/"+skin+"/search_content_on.gif";
  }
  else{
    document.all("imgSearchName").src = "./skin/"+skin+"/search_name_off.gif";
	document.all("imgSearchSubject").src = "./skin/"+skin+"/search_subject_on.gif";
	document.all("imgSearchContent").src = "./skin/"+skin+"/search_content_off.gif";
  }
  document.boardSearchForm.sfield.value = v;
}

function tbsWmpOpen(f){
  if(f.m.value!="" && f.s.value!="" && f.d.value!=""){
    window.open("", "player", "width=340,height=442,top=0,left=0,status=yes,scrollbar=no,resizable=no");
    f.target="player";
    return true;
  }else{
    return false;
  }
}

function lowPlayerOpen(f){
  if(f.m.value!="" && f.s.value!="" && f.d.value!=""){
    window.open("", "player", "width=340,height=437,top=0,left=0,status=yes,scrollbar=no,resizable=no");
    f.action="player.html";
    f.target="player";
    return true;
  }else{
    return false;
  }
}

function lowPlayerOpenPHP(f){
  if(f.m.value!="" && f.s.value!="" && f.d.value!=""){
    window.open("", "player", "width=340,height=437,top=0,left=0,status=yes,scrollbar=no,resizable=no");
    f.action="player.php";
    f.target="player";
    return true;
  }else{
    return false;
  }
}

function highPlayerOpen(mediaID,c){
  window.open('../board/playerHigh.html?mediaID='+mediaID+'&code='+c, 'player', 'width=512,height=605,top=0,left=0,status=yes,scrollbar=no,resizable=no');
}

function highPlayerChatOpen(mediaID){
  window.open('../board/playerHighChat.html?mediaID=' + mediaID, 'player', 'width=512,height=605,top=0,left=0,status=yes,scrollbar=no,resizable=yes');
}


function highPlayerSampleOpen(mediaID){
  window.open('../board/playerHighSample.html?mediaID=' + mediaID, 'player', 'width=512,height=605,top=0,left=0,status=yes,scrollbar=no,resizable=no');
}

function playerOpen(mediaURL)
{
  window.open('player.html?mediaURL=' + mediaURL, 'player', 'width=340,height=421,top=5,left=5,scrollbar=no,resizeable=no');
}

function japanCafePlayerOpen(mediaURL)
{
  window.open('player.html?mediaURL=' + mediaURL, 'player', 'width=340,height=437,top=5,left=5,status=yes,scrollbar=no,resizeable=no');
}

// ÆäÀÌÁöÀÌµ¿
function goPage(code, page, category, sfield, skey)
{
  document.location.href = './index.html?code=' + code + '&page=' + page + '&category=' + category + '&sfield=' + sfield + '&skey=' + skey;
}

// Ä«Å×°í¸®º°¸ñ·Ïº¸±â
function categoryView(category, code)
{
  document.location.href = './index.html?code=' + code  + '&category=' + category.value;
}

// ±Û¾²±âÀÌµ¿
function goWrite(code)
{
  document.location.href = './write.html?code=' + code;
}

// ±ÛÀÐ±âÀÌµ¿
function goView(code, category, number, page, sfield, skey)
{
  document.location.href = './view.html?code=' + code + '&category=' + category + '&number=' + number + '&page=' + page + '&sfield=' + sfield + '&skey=' + skey;
}

// ¸ñ·ÏÀÌµ¿
function goList(code, category, page, sfield, skey)
{
  document.location.href = './index.html?code=' + code + '&category=' + category + '&page=' + page + '&sfield=' + sfield + '&skey=' + skey;
}

// ±Û¼öÁ¤ÀÌµ¿
function goEdit(code, number)
{
  document.location.href = './edit.html?code=' + code + '&number=' + number;
}

// ±Û¾²±âÃ³¸®
function articleWrite(f)
{
  if(f.category.value == 'null')
  {
    alert('Ä«Å×°í¸®¸¦ ¼±ÅÃÇÏ¼¼¿ä');
    return false;
  }
  if(emptyCheck(f.subject, 'Á¦¸ñ')) return false;
  if(firstSpaceCheck(f.subject, 'Á¦¸ñ')) return false;
	if(dhtml.document.body.innerHTML == '')
	{
		alert('³»¿ë Ç×¸ñÀÇ °ªÀÌ ÀÔ·ÂµÇÁö ¾Ê¾Ò½À´Ï´Ù');
    dhtml.document.body.focus();
		return false;
	}
	for(var i = 0; i < dhtml.document.links.length; i++)
	{
		dhtml.document.links[i].target = "_blank";
	}
	for(var i=0; i < dhtml.document.images.lenght; i++)
	{
		dhtml.document.images[i].width = 100;
	}
	f.content.value = dhtml.document.body.innerHTML;
  f.action = "./process.html";
  return true;
}


// ÄÚ¸àÆ®¾²±âÃ³¸®
function commentWrite(f)
{
  if(emptyCheck(f.comment, 'ÀÇ°ß')) return false;
  if(firstSpaceCheck(f.comment, 'ÀÇ°ß')) return false;
  f.action = "./process.html";
}

// ÄÚ¸àÆ®¾²±âÃ³¸®
function commentDelete(r)
{
  document.commentDeleteForm.rank.value = r;
  document.commentDeleteForm.action = "./process.html";
  document.commentDeleteForm.submit();
}

// ±Û»èÁ¦Ã³¸®
function articleDelete(f)
{
  if(confirm("»èÁ¦ÇÏ°Ú½À´Ï±î?"))
  {
    f.action = "./process.html";
    f.submit();
    return true;
  }
  else
  {
    return false;
  }
}


function articleCheckAll()
{
  var f = document.boardListForm;
  if(f.flag.value == "0")
  {
    for(i = 0; i < f.elements.length; i++)
    {
      if(f.elements[i].name == "n[]")
      {
        f.elements[i].checked = true;
      }
    }
    f.flag.value = "1";
    ca.innerHTML = "¼±ÅÃÇØÁ¦";
  }
  else
  {
    for(i = 0; i < f.elements.length; i++)
    {
      if(f.elements[i].name == "n[]")
      {
        f.elements[i].checked = false;
      }
    }
    f.flag.value = "0";
    ca.innerHTML = "ÀüÃ¼¼±ÅÃ";
  }
}









function regulateSelect(code)
{
  var f = document.boardListForm;
  var sValue = "";
  var cnt = 0;

  for(var i = 0; i < f.elements.length; i++)
  {
    if(f.elements[i].name == "n[]")
    {
      if(f.elements[i].checked)
      {
        if(cnt == 0) sValue = f.elements[i].value;
        else sValue = f.elements[i].value + "|" + sValue;
        cnt = cnt + 1;
      }
    }
  }
  if(cnt < 1)
  {
    alert('¼±ÅÃµÈ °Ô½Ã¹°ÀÌ ¾ø½À´Ï´Ù');
  }
  else
  {
    cw = screen.width;
    ch = screen.height;
    cw = cw/2-190;
    ch = (ch/2-100)-200;
    syoonOpen('regulate.html?code=' + code + '&sValue=' + sValue, 'regulate', cw, ch, 380, 320, 0, 0);
  }
}






/////////////////////////////////////////////
//BASIC EDIT FUNCTION
//±âº»ÀûÀÎ DHTML¿¡µðÆ¼ ÇÔ¼ö
/////////////////////////////////////////////
function webEditor_dhtmlEdit(excute, values)
{
  dhtml.focus();
  targetText = dhtml.document.selection.createRange();
  if(values==null) targetText.execCommand(excute);
  else targetText.execCommand(excute, "", values);
}


////////////////////////////////////////////
//SET FORECOLOR FUNCTION
//±ÛÀÚ»ö ¼³Á¤ ÇÔ¼ö
////////////////////////////////////////////
function webEditor_setForeColor()
{
	var color = showModalDialog("./colorchart.html", 0, "dialogHeight=140px; dialogWidth=120px; scrollbars=no; status=1; help=0");

  if(color!=null) dhtml.document.execCommand('ForeColor', '', color);
  dhtml.focus();
}

function webEditor_setBackColor()
{
	//SHOW MODALDIALOG WIDOW;
	var color = showModalDialog("./colorchart.html", 0, "dialogHeight=114px; dialogWidth=120px; scrollbars=no; status=0; help=0");

	//CHANGE FONT COLOR
	if(color!=null) dhtml.document.execCommand('BackColor', '', color);
	dhtml.focus();
}


/////////////////////////////////////////////
//CREATE LINK
//¸µÅ© ¼³Á¤ ÇÔ¼ö
/////////////////////////////////////////////
function webEditor_createLink()
{
	dhtml.focus();
	targetText = dhtml.document.selection.createRange();
	targetText.execCommand('CreateLink',1,'');
}


/////////////////////////////////////////////
//OPTIMIZING INNER HTML
//INNER HTML °ªÀ» ÀûÀýÇÑ ÇüÅÂ·Î º¯È¯
/////////////////////////////////////////////
function webEditor_optimizing()
{
	//CHECK CHAR
  if(emptyCheck(dhtml.document.body.innerHTML, '³»¿ë')) return false;

	if(dhtml.document.body.innerHTML=='')
	{
		alert('³»¿ëÀ» ÀÔ·ÂÇØÁÖ½Ê½Ã¿ä.');
		return false;
	}
	
	//CHANGE LINK TARGET INTO _NEW
	for(var i = 0; i < dhtml.document.links.length; i++)
	{
		dhtml.document.links[i].target = "_blank";
	}

	//CHANGE WIDTH ATTRIBUTE VALUE
	for(var i=0; i < dhtml.document.images.lenght; i++)
	{
		dhtml.document.images[i].width = 100;
	}

	//CHANGE DHTMLFRAME INTO TEXTAREA.VALUE
	f.content.value = dhtml.document.body.innerHTML;
}

function webEditor_changeMode(mode)
{
	if(mode=='html')
	{
		document.articleEditForm.content.value = dhtml.document.body.innerHTML;
		div_textarea.style.display = '';
		div_dhtml.style.display = 'none';
	}else{
		dhtml.document.body.innerHTML = document.articleEditForm.content.value;
		div_dhtml.style.display='';
		div_textarea.style.display='none';
	}
}

function imageUploadOpen(c)
{
  cw = screen.width;
  ch = screen.height;
  cw = cw/2-150;
  ch = (ch/2-100)-100;
  syoonOpen('upload.html?code=' + c, 'upload', cw, ch, 300, 180, 0, 0);
}

function imageUpload(f)
{
  f.action = "./process.html";
  f.submit();
}

function memoSendOpen(t)
{
  cw = screen.width;
  ch = screen.height;
  cw = cw/2-190;
  ch = (ch/2-100)-200;
  syoonOpen('../memo/memoSend.html?to=' + t, 'memosend', cw, ch, 380, 320, 0, 0)
}

function memoSendCheck(f)
{
  if(emptyCheck(f.to, '¹Þ´Â»ç¶÷')) return false;
  if(firstSpaceCheck(f.to, '¹Þ´Â»ç¶÷')) return false;
  if(emptyCheck(f.content, '³»¿ë')) return false;
  if(firstSpaceCheck(f.content, '³»¿ë')) return false;
  f.action = "../memo/memoProc.html";
  return true;
}

function emailSend()
{
  alert('ÁØºñÁßÀÔ´Ï´Ù');
}

function memInfoView()
{
  alert('ÁØºñÁßÀÔ´Ï´Ù');
}

function printLayer(name, memid, memnick)
{
  var layerHeader="<div id='"+name+"' style='position:absolute; left:0; top:0; width:120px; z-index:1; visibility:hidden' onMouseOver=\"showLayerStop('"+name+"')\" onMouseOut=\"hideLayer('"+name+"')\"><table width='120' border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff' style='border:2px solid #ff9900' style='cursor:hand'>";
  var layerMain="<tr onmouseover=\"this.style.backgroundColor='#fffff0'\" onmouseout=\"this.style.backgroundColor=''\"><td height='21' style='padding:3 0 0 5' onClick=\"memoSendOpen('"+memid+"')\"><font color='#ff6600'>ÂÊÁöº¸³»±â</font></td></tr><tr><td height='1' bgcolor='#f9f9f9'></td></tr><tr onmouseover=\"this.style.backgroundColor='#fffff0'\" onmouseout=\"this.style.backgroundColor=''\"><td height='21' style='padding:3 0 0 5' onClick=\"memInfoView()\"><font color='#ff6600'>È¸¿øÁ¤º¸º¸±â</font></td></tr>";
  var layerFooter="</table></div>";
  document.write(layerHeader + layerMain +  layerFooter);
}

function showLayer(name)
{
  var obj = document.all[name];
  _tmpx = event.clientX + parseInt(obj.offsetWidth);
  _tmpy = event.clientY + parseInt(obj.offsetHeight);
  _marginx = document.body.clientWidth - _tmpx;
  _marginy = document.body.clientHeight - _tmpy;
  if(_marginx < 0) _tmpx = event.clientX + document.body.scrollLeft + _marginx;
  else _tmpx = event.clientX + document.body.scrollLeft;
  if(_marginy < 0) _tmpy = event.clientY + document.body.scrollTop + _marginy +20;
  else _tmpy = event.clientY + document.body.scrollTop;
  obj.style.posLeft=_tmpx-13;
  obj.style.posTop=_tmpy-12;
  obj.style.visibility = "visible";
}

function showLayerStop(name)
{
  var obj = document.all[name];
  obj.style.visibility = "visible";
}

function hideLayer(name)
{
  var obj = document.all[name];
  document.all[name].style.visibility = "hidden";
}