var maxWidth = 550;

browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
if (browserName == "Netscape" && browserVer >= 3) {
  ini = "net";
}
else {
  ini = "ie";
}

if ((ini == "net")||((ini == "ie")&&(browserVer >= 4))){
  img_array=new Array();
  img_array[0]=new Image;
  img_array[0].src="/editor/icon/t_article.gif";
  img_array[1]=new Image;
  img_array[1].src="/editor/icon/t_notice.gif";
  img_array[2]=new Image;
  img_array[2].src="/editor/icon/t_note.gif";
  img_array[3]=new Image;
  img_array[3].src="/editor/icon/t_pin.gif";
  img_array[4]=new Image;
  img_array[4].src="/editor/icon/t_pen.gif";
  img_array[5]=new Image;
  img_array[5].src="/editor/icon/t_schedule.gif";
  img_array[6]=new Image;
  img_array[6].src="/editor/icon/t_news.gif";
  img_array[7]=new Image;
  img_array[7].src="/editor/icon/t_file.gif";
  img_array[8]=new Image;
  img_array[8].src="/editor/icon/t_question.gif";
  img_array[9]=new Image;
  img_array[9].src="/editor/icon/t_answer.gif";
  img_array[10]=new Image;
  img_array[10].src="/editor/icon/t_cake.gif";
  img_array[11]=new Image;
  img_array[11].src="/editor/icon/t_program.gif";
  img_array[12]=new Image;
  img_array[12].src="/editor/icon/t_wedding.gif";
  img_array[13]=new Image;
  img_array[13].src="/editor/icon/t_smile.gif";
  img_array[14]=new Image;
  img_array[14].src="/editor/icon/t_sad.gif";
  img_array[15]=new Image;
  img_array[15].src="/editor/icon/t_bungae.gif";
}    

function imgChange(se) {
  name1=se.options[se.selectedIndex].value;
  no=0;
  if (name1=='t_articel.gif') no=1;
  if (name1=='t_notice.gif') no=2;
  if (name1=='t_note.gif') no=3;
  if (name1=='t_pen.gif') no=4;
  if (name1=='t_schedule.gif') no=5;
  if (name1=='t_news.gif') no=6;
  if (name1=='t_file.gif') no=7;
  if (name1=='t_question.gif') no=8;
  if (name1=='t_answer.gif') no=9;
  if (name1=='t_cake.gif') no=10;
  if (name1=='t_program.gif') no=11;
  if (name1=='t_wedding.gif') no=12;
  if (name1=='t_smile.gif') no=13;
  if (name1=='t_sad.gif') no=14;
  if (name1=='t_bungae.gif') no=15;
  document.CategoryImg.src=img_array[no].src;  
}

function init(param){
  var iText = content.document;
  iText.designMode = "On";
  TextEditView.style.display="inline";
  //content.document.onmousedown = new Function("contentEvent()");
  iText.execCommand("2D-Position",1);
  iText.execCommand("LiveResize",1);
  content.focus();
  no = write_f.currentMode.value;
   if(no == 2){
    write_text.style.display = "";
    write_html.style.display = "none";
    write_f.html_yn.value = "n"; 
   }else if(no == 3){
     write_text.style.display = "";
    write_html.style.display = "none";
    write_f.html_yn.value = "y"; 
   }else if(no == 0){
     write_text.style.display = "none";
    write_html.style.display = "";
    write_f.html_yn.value = "y"; 

   }
  if(param == "edit" || param == "reply"){
    setTimeout(boardEdit,3);
    
  }
  
}

function btnUp(param) {
  param.style.border="1px outset";
  param.style.background="#D4D4D4";
}

function btnDn(param) {
  param.style.border="";
  param.style.background="#D4D4D4";
}

function CommandExec(Btn, cmd) {
  content.focus();
  var EdRange = content.document.selection.createRange();
  EdRange.execCommand(cmd);
}

function changeFC(param,cmd){
  var ed
  ed = content.document.selection.createRange();
  ed.execCommand(cmd, false, param);
}

function changeFN_FS(o, cmd) {
  var ed=content.document.selection.createRange();
  ed.execCommand(cmd, false, o.value);
}

function insSmile(){
  content.focus();
  str=showModalDialog('/editor/Smile.html', 0, 'dialogWidth:500px; dialogHeight:340px;status:0;scroll:1; help:0;');
  if (str)
    content.document.selection.createRange().pasteHTML(str);
}

function insTable(){
  content.focus();
  str=showModalDialog('/editor/insTable.html', 0, 'dialogWidth:550px; dialogHeight:600px;status:0;scroll:1; help:0;');
  if (str)
    content.document.selection.createRange().pasteHTML(str);
}

function insFile(code)
{
  var FileCmd = "/editor/insFile.html?code=" + code;
  window.open(FileCmd, 'InsertFile', 'Width=500, Height=200, resizable=no,channelmode=no');
}

function insImage(code)
{
  var ImgCmd = "/editor/insImage.html?code=" + code;
  window.open(ImgCmd, 'insImage', 'width=600, height=500');
}

function addBground()
{
  var addurl = "/editor/addBground.html";
  window.open(addurl, 'addBground', 'width=500, height=200');
}

function help()
{
  var addurl = "/editor/help.html";
  window.open(addurl, 'help', 'width=500, height=450,scrollbars=yes,resizable=yes');
}

function chMode(text) { //ÆíÁýÈ­¸é, HTML, ¹Ì¸®º¸±â ¼±ÅÃ
  var strPos = write_f.currentMode.value;
  if (text == 0) {  // ÆíÁýÈ­¸é
    write_f.currentMode.value=0;
    htmlView.style.display="none";
    Preview.style.display="none";
    TextEditView.style.display="inline";
  }
  else if (text == 1) {  // html º¸±â
    write_f.currentMode.value=1;
    write_f.contents.value = content.document.body.innerHTML;
    TextEditView.style.display="none";
    Preview.style.display="none";
    htmlView.style.display="inline";
  }
  else if (text == 2) {  // ¹Ì¸®º¸±â
    if (strPos == 0) {
      Preview.innerHTML = content.document.body.innerHTML;
      write_f.contents.value = content.document.body.innerHTML;
    }
    else if (strPos == 1) {
      Preview.innerHTML = write_f.contents.value;
      content.document.body.innerHTML = write_f.contents.value;
    }
    TextEditView.style.display="none";
    htmlView.style.display="none";
    Preview.style.display="inline";
  }
}

function SaveAs() {
//  document.form1.contents.value = window.frames.content.document.body.innerHTML;
  //var theForm = document.form1;

  form.submit();
}

function boardEdit() {
	TextEditView.style.display="inline";
  content.document.body.innerHTML = write_f.tmpcontent.value;	
}

function ReturnList(code,where) {
  document.location = "./" + where + "?code=" + code;
}

function contentEvent() {

  if (content.event.button==2 || content.event.button==3) {
    var oSource = content.event.srcElement ;
    if (!oSource.isTextEdit)
      oSource = content.event.srcElement.parentTextEdit;

    var strValue = content.event.srcElement.tagName; //¼±ÅÃµÈ ºÎºÐÀÇ ÅÂ±× Á¾·ù
    if ((strValue == "IMG" || strValue == "HR") && oSource != null) {
      var oTextRange = oSource.createTextRange();
    }

    var selectedRange = content.document.selection.createRange();
    var edValue = selectedRange.htmlText;

    var strX = content.event.x;
    var strY = content.event.y+180;

    if (strValue == "IMG")
      strH = "180px";
    else if (strValue == "HR" || strValue == "TABLE")
      strH = "135px";
    else
      strH = "300px";

    var strParam = "dialogLeft:" + strX + ";dialogTop:" + strY + ";"
    strParam = strParam + "center:no;dialogWidth:150px; dialogHeight:" + strH + ";status:0;scroll:0; help:0;unadorned:yes;"

    var strRmenu = window.showModalDialog("rightMenu.html", strValue , strParam);

    if (strRmenu == "TableEdit") {
      content.focus();
      var edValue = content.event.srcElement;
      if ( strValue == "TR" || strValue == "TD") {
        str=showModalDialog('editCell.html', edValue, 'dialogWidth:550px; dialogHeight:600px;status:0;scroll:1; help:0;');
      }
      else {
        str=showModalDialog('insTable.html?mode=edit', edValue, 'dialogWidth:550px; dialogHeight:600px;status:0;scroll:1; help:0;');
      }

      if (str) {
        if ( strValue == "TABLE") {
          content.event.srcElement.cellPadding=str.cellPadding;
          content.event.srcElement.cellSpacing=str.cellSpacing;
          if (str.border) {
            content.event.srcElement.border=str.border;
          }
        }
        else {
          content.event.srcElement.vAlign=str.vAlign;
        }

        content.event.srcElement.style.width=str.style.width;
        content.event.srcElement.style.height=str.style.height;

        content.event.srcElement.align=str.align
        content.event.srcElement.borderColor=str.borderColor
        content.event.srcElement.bgColor=str.bgColor
      }
    }
    else if (strRmenu == "Table") {
      content.focus();
      var edValue = content.event.srcElement;
      str=showModalDialog('insTable.html',edValue, 'dialogWidth:500px; dialogHeight:600px; status:0; scroll:0; help:0;');
      if (str)
        content.document.selection.createRange().pasteHTML(str);
    }
    else if (strRmenu == "FileAttach"){
		var code = document.form1.code.value ;
      insFile(code);
	}

    else if (strRmenu == "insImage"){
		var code = document.form1.code.value ;
      insImage(code);
	}

    else if (strRmenu == "ImageEdit") {
      content.focus();
      var edValue = content.event.srcElement;
      str=showModalDialog('imgEdit.html', edValue, 'dialogWidth:500px; dialogHeight:300px; status:0; scroll:0; help:0;');
      if (str) {
        content.event.srcElement.style.width=str.style.width;
        content.event.srcElement.style.height=str.style.height;
        content.event.srcElement.vspace=str.vspace;
        content.event.srcElement.align=str.align;
        content.event.srcElement.hspace=str.hspace;
        content.event.srcElement.border=str.border;
      }
    }
    else if (strRmenu == "HREdit") {
      content.focus();
      var edValue = content.event.srcElement;
      str=showModalDialog('editHR.html', edValue, 'dialogWidth:500px; dialogHeight:320px; status:0; scroll:1; help:0;');
      if (str) {
        content.event.srcElement.style.width = str.style.width;
        content.event.srcElement.style.height = str.style.height;
        content.event.srcElement.color = str.color;
        content.event.srcElement.noShade = str.noShade;
      }
    }
    else if (strRmenu == "Clipart") {
      insSmile()
    }
    else if (strRmenu == "InsertTemplate")
      InsertTemplate();
    else if (strRmenu == "ParaHeight")
      ParaHeight();
    else
      CommandExec(this,strRmenu);
  }
}


function viewImg(src) {
  tempImg = new Image();
  tempImg.src = src
  if(tempImg.width > 780){
	  width = 780;
  }else{
	width = tempImg.width + 18;
  }
  if(tempImg.height > 520){
	  height = 540;
  }else{
	  height = tempImg.height +23;
  }
  style = "width=" + width +", height=" + height +", scrollbars=yes";
  window.open("imgView.html?src=" + src, "view", style);
}

function upEvent(e) {
  alert('merong');
}

function sendMail(param) {
  SM = window.open('./mail.html?' + param,'SendMail','width=600,height=680,scrollbars=0,resizable=0');
  SM.moveTo(0, 0);
}


function mode_ch(no){
  if(no == 0){
    write_text.style.display = "";
    write_html.style.display = "none";
    write_f.html_yn.value = "n"; 
    if(write_f.currentMode.value == 0 || write_f.currentMode.value == 1){
      write_f.text_contents.value = content.document.body.innerHTML;
      content.document.body.innerHTML = "";
    }
    write_f.text_contents.focus();
    write_f.currentMode.value = 2;
  }else if(no == 1){
    write_text.style.display = "";
    write_html.style.display = "none";
    write_f.html_yn.value = "y";
    if(write_f.currentMode.value == 0 || write_f.currentMode.value == 1){
      write_f.text_contents.value = content.document.body.innerHTML;
      content.document.body.innerHTML = "";
      
    }write_f.text_contents.focus();
    write_f.currentMode.value = 3;
  }else if(no == 2){
    write_text.style.display = "none";
    write_html.style.display = "";
    write_f.html_yn.value = "y";
    if(write_f.currentMode.value == 2 || write_f.currentMode.value == 3){
      content.document.body.innerHTML = write_f.text_contents.value;
      write_f.text_contents.value = "";
      content.focus();
    }
    write_f.currentMode.value = 0;
  }

}
