
var iframeStyle = "<style>P,TD,BODY,HTML {margin:0px; padding:1px; border=0; FONT-FAMILY:±¼¸²; FONT-SIZE: 10PT; COLOR: #000000;}</style>";
var inputMode ='TEXT';
var iframeWidth = 437
var iframeHeight = 173;


// focus
function Focus(){
	if(inputMode == 'HTML')
		htmlContent.focus();	
	else
		document.shForm.textContent.focus();
}


/* ºê¶ó¿ìÀú ¹öÀü Ã¼Å© */
function exploerVerCheck(){
	
	if(navigator.userAgent.indexOf('MSIE 5.') != -1) return true;
	else if(navigator.userAgent.indexOf('MSIE 6.') != -1) return true;
		else if(navigator.userAgent.indexOf('MSIE 7.') != -1) return true;
	return false;
}


/* execCommand ½ÇÇà */
function execComm(comm, value){
	// ½ÇÇàÀü¿¡ Æ÷Ä¿½º¸¦ ¹Ì¸®ÁØ´Ù
	Focus();
	if(inputMode == 'HTML')
		htmlContent.document.execCommand(comm, false, value);
	else
		alert('Edit ÆíÁý¸ðµå¿¡¼­¸¸ ÀÛµ¿ÇÕ´Ï´Ù');
	return false;
}


/* edit ±â´ÉÀ¸·Î ÀüÈ¯½Ã ³»¿ëº¯È¯ */
// text,html¿¡¼­ edit ±â´ÉÀ¸·Î ³Ñ¾î°¥¶§ \rµîÀÇ Ã³¸®¸¦ ÇÏÁö¾Ê´Â´Ù.
// Áï text¸é text edit¸é edit¸¸ »ç¿ëÇØ¾ßÇÕ.
// ³»¿ëÃâ·Â½Ã ¿©·¯°¡Áö ¹®Á¦Á¡ÀÌ ¹ß»ýµÊ
function ChangeHtml(string){
	
	//string = string.replace(/>\r\n/g, ">");
	//string = string.replace(/\r\n<P>/g, "<P>");
	//string = string.replace(/\r\n/g, "<BR>");
	return iframeStyle + string;
}


/* text ¸ðµå·Î ÀüÈ¯½Ã ³»¿ëº¯È¯ */
function ChangeText(string){
	a = string.indexOf("<BODY>")+6;
	b = string.indexOf("</BODY>");
	string = string.substring(a, b);
	//string = string.replace(/<BR>/g, "\r\n");
	return string;
}


/* change Mode  */
function changeMode(){
	var tempStr = '';

	// ¹öÀü Ã¼Å© 
	if(!exploerVerCheck()){
		alert('HTML Edit ÆíÁý¸ðµå´Â ÀÍ½ºÇÁ·Î·¯ 5.0 ÀÌ»ó¿¡¼­¸¸ ÀÛµ¿ÇÕ´Ï´Ù.');
		return false;
	}
	if(inputMode=='TEXT'){ // text->html
		
		inputMode='HTML';
		tempStr = document.shForm.textContent.value;
		sp_textarea.style.display='none';
		sp_textarea.style.position = 'absolute';
		sp_iframe.innerHTML = "<iframe id='htmlContent' margintop=0 marginleft=0 width="+iframeWidth+" height="+iframeHeight+" style='BORDER:1 SOLID #B6B5B5; PADDING: 1PT; margin:0px;font-family:±¼¸²;font-size: 10pt;'></iframe>";

		htmlContent.document.designMode = 'on';
		htmlContent.document.open();
		htmlContent.document.write(ChangeHtml(tempStr));
		htmlContent.document.close();
		htmlContent.document.execCommand('2D-Position',1);
		htmlContent.document.execCommand('LiveResize',1);

	}else{ // html->text
		inputMode='TEXT';
		tempStr = htmlContent.document.documentElement.outerHTML + '';
		sp_iframe.style.height=1;
		sp_iframe.innerHTML='';
		sp_textarea.style.display='';
		sp_textarea.style.position='';
		document.shForm.textContent.innerText = ChangeText(tempStr);
	}

	Focus();
	return false;
}


/* ÆÈ·¡Æ® ºä */
function showPalette(){
	if(inputMode == 'HTML'){
		div_palette.style.posLeft = event.clientX - 60;
		div_palette.style.posTop = event.clientY + document.body.scrollTop + 10;
		div_palette.style.display = "";
	}else{
		alert('Edit ÆíÁý¸ðµå¿¡¼­¸¸ ÀÛµ¿ÇÕ´Ï´Ù');
	}
}

/* ÆÈ·¡Æ® °¨Ãã */
function hidePalette(){
	div_palette.style.display = "none";
}


function cgInfoSubmit(){
	
	if(inputMode=='HTML') changeMode();
	document.shForm.submit();
	return true;
}


function ctChange(){
	
	var form = document.shForm;
	var ctVal = form.isHtml.options[form.isHtml.selectedIndex].value;
	if(ctVal =="EDIT" && inputMode=="TEXT"){
		changeMode();
	}else if(inputMode=="HTML"){
		changeMode();
	}
}

