/*
 * TTBOARD 2002 BOARD SKIN
 * Description		: CALENDAR Script
 * Last Modified	: 2002/08/23
 */

/*************************************************************************
	PREVIEW script
*************************************************************************/
function preview(content) {
	var obj = document.all["id_preview"];

	// check content
	if(content == "") {
		obj.innerHTML = "";
		return;
	}

	var text = "";
	text =  "<table width='100%' border='0' cellspacing='0' cellpadding='0' align='center'>"
	text += "    <tr>";
	text += "        <td>";
	text += "            <table width='100%' border='0' cellspacing='0' cellpadding='0'>";
	text += "                <tr>";
	text += "                    <td><img src='" + PATH_SKIN + "images/vbox_tl3.gif' width='35' height='25'></td>";
	text += "                </tr>";
	text += "            </table>";
	text += "            <table width='100%' border='0' cellspacing='0' cellpadding='0' align='center'>";
	text += "                <tr>";
	text += "                    <td height='8' width='8'><img src='" + PATH_SKIN + "images/vbox_tl.gif' width='8' height='8'></td>";
	text += "                    <td background='" + PATH_SKIN + "images/vbox_tbg.gif'>";
	text += "                        <img src='" + PATH_SKIN + "images/vbox_tl2.gif' width='27' height='8'></td>";
	text += "                    <td height='8' width='8'><img src='" + PATH_SKIN + "images/vbox_tr.gif' width='8' height='8'></td>";
	text += "                </tr>";
	text += "                <tr>";
	text += "                    <td background='" + PATH_SKIN + "images/vbox_ml.gif'></td>";
	text += "                    <td background='" + PATH_SKIN + "images/vbox_bg.gif' style='word-break:break-all;'>" + content + "</td>";
	text += "                    <td background='" + PATH_SKIN + "images/vbox_mr.gif'></td>";
	text += "                </tr>";
	text += "                <tr>";
	text += "                    <td height='5' width='8'><img src='" + PATH_SKIN + "images/vbox_bl.gif' width='8' height='5'></td>";
	text += "                    <td background='" + PATH_SKIN + "images/vbox_bbg.gif'></td>";
	text += "                    <td height='5' width='8'><img src='" + PATH_SKIN + "images/vbox_br.gif' width='8' height='5'></td>";
	text += "                </tr>";
	text += "            </table>";
	text += "        </td>";
	text += "    </tr>";
	text += "</table>";

	obj.innerHTML = text;
	move_preview();
	obj.style.visibility = "visible";
}

function move_preview() {
	var obj = document.all["id_preview"];

	if(obj.innerHTML != "") {
		obj.style.posLeft = event.x - 40 + document.body.scrollLeft;
		obj.style.posTop = event.y + 10 + document.body.scrollTop;
	}
}

function hide_preview() {
	document.all["id_preview"].style.visibility = "hidden";
}

/*************************************************************************
	CELL_MENU script
*************************************************************************/
function cell_menu(day) {
	// set day
	document.all["cur_day"].value = day;

	var obj = document.all["id_cell_menu"];
	obj.style.posLeft = event.x -10 + document.body.scrollLeft;
	obj.style.posTop = event.y -10 + document.body.scrollTop;
	obj.style.visibility = "visible";
}

function show_cell_menu() {
	document.all["id_cell_menu"].style.visibility = "visible";
}

function hide_cell_menu() {
	document.all["id_cell_menu"].style.visibility = "hidden";
}

/*************************************************************************
	COMMENT script
*************************************************************************/
// WRITE COMMENT
function write_comment(idx) {
	comment_form.article_idx.value = idx;

	// initialize value
	comment_form.comment_pwd.value = "";
	comment_form.comment_content.value = "";

	// show layer
	var obj_cmt = document.all["id_comment"];
	obj_cmt.style.posLeft = event.x - 250 + document.body.scrollLeft;
	obj_cmt.style.posTop = event.y + document.body.scrollTop;
	obj_cmt.style.visibility = "visible";
}

function add_comment() {
	// for comment on multiple read
	var idx = comment_form.article_idx.value;

	if(comment_form.comment_name.value == "") {
		alert("ÀÌ¸§À» ½á ÁÖ¼¼¿ä");
		comment_form.comment_name.focus();
		return;
	} else if(comment_form.comment_pwd.value == "") {
		alert("ºñ¹Ð¹øÈ£À» ½á ÁÖ¼¼¿ä");
		comment_form.comment_pwd.focus();
		return;
	} else if(comment_form.comment_content.value == "") {
		alert("³»¿ëÀ» ½á ÁÖ¼¼¿ä");
		comment_form.comment_content.focus();
		return;
	}

	comment_form.action = LINK_ADD_COMMENT + "&idx=" + idx;
	comment_form.submit();
}

function hide_comment() {
	comment_form.article_idx.value = "";
	document.all["id_comment"].style.visibility = "hidden";
}

// DELETE COMMENT
function show_comment_pwd(article_idx, comment_idx) {
	var obj_pwd = document.all["id_comment_pwd"];

	if(article_idx != 0 && comment_idx != 0) {
		comment_form.del_pwd.value = "";
		comment_form.article_idx.value = article_idx;
		comment_form.comment_idx.value = comment_idx;

		obj_pwd.style.posLeft = event.x - 170 + document.body.scrollLeft;
		obj_pwd.style.posTop = event.y + document.body.scrollTop;
	}

	obj_pwd.style.visibility = "visible";
	comment_form.del_pwd.focus();
}

function hide_comment_pwd() {
	document.all["id_comment_pwd"].style.visibility = "hidden";
}

function del_comment() {
	var pwd = comment_form.del_pwd.value;

	comment_form.action = LINK_DEL_COMMENT + "&pwd=" + pwd;
	comment_form.submit();
}

/*************************************************************************
	WRITE script
*************************************************************************/
function verify_data() {
	if(write_form.name.value == "") {
		alert("ÀÌ¸§À» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		write_form.name.focus();
		return;
	} else if(write_form.email.value != "") {
		if(!check_email(write_form.email.value)) {
			alert("ÀÌ¸ÞÀÏ Çü½ÄÀÌ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù.");
			write_form.email.focus();
			return;
		}
	} else if(write_form.title.value == "") {
		alert("Á¦¸ñÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		write_form.title.focus();
		return;
	} else if(write_form.content.value == "") {
		alert("³»¿ëÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		write_form.content.focus();
		return;
	}

	if(WRITE_MODE != "modify") {
		if(write_form.pwd && write_form.pwd.value == "") {
			alert("ÆÐ½º¿öµå¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä.");
			write_form.pwd.focus();
			return;
		}
	}

	// set content info
	if(write_form.content_width)
		write_form.content_width.value = parseInt(document.all['content'].style.width);
	if(write_form.content_height)
		write_form.content_height.value = parseInt(document.all['content'].style.height);

	write_form.submit();
}

// resize
function resize_content_width(width) {
	var obj, total_count;

	// url
	resize_object_width("url", width, CONTENT_WIDTH);

	// title
	resize_object_width("title", width, CONTENT_WIDTH);

	// content
	resize_object_width("content", width, CONTENT_WIDTH);
}

function resize_object_width(obj, width, min_width) {
	if(document.all[obj]) {
		var obj_width = parseInt(document.all[obj].style.width);
		if(obj_width + width >= min_width)
			document.all[obj].style.width = obj_width + width;
	}
}

function resize_content_height(height) {
	if(document.all["content"]) {
		var obj_height = parseInt(document.all['content'].style.height);
		if(obj_height + height >= CONTENT_HEIGHT)
			document.all['content'].style.height = obj_height + height;
	}
}

/*************************************************************************
	ACTION script
*************************************************************************/
function check_enter(id) {
	if(event.keyCode == 13) {
		if(id == "search") search('default');
		else if(id == "jump_page") jump_to();
		else if(id == "search_num") set_search_num();
		else if(id == "del_comment") del_comment();

		event.returnValue = false;
	}
}

function read_article(idx, day) {
	var date = "&year="+CALENDAR_YEAR+"&month="+CALENDAR_MONTH+"&day="+day;

	if(LIST_TITLE_ON_CLICK == 0) {
		location.href = LINK_READ + "&idx=" + idx + date;
	} else if(LIST_TITLE_ON_CLICK == 1) {
		window.open(LINK_POPUP + "&idx=" + idx + date, "", "width="+LIST_POPUP_WIDTH+", height="+LIST_POPUP_HEIGHT+", scrollbars=1, resizable=1");
	} else if(LIST_TITLE_ON_CLICK == 2) {
		window.open(LINK_READ + "&idx=" + idx + date, "", "width="+LIST_POPUP_WIDTH+", height="+LIST_POPUP_HEIGHT+", scrollbars=1, resizable=1");
	}
}

function multi_read() {
	var year = CALENDAR_YEAR;
	var month = CALENDAR_MONTH;
	var day = document.all["cur_day"].value;
	var date = "&year="+year+"&month="+month+"&day="+day;

	location.href = LINK_MULTI_READ + date;
}

function reply_article(idx) {
	hform.action = LINK_REPLY + "&idx=" + idx;
	hform.submit();
}

function modify_article(idx) {
	hform.action = LINK_MODIFY + "&idx=" + idx + "&year=" + CALENDAR_YEAR + "&month=" + CALENDAR_MONTH + "&day=" + CALENDAR_DAY;
	hform.submit();
}

function delete_article(idx) {
	if(confirm("°Ô½Ã¹°À» »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) {
		hform.action = LINK_DELETE + "&idx=" + idx;
		hform.submit();
	}
}

function recommend(idx) {
	hform.action = LINK_RECOM + "&idx=" + idx;
	hform.submit();
}

function ttmailer(email) {
	if(email) {
		window.open("ttmailer.cgi?act=write&to="+email, "", "width=320, height=350, resizable=1, scrollbars=1");
	}
}

function write_schedule() {
	var year = CALENDAR_YEAR;
	var month = CALENDAR_MONTH;
	if(document.all["cur_day"])
		var day = document.all["cur_day"].value;
	else
		var day = CALENDAR_DAY;
	write_form.action = LINK_WRITE + "&year="+year+"&month="+month+"&day="+day;
	write_form.submit();
}

function list_calendar(year, month, day) {
	var url = LINK_LIST;

	// year
	if(year != 0) url = url + "&year=" + year;
	else url = url + "&year=" + CALENDAR_YEAR;

	// month
	if(month != 0) url = url + "&month=" + month;
	else url = url + "&month=" + CALENDAR_MONTH;

	// day
	if(day != 0) url = url + "&day=" + day;
	else url = url + "&day=" + CALENDAR_DAY;

	location.href = url;
}

/*************************************************************************
	date/time script
*************************************************************************/
var arr_day_name = new Array("ÀÏ¿äÀÏ", "¿ù¿äÀÏ", "È­¿äÀÏ", "¼ö¿äÀÏ", "¸ñ¿äÀÏ", "±Ý¿äÀÏ", "Åä¿äÀÏ");

function day_name(year, month, day) {
	var objDate = new Date(year, month-1, day);
	var day_of_week = objDate.getDay();

	document.write(arr_day_name[day_of_week]);
}	