/**
 * @file   modules/board/js/board.js
 * @author zero (zero@nzeo.com)
 * @brief  board 모듈의 javascript
 **/

/* 글쓰기 작성후 */
function completeDocumentInserted(ret_obj) {
    var error = ret_obj['error'];
    var message = ret_obj['message'];
    var mid = ret_obj['mid'];
    var document_srl = ret_obj['document_srl'];
    var category_srl = ret_obj['category_srl'];

    //alert(message);

    var url;
    if(!document_srl)
    {
        url = current_url.setQuery('mid',mid).setQuery('act','');
    }
    else
    {
        url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act','');
    }
    if(category_srl) url = url.setQuery('category',category_srl);
    location.href = url;
}

/* 글 삭제 */
function completeDeleteDocument(ret_obj) {
    var error = ret_obj['error'];
    var message = ret_obj['message'];
    var mid = ret_obj['mid'];
    var page = ret_obj['page'];

    var url = current_url.setQuery('mid',mid).setQuery('act','').setQuery('document_srl','');
    if(page) url = url.setQuery('page',page);

    //alert(message);

    location.href = url;
}

/* 검색 실행 */
function completeSearch(fo_obj, params) {
    fo_obj.submit();
}

function completeVote(ret_obj) {
    var error = ret_obj['error'];
    var message = ret_obj['message'];
    alert(message);
    location.href = location.href;
}

// 현재 페이지 reload
function completeReload(ret_obj) {
    var error = ret_obj['error'];
    var message = ret_obj['message'];

    location.href = location.href;
}

/* 댓글 글쓰기 작성후 */
function completeInsertComment(ret_obj) {
    var error = ret_obj['error'];
    var message = ret_obj['message'];
    var mid = ret_obj['mid'];
    var document_srl = ret_obj['document_srl'];
    var comment_srl = ret_obj['comment_srl'];

    var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act','');
    if(comment_srl) url = url.setQuery('rnd',comment_srl)+"#comment_"+comment_srl;

    //alert(message);

    location.href = url;
}

/* 댓글 삭제 */
function completeDeleteComment(ret_obj) {
    var error = ret_obj['error'];
    var message = ret_obj['message'];
    var mid = ret_obj['mid'];
    var document_srl = ret_obj['document_srl'];
    var page = ret_obj['page'];

    var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act','');
    if(page) url = url.setQuery('page',page);

    //alert(message);

    location.href = url;
}

/* 트랙백 삭제 */
function completeDeleteTrackback(ret_obj) {
    var error = ret_obj['error'];
    var message = ret_obj['message'];
    var mid = ret_obj['mid'];
    var document_srl = ret_obj['document_srl'];
    var page = ret_obj['page'];

    var url = current_url.setQuery('mid',mid).setQuery('document_srl',document_srl).setQuery('act','');
    if(page) url = url.setQuery('page',page);

    //alert(message);

    location.href = url;
}

/* 카테고리 이동 */
function doChangeCategory() {
    var category_srl = jQuery('#board_category option:selected').val();
    location.href = decodeURI(current_url).setQuery('category',category_srl);
}

/* 스크랩 */
function doScrap(document_srl) {
    var params = new Array();
    params["document_srl"] = document_srl;
    exec_xml("member","procMemberScrapDocument", params, null);
}

/* 메일 발송*/
//sw 값이 있으면 저장하지 하는 부부늘 호출 하지 않음
var windowInstance=null;
function doSandMail(form_name,sw,$member_srl) {
    // 설정된 그룹으로 현제 문서를 메일로 발송한다.
	var extra_vars_value_obj = xGetElementById('extra_vars_value');
	sw=(sw==null ? "": sw);
	windowInstance=window.open(request_uri.setQuery('module','board').setQuery('act','dispMailPress').setQuery('savemode',sw), "sendmain", "left=10,top=10,width=10,height=10,scrollbars=no,resizable=yes,toolbars=no");// 보네는 메세지 출력 창
	var hrefs=request_uri.setQuery('module','mails').setQuery('act','dispMailsSend').setQuery('savemode',sw);

	old_form_name=form_name.action;
	form_name.action=hrefs;
	form_name.target="hiddenFramess";
	
	if(xGetElementById('extra_vars2').value == ""){
		form_name.sendid.value=extra_vars_value_obj.value;
	}
	else
	{
		form_name.sendid.value=xGetElementById('extra_vars2').value;
	}
    var editor_sequence = form_name.getAttribute('editor_sequence');
    if(typeof(editor_sequence)!='undefined' && editor_sequence && typeof(editorRelKeys)!='undefined') { 
       form_name.content.value = editorGetContent(editor_sequence);
	}
	  //alert(form_name.content.value)
	form_name.submit();
	
	form_name.action=old_form_name;
}

/* 메일 발송*/
//보기에서 메일발송

function doViewFormSandMail(form_name) {
    // 설정된 그룹으로 현제 문서를 메일로 발송한다.
	windowInstance=window.open(request_uri.setQuery('module','board').setQuery('act','dispMailPress'), "sendmain", "left=10,top=10,width=10,height=10,scrollbars=no,resizable=yes,toolbars=no");// 보네는 메세지 출력 창
	var hrefs=request_uri.setQuery('module','mails').setQuery('act','dispMailsSend');
	form_name.action=hrefs;
	form_name.target="hiddenFramess";
	form_name.submit();
	winCentre(windowInstance);
}

//발송후 저장이나 수정을 한다.
//메일 발송후 호출된다.
//2009-04-23 grampus
function doSandMailResult(sendFlag,sendMod) 
{
	if(!sendFlag)sendFlag="메일발송 건이 없습니다.";
	else sendFlag=sendFlag+"건을 발송 하였습니다.";
	alert(sendFlag);//결과 출력
	windowInstance.close();
	if(sendMod)
	{
		var fo_write = xGetElementById('fo_write');
		fo_write.target="_self";
		fo_write.submit();
	}
}
//발송후 저장이나 수정을 한다.
//메일 발송후 호출된다.
//2009-04-23 grampus
function doResult(msg,href) 
{
	if(msg)msg="성공 하였습다.";else msg="실패 하였습니다.";
	alert(msg);//결과 출력
	location.href=href;
}
//중앙정렬
function winCentre(win) { 
   if (document.layers) { 
       var sinist = screen.width / 2 - outerWidth / 2; 
       var toppo = screen.height / 2 - outerHeight / 2; 
   } else { 
       var sinist = screen.width / 2 - document.body.offsetWidth / 2; 
       var toppo = -75 + screen.height / 2 - document.body.offsetHeight / 2; 
   } 
   win.moveTo(sinist, toppo); 
} 

