﻿// JScript 파일
var xed;
var f;
var _xedId = "xqEditor";

function SearchPostSet(qry)
{
	var flag = 0;
	$$("input[name='chkSrch']").each(function(en){
		flag += (en.checked)? parseInt(en.value):0;
	});

	if (flag == 0)
		return false;
	
	var key = $("txtSrchKey").value;
	if (!key)
	{
		url = document.URL;
		if (url.indexOf("&ff=") >= 0)
			document.location.replace("./List.aspx?" + qry + "&pNo=0");
		else
			return false;
	}

	document.location.replace("./List.aspx?" + qry + "&ff=" + flag + "&s_key=" + key + "&pNo=0");
	//top.location.href = "Board.aspx?id=" + bid + sQry + "&s_key=" + f.fs_key.value + "&cate=" + cate;
}

function SearchPostKey(qry)
{
	if (event.keyCode == 13)
		return SearchPostSet(qry);
}

function ChangePostCategory(o, qry)
{
	val = o.options[o.selectedIndex].value;
	url = document.URL;
	if (url.indexOf("cat=") < 0)
	{
		url = "./List.aspx?" + qry + "&cat=" + val;
	}
	else
	{
		re = /^([^\?]+)\?(.*)cat=[^&]*(&?.*)/ig;
		url = url.replace(re, "$1?$2cat=" + val + "$3");
	}
	
	document.location.href = url;
}

function ChangePostOrder(o, qry)
{
	val = o.options[o.selectedIndex].value;
	url = document.URL;
	
	document.location.replace("./List.aspx?" + qry + "&od=" + val);
}

function XedSubmit()
{
	f._editor.value = $(_xedId).value;
	return true;
}

function DeleteComment(qry)
{
	if (!confirm("삭제합니까?"))
		return;
		
	new Ajax.Request("/ws/DeleteComment.ashx?" + qry, {
		on200: function (ret)
		{
			val = ret.responseText;
			if (val == "0")
				document.location.reload();
			else
				alert("Error (" + val + ")");
		},
		on500: function (ret)
		{
			//alert(ret.responseText);
			alert("Error");
		}
	});
}

function DeletePost(qry)
{
	if (!confirm("삭제합니까?"))
		return;

	new Ajax.Request("/ws/DeletePost.ashx?" + qry, {
		on200: function (ret)
		{
			val = ret.responseText;
			if (val == "0")
				document.location.replace("./List.aspx?" + qry);
			else
				alert("Error (" + val + ")");
		},
		on500: function (ret)
		{
			//alert(ret.responseText);
			alert("Error");
		}
	});
}

function RecommendPost(qry, mode)
{
	if (!NoadUser.IsLogin())
	{
		alert("로그인 후 가능합니다.");
		return;
	}
		
	new Ajax.Request("/ws/RecommendPost.ashx?" + qry, {
		parameters: "dat=" + mode,
		on200: function (ret)
		{
			val = ret.responseText;
			if (val>0)
				document.location.reload();
		},
		on500: function (ret)
		{
			//alert(ret.responseText);
			alert("Error");
		}
	});
}

//Event.observe(window, "load", function () {
//	InitXed();
//});

function InitXed ()
{
	f = document.forms[0];
	xed = new xq.Editor(_xedId);
	xed.config.contentCssList = ["/Lib/xquared/xq_contents.css"];
	xed.config.imagePathForDefaultToolbar = "/images/toolbar/";
	xed.config.imagePathForContent = "/images/content/";
	xed.config.defaultToolbarButtonMap = [
		[
			{className:"fontFace", title:"글꼴", list:[
				{title:"돋움", handler:"xed.handleFontFace('돋움')"},
				{title:"굴림", handler:"xed.handleFontFace('굴림')"},
				{title:"궁서", handler:"xed.handleFontFace('궁서')"},
				{title:"Arial", handler:"xed.handleFontFace('Arial')"},
				{title:"Helvetica", handler:"xed.handleFontFace('Helvetica')"},
				{title:"Serif", handler:"xed.handleFontFace('Serif')"},
				{title:"Tahoma", handler:"xed.handleFontFace('Tahoma')"},
				{title:"Verdana", handler:"xed.handleFontFace('Verdana')"}
			]},
			{className:"fontSize", title:"크기", list:[
				{title:"1", handler:"xed.handleFontSize('1')"},
				{title:"2", handler:"xed.handleFontSize('2')"},
				{title:"3", handler:"xed.handleFontSize('3')"},
				{title:"4", handler:"xed.handleFontSize('4')"},
				{title:"5", handler:"xed.handleFontSize('5')"},
				{title:"6", handler:"xed.handleFontSize('6')"}
			]}
		],
		[
			{className:"foregroundColor", title:"글자색", handler:"xed.handleForegroundColor()"},
			{className:"backgroundColor", title:"글자 배경색", handler:"xed.handleBackgroundColor()"}
		],
		[
			{className:"link", title:"링크", handler:"xed.handleLink()"}
		],
		[
			{className:"strongEmphasis", title:"굵게", handler:"xed.handleStrongEmphasis()"},
			{className:"emphasis", title:"기울게", handler:"xed.handleEmphasis()"},
			{className:"underline", title:"밑줄", handler:"xed.handleUnderline()"},
			{className:"strike", title:"취소선", handler:"xed.handleStrike()"}
		],
		[
			{className:"indent", title:"들여쓰기", handler:"xed.handleIndent()"},
			{className:"outdent", title:"내어쓰기", handler:"xed.handleOutdent()"}
		],
		[
			{className:"paragraph", title:"문단", handler:"xed.handleApplyBlock('P')"},
			{className:"heading1", title:"제목", handler:"xed.handleApplyBlock('H1')"},
			{className:"blockquote", title:"인용구", handler:"xed.handleApplyBlock('BLOCKQUOTE')"},
			{className:"code", title:"소스코드", handler:"xed.handleList('OL', 'code')"},
			{className:"division", title:"<div>", handler:"xed.handleApplyBlock('DIV')"},
			{className:"unorderedList", title:"글머리기호 목록", handler:"xed.handleList('UL')"},
			{className:"orderedList", title:"번호가 매겨진 목록", handler:"xed.handleList('OL')"}
		],
		[
			{className:"table", title:"표", handler:"xed.handleTable(4, 4,'tl')"},
			{className:"separator", title:"나누기", handler:"xed.handleSeparator()"}
		]
	];
	xed.setEditMode("wysiwyg");
}

