
var onEditMode = true;

var eobj = null;

var Selection = null;
			 
function SetFont(ch){
	if (ch.options[ch.selectedIndex].value != '')
       eobj.document.execCommand("FontName", null, ch.options[ch.selectedIndex].value);
}

function SetFontSize(ch){
	if (ch.options[ch.selectedIndex].value != '')
          eobj.document.execCommand("FontSize", null, ch.options[ch.selectedIndex].value);
}

function checkpos(){

	try {
   	var sText = eobj.document.selection.createRange();
	if (sText.parentElement().all.eobj == null && sText.parentElement().all.papermain == null){
		
         var lineval = sText.parentElement().outerHTML;
         lineval = lineval.toLowerCase();

		 var idx = lineval.indexOf("<font");
		 if (idx > -1)
		 {
			 try{
             
             if (sText.parentElement().face != null)
             {
				 if (sText.parentElement().face != "")
				 {
					 document.all.fontface.value = sText.parentElement().face;
				 }
			      else{
					 document.all.fontface.selectedIndex = 1;
				 }

             }
				 else{
					 document.all.fontface.selectedIndex = 1;
				 }
             if (sText.parentElement().size != null)
             {
				 if (sText.parentElement().size != "")
				 {
				      document.all.fontsize.value = sText.parentElement().size;
				 }
				 else{
					 document.all.fontsize.selectedIndex = 0;
				 }
             }
				 else{
					 document.all.fontsize.selectedIndex = 0;
				 }

			 }
			 catch(e){}

		
		 }else{
			 try{
             document.all.fontface.selectedIndex = 1;
             document.all.fontsize.selectedIndex = 0;
			 }
			 catch(e){}

		 }
	}
}
			 catch(e){}
}

function checkposkey( ) {

	if (eobj.event.keyCode >= 37 && eobj.event.keyCode <= 40)
	{
		var sText = eobj.document.selection.createRange();
		if (sText.parentElement().all.eobj == null && sText.parentElement().all.papermain == null){
			 var lineval = sText.parentElement().outerHTML;
			 lineval = lineval.toLowerCase();
			 var idx = lineval.indexOf("<font");
			 if (idx > -1)
			 {
			 try {
             	if (sText.parentElement().face != null)
             	{
					 if (sText.parentElement().face != "")
					 {
						 document.all.fontface.value = sText.parentElement().face;
					 }
			 	     else{
						 document.all.fontface.selectedIndex = 1;
					 }
             	
             	} else {
						 document.all.fontface.selectedIndex = 1;
			 	}
			 	
             	if (sText.parentElement().size != null)
             	{
					 if (sText.parentElement().size != "")
					 {
					      document.all.fontsize.value = sText.parentElement().size;
					 }
					 else{
						 document.all.fontsize.selectedIndex = 0;
					 }
             	} else {
						 document.all.fontsize.selectedIndex = 0;
			 	}
			 }
			 catch(e) { }

			 } else {
			 	try {
             		document.all.fontface.selectedIndex = 1;
             		document.all.fontsize.selectedIndex = 0;
			 	}
				catch(e){}
			}
		}

	}

}
	
function action(order){

	if ( !onEditMode ) {
		alert("¼Ò½ºº¸±â »óÅÂ¿¡¼­´Â ¿¡µðÅÍ¸¦ »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù!")
		return false;
	}						

	Selection = eobj.document.selection.createRange();
	
	if (Selection!=null) Selection.select();

	if (Selection.text == '')
	{
		return;
	}
	
	if (order == "Bold"){
	  eobj.document.execCommand("Bold");
	}
	else if (order == "Italic"){
	  eobj.document.execCommand("Italic");
	}
	else if (order == "Underline"){
	  eobj.document.execCommand("Underline");
	}
	else if (order == "fontcolor") {
	  FontColor('1');
	}
	else if (order == "bgcolor") {
	  FontColor('2');
	}
	else if (order == "alignLeft") {
	  eobj.document.execCommand("JustifyLeft");
	}
	else if (order == "alignCenter") {
	  eobj.document.execCommand("JustifyCenter");
	}
	else if (order == "alignRight")   {
	  eobj.document.execCommand("JustifyRight");  
	}
	else if (order == "link")   {
	   eobj.focus();
	   eobj.document.execCommand("CreateLink",1);  	
	}
	else if (order == "Strike")   {
	  eobj.document.execCommand("StrikeThrough");
	}

}

function FontColor( ch ){

	if (navigator.userAgent.indexOf("MSIE 5.0") > 0)
	{
		 document.all["TableFontColor"].style.top = "65";
	     document.all["TableFontBackColor"].style.top = "65";
	}

	if (ch=="1") {  
		document.all["TableFontColor"].style.display = "";
		document.all["TableLink"].style.display = "none";
		document.all["TableFontBackColor"].style.display = "none";
	}
	if (ch=="2") {
		document.all["TableLink"].style.display = "none";
		document.all["TableFontColor"].style.display = "none";
		document.all["TableFontBackColor"].style.display = "";
	}
}


function Set_fontcolor(color){

    if (Selection!=null)Selection.select();
    eobj.document.execCommand("forecolor", null, color);
    document.all["TableFontColor"].style.display = "none";
	eobj.document.selection.empty()
	
}

function Set_bgcolor(color,color2) {
    
if( Selection!=null ) Selection.select();
	eobj.document.execCommand( "BackColor", null, color );
	if (color2 != "")
	{
          eobj.document.execCommand("forecolor", null, color2);
	}
    document.all["TableFontBackColor"].style.display = "none";
	eobj.document.selection.empty()

}

function Set_backcolor(color) {

	eobj.document.body.style.backgroundColor = color;

}

function Set_link(mylink){
	if( Selection!=null ) Selection.select();
	
	eobj.document.execCommand("CreateLink", null, mylink);
	document.all["TableLink"].style.display = "none";
	document.all["linkbox"].value = 'http://';

}

function ShowHtml(){
	var source = "<html><head>"
		+ "\n<style>"
		+ "\nP {margin-top:2px;margin-bottom:2px;} "
//		+ "\ntable {border:1 solid C6C3C6}"
		+ "\nbody {margin:5px}"
		+ "\n</style>"
		+ "\n<script>"
		+ "\nfunction resizeImage(num){}"
		+ "\n</script>"
		+ "\n</head>"
		+ "\n<body>"
		+ "\n</body>"
		+ "\n</html>"
	if (document.compose.HtmlYn.selectedIndex == 1)
	{
		document.compose.body.value = eobj.document.body.innerHTML.replace(/<br>/gi,"<br>\n");
		document.getElementById('POSTEDITOR').style.display = "none";
		document.compose.body.style.display = "";
		onEditMode = false;
	}
	else{
 		eobj = POSTEDITOR;
		POSTEDITOR.document.designMode="On"
		POSTEDITOR.document.open("text/html");
		POSTEDITOR.document.write(source);
		POSTEDITOR.document.close();
		POSTEDITOR.document.body.style.fontSize = "9pt";
		POSTEDITOR.document.body.style.fontFamily = "µ¸¿ò";
		POSTEDITOR.document.onmouseup = checkpos;
		POSTEDITOR.document.onkeyup = checkposkey;

		POSTEDITOR.document.body.innerHTML = document.compose.body.value;
		document.compose.body.style.display = "none";
		document.getElementById('POSTEDITOR').style.display = "";

        onEditMode = true;
	}
}

function setSubmitValue() {
	document.compose.body.value = "<html><head>"
		+ "\n</head>"
		+ "\n<body>";
	document.compose.body.value += POSTEDITOR.document.body.innerHTML;
	document.compose.body.value += "</body></html>";
}

