/*******************************************************************************
	Description		: CALENDAR Script
	Last Modified	: 2003/04/14
*******************************************************************************/
/*******************************************************************************
	USER_MENU script
*******************************************************************************/
function user_menu(id, name, email, url) {
	// user menu layer
	var obj = document.all["id_user_menu"];

	// set position
	obj.style.posLeft = event.x + document.body.scrollLeft;
	obj.style.posTop = event.y + document.body.scrollTop;

	var text = "";
	text += "";
	text += "<table width='100' border='0' cellspacing='0' cellpadding='0' align='center' class='border'>";
	text += "	<tr>";
	text += "		<td class='barcolor' height='12' style='padding-left:5px'><img src='" + PATH_SKIN + "images/user_menu_title.gif' width='59' height='5'></td>";
	text += "	</tr>";
	text += "	<tr>";
	text += "		<td bgcolor='#FFFFFF'>";
	text += "			<table width='100%' border='0' cellspacing='0' cellpadding='0' class='bordertb'>";

	// id or name
	if(id != "") {
		text += "				<tr height='18' onMouseOver=\"this.style.backgroundColor='#F5F5F5'\" onMouseOut=\"this.style.backgroundColor=''\">";
		text += "					<td width='5'></td>";
		text += "					<td align='center' width='20'><a href=\"javascript:search_by_id('" + id + "');\"><img src='" + PATH_SKIN + "images/usermenu_search.gif' border=0 width='11' height='11'></a></td>";
		text += "					<td><a href=\"javascript:search_by_id('" + id + "');\" class='menu' title='¾ÆÀÌµð·Î °Ë»ö'>Search Id</a></td>";
		text += "					<td width='5'></td>";
		text += "				</tr>";
		text += "				<tr height='18' onMouseOver=\"this.style.backgroundColor='#F5F5F5'\" onMouseOut=\"this.style.backgroundColor=''\">";
		text += "					<td width='5'></td>";
		text += "					<td align='center' width='20'><a href=\"javascript:search_by_name('" + name + "');\"><img src='" + PATH_SKIN + "images/usermenu_search.gif' border=0 width='11' height='11'></a></td>";
		text += "					<td><a href=\"javascript:search_by_name('" + name + "');\" class='menu' title='ÀÌ¸§À¸·Î °Ë»ö'>Search Name</a></td>";
		text += "					<td width='5'></td>";
		text += "				</tr>";
	} else {
		text += "				<tr height='18' onMouseOver=\"this.style.backgroundColor='#F5F5F5'\" onMouseOut=\"this.style.backgroundColor=''\">";
		text += "					<td width='5'></td>";
		text += "					<td align='center' width='20'><a href=\"javascript:search_by_name('" + name + "');\"><img src='" + PATH_SKIN + "images/usermenu_search.gif' border=0 width='11' height='11'></a></td>";
		text += "					<td><a href=\"javascript:search_by_name('" + name + "');\" class='menu' title='ÀÌ¸§À¸·Î °Ë»ö'>Search Name</a></td>";
		text += "					<td width='5'></td>";
		text += "				</tr>";
	}
	// email
	if(email != "") {
		text += "				<tr height='18' onMouseOver=\"this.style.backgroundColor='#F5F5F5'\" onMouseOut=\"this.style.backgroundColor=''\">";
		text += "					<td></td>";
		text += "					<td align='center'><a href=\"javascript:write_mail('" + email + "', '" + name + "', '');hide_user_menu();\"><img src='" + PATH_SKIN + "images/usermenu_mail.gif' border=0 width='12' height='10'></a></td>";
		text += "					<td><a href=\"javascript:write_mail('" + email + "', '" + name + "', '');hide_user_menu();\" class='menu' title='¸ÞÀÏº¸³»±â'>E-Mail</a></td>";
		text += "					<td></td>";
		text += "				</tr>";
	}

	// url
	if(url != "" && url != "http://" && url != "HTTP://") {
		text += "				<tr height='18' onMouseOver=\"this.style.backgroundColor='#F5F5F5'\" onMouseOut=\"this.style.backgroundColor=''\">";
		text += "					<td></td>";
		text += "					<td align='center'><a href=\"javascript:open_url('" + url + "');hide_user_menu();\"><img src='" + PATH_SKIN + "images/usermenu_home.gif' border=0 width='13' height='11'></a></td>";
		text += "					<td><a href=\"javascript:open_url('" + url + "');hide_user_menu();\" class='menu' title='È¨ÆäÀÌÁö'>Homepage</a></td>";
		text += "					<td></td>";
		text += "				</tr>";
	}

	// memo and personal info
	if(id != "")  {
		text += "				<tr height='18' onMouseOver=\"this.style.backgroundColor='#F5F5F5'\" onMouseOut=\"this.style.backgroundColor=''\">";
		text += "					<td></td>";
		text += "					<td align='center'><a href=javascript:write_memo('" + id + "');hide_user_menu();><img src='" + PATH_SKIN + "images/usermenu_memo.gif' width='13' height='13' border=0></a></td>";
		text += "					<td><a href=\"javascript:write_memo('" + id + "');hide_user_menu();\" class='menu' title='¸Þ¸ð º¸³»±â'>Memo</td>";
		text += "					<td></td>";
		text += "				</tr>";
		text += "					<tr height='18' onMouseOver=\"this.style.backgroundColor='#F5F5F5'\" onMouseOut=\"this.style.backgroundColor=''\">";
		text += "					<td></td>";
		text += "					<td align='center'><a href=javascript:user_info('" + id + "');hide_user_menu();><img src='" + PATH_SKIN + "images/usermenu_info.gif' width='11' height='12' border=0></a></td>";
		text += "					<td><a href=\"javascript:user_info('" + id + "');hide_user_menu();\" class='menu' title='È¸¿øÁ¤º¸'>Member Info</a></td>";
		text += "					<td></td>";
		text += "				</tr>";
	}

	text += "			</table>";
	text += "		</td>";
	text += "	</tr>";
	text += "	<tr>";
	text += "		<td class='barcolor' height='12' style='padding-right:5px; cursor:hand' align='right' onClick='javascript:hide_user_menu();'><img src='" + PATH_SKIN + "images/user_menu_close.gif' width='29' height='5' border='0'></td>";
	text += "	</tr>";
	text += "</table>";

	obj.innerHTML = text;
	obj.style.visibility = "visible";
}
function show_user_menu() {
	document.all["id_user_menu"].style.visibility = "visible";
}

function hide_user_menu() {
	document.all["id_user_menu"].style.visibility = "hidden";
}
function send_mail(email) {
	if(email == "") return;
	location.href = "mailto:" + email;
}

function open_url(url) {
	if(url == "") return;
	window.open(url, "", "");
}

function user_info(id) {
	profile(id, 1, "");
}
/*************************************************************************
	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'>"
	text += "    <tr>";
	text += "        <td>";
	text += "            <td bgcolor='#FFFFFF' style='word-break:break-all; padding:5px;'>" + content + "</td>";
	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
	if(comment_form.comment_pwd) 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(document.all["comment_name"].value == "") {
		alert("ÀÌ¸§À» ½á ÁÖ¼¼¿ä");
		document.all["comment_name"].focus();
		return;
	}

	if(MEMBER_IDX == 0) {
		// ·Î±×ÀÎÇÑ °æ¿ì´Â ºñ¹Ð¹øÈ£¸¦ ¹ÞÁö¾ÊÀ½.
		if(document.all["comment_pwd"].value == "") {
			alert("ºñ¹Ð¹øÈ£À» ½á ÁÖ¼¼¿ä");
			document.all["comment_pwd"].focus();
			return;
		}
	}

	if(document.all["comment_content"].value == "") {
		alert("³»¿ëÀ» ½á ÁÖ¼¼¿ä");
		document.all["comment_content"].focus();
		return;
	}

	comment_form.action = "ttboard.cgi?act=add_comment" + QUERY_DB + "&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) {
	if(MEMBER_IDX == 0) {
		// before login
		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();
	} else {
		// after login
		comment_form.del_pwd.value = "";
		comment_form.article_idx.value = article_idx;
		comment_form.comment_idx.value = comment_idx;

		del_comment();
		event.returnValue = false;
	}
}

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

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

	hide_comment_pwd();
	comment_form.action = "ttboard.cgi?act=del_comment" + QUERY_DB + "&pwd=" + pwd;
	comment_form.submit();
}

/*******************************************************************************
	WRITE script
*******************************************************************************/
function verify_data() {
	// check name
	if(write_form.name.value == "") {
		alert("ÀÌ¸§À» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		write_form.name.focus();
		return;
	}
	// check email
	if(write_form.email.value != "") {
		if(!check_email(write_form.email.value)) {
			alert("ÀÌ¸ÞÀÏ Çü½ÄÀÌ ¿Ã¹Ù¸£Áö ¾Ê½À´Ï´Ù.");
			write_form.email.focus();
			return;
		}
	}
	// check password
	if(WRITE_MODE != "modify" && MEMBER_IDX == 0) {
		if(write_form.pwd && write_form.pwd.value == "") {
			alert("ÆÐ½º¿öµå¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä.");
			write_form.pwd.focus();
			return;
		}
	}
	// check title
	if(write_form.title.value == "") {
		alert("Á¦¸ñÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		write_form.title.focus();
		return;
	}
	// check content
	if(write_form.content.value == "") {
		alert("³»¿ëÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		write_form.content.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
*************************************************************************/
// rollover bgcolor.
function rollover(obj, color) {
	if(!obj) return false;
	obj.style.backgroundColor = color;
}

function check_enter(id) {
	if(event.keyCode == 13) {
		if(id == "search") search('default');
		else if(id == "jump_page") jump_to();
		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 = "ttboard.cgi?act=read" + QUERY + "&idx=" + idx + date;
	} else if(LIST_TITLE_ON_CLICK == 1) {
		window.open("ttboard.cgi?act=popup" + QUERY + "&idx=" + idx + date, "", "width="+LIST_POPUP_WIDTH+", height="+LIST_POPUP_HEIGHT+", scrollbars=1, resizable=1");
	} else if(LIST_TITLE_ON_CLICK == 2) {
		window.open("ttboard.cgi?act=read" + QUERY + "&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 = "ttboard.cgi?act=multi_read" + QUERY + date;
}

function reply_article(idx) {
	hform.action = "ttboard.cgi?act=reply" + QUERY + "&idx=" + idx;
	hform.submit();
}

function modify_article(idx) {
	hform.action = "ttboard.cgi?act=modify" + QUERY + "&idx=" + idx;
	hform.submit();
}

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

function recommend(idx) {
	location.href = "ttboard.cgi?act=recommend" + QUERY_DB + "&idx="+idx;
}

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 = "ttboard.cgi?act=write" + QUERY + "&year="+year+"&month="+month+"&day="+day;
	write_form.submit();
}

function list_calendar(year, month, day) {
	var url = "ttboard.cgi?act=list" + QUERY_DB;

	// 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;
}

function whois(ip) {
	// check ip.
	if(ip == "") return;

	var left = (screen.width - 520) / 2;
	var top	= (screen.height - 500) / 3;

	window.open("ttadmin.cgi?act=whois&ip="+ip, "",
		"width=520, height=500, left="+left+", top="+top+", scrollbars=1, resizable=1");
}

function view_image(idx,imgpath) {
	url = "ttboard.cgi?act=popup" + QUERY_DB + "&object=popupimage&idx=" + idx + "&imgpath=" + imgpath;
	viewWin = window.open(url,'', 'width=500, height=400, scrollbars=yes, resizable=yes');
}

/*************************************************************************
	date/time script
*************************************************************************/
var arr_day_name = new Array("Sunday", "Monday", "Tuesday", "Wendnesday", "Thursday", "Friday", "Saturday");

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]);
}

function month_menu() {
	var obj = document.all["id_month_menu"];
	obj.style.posLeft = event.x -35 + document.body.scrollLeft;
	obj.style.posTop = event.y -5 + document.body.scrollTop;
	obj.style.visibility = "visible";
}

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

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

function year_menu() {
	var obj = document.all["id_year_menu"];
	obj.style.posLeft = event.x -35 + document.body.scrollLeft;
	obj.style.posTop = event.y -5 + document.body.scrollTop;
	obj.style.visibility = "visible";
}

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

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

