﻿
function initEditor() {
	var source = '<html><head>';
	source += '<style>P {margin-top:2px;margin-bottom:2px;} table {border:1 solid C6C3C6}</style> ';
	source += '<script>function ResizeImage(num){}</script>';
    source += '</head><body style=BACKGROUND-COLOR:#FFFFFF;COLOR:Gray ></body></html>';
	
	EDITOR.document.designMode = 'On';
	EDITOR.document.open('text/html');
	EDITOR.document.write(source);
	EDITOR.document.close();
	
	EDITOR.document.body.style.fontSize = '10pt';
	EDITOR.document.body.style.fontFamily = '돋움';
	EDITOR.document.body.style.scrollbarFaceColor = '#D7D9DD';
	EDITOR.document.body.style.scrollbarShadowColor = '#ABB0B6';
	EDITOR.document.body.style.scrollbarHighlightColor = '#D7D9DD';
	EDITOR.document.body.style.scrollbar3dLightColor = '#FFFFFF';
	EDITOR.document.body.style.scrollbarDarkShadowColor = '#D7D9DD';
	EDITOR.document.body.style.scrollbarTrackColor = '#E7E7E7';
	EDITOR.document.body.style.scrollbarArrowColor = '#989FA5';

	// 내용
	if (document.body.getElementsByTagName("TEXTAREA")[0] != null && document.body.getElementsByTagName("TEXTAREA")[0].value.length > 0) {
		EDITOR.document.body.innerHTML = document.body.getElementsByTagName("TEXTAREA")[0].value;
	}
}

// 글꼴 종류
function setFont(ch) {
	if (ch.options[ch.selectedIndex].value != '')  {
		EDITOR.document.execCommand('FontName', null, ch.options[ch.selectedIndex].value);
	}
}

// 글꼴 크기
function setFontSize(ch) {
	if (ch.options[ch.selectedIndex].value != '')  {
		EDITOR.document.execCommand('FontSize', null, ch.options[ch.selectedIndex].value);
	}
}

// 액션
function action(order) {
	Selection = EDITOR.document.selection.createRange();
	
	if (Selection != null) {
		Selection.select();
	}
	
	if (order == 'Bold') {
		EDITOR.document.execCommand('Bold');
	} else if (order == 'Italic') {
		EDITOR.document.execCommand('Italic');
	} else if (order == 'Underline') {
		EDITOR.document.execCommand('Underline');
	} else if (order == 'fontcolor') {
		FontColor('1');
	} else if (order == 'bgcolor') {
		FontColor('2');
	} else if (order == 'alignLeft') {
		EDITOR.document.execCommand("JustifyLeft");
	} else if (order == "alignCenter") {
		EDITOR.document.execCommand("JustifyCenter");
	} else if (order == "alignRight") {
		EDITOR.document.execCommand("JustifyRight");  
	} else if (order == "link") {
		EDITOR.focus();
		EDITOR.document.execCommand("CreateLink",1);
	} else if (order == "Strike")   {
		EDITOR.document.execCommand("StrikeThrough");
	}
}

function CheckEditor() {
	try {
		var selectedText = EDITOR.document.selection.createRange();
		var literal = selectedText.parentElement().outerHTML.toLowerCase();
		
		if (literal.indexOf("<font") > -1) {
			// selected font face
			if (selectedText.parentElement().face != null && selectedText.parentElement().face != "") {
				document.forms[0].PostFontFamily.value = selectedText.parentElement().face;
			} else {
				document.forms[0].PostFontFamily.selectedIndex = 0;
			}

			// selected font size
			if (selectedText.parentElement().size != null && selectedText.parentElement().size != "") {
				document.forms[0].PostFontSize.value = selectedText.parentElement().size;
			} else {
				document.forms[0].PostFontSize.selectedIndex = 1;
			}
		} else {
			document.forms[0].PostFontFamily.selectedIndex = 0;
			document.forms[0].PostFontSize.selectedIndex = 1;
		}
	} catch (e) {
		document.forms[0].PostFontFamily.selectedIndex = 0;
		document.forms[0].PostFontSize.selectedIndex = 1;
	}
}

function CheckEditorByKey() {
	if (EDITOR.event.keyCode >= 37 && EDITOR.event.keyCode <= 40) {
		try {
			var selectedText = EDITOR.document.selection.createRange();
			var literal = selectedText.parentElement().outerHTML.toLowerCase();

			if (literal.indexOf("<font") > -1) {
				// selected font face
				if (selectedText.parentElement().face != null && selectedText.parentElement().face != "") {
					document.forms[0].PostFontFamily.value = selectedText.parentElement().face;
				} else {
					document.forms[0].PostFontFamily.selectedIndex = 0;
				}

				// selected font size
				if (selectedText.parentElement().size != null && selectedText.parentElement().size != "") {
					document.forms[0].PostFontSize.value = selectedText.parentElement().size;
				} else {
					document.forms[0].PostFontSize.selectedIndex = 1;
				}
			} else {
				document.forms[0].PostFontFamily.selectedIndex = 0;
				document.forms[0].PostFontSize.selectedIndex = 1;
			}
		} catch (e) {
			document.forms[0].PostFontFamily.selectedIndex = 0;
			document.forms[0].PostFontSize.selectedIndex = 1;
		}
	}
}


// 메뉴 숨기기
function hidemenu() {
	document.getElementById("TableFontColor").style.display = "none";
	document.getElementById("TableFontBackColor").style.display = "none";
}

// 전경, 배경색 레이어 띄우기
function FontColor(ch) {
	switch (ch) {
		case "1":
			if (document.getElementById("TableFontColor").style.display != "none")
				document.getElementById("TableFontColor").style.display = "none";
			else
				document.getElementById("TableFontColor").style.display = "block";

			document.getElementById("TableFontBackColor").style.display = "none";
			break;

		case "2":
			document.getElementById("TableFontColor").style.display = "none";
			if (document.getElementById("TableFontBackColor").style.display != "none")
				document.getElementById("TableFontBackColor").style.display = "none";
			else
				document.getElementById("TableFontBackColor").style.display = "block";

			break;
	}
}

// 전경색
function SetFontColor(color) {
	if (Selection != null)
		Selection.select();

	EDITOR.document.execCommand("forecolor", null, color);
	document.getElementById("TableFontColor").style.display = "none";
	EDITOR.document.selection.empty();
}

// 배경색(글)
function SetBgColor(color, color2) {
	if (Selection != null)
		Selection.select();
	
	EDITOR.document.execCommand("BackColor", null, color);
	
	if (color2 != "")
		EDITOR.document.execCommand("forecolor", null, color2);
	
	document.getElementById("TableFontBackColor").style.display = "none";
	EDITOR.document.selection.empty();
}

// 배경색(문서)
function SetBackColor(color) {
	EDITOR.document.body.style.backgroundColor = color;
}

function setCookie(name, value, expiredays)	{
    var expire_date = new Date();
    expire_date.setDate(expire_date.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; expires=" + expire_date.toGMTString() + "; path=/";

    closeLayer();
 }

function closeLayer(){
    location.href= "/Home/Home.aspx";
}

function clearCookie(name) {
    var expire_date = new Date();
    expire_date.setDate(expire_date.getDate() - 1);
    document.cookie = name + "= " + "; expires=" + expire_date.toGMTString() + "; path=/";
}


function controlCookie(elemnt) {
    if (elemnt.checked) {
        setCookie("popo20080620","true", 1);
    }
    else {
        clearCookie("popo20080422");
    }
    return;
}

function SetTrankCheck(eventid, flag, regsite, kind, etc, host)
{    
   HanbitSoft.Official.Popo.Web.Service.MembershipAuthService.SetTrackLog( eventid, flag, regsite, kind, etc, host, OnTrankSuccess, OnFailed );         
}

function OnTrankSuccess(result, context, methodName)
{           
     if(result != "0")
     {
         alert("에러");
     } 
}

function OnFailed(results, context, methodName)
{ 
    alert(results.get_message());
}


function ShowTable(TrId)
{    
    var arrVal = new Array(5);

    for (i=0; i < 5; i++)
    {
        arrVal[i] = i+1;
    }
    
   for (j=0; j < arrVal.length; j++)
   {
        if(TrId == arrVal[j])
        {
            if( document.getElementById(arrVal[j]).style.display == "none" )
                document.getElementById(arrVal[j]).style.display = "block";
            else
                document.getElementById(arrVal[j]).style.display = "none";
        }
        else 
        {
            document.getElementById(arrVal[j]).style.display = "none";
        }   
   }
}