/**
 * ·¹Æ÷Æ®
 */
function SendReport(type, comment_yn, article_sn, kind_sn, comment_sn, title, art_writer_id) {
	if (!g_UserInfo.login) {
		if (window.confirm("·Î±×ÀÎÀ» ÇØ¾ß »ç¿ëÇÒ ¼ö ÀÖ´Â ±â´ÉÀÔ´Ï´Ù. ·Î±×ÀÎ ÇÏ½Ã°Ú½À´Ï±î?")) {
			MoveLogin();
		}
		return;
	}
	window.open("/helpdesk/report/add/"+article_sn+"/"+kind_sn+"/"+comment_sn+"/"+type+"/"+comment_yn+"/"+art_writer_id+"?title="+title, "SendReportP", "width=450, height=490");
}

/**
 * °ü½É ¾ÆÀÌÅÛ
 */
function AddFavoriteItem() {
	if (g_UserInfo.login) {
		if (window.confirm("°ü½É ¾ÆÀÌÅÛÀ¸·Î µî·ÏÇÏ½Ã°Ú½À´Ï±î?")) {
			document.FavoriteItemForm.submit();
		}
	} else {
		if (window.confirm("·Î±×ÀÎÀ» ÇØ¾ß »ç¿ëÇÒ ¼ö ÀÖ´Â ±â´ÉÀÔ´Ï´Ù. ·Î±×ÀÎ ÇÏ½Ã°Ú½À´Ï±î?")) {
			MoveLogin();
		}
	}
}

/**
 * µ¡±Û
 */
function ViewCommentModifyForm(comment_sn) {
	if (!ViewCommentLoginChk()) return false;

	$('comment_form_'+comment_sn).show();

	var modify_obj = $('comment_modify_'+comment_sn);
	var contents_obj = $('comment_contents_'+comment_sn);
	modify_obj.value = $TEXT(contents_obj);

	contents_obj.hide();
}

function ViewCommentModify(comment_sn) {
	if (!ViewCommentLoginChk()) return false;

	var contents = $F('comment_modify_'+comment_sn);

	if (contents.empty()) {
		window.alert("´ä±ÛÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		$('comment_modify_'+comment_sn).focus();
		return false;
	} else {
                // ´ä±Û ±ÝÄ¢¾î Ã¼Å©
		var ResultBadWord = check_badword(contents);

		if( ResultBadWord != 0 ) {
			alert("°Ô½Ã¹°À» µî·ÏÇÒ ¼ö ¾ø½À´Ï´Ù.\n°Ô½Ã¹°ÀÇ ³»¿ë¿¡ ºÎÀûÀýÇÑ ´Ü¾î°¡ »ç¿ëµÇ¾ú½À´Ï´Ù.");
                        $('comment_modify_'+comment_sn).value = "";
                        $('comment_modify_'+comment_sn).focus();
                        return false;
                }
	}

	var form = document.CommentForm;
	form.mode.value = "modify";
	form.contents.value = contents;
	form.comment_sn.value = comment_sn;
	form.submit();
}

function ViewCommentSave() {
	if (!ViewCommentLoginChk()) return false;

	var contents = $F('comment_form_contents');

	if (contents.empty()) {
		window.alert("´ä±ÛÀ» ÀÔ·ÂÇØÁÖ¼¼¿ä.");
		$('comment_form_contents').focus();
		return false;
	} else {
		// ´ä±Û ±ÝÄ¢¾î Ã¼Å©
		var ResultBadWord = check_badword(contents);

		if( ResultBadWord != 0 ) {
			alert("°Ô½Ã¹°À» µî·ÏÇÒ ¼ö ¾ø½À´Ï´Ù.\n°Ô½Ã¹°ÀÇ ³»¿ë¿¡ ºÎÀûÀýÇÑ ´Ü¾î°¡ »ç¿ëµÇ¾ú½À´Ï´Ù.");
			$('comment_form_contents').value = "";
			$('comment_form_contents').focus();
			return false;
		}
	}

	var form = document.CommentForm;
	form.mode.value = "add";
	form.contents.value = contents;
	form.submit();
}

function ViewCommentDelete(comment_sn) {
	if (!ViewCommentLoginChk()) return false;

	if (window.confirm("¼±ÅÃÇÏ½Å ´ä±ÛÀ» »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) {
		var form = document.CommentForm;
		form.mode.value = "delete";
		form.comment_sn.value = comment_sn;
		form.submit();
	}
}

function ViewCommentLoginChk() {
	if (!g_UserInfo.login) {
		if (window.confirm("·Î±×ÀÎÇØ¾ß ´ä±ÛÀ» ÀÛ¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù. ·Î±×ÀÎÇÏ½Ã°Ú½À´Ï±î?"))
		{
			MoveLogin('#comment_form');
		} else {
			$('comment_form_contents').blur();
		}

		return false;
	} else if (!g_UserInfo.rid_auth) {

		$('comment_form_contents').blur();
		OpenRealName();
		return false;
	}

	return true;
}

/**
 * ÃßÃµÇÏ±â
 */
function RecommendRequest(type, user_id, recommend_cnt, article_sn, kind_sn, kind_type, comment_sn) {
	if (!g_UserInfo.login) {
		if (window.confirm("·Î±×ÀÎÀ» ÇØ¾ß »ç¿ëÇÒ ¼ö ÀÖ´Â ±â´ÉÀÔ´Ï´Ù. ·Î±×ÀÎ ÇÏ½Ã°Ú½À´Ï±î?")) {
			MoveLogin();
		}

		return;
	}

	if (g_UserInfo.id == user_id) {
		if (type=="review_comment" || type=="desc_comment") {
			window.alert("º»ÀÎÀÇ ±ÛÀº °ø°¨ÇÒ ¼ö ¾ø½À´Ï´Ù.");
		} else {
			RecommendMsg(kind_sn, kind_type, "º»ÀÎÀÇ ±ÛÀº <span>ÃßÃµ</span>ÇÒ ¼ö ¾ø½À´Ï´Ù");
		}

		return;
	}

	var url = "/view/ajax/recommend";
	var param = "type="+type+"&article_sn="+article_sn+"&kind_sn="+kind_sn;

	if (typeof(kind_type)!="undefined") {
		param += "&kind_type="+kind_type;
	} else {
		kind_type = "";
	}

	if (typeof(comment_sn)!="undefined") {
		param += "&comment_sn="+comment_sn;
	}

	new Empas.Ajax.Request(url, {
		parameters: param,
		onComplete: function(transport) {			
			switch(transport.responseText) {
				case 'BAD_USER':
					window.alert("È¸¿ø´ÔÀÇ ÃßÃµ(°ø°¨)ÀÌ Á¦ÇÑµÇ¾ú½À´Ï´Ù.\r\nÀÚ¼¼ÇÑ »çÇ×Àº ¸®ºä Á¦¾È/¹®ÀÇ¸¦ ÅëÇØ ¹®ÀÇÇØÁÖ¼¼¿ä.");
				break;

				case 'NO_LOGIN':
					window.alert("·Î±×ÀÎÀ» ÇØ¾ß ÃßÃµÇÒ ¼ö ÀÖ½À´Ï´Ù.");
				break;
				
				case 'ALREADY':
					if (type=="review_comment" || type=="desc_comment") {
						window.alert("°ø°¨Àº ÇÑ ¹ø¸¸ Âü¿©ÇÒ ¼ö ÀÖ½À´Ï´Ù.");
					} else {
						RecommendMsg(kind_sn, kind_type, "ÀÌ¹Ì <span>ÃßÃµ</span>ÇÏ¿´½À´Ï´Ù");
					}
				break;

				case 'OK':
					if (type=="review_comment" || type=="desc_comment") {
						$('c_recommend_cnt_'+comment_sn).update("("+ (recommend_cnt+1) + ")");
						var msg = $('c_recommend_msg_'+comment_sn);
					} else {
						try {
							$('recommend_cnt_'+kind_sn+kind_type).update(recommend_cnt+1);
						} catch (e) {
							$('recommend_cnt_'+kind_sn).update(recommend_cnt+1);
						}

						RecommendMsg(kind_sn, kind_type, "<span>ÃßÃµ</span>ÇÏ¿´½À´Ï´Ù");

						// Á¦¸ñ ¿µ¿ª
						try {
							$('recommend_cnt_title_'+kind_sn).update(recommend_cnt+1);
						} catch (e) {}
						
						// ÇÏ´Ü ¸®½ºÆ® ¿µ¿ª
						try {
							$('recommend_cnt_list_'+kind_sn+kind_type).update(recommend_cnt+1);
						} catch (e) {}
					}
				break;

				default:
//					window.alert(transport.responseText);
				break;
			}
		},
		onFailure: function(transport) {
			window.alert("ÃßÃµÇÏ±â ¿äÃ»¿¡ ½ÇÆÐÇß½À´Ï´Ù.");
		}
	});
}

function RecommendMsg(kind_sn, kind_type, msg) {
	var MSGOBJ = $('recommend_msg_'+kind_sn+kind_type);
	if (MSGOBJ==null) {
		MSGOBJ = $('recommend_msg_'+kind_sn);
	}

	MSGOBJ.show();
	MSGOBJ.update(msg);

	new PeriodicalExecuter(function(pe) {
		MSGOBJ.hide();
		pe.stop();
	}, 1);
}

/**
 * »èÁ¦
 */
function DescDelete(article_sn, desc_sn) {
	if (window.confirm("»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) {
		location.replace("/write/proc/desc_delete/" + article_sn + "/" + desc_sn);
	}
}

function ReviewDelete(article_sn, review_sn, type) {
	if (window.confirm("»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) {
		location.replace("/write/proc/review_delete/" + article_sn + "/" + type + "/" + review_sn);
	}
}

// ÀÌ¹ÌÁö ÀÚµ¿ ¸®»çÀÌÂ¡ °ü·Ã ==================================================

// ÃÖ´ë °¡·ÎÆø
var IMG_MAX_WIDTH = 620; 

// 0.1ÃÊ¸¶´Ù ÀÌ¹ÌÁö Àü¼Û ¿Ï·á Ã¼Å© ÈÄ ¸®»çÀÌÂ¡
function ImgAutoResize(idx) {
	obj = document.images['resize_img_'+idx];

    if (typeof(obj.complete)!="undefined" && obj.complete) {
		obj.org_height = obj.height;
		obj.org_width = obj.width;

		if (obj.width>IMG_MAX_WIDTH) {
			obj.height = (IMG_MAX_WIDTH*obj.height)/obj.width;
			obj.width = IMG_MAX_WIDTH;
		}
	} else {
		setTimeout('ImgAutoResize('+idx+')',100);
	}
}

// ÀÌ¹ÌÁö Å¬¸¯½Ã ¿øº» ÀÌ¹ÌÁö ÆË¾÷
function ImgOriginal(idx) {
	obj = document.images['resize_img_'+idx];

	var Size = { height:obj.org_height+25, width:obj.org_width+30 };

	if (Size.height>600) Size.height = 600;
	if (Size.width>900) Size.height = 900;

	window.open(obj.src,'_new');
}

// ============================================================================

/**
 * ºä ÆäÀÌÁö ÇÏ´Ü °Ë»ö°á°ú
 */
function BottomSearchResultRequest(category_sn,searchcomment) {



	var url = "http://review.search.nate.com/xml/item_search.xml";
	var param = "sn="+category_sn+"&q="+searchcomment;


	new Empas.Ajax.Request(url, {
		parameters: param,
		onComplete: function(transport) {			
			switch(transport.responseText) {

/*				
				case 'ALREADY':
					if (type=="review_comment" || type=="desc_comment") {
						window.alert("°ø°¨Àº ÇÑ ¹ø¸¸ Âü¿©ÇÒ ¼ö ÀÖ½À´Ï´Ù.");
					} else {
						RecommendMsg(kind_sn, kind_type, "ÀÌ¹Ì <span>ÃßÃµ</span>ÇÏ¿´½À´Ï´Ù");
					}
				break;
*/

				default:
					window.alert(transport.responseXML);
				break;
			}
		},
		onFailure: function(transport) {
			window.alert("ÃßÃµÇÏ±â ¿äÃ»¿¡ ½ÇÆÐÇß½À´Ï´Ù.");
		}
	});
}
