
/* ¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê

	º»ÆäÀÌÁö´Â ¾ÆÁöÆ® °Ô½ÃÆÇ, »çÁøÃ¸, ´ÙÀÌ¾î¸®, °³ÀÎÇÁ·ÎÇÊ¿¡ »ç¿ëµÇ´Â 
	¿¡µðÅÍ¸¦ Á¦¾îÇÏ±âÀ§ÇÑ ½ºÅ©¸³Æ®ÀÔ´Ï´Ù.

¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê¢Ê */
// ±âº»Á¤º¸
var iframeStyle = "<style>P,TD,BODY,HTML {margin:0px; padding:1px; border=0; FONT-FAMILY:±¼¸²; FONT-SIZE: 9PT; COLOR: #000000; scrollbar-face-color:#DDDDDD;scrollbar-highlight-color:#DDDDDD;scrollbar-shadow-color:#DDDDDD;scrollbar-3dlight-color:#CCCCCC;scrollbar-arrow-color:#FFFFFF;scrollbar-track-color:#FBFBFB;scrollbar-darkshadow-color:#CCCCCC;scrollbar-base-color:#DDDDDD;}</style>";
    iframeStyle += "<script>function resizeImg(idStr){ var width = eval(\"document.all['Media_\"+idStr+\"'].width\"); if( width > 500 ) eval(\"document.all['Media_\"+idStr+\"'].width = 500\"); }</script>";
var inputMode ='TEXT';
var iframeWidth = 737;
var iframeHeight = 260;


/* focus */
function Focus(){
	if(inputMode == 'EDIT')
		htmlContent.focus();	
	else
		document.boardForm.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;
	else if(navigator.userAgent.indexOf('MSIE 7.') != -1) return true;
	else if(navigator.userAgent.indexOf('MSIE 8.') != -1) return true;
	else if(navigator.userAgent.indexOf('MSIE 9.') != -1) return true;
	return false;
}


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


/* edit ±â´ÉÀ¸·Î ÀüÈ¯½Ã ³»¿ëº¯È¯ */
function ChangeEdit(string){
	
	//string = string.replace(/>\r\n/g, ">");
	//string = string.replace(/\r\n<P>/g, "<P>");
	//string = string.replace(/\r\n/g, "<BR>");
	string = string.replace('<P align=center>&nbsp;</P>', "");
	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");
	string = string.replace("\r\n",''); // ÀüÈ­½Å Ã¹ ¹®´Ü¿¡ \r\nºÙ´Â°Í ÇÑ¹ø Á¦°Å
	string = string.replace('<P align=center>&nbsp;</P>', "");
	return string;
}


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

	// ¹öÀü Ã¼Å© 
/*
	if(!exploerVerCheck()){
		alert('HTML Edit ÆíÁý¸ðµå´Â ÀÍ½ºÇÁ·Î·¯ 5.0 ÀÌ»ó¿¡¼­¸¸ ÀÛµ¿ÇÕ´Ï´Ù.');
		return false;
	}
*/	
	if(inputMode=='TEXT'){ // text->edit

		inputMode='EDIT';
		tempStr = document.boardForm.textContent.value;
		sp_textarea.style.display='none';
		sp_textarea.style.position = 'absolute';
		sp_iframe.innerHTML = "<iframe id='htmlContent' name='htmlContent'  width="+iframeWidth+" height="+iframeHeight+" style='BORDER:1 SOLID #B6B5B5; padding-top:2px; margin:0px;' ></iframe>";

		htmlContent.document.designMode = 'on';
		htmlContent.document.execCommand('2D-Position',1);
		htmlContent.document.execCommand('LiveResize',1);
		htmlContent.document.open("text/html");
		htmlContent.document.write(ChangeEdit(tempStr));
		htmlContent.document.close();
		document.all('htmlContent').focus();


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

	Focus();
	return false;
}













/* ¸ðµç ·¹ÀÌ¾î div¸¦ ´Ý´Â´Ù. */
var layerArr = new Array('div_emoti','div_bgColor','div_fontColor');

function layerClose(cLayer){
	
	var divObj='';
	try{
		if(!cLayer || typeof(cLayer)=='undefinded'){
			for(i=0; i<layerArr.length; i++){
				divObj = eval(layerArr[i]);
				divObj.style.display = "none";
			}

		}else{
			divObj = eval("div_"+cLayer);
			divObj.style.display = "none";

		}
	}catch(e){}
}



/* ·¹ÀÌ¾î Ç¥Ãâ(±ÛÀÚ»ö, ¾ß±¤Ææ, ÀÌ¸ðÆ¼ÄÜ) */
function layerAction(name,action){

	// inputMode´Â /css/edit_script.js
	// ¸ðµç ·¹ÀÌ¾î¸¦ ¸ðµÎ ´Ý´Â´Ù.
	layerClose(0);

	if(inputMode == 'EDIT'){
		
		var divObj = eval("div_"+name);
		if(action=='open'){

			if(name=='fontColor'){
				divObj.style.top = div_editForm.offsetTop + 64;
				divObj.style.left = div_editForm.offsetLeft + 10;
			}else if(name=='bgColor'){
				divObj.style.top = div_editForm.offsetTop + 64;
				divObj.style.left = div_editForm.offsetLeft + 74;
			}else if(name=='emoti'){
				divObj.style.top = div_editForm.offsetTop + 64;
				divObj.style.left = div_editForm.offsetLeft + 250;
			}


			divObj.style.display = "block";

		}else{
			divObj.style.display = "none";
		}
	}else{
		alert('Edit ÆíÁý¸ðµå¿¡¼­¸¸ ÀÛµ¿ÇÕ´Ï´Ù');
		return false;
	}
}



/* »ö»ó ¼³Á¤ */
function setFColor(color){
	execComm("backcolor",'#ffffff');
	execComm('ForeColor',color);
	layerClose('fontColor');
}



/* Çü±¤Ææ */
function setBColor(bcolor,fcolor){
	
	if(typeof(fcolor)=='undefinded' || fcolor=='') fcolor='#000000';
	execComm("backcolor",bcolor );
	execComm("forecolor",fcolor);
	layerClose('bgColor');
}



/* ÀÌ¸ðÆ¼ÄÜ ÀÔ·Â */
function addEmotiCon(icon){

	execComm("InsertImage",icon);
	layerClose('emoti');
}



/* »çÁø³Ö±â */
function popImage(){
	
	if(inputMode != 'EDIT'){
		alert('Edit ÆíÁý¸ðµå¿¡¼­¸¸ ÀÛµ¿ÇÕ´Ï´Ù');
	}else{
		window.open('/rboard/img_iform.html','addImg',"width=342, height=380, scrollbars=no");
		//window.open('/rboard/img_iform.html');
	}
}




/* ¸ÖÆ¼¹Ìµð¾î ¸µÅ© */
function popMultimedia(){
	
	if(inputMode != 'EDIT'){
		alert('Edit ÆíÁý¸ðµå¿¡¼­¸¸ ÀÛµ¿ÇÕ´Ï´Ù');
	}else{
		window.open('/rboard/media_iform.html','addMedia',"width=324, height=276, scrollbars=no");
	}
}




/* ¸ÖÆ¼ ¹Ìµð¾î ¸µÅ© */
function addMediaLink(mediaURL,capturText,valign){
	
	if(mediaURL.indexOf("<") >= 0){
		alert("Çã¿ëÇÏÁö ¾Ê´Â ¸µÅ©ÁÖ¼ÒÀÔ´Ï´Ù");
		return;
	}


	if(typeof(valign)=='undefinded' || valign=='') valign='bottom';
	var ext = mediaURL.slice(mediaURL.lastIndexOf(".")+1).toLowerCase();
	
	
	// ÀÌ¹ÌÁö ÀÎ°æ¿ì
    if  (ext == "gif" || ext == "jpg" || ext == "png"){
		
		var imgID = Number((Math.random()*100000));	
		if (valign=='top' || valign == 'bottom'){   
			contents = "<p><center><img src=\"" + mediaURL + "\"  id='Media_" + imgID + "' onload='setTimeout(\"resizeImg(" + imgID + ")\",300)' style='cursor:hand' onclick='popview(this.src)'>" + capturText + "</center></p>" ;	 
		}else{
			contents = "<img src=\"" + mediaURL + "\"  id='Media_" + imgID + "' onload='setTimeout(\"resizeImg(" + imgID + ")\",300)' style='cursor:hand' onclick='popview(this.src)'>" + capturText  ;
			// align='" + valign + "'
		}


	// µ¿¿µ»ó / ÇÃ·¡½¬ÀÎ°æ¿ì
	}else{
		
		contents = "<embed autostart='true' src=\"" + mediaURL + "\" >" + capturText;
	}


	/* ¸ÖÆ¼¹Ìµð¾î ³Ö±â */
	var myContents = htmlContent.document.body.innerHTML;
	if(valign=='top'){
		htmlContent.document.body.innerHTML =  contents + "<br>" + myContents ;

	}else if(valign=='bottom'){
		htmlContent.document.body.innerHTML =  myContents + "<br>" + contents  ;

	}else{
		htmlContent.document.body.innerHTML =  myContents + "<br>" + contents  ;
	}
}



/* ÀÌ¹ÌÁö º¸±â */
function popview(imgObj){
	window.open("/rboard/popview.php?imgName="+imgObj,'popView',"width=200,height=200,scrollbars=yes");
}
