var Myselect = null;
var edittype = '3';

function Editinit(ch) 
{

    //var Mysource = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=ks_c_5601-1987'><META content='MSHTML 6.00.2800.1141' name=GENERATOR><style>P {margin-top:2px;margin-bottom:2px;}</style></head><body></body></html>";

    var Mysource = "<style>P {margin-top:0px;margin-bottom:0+px;}</style>"

    HTMLEDITOR.document.designMode="On"
    HTMLEDITOR.document.open("text/html");
    HTMLEDITOR.document.write(Mysource);
    HTMLEDITOR.document.close();
    HTMLEDITOR.document.body.style.fontSize = "9pt";
    HTMLEDITOR.document.body.style.fontFamily = "±¼¸²";
    HTMLEDITOR.document.oncontextmenu = new Function("return false;");
  //  document.cgiForm.name.focus();

    edit_type(ch);

}


function Viewinit(tag) 
{
    var Mysource = "<style>P {margin-top:0px;margin-bottom:0px;}</style>"

    HTMLEDITOR.document.designMode="off"
    HTMLEDITOR.document.open("text/html");
    HTMLEDITOR.document.write(Mysource);
    HTMLEDITOR.document.close();
    HTMLEDITOR.document.body.style.fontSize = "9pt";
    HTMLEDITOR.document.body.style.fontFamily = "±¼¸²";
    HTMLEDITOR.document.oncontextmenu = new Function("return false;");

    view_content(tag)

}
			
function view_content(ch)
{
    var height1;
    document.cgiForm.content.style.display = 'none';
    HTMLEDITOR.document.body.innerHTML = document.cgiForm.content.value;
    height1=document.all.HTMLEDITOR.document.body.scrollHeight + 20;
    alert(height1);
    document.all.HTMLEDITOR.height = height1;
}


function edit_type(ch){
	if (edittype != ch){
          var br_content	          
          
          
          if (ch=='1'){
            document.all.editorTable.style.display='';
            document.cgiForm.content.style.display = 'none';
            HTMLEDITOR.document.body.innerHTML = document.cgiForm.content.value;
            HTMLEDITOR.focus();
          }
          else if(ch=='2'){
            document.all.editorTable.style.display='none';
            document.cgiForm.content.style.display = '';
            if (edittype =='1')
            {
              document.cgiForm.content.value = HTMLEDITOR.document.body.innerHTML;
            }
            document.cgiForm.content.focus();
          }
          else if(ch=='3'){
            document.all.editorTable.style.display='none';
            document.cgiForm.content.style.display = '';
            if (edittype =='1')
            {
              document.cgiForm.content.value = HTMLEDITOR.document.body.innerHTML;
            }
//            document.cgiForm.content.value = replace_str(document.cgiForm.content.value,3);
            document.cgiForm.content.focus();
          }
          
          edittype = ch;
       //   document.cgiForm.edit_type2.value = ch;   
	}
}       




function SetFont(ch){
			
    if (ch.options[ch.selectedIndex].value != '')
           HTMLEDITOR.document.execCommand("FontName", null, ch.options[ch.selectedIndex].value);
                 
    //ch.selectedIndex = 0;   
    //document.all.HTMLEDITOR.focus();    
			
}


function SetFontSize(ch){
			
    if (ch.options[ch.selectedIndex].value != '')
              HTMLEDITOR.document.execCommand("FontSize", null, ch.options[ch.selectedIndex].value);
                    
    //ch.selectedIndex = 0;
    //document.all.HTMLEDITOR.focus();
}


//ÀÌ¹ÌÁö ¾ÆÀÌÄÜ °ü·Ã ½ºÅ©¸³Æ®
//ÀÌ¹ÌÁö ¾ÆÀÌÄÜ °ü·Ã ½ºÅ©¸³Æ®
function ImgSrc(imgURL){
    this.imginsert2('http://www.ddorongi.com'+imgURL);
}


function findarea(){
	
  i_emoticon.location.href = '/webediter/Select_EmoIcon.asp';
  emoticonLayer.style.display="";
//  emoticonLayer.style.left = event.x-1;
//  emoticonLayer.style.top = event.y-2;
}

function close_area(){
parent.document.all.emoticonLayer.style.display = 'none';
}

function go_display()
{

    var xx, yy, x1, x2, y1, y2;
    var mousex, mousey;
    var xcheck_value, ycheck_value;

    // ¸¶¿ì½ºÀÇ ÇöÀç À§Ä¡
    mousex = event.x+10;
	  mousey  = event.y+10;
    
    xx = document.all.emoticonLayer.style.left.split("px");
    yy = document.all.emoticonLayer.style.top.split("px");
    
    x1 = parseInt(xx[0]);
    y1 = parseInt(yy[0]);

    x2 = x1 + 110; 
    y2 = y1 + 63;

   
    // ¸¶¿ì½º ·¹ÀÌ¾î ¹üÀ§ ¾È¿¡ ÀÖ´ÂÁö °Ë»ç
    if ( x1 <= mousex  &&  mousex <= x2 )        xcheck_value =1;
    if ( y1 <= mousey  && mousey <= y2 )         ycheck_value =1;

    if (xcheck_value == 1 && ycheck_value  == 1) ;
    else     document.all.emoticonLayer.style.display='none'; 

} 


function  event_mouse()
{
    go_display();
}



function AttachFile(frm_name,align, file_size){

  window.open('/webediter/insertImage.asp?old_filesize='+file_size,'FileUpLoad','height=205,width=305,scrollbars=no,resizable=no');
 
}



function GetSource(){

    var backcolor = HTMLEDITOR.document.body.style.backgroundColor;
    var obj = HTMLEDITOR.document.all["backcolor"];
    var HTMLSOURCE = '';			                                

    if (HTMLEDITOR.document.body.innerHTML == ''){
      alert('Please! Insert a content.');
      HTMLEDITOR.focus();
      return;
    }


    if (backcolor.length == 0 || obj != null)
        HTMLSOURCE = "<STYLE>P {MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px}</STYLE>\n" + HTMLEDITOR.document.body.innerHTML;
    else
      HTMLSOURCE = "<div id='backcolor' style='background-color:" + backcolor + "'><STYLE>P {MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px}</STYLE>\n" + HTMLEDITOR.document.body.innerHTML + "</div>";

    return HTMLSOURCE;

}
			
function test(){
			
    alert(HTMLEDITOR.document.all.tags("html")[0].outerHTML);
			
}
			
function mouse_on(obj){
			
    obj.borderColorDark = "white";
    obj.borderColorLight = "black";
    obj.style.cursor = "hand";
          
    //alert(obj.id);
			
}
			
function mouse_out(obj){
			

obj.borderColorDark = "#F9F9F9";
obj.borderColorLight = "#F9F9F9";
			
			
//alert(obj.id);
			
}
function mouse_click(obj){
			

    Myselect = HTMLEDITOR.document.selection.createRange();
          
    obj.borderColorDark = "black";
    obj.borderColorLight = "white";	
			
			  		
}
			
function menu_click(obj){
						
    if (Myselect!=null)Myselect.select();
          
    if (obj.id == "id_Bold"){
      HTMLEDITOR.document.execCommand("Bold");
    }
    else if (obj.id == "id_Italic"){
      HTMLEDITOR.document.execCommand("Italic");
    }
    else if (obj.id == "id_Underline"){
      HTMLEDITOR.document.execCommand("Underline");
    }
    else if (obj.id == "id_fontcolor") {
      Select_Color('1');
    }
    else if (obj.id == "id_bgcolor") {
      Select_Color('2');
    }
    else if (obj.id == "id_backcolor") {
      Select_Color('3');
    }
    else if (obj.id == "id_alignLeft") {
      HTMLEDITOR.document.execCommand("JustifyLeft");
    }
    else if (obj.id == "id_alignCenter") {
      HTMLEDITOR.document.execCommand("JustifyCenter");
    }
    else if (obj.id == "id_alignRight")   {
      HTMLEDITOR.document.execCommand("JustifyRight");  
    }
    else if (obj.id == "id_imgup")   {
      InsertImage();	
    }
    else if (obj.id == "id_link")   {
      Set_link();	
    }  					

}
			
function Select_Color(type)
{
    var opener

    if(opener == true)
        opener.close();
    opener = window.open('/Webediter/Select_Color.asp?type=' + type, 'Editcolorpicker', 'width=320,height=369 resizable=no,menubar=no');
}

function Set_fontcolor(color){

    HTMLEDITOR.document.execCommand("forecolor", null, color);

}

function Set_bgcolor(color){

HTMLEDITOR.document.execCommand( "BackColor", null, color );

}

function Set_backcolor(color){

var obj = HTMLEDITOR.document.all["backcolor"];

if (obj != null)
  HTMLEDITOR.document.all["backcolor"].style.backgroundColor = color;
else
  HTMLEDITOR.document.body.style.backgroundColor = color;

}

function InsertImage(){
   open("/WebEditer/Insert_Image.asp","insertImage","height=205,width=305");
}

function Set_link(){

var mylink = prompt("Please! Insert a link.","http://");
//HTMLEDITOR.document.execCommand("CreateLink", null, mylink);
Myselect = HTMLEDITOR.document.selection.createRange();
if (Myselect!=null){
    Myselect.pasteHTML("<a href=\"" + mylink + "\" target=\"_blank\">" + Myselect.text + "</a> ");
}

}

function imginsert(url,type){
  try{
  var sText = HTMLEDITOR.document.selection.createRange();
  if (sText.parentElement().all.HTMLEDITOR == null){
      if (sText.parentElement().outerHTML.indexOf('<BODY') > 0){
      sText.parentElement().innerHTML = "<P><img src='" + url + "' align='" + type + "' border=0>" + sText.parentElement().innerHTML + "</P>"
      }
      else{
      sText.parentElement().innerHTML = "<img src='" + url + "' align='" + type + "' border=0>" + sText.parentElement().innerHTML;
      }    
      }
  else{
   HTMLEDITOR.document.body.innerHTML =  "<img src='" + url + "' align='" + type + "' border=0>" + HTMLEDITOR.document.body.innerHTML
  }    
  }
  catch(e){           
   alert('There is not a possibility of doing an icon insertion')
   }
}


function imginsert2(url, width, height){

  try{
  var sText = HTMLEDITOR.document.selection.createRange();
  if (sText.parentElement().all.HTMLEDITOR == null){
            sText.pasteHTML("<img src='"+url+"' width='"+width+"'  border=0>");
            sText.select();
             //HTMLEDITOR.document.execCommand("InsertImage", null, url);
             }
  else{
  HTMLEDITOR.document.body.innerHTML =  "<img src='"+url+"' width='"+width+"'  border=0>" + HTMLEDITOR.document.body.innerHTML
  HTMLEDITOR.focus();
  }           
             
  }
  catch(e){           
   alert('There is not a possibility of doing an icon insertion')
   }
}


function imginsert3(url){

  try{
  var sText = HTMLEDITOR.document.selection.createRange();
  if (sText.parentElement().all.HTMLEDITOR == null){
            sText.pasteHTML("<img src='"+url+"' >");
            sText.select();
             //HTMLEDITOR.document.execCommand("InsertImage", null, url);
             }
  else{
  HTMLEDITOR.document.body.innerHTML =  "<img src='"+url+"'>" + HTMLEDITOR.document.body.innerHTML
  HTMLEDITOR.focus();
  }           
             
  }
  catch(e){           
   alert('There is not a possibility of doing an icon insertion')
   }
}


