/*******************************************************************************
	Description		: GENERAL Script
	Last Modified	: 2003/03/11
*******************************************************************************/
/*******************************************************************************
	CHECKBOX script
*******************************************************************************/
function check_option() {
	// check option layer
	var obj = document.all["id_checkbox"];

	// set position
	obj.style.posLeft = event.x + document.body.scrollLeft;
	obj.style.posTop = event.y + document.body.scrollTop;
	obj.style.visibility = "visible";
}

function show_check_option() {
	document.all["id_checkbox"].style.visibility = "visible";
}

function hide_check_option() {
	document.all["id_checkbox"].style.visibility = "hidden";
}

function select_all() {
	for(var i = 1; i <= ARTICLE_ROWS; i++) {
		var obj = document.all["check" + i];

		if(obj) {
			obj.value = document.all["article" + i + "_idx"].value;
			document.all["check_img" + i].src = PATH_SKIN + "images/chkbox_on.gif";
		}
	}

	hide_check_option();
}

function cancel_all() {
	for(var i = 1; i <= ARTICLE_ROWS; i++) {
		var obj = document.all["check" + i];

		if(document.all["check" + i]) {
			obj.value = 0;
			document.all["check_img" + i].src = PATH_SKIN + "images/chkbox_off.gif";
		}
	}

	hide_check_option();
}

function reverse_chk() {
	for(var i = 1; i <= ARTICLE_ROWS; i++) {
		if(document.all["check" + i]) set_check(i);
	}

	hide_check_option();
}

function set_check(row_num) {
	var obj = document.all["check" + row_num];
	var idx = document.all["article" + row_num + "_idx"].value;

	if(obj.value == idx) {
		obj.value = 0;
		document.all["check_img" + row_num].src = PATH_SKIN + "images/chkbox_off.gif";
	} else {
		obj.value = idx;
		document.all["check_img" + row_num].src = PATH_SKIN + "images/chkbox_on.gif";
	}
}

/*******************************************************************************
	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 align=right><img src='" + PATH_SKIN + "img/preview.gif'></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 += "                    </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;' filter: Alpha(Opacity=70)>" + 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";
}

/*******************************************************************************
	USER_MENU script
*******************************************************************************/
function user_menu(id, name, email, url) {
	// user menu layer
	var obj = document.all["id_user_menu"];

	if(obj.style.visibility == "hidden") {
		// 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' style='border: 1px solid #666666'>";
		text += "	<tr>";
		text += "		<td bgcolor='#FFFFFF'>";
		text += "			<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
		text += "				<tr>";
		text += "					<td width='5'><img src='" + PATH_SKIN + "images/pmenu/box_tl.gif' width=5 height=11></td>";
		text += "					<td background='" + PATH_SKIN + "images/pmenu/box_tr2.gif'><img src='" + PATH_SKIN + "images/pmenu/box_tl1.gif' width=10 height=11></td>";
		text += "					<td align='right' width='5'><img src='" + PATH_SKIN + "images/pmenu/box_tr.gif' width=5 height=11></td>";
		text += "				</tr>";
		text += "				<tr>";
		text += "					<td background='" + PATH_SKIN + "images/pmenu/box_ml.gif'></td>";
		text += "				    <td>";
		text += "						<table width='100%' border='0' cellspacing='0' cellpadding='0' class='text8pt' style='border: 1px solid #666666'>";

		// id or name
		text += "							<tr height='20' onMouseOver=\"this.style.backgroundColor='#EFEFEF'\" onMouseOut=\"this.style.backgroundColor=''\">";
		text += "								<td width='5'></td>";
		if(id != "") {
			text += "				        		<td align='center' width='20'><a href=\"javascript:search_by_name('" + id + "');\"><img src='" + PATH_SKIN + "images/pmenu/usermenu_search.gif' border=0 width='13' height='11'></a></td>";
			text += "				        		<td><a href=\"javascript:search_by_id('" + id + "');\"><font class='text8pt' color=black>Search</font></a></td>";
		} else {
			text += "				                <td align='center' width='20'><a href=\"javascript:search_by_name('" + name + "');\"><img src='" + PATH_SKIN + "images/pmenu/usermenu_search.gif' border=0 width='13' height='11'></a></td>";
			text += "				                <td><a href=\"javascript:search_by_name('" + name + "');\"><font class='text8pt' color=black>Search</font></a></td>";
		}
		text += "				                <td width='5'></td>";
		text += "							</tr>";

		// email
		if(email != "") {
			text += "							<tr>";
			text += "                           	<td colspan='4' background='" + PATH_SKIN + "images/pmenu/line.gif'></td>";
			text += "							</tr>";
			text += "							<tr height='20' onMouseOver=\"this.style.backgroundColor='#EFEFEF'\" onMouseOut=\"this.style.backgroundColor=''\">";
			text += "                                <td></td>";
			text += "                                <td align='center' width='20'><a href=\"javascript:ttmailer('" + email + "');hide_user_menu();\"><img src='" + PATH_SKIN + "images/pmenu/usermenu_mail.gif' border=0 width='13' height='11'></a></td>";
			text += "                                <td><a href=\"javascript:ttmailer('" + email + "');hide_user_menu();\"><font class='text8pt' color=black>Mail</font></a></td>";
			text += "                                <td></td>";
			text += "							</tr>";
		}

		// url
		if(url != "" && url != "http://" && url != "HTTP://") {
			text += "							<tr>";
			text += "                           	<td colspan='4' background='" + PATH_SKIN + "images/pmenu/line.gif'></td>";
			text += "							</tr>";
			text += "							<tr height='20' onMouseOver=\"this.style.backgroundColor='#EFEFEF'\" onMouseOut=\"this.style.backgroundColor=''\">";
			text += "								<td></td>";
			text += "								<td align='center' width='20'><a href=\"javascript:open_url('" + url + "');hide_user_menu();\"><img src='" + PATH_SKIN + "images/pmenu/usermenu_home.gif' border=0 width='13' height='11'></a></td>";
			text += "								<td><a href=\"javascript:open_url('" + url + "');hide_user_menu();\"><font class='text8pt' color=black>Home</font></a></td>";
			text += "								<td></td>";
			text += "							</tr>";
		}

		// memo and personal info
		if(id != "")  {
			text += "							<tr>";
			text += "                           	<td colspan='4' background='" + PATH_SKIN + "images/pmenu/line.gif'></td>";
			text += "                           </tr>";
			text += "							<tr height='20' onMouseOver=\"this.style.backgroundColor='#EFEFEF'\" onMouseOut=\"this.style.backgroundColor=''\">";
			text += "								<td></td>";
			text += "								<td align='center' width='20'><a href=javascript:write_memo('" + id + "');hide_user_menu();><img src='" + PATH_SKIN + "images/pmenu/usermenu_memo.gif' border=0></a></td>";
			text += "								<td><a href=\"javascript:write_memo('" + id + "');hide_user_menu();\"><font class='text8pt' color=black>Memo</td>";
			text += "								<td></td>";
			text += "							</tr>";
			text += "							<tr>";
			text += "                           	<td colspan='4' background='" + PATH_SKIN + "images/pmenu/line.gif'></td>";
			text += "                           </tr>";
			text += "							<tr height='20' onMouseOver=\"this.style.backgroundColor='#EFEFEF'\" onMouseOut=\"this.style.backgroundColor=''\">";
			text += "								<td></td>";
			text += "								<td align='center' width='20'><a href=javascript:user_info('" + id + "');hide_user_menu();><img src='" + PATH_SKIN + "images/pmenu/usermenu_info.gif' border=0></a></td>";
			text += "								<td><a href=\"javascript:user_info('" + id + "');hide_user_menu();\"><font class='text8pt' color=black>Info</td>";
			text += "								<td></td>";
			text += "							</tr>";
		}

		text += "                        </table>";
		text += "                    </td>";
		text += "                    <td align='right' background='" + PATH_SKIN + "images/pmenu/box_mr.gif'></td>";
		text += "                </tr>";
		text += "				<tr>";
		text += "					<td width='5'><img src='" + PATH_SKIN + "images/pmenu/box_bl.gif' width=5 height=5></td>";
		text += "                    <td background='" + PATH_SKIN + "images/pmenu/box_bm.gif'></td>";
		text += "                    <td align='right' width='5'><img src='" + PATH_SKIN + "images/pmenu/box_br.gif' width=5 height=5></td>";
		text += "                </tr>";
		text += "			</table>";
		text += "        </td>";
		text += "    </tr>";
		text += "</table>";

		obj.innerHTML = text;
		obj.style.visibility = "visible";
	} else {
		hide_user_menu();
	}
}

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 search_by_id(id) {
	location.href = "ttboard.cgi?act=list" + QUERY_DB + "&s_mode=def&s_id=1&s_key=" + id;
	hide_user_menu();
}

function search_by_name(name) {
	location.href = "ttboard.cgi?act=list" + QUERY_DB + "&s_mode=def&s_name=1&s_key=" + name;
	hide_user_menu();
}

function send_mail(email) {
	if(email == "") return;
	location.href = "mailto:" + email;
}

function ttmailer(email) {
	if(email == "") return;
	window.open("ttmailer.cgi?act=write&to="+email, "", "width=320, height=350, resizable=1, scrollbars=1");
}

function open_url(url) {
	if(url == "") return;
	window.open(url, "", "");
}

function user_info(id) {
	profile(id, 1, "");
}

/*******************************************************************************
	SEARCH script
*******************************************************************************/
function set_search(field) {
	var obj_field = document.all["s_"+field];

	if(obj_field.value == 1) {
		document.all["s_"+field+"_chk"].src = PATH_SKIN + "images/chkbox_off.gif";
		obj_field.value = 0;
	} else {
		document.all["s_"+field+"_chk"].src = PATH_SKIN + "images/chkbox_on.gif";
		obj_field.value = 1;
	}
}

function set_search_num() {
	var total_num = SEARCH_TOTAL_COUNT;
	var search_num = search_form.s_num.value;

	if(search_num != '') {
		if(search_num > total_num) {
			search_num = total_num;
			search_form.s_num.value = total_num;
		}

		// show search field
		for(var i = 1; i <= total_num; i++) {
			if(i <= search_num)
				document.all["id_search" + i].style.display = "block";
			else
				document.all["id_search" + i].style.display = "none";
		}
	}
}

function show_adv_search() {
	document.all["id_default_search"].style.display = "none";
	document.all["id_adv_search"].style.display = "block";
}

function show_default_search() {
	document.all["id_default_search"].style.display = "block";
	document.all["id_adv_search"].style.display = "none";
}

function search(mode) {
	if(mode == "default") {
		if(search_form.s_id.value == 0 && search_form.s_name.value == 0
			&& search_form.s_title.value == 0 && search_form.s_content.value == 0) {
			alert("°Ë»öÇÒ ÇÊµå¸¦ ¼±ÅÃÇØ ÁÖ½Ê½Ã¿À.");
			return;
		} else if(search_form.s_key.value == "")  {
			alert("°Ë»ö¾î¸¦ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.");
			search_form.s_key.focus();
			return;
		}

		search_form.action = "ttboard.cgi?act=list" + QUERY_DB + "&s_mode=def";
	} else if(mode == "advanced") {
		// check search key
		for(var i = 1; i <= search_form.s_num.value; i++) {
			var obj = document.all["s_key" + i];

			if(obj.value == "") {
				alert("°Ë»ö¾î¸¦ ÀÔ·ÂÇØ ÁÖ½Ê½Ã¿À.");
				obj.focus();
				return;
			}
		}

		search_form.action = "ttboard.cgi?act=list" + QUERY_DB + "&s_mode=adv";
	}

	search_form.submit();
}

/*******************************************************************************
	COMMENT script
*******************************************************************************/
function add_comment(idx) {
	if(document.all["cmt"+idx+"_name"].value == "") {
		alert("ÀÌ¸§À» ½á ÁÖ¼¼¿ä");
		document.all["cmt"+idx+"_name"].focus();
		return;
	}

	if(MEMBER_IDX == 0) {
		// ·Î±×ÀÎÇÑ °æ¿ì´Â ºñ¹Ð¹øÈ£¸¦ ¹ÞÁö¾ÊÀ½.
		if(document.all["cmt"+idx+"_pwd"].value == "") {
			alert("ºñ¹Ð¹øÈ£À» ½á ÁÖ¼¼¿ä");
			document.all["cmt"+idx+"_pwd"].focus();
			return;
		}
	}

	if(document.all["cmt"+idx+"_content"].value == "") {
		alert("³»¿ëÀ» ½á ÁÖ¼¼¿ä");
		document.all["cmt"+idx+"_content"].focus();
		return;
	}

	// set value
	comment_form.comment_name.value = document.all["cmt"+idx+"_name"].value;
	if(MEMBER_IDX == 0) {
		comment_form.comment_pwd.value = document.all["cmt"+idx+"_pwd"].value;
	}
	comment_form.comment_content.value = document.all["cmt"+idx+"_content"].value;

	comment_form.action = "ttboard.cgi?act=add_comment" + QUERY_DB + "&idx=" + idx;
	comment_form.submit();
}

function show_comment_pwd(article_idx, comment_idx) {
	if(MEMBER_IDX == 0) {
		// before login
		var obj = 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.style.posLeft = event.x - 170 + document.body.scrollLeft;
			obj.style.posTop = event.y + document.body.scrollTop;
		}

		obj.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;
	}
	// check category
	if(write_form.cate_idx) {
		// use categoy
		if(CATEGORY_WRITE_METHOD == 0) {
			// essential field
			if(write_form.cate_idx.value == "") {
				alert("Ä«Å×°í¸®¸¦ ¼±ÅÃÇØÁÖ¼¼¿ä.");
				return;
			}
		} else if(CATEGORY_WRITE_METHOD == 1) {
			// alert message
			if(write_form.cate_idx.value == 0) {
				var bYes = confirm("Ä«Å×°í¸®¸¦ ¼±ÅÃÇÏÁö ¾ÊÀ¸¼Ì½À´Ï´Ù.\nÀúÀåÇÏ½Ã°Ú½À´Ï±î?");
				if(!bYes) return;
			}
		} else if(CATEGORY_WRITE_METHOD == 2) {
			// no action
		}
	}

	// 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);

	// file
	obj = document.all['file_num'];
	if(obj) {
		total_count = obj.options[obj.length-1].value;
		for(var i = 1; i <= total_count; i++) {
			resize_object_width("file"+i, width, FILE_WIDTH);
			if(i >= 2) resize_object_width("file"+i+"_desc", width, FILE_WIDTH);
		}
	}

	// link
	obj = document.all['link_num'];
	if(obj) {
		total_count = obj.options[obj.length-1].value;
		for(var i = 1; i <= total_count; i++) {
			resize_object_width("link"+i, width, FILE_WIDTH);
			resize_object_width("link"+i+"_desc", width, FILE_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;
	}
}

// file & link
function show_file() {
	var obj = write_form.file_num;
	var file_num = obj.options[obj.selectedIndex].value;
	var total_file = obj.options[obj.length-1].value;

	for(var i = 1; i <= total_file; i++) {
		var obj_file = document.all["id_file" + i];
		var obj_info = document.all["id_file" + i + "_info"];

		if(i <= file_num) {
			obj_file.style.display = 'block';
			if(obj_info) obj_info.style.display = 'block';
		} else {
			obj_file.style.display = 'none';
			if(obj_info) obj_info.style.display = 'none';
		}
	}
}

function show_link() {
	var obj = write_form.link_num;
	var link_num = obj.options[obj.selectedIndex].value;
	var total_link = obj.options[obj.length-1].value;

	for(var i = 1; i <= total_link; i++) {
		if(i <= link_num)
			document.all["id_link" + i].style.display = 'block';
		else
			document.all["id_link" + i].style.display = 'none';
	}
}

function add_var(id, idx) {
	if(id == 'link') {
		write_form.all["content"].value += "{LINK:" + idx + "}";
	} else if(id == 'file') {
		write_form.all["content"].value += "{FILE:" + idx + "}";;
	}
}

/*******************************************************************************
	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();
		else if(id == 'link') show_link();
		else if(id == 'file') show_file();

		event.returnValue = false;
	}
}

function read_article(idx) {
	if(LIST_TITLE_ON_CLICK == 0) {
		location.href = "ttboard.cgi?act=read" + QUERY + "&page=" + PAGE_CUR_PAGE + "&idx=" + idx;
	} else if(LIST_TITLE_ON_CLICK == 1) {
		window.open("ttboard.cgi?act=popup" + QUERY + "&page=" + PAGE_CUR_PAGE + "&idx=" + idx,
			"", "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 + "&page=" + PAGE_CUR_PAGE + "&idx=" + idx,
			"", "width="+LIST_POPUP_WIDTH+", height="+LIST_POPUP_HEIGHT+", scrollbars=1, resizable=1");
	}
}

function multi_read() {
	var	flag = 0;

	// check index
	for(var i = 1; i <= ARTICLE_ROWS; i++) {
		var obj = document.all["check" + i];
		if(obj && obj.value != 0) {
			// check secret article
			if(document.all["article" + i + "_secret"].value == 1) {
				alert("ºñ¹Ð °Ô½Ã¹°Àº ´ÙÁßÀÐ±â¸¦ ÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
				return;
			}

			flag = 1;
		}
	}

	if(!flag) {
		alert("ÀÐÀ» °Ô½Ã¹°À» ¼±ÅÃÇØÁÖ½Ê½Ã¿À.");
		return;
	}

	list_form.action = "ttboard.cgi?act=multi_read" + QUERY;
	list_form.submit();
}

function multi_delete() {
	var	flag = 0;

	// check index
	for(var i = 1; i <= ARTICLE_ROWS; i++) {
		var obj = document.all["check" + i];
		if(obj && obj.value != 0) flag = 1;
	}

	if(!flag) {
		alert("»èÁ¦ÇÒ °Ô½Ã¹°À» ¼±ÅÃÇØÁÖ½Ê½Ã¿À.");
		return;
	}

	list_form.action = "ttboard.cgi?act=multi_del" + QUERY + "&page=" + PAGE_CUR_PAGE;
	list_form.submit();
}

function list_article() {
	location.href = LINK_LIST_QUERY;
}

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 jump_to() {
	var obj = document.all["jump_page"];
	var page = obj.value;
	var last_page = document.all["last_page"].value;

	if(!check_number(page)) {
		alert("page¿¡´Â ¼ýÀÚ¸¸ ¾²½Ç ¼ö ÀÖ½À´Ï´Ù.");
		obj.value = "";
		obj.focus();
		return;
	}

	if(page != "") {
		if(parseInt(page) < 1) {
			alert("ÆäÀÌÁö´Â 1º¸´Ù Ä¿¾ßÇÕ´Ï´Ù.");
			obj.value = "";
			obj.focus();
			return;
		} else if(parseInt(page) > parseInt(last_page)) {
			alert(page + " ÆäÀÌÁö´Â Á¸ÀçÇÏÁö ¾Ê´Â ÆäÀÌÁöÀÔ´Ï´Ù.");
			obj.value = "";
			obj.focus();
			return;
		} else {
			location.href = "ttboard.cgi?act=list" + QUERY_DB + "&page="+page;
		}
	}
}

/*******************************************************************************
	JUKEBOX script
*******************************************************************************/
var state = 0;						// 0:stop, 1:pause, 2:play
var random = 0;						// 0:sequently, 1:random
var repeat = 0;						// 0:play once, 1:repeat
var interval = 2;					// interval betwenn music
var timer = 0;						// timer (0:total time, 1:left time, 3:playing time)

var idx_list = new Array();			// index list
var music_list = new Array();		// music list
var title_list = new Array();		// title list
var cnt_music = 0;					// count of music
var player = "";					// player ("LIST", "READ", "JUKEBOX")

function add_music(idx, url, title) {
	idx_list[cnt_music] = idx;
	music_list[cnt_music] = url;
	title_list[cnt_music] = title;

	return cnt_music++;
}

function play(file) {
	// play music
	if(state == 2) stop();

	state = 2;
	set_timer();
	jukebox.open(file);
}

function pause() {
	if(state == 2) {
		state = 1;
		jukebox.pause();
	} else if(state == 1) {
		state = 2;
		jukebox.play();
	}
}

function stop() {
	if(typeof(timeoutID) == "number") clearTimeout(timeoutID);

	state = 0;
	jukebox.stop();
}

function next_music(bResult) {
	if(bResult == 0 && jukebox.PlayCount == 1) {
		if(player == "JUKEBOX")
			timeoutID = setTimeout("jukebox_next();", interval*1000);
		else if(player == "LIST")
			timeoutID = setTimeout("l_next(cur_idx);", interval*1000);
	}
}

function set_timer() {
	if(player == "READ") return;

	if(state != 0) {
		var running_time = jukebox.Duration;
		var playing_time = jukebox.currentPosition;
		var left_time = running_time - playing_time;
		var min, sec;

		switch(timer) {
			case 0:
				min = Math.floor(running_time/60);
				sec = (running_time%60 < 10) ? "0"+Math.floor(running_time%60) : Math.floor(running_time%60);
				break;
			case 1:
				min = "- "+Math.floor(left_time/60);
				sec = (left_time%60 < 10) ? "0"+Math.floor(left_time%60) : Math.floor(left_time%60);
				break;
			case 2:
				min = "+ "+Math.floor(playing_time/60);
				sec = (playing_time%60 < 10) ? "0"+Math.floor(playing_time%60) : Math.floor(playing_time%60);
				break;
			default:
		}

		document.all["jukebox_timer"].value = min + " : " + sec;
	} else {
		document.all["jukebox_timer"].value = "-- : --";
	}

	setTimeout("set_timer();", 500);
}

function change_timer() {
	if(state != 0) {
		timer = (timer == 2) ? 0 : timer + 1;
	}
}

/*******************************************************************************
	JUKEBOX PLAY script
*******************************************************************************/
var jukebox_list = new Array();		// pointer to music_list
var cnt_jukebox = 0;
var cur_jidx = 0;		// current jukebox index (point music index)
var next_jidx = 0;		// next jukebox index (point music index)

// get index list to be checked and re-index.
function make_jukebox() {
	var idx;
	cnt_jukebox = 0, cur_jidx = 0, next_jidx = 0;

	for(var i = 1; i <= ARTICLE_ROWS; i++) {
		if(!document.all["article"+i+"_idx"]) continue;

		idx = document.all["article"+i+"_idx"].value;
		if(document.all["check"+i].value == idx)
			reidx_jukebox(idx);
	}
}

// add jukebox index that matched by index.
function reidx_jukebox(idx) {
	for(var i = 0; i < cnt_music; i++) {
		if(idx == idx_list[i])
			jukebox_list[cnt_jukebox++] = i;
	}
}

function reset_button() {
	// reset jukebox button
	document.all["jbtn_play"].src = PATH_SKIN + "images/jbtn_play.gif";
	document.all["jbtn_pause"].src = PATH_SKIN + "images/jbtn_pause.gif";
	document.all["equalizer"].src = PATH_SKIN + "images/equal_off.gif";
	// reset list buttton

	for(i = 1; i <= ARTICLE_ROWS; i++) {
		if(!document.all["article"+i+"_idx"]) continue;
		article_idx = document.all["article"+i+"_idx"].value;
		document.all["lbtn_play" + article_idx].src = PATH_SKIN + "images/lbtn_play.gif";
		document.all["lbtn_pause" + article_idx].src = PATH_SKIN + "images/lbtn_pause.gif";
	}
}

function jukebox_play(mode) {
	var cur_midx, next_midx;		// music index
	var cur_idx, next_idx;			// article index

	if(mode == 0) {
		make_jukebox();
		if(cnt_jukebox == 0) return;
	}

	player = "JUKEBOX";
	if(random == 0) {
		// sequently
		next_jidx = cur_jidx + 1;
		if(next_jidx > cnt_jukebox-1) next_jidx = 0;
	} else {
		// randomly
		next_jidx = Math.ceil(Math.random()*cnt_jukebox);
	}

	// get music, article index
	cur_midx = jukebox_list[cur_jidx];
	next_midx = jukebox_list[next_jidx];
	cur_idx = idx_list[cur_midx];
	next_idx = idx_list[next_midx];

	// change jacket
	document.all.jacket.src = document.all["music"+cur_idx+"_jacket"].value;

	// change button
	reset_button();
	document.all["jbtn_play"].src = PATH_SKIN + "images/jbtn_play_on.gif";
	document.all["jbtn_pause"].src = PATH_SKIN + "images/jbtn_pause.gif";
	document.all["equalizer"].src = PATH_SKIN + "images/equal_on.gif";

	// change title
	document.all["cur_title"].value = title_list[cur_midx];
	document.all["next_title"].value = title_list[next_midx];

	// set song count
	document.all["song_count"].value = "" + cur_jidx + " / " + cnt_jukebox;

	// play music
	play(music_list[cur_midx]);
	prev_idx = cur_idx;
	cur_idx = idx;
}

function jukebox_pause() {
	if(player == "LIST") return;

	// change button
	if(state == 2) {
		document.all["jbtn_play"].src = PATH_SKIN + "images/jbtn_play.gif";
		document.all["jbtn_pause"].src = PATH_SKIN + "images/jbtn_pause_on.gif";
		document.all["equalizer"].src = PATH_SKIN + "images/equal_off.gif";
	} else if(state == 1) {
		document.all["jbtn_play"].src = PATH_SKIN + "images/jbtn_play_on.gif";
		document.all["jbtn_pause"].src = PATH_SKIN + "images/jbtn_pause.gif";
		document.all["equalizer"].src = PATH_SKIN + "images/equal_off.gif";
	}

	// pause music
	pause();
}

function jukebox_next() {
	if(player == "LIST") return;

	cur_jidx = next_jidx;
	if(state == 2) stop();
	jukebox_play(1);
}

function jukebox_stop() {
	if(player == "LIST") return;

	// change button
	document.all["jbtn_play"].src = PATH_SKIN + "images/jbtn_play.gif";
	document.all["jbtn_pause"].src = PATH_SKIN + "images/jbtn_pause.gif";
	document.all["equalizer"].src = PATH_SKIN + "images/equal_off.gif";

	// pause music
	stop();
}

function jukebox_repeat() {
	if(repeat) {
		repeat = 0;
		document.all["repeat"].src = PATH_SKIN + "images/jbtn_repeat.gif";
	} else {
		repeat = 1;
		document.all["repeat"].src = PATH_SKIN + "images/jbtn_repeat_on.gif";
	}
}

function jukebox_random() {
	if(random) {
		random = 0;
		document.all["random"].src = PATH_SKIN + "images/jbtn_random.gif";
	} else {
		random = 1;
		document.all["random"].src = PATH_SKIN + "images/jbtn_random_on.gif";
	}
}

function show_jacket() {
	if(cur_idx != 0) {
		jaket = document.all['jaketimg'+cur_idx].value;
		viewWin = window.open('','', 'width=500, height=400, scrollbars=yes, resizable=yes');
		popcontent  = "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=euc-kr'>\n";
		popcontent += "<title>TT BoardEngine</title>\n</head>\n";
		popcontent += "<script>\n";
		popcontent += "function WinReSize() {\n";
		popcontent += "  popup_Width  = document.all['shotimg'].width + 28;\n;";
		popcontent += "  popup_Height = document.all['shotimg'].height + 32;\n";
		popcontent += "  popup_left = (screen.width / 2) - (popup_Width /2);\n";
		popcontent += "  popup_top = (screen.height / 2) - (popup_Height / 2);\n";
		popcontent += "  if(screen.width < popup_Width)\n";
		popcontent += "  {\n";
		popcontent += "    popup_left=0;\n";
		popcontent += "    popup_Width = screen.width;\n";
		popcontent += "  }\n";
		popcontent += "  if(screen.height < popup_Height)\n";
		popcontent += "		{\n";
		popcontent += "        popup_top = 0;\n";
		popcontent += "	       popup_Height = screen.height-55;\n";
		popcontent += "     }\n";
		popcontent += "  window.resizeTo(popup_Width, popup_Height);\n";
		popcontent += "  moveTo(popup_left , popup_top);\n";
		popcontent += "}\n";
		popcontent += "</script>\n";
		popcontent += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 name='dd'>\n";
		popcontent += "<a href='javascript:self.close();'><img src=" + jaket + " border=0 name='shotimg' onLoad='WinReSize();'></a>\n";
		popcontent += "</body>\n</html>\n";
		viewWin.document.write(popcontent);
	}
}

function Read_popup_image(idx) {
	viewWin = window.open('','', 'width=500, height=400, scrollbars=yes, resizable=yes');
	popcontent  = "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=euc-kr'>\n";
	popcontent += "<title>TT BoardEngine</title>\n</head>\n";
	popcontent += "<script>\n";
	popcontent += "function WinReSize() {\n";
	popcontent += "  popup_Width  = document.all['shotimg'].width + 28;\n;";
	popcontent += "  popup_Height = document.all['shotimg'].height + 32;\n";
	popcontent += "  popup_left = (screen.width / 2) - (popup_Width /2);\n";
	popcontent += "  popup_top = (screen.height / 2) - (popup_Height / 2);\n";
	popcontent += "  if(screen.width < popup_Width)\n";
	popcontent += "  {\n";
	popcontent += "    popup_left=0;\n";
	popcontent += "    popup_Width = screen.width;\n";
	popcontent += "  }\n";
	popcontent += "  if(screen.height < popup_Height)\n";
	popcontent += "		{\n";
	popcontent += "        popup_top = 0;\n";
	popcontent += "	       popup_Height = screen.height-55;\n";
	popcontent += "     }\n";
	popcontent += "  window.resizeTo(popup_Width, popup_Height);\n";
	popcontent += "  moveTo(popup_left , popup_top);\n";
	popcontent += "}\n";
	popcontent += "</script>\n";
	popcontent += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 name='dd'>\n";
	popcontent += "<a href='javascript:self.close();'><img src=" + idx + " border=0 name='shotimg' onLoad='WinReSize();'></a>\n";
	popcontent += "</body>\n</html>\n";
	viewWin.document.write(popcontent);
}

/*******************************************************************************
	LIST PLAY script
*******************************************************************************/
var prev_idx = 0;			// previous article index
var cur_idx = 0;			// current article index
var cur_midx = 0;			// current music index
var next_midx = 0;			// next music index
var next_music = 0;			// next music

function set_music_idx(idx) {
	var begin_midx = document.all["music"+idx+"_midx"].value;		// begin index
	var cur_music = document.all["music"+idx+"_cur"].value;			// music count
	var total_music = document.all["music"+idx+"_total"].value;		// total count of music

	// check index
	if(begin_midx == "" || cur_music == "" || total_music == "") return -1;
	if(parseInt(cur_music) == 0) return -1;

	begin_midx = parseInt(begin_midx);
	cur_music = parseInt(cur_music);
	total_music = parseInt(total_music);

	// get music index
	if(cur_music > total_music) {
		cur_music = 1;
		document.all["music"+idx+"_cur"].value = cur_music;
	}

	// set song count
	document.all["song_count"].value = "" + cur_music + " / " + total_music;

	// current music index
	cur_midx = begin_midx + cur_music - 1;
	// next music index
	if(random == 0) {
		// sequently
		if(cur_music == total_music) next_music = 1;
		else next_music = cur_music + 1;
	} else {
		// randomly
		next_music = Math.ceil(Math.random()*total_music);
	}
	next_midx = begin_midx + next_music - 1;
}

function l_play(idx) {
	var article_idx;
	player = "LIST";
	set_music_idx(idx);

	// change jacket
	document.all.jacket.src = document.all["music"+idx+"_jacket"].value;

	// change play button
	reset_button();
	document.all["lbtn_play" + idx].src = PATH_SKIN + "images/lbtn_play_on.gif";
	document.all["lbtn_pause" + idx].src = PATH_SKIN + "images/lbtn_pause.gif";
	document.all["equalizer"].src = PATH_SKIN + "images/equal_on.gif";

	// change title
	document.all["cur_title"].value = title_list[cur_midx];
	document.all["next_title"].value = title_list[next_midx];

	// play music
	prev_idx = cur_idx;
	cur_idx = idx;
	play(music_list[cur_midx]);
}

function l_pause(idx) {
	if(cur_idx == 0 || cur_idx != idx) return;

	// change button
	document.all["jbtn_play"].src = PATH_SKIN + "images/jbtn_play.gif";
	document.all["jbtn_pause"].src = PATH_SKIN + "images/jbtn_pause.gif";
	document.all["equalizer"].src = PATH_SKIN + "images/equal_off.gif";
	if(state == 2) {
		document.all["lbtn_play" + idx].src = PATH_SKIN + "images/lbtn_play.gif";
		document.all["lbtn_pause" + idx].src = PATH_SKIN + "images/lbtn_pause_on.gif";
		document.all["equalizer"].src = PATH_SKIN + "images/equal_off.gif";
	} else if(state == 1) {
		document.all["lbtn_play" + idx].src = PATH_SKIN + "images/lbtn_play_on.gif";
		document.all["lbtn_pause" + idx].src = PATH_SKIN + "images/lbtn_pause.gif";
		document.all["equalizer"].src = PATH_SKIN + "images/equal_off.gif";
	}

	// pause music
	pause();
}

function l_next(idx) {
	if(cur_idx == 0 || cur_idx != idx) return;

	// next music
	if(state == 2) stop();
	document.all["music"+idx+"_cur"].value = next_music;
	l_play(idx);
}

function l_stop(idx) {
	if(cur_idx == 0 || cur_idx != idx) return;

	// change jacket
	document.all.jacket.src = PATH_SKIN + "images/no_image.gif";

	// change button
	document.all["jbtn_play"].src = PATH_SKIN + "images/jbtn_play.gif";
	document.all["jbtn_pause"].src = PATH_SKIN + "images/jbtn_pause.gif";
	document.all["equalizer"].src = PATH_SKIN + "images/equal_off.gif";
	document.all["lbtn_play" + idx].src = PATH_SKIN + "images/lbtn_play.gif";
	document.all["lbtn_pause" + idx].src = PATH_SKIN + "images/lbtn_pause.gif";
	document.all["equalizer"].src = PATH_SKIN + "images/equal_off.gif";

	// stop music
	stop();
}

/*******************************************************************************
	READ PLAY script
*******************************************************************************/
var cur_id = "";		// current id to be played

function r_play(id) {
	player = "READ";

	// change button
	if(cur_id != "") {
		document.all[cur_id + "_play"].src = PATH_SKIN + "images/lbtn_play.gif";
		document.all[cur_id + "_pause"].src = PATH_SKIN + "images/lbtn_pause.gif";
		document.all[cur_id + "_stop"].src = PATH_SKIN + "images/lbtn_stop.gif";
	}

	document.all[id + "_play"].src = PATH_SKIN + "images/lbtn_play_on.gif";
	document.all[id + "_pause"].src = PATH_SKIN + "images/lbtn_pause.gif";
	document.all[id + "_stop"].src = PATH_SKIN + "images/lbtn_stop.gif";
	cur_id = id;

	// play music
	play(document.all[id+"_file"].value);
}

function r_pause(id) {
	if(cur_id == "" || cur_id != id) return;

	// change button
	if(state == 2) {
		document.all[cur_id + "_play"].src = PATH_SKIN + "images/lbtn_play.gif";
		document.all[cur_id + "_pause"].src = PATH_SKIN + "images/lbtn_pause_on.gif";
		document.all[cur_id + "_stop"].src = PATH_SKIN + "images/lbtn_stop.gif";
	} else if(state == 1) {
		document.all[cur_id + "_play"].src = PATH_SKIN + "images/lbtn_play_on.gif";
		document.all[cur_id + "_pause"].src = PATH_SKIN + "images/lbtn_pause.gif";
		document.all[cur_id + "_stop"].src = PATH_SKIN + "images/lbtn_stop.gif";
	}

	// pause music
	pause();
}

function r_stop(id) {
	if(cur_id == "" || cur_id != id) return;

	// change button
	if(cur_id != "") {
		document.all[cur_id + "_play"].src = PATH_SKIN + "images/lbtn_play.gif";
		document.all[cur_id + "_pause"].src = PATH_SKIN + "images/lbtn_pause.gif";
		document.all[cur_id + "_stop"].src = PATH_SKIN + "images/lbtn_stop.gif";
	}

	// stop music
	stop();
}

function bluring(){ 
if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus(); 
} 
document.onfocusin=bluring; 

function skin_info(features) {
	if(arguments.length == 0)
		features = "width=400, height=600, resizable=1, scrollbars=1";

	window.open("ttboard.cgi?act=skin_info"+QUERY_DB, "", features);
}

function viewPic(img){
  foto1= new Image();
  foto1.src=(img);
  contImg(img);
}
function contImg(img){
  if((foto1.width!=0)&&(foto1.height!=0)){
    viewImg(img);
  }
  else{
    funzione="contImg('"+img+"')";
    intervallo=setTimeout(funzione,0);
  }
}
function viewImg(img){
  largh=foto1.width+0;
  altez=foto1.height+0;
  stringa="width="+largh+",height="+altez;
  finestra=window.open(img,"",stringa);
}






