<!--

var JBbyBbs = function( bbsid )
{
	// Properties
	this.Bbsid = bbsid;
	this.Seq = 0;
	this.FBSeq = 0;
	this.Category = 0;
	this.PrePage = 0;
	this.Page = 1;
	this.SearchKey = '';
	this.SearchString = '';
	this.LinkUrl = '';
	this.Mode = '';
	this.FileCnt = 1;
	this.Type = '';
	this.OpenAuth = 1;
}

JBbyBbs.prototype.Create = function()
{
	// Check for errors
	if ( !this.Bbsid || this.Bbsid.length == 0 )
	{
		alert('존재하지 않는 게시판테이블 입니다.');
		history.go(-1);
		return;
	}
}

JBbyBbs.prototype.GetFileName = function( section )
{
	if (section == 'list') {
		if (this.Bbsid == 'notice') return './';
		else if (this.Bbsid == 'qna') return './qna_list.asp';
		else if (this.Bbsid == 'nowadays') return './pr_list.asp';
		else if (this.Bbsid == 'faq' && this.Type == 'specialship' ) return './specialship_faqlist.asp';
		else if (this.Bbsid == 'knowledge') return './tip_list.asp';
		else if (this.Bbsid == 'newreview') return './review_list.asp';
		else if (this.Bbsid == 'trend') return './trend_list.asp';
		else if (this.Bbsid == 'BBS__REQUEST_SEARCH') return './request_search.asp';
		else return './';
	} else if (section == 'del') {
		if (this.Bbsid == 'notice') return './delete_ok.asp';
		else if (this.Bbsid == 'qna') return './qna_delete_ok.asp';
		else if (this.Bbsid == 'knowledge') return './tip_delete_ok.asp';
		else if (this.Bbsid == 'newreview') return './review_delete_ok.asp';
		else if (this.Bbsid == 'trend') return './trend_delete_ok.asp';
		else if (this.Bbsid == 'BBS__REQUEST_SEARCH') return './request_search_delete_ok.asp';
		else return './delete_ok.asp';
	} else if (section == 'view') {
		if (this.Bbsid == 'notice') return './view.asp';
		else if (this.Bbsid == 'qna') return './qna_view.asp';
		else if (this.Bbsid == 'nowadays') return './pr_view.asp';
		else if (this.Bbsid == 'faq' && this.Type == 'specialship' ) return './specialship_faqview.asp';
		else if (this.Bbsid == 'knowledge') return './tip_view.asp';
		else if (this.Bbsid == 'newreview') return './review_view.asp';
		else if (this.Bbsid == 'trend') return './trend_view.asp';
		else if (this.Bbsid == 'BBS__REQUEST_SEARCH') return './request_search_view.asp';
		else return './view.asp';
	}
}

JBbyBbs.prototype.GoList = function()
{
	window.location = this.GetFileName("list") + "?" + this.LinkUrl + "&bseq=" + this.Seq + "&key=" + this.SearchKey + "&string=" + this.Query(this.SearchString);
}

JBbyBbs.prototype.ReadArticle = function( seq )
{
	window.location = this.GetFileName("view") + "?" + this.LinkUrl + "&bseq=" + seq + "&key=" + this.SearchKey + "&string=" + this.Query(this.SearchString);
}


// 게시물 질문 보기
JBbyBbs.prototype.ReplyView = function( iObject )
{
	if (iObject.style.display != "none") iObject.style.display = "none";
	else iObject.style.display = "" ;
}

// 게시물 삭제
JBbyBbs.prototype.BbsDelete = function()
{
	if (confirm("현재 글을 삭제하시겠습니까?")) {
		location.href = this.GetFileName("del") + "?" + this.LinkUrl + "&bseq=" + this.Seq + "&key=" + this.SearchKey + "&string=" + this.Query(this.SearchString);
	}
}

// 게시물 등록
JBbyBbs.prototype.BbsWrite = function( frm )
{

	if (!loginCheck) {
		alert("로그인후 이용하실 수 있습니다.\t\n");
		return false;
	}

	if (!frm.Subject.value.Trim()) {
		alert("제목을 입력하여 주세요.");
		frm.Subject.focus();
		return false;
	}

	if (!frm.Content.value.Trim()) {
		alert("내용을 입력하여 주세요.");
		frm.Content.focus();
		return false;
	}


	for (var i = 0; i < frm.elements.length; ++i) {
		var pObjEL = frm.elements[i];
		if (pObjEL.name == 'UpFiles') {
			var pObjELValue = pObjEL.value;
			if (pObjELValue != "") {
				if (!(/(.jpg|.jpeg|.gif|.png|.swf)$/i).test(pObjEL.value)) {
					alert("이미지는 gif, jpg, png, swf 파일만 가능합니다.");
					return false;
				}
			}
		}
	}

	if ( frm.bsid.value == 'sucpostscript' && frm.Content.value.getByteLength() < 60 ) {
		if (!confirm('30글자 이상의 글에만 마일리지가 지급됩니다.\t\n\n글을 등록하시겠습니까?')) {
			return false;
		}
	}

	return true;
}

// 코멘트 등록
JBbyBbs.prototype.ComWrite = function( frm )
{
	if (!loginCheck) {
		alert("로그인후 이용하실 수 있습니다.\t\n");
	} else {
		if (frm.Comment.value.Trim() == "") {
			alert("내용을 입력하여 주세요.");
			frm.Comment.focus();
			return;
		}
		frm.mode.value = "write";
		frm.action = "comment_ok.asp";
		frm.submit();
	}
}

// 코멘트 삭제
JBbyBbs.prototype.ComDelete = function( frm, comSeq )
{
	if (confirm("Comment를 삭제하시겠습니까?")) {
		frm.CommSeq.value = comSeq;
		frm.mode.value = "del";
		frm.action = "comment_ok.asp";
		frm.submit();
	}
}

// 첨부파일 추가
JBbyBbs.prototype.AddFile = function()
{
	if (this.FileCnt <= 3) {
		var objTbl = $('idUpFiles');
		var objRow = objTbl.insertRow(-1);		 /* 파이어폭스에서는 -1 을 해줘야 정상적으로 작동합 */
		var objCell_1 = objRow.insertCell(-1);
		objCell_1.innerHTML = "<input type='file' OnChange='Bbs.CheckImage(event)' name='UpFiles' size='52' class='form_gray'>";
		var objCell_2 = objRow.insertCell(-1);
		objCell_2.innerHTML = "&nbsp; <img src='http://static.bidbuy.co.kr/v3/common/btn_input.gif' border='0' onclick='Bbs.AddVar(" + this.FileCnt + ");' style='cursor:pointer;'>";
		this.FileCnt ++;
		document.recalc();
	}
}

// 게시물 내용에 첨부파일 출력 위치 설정
JBbyBbs.prototype.AddVar = function( fileIDX )
{
	$('Content').setValue($F('Content') + "{FILE:" + fileIDX + "}");
}

// 첨부 파일 체크
JBbyBbs.prototype.CheckImage = function(e)
{
	var elem = e.target || e.srcElement;
	var fname = elem.value;
	if (fname.notNull() && !(/(.jpg|.jpeg|.gif|.png|.swf)$/i).test(fname)) {
		alert("이미지는 gif, jpg, png, swf 파일만 가능합니다.");
		elem.value = '';
	} else {
		this.AddFile();
	}
}

// 첨부파일 보기
JBbyBbs.prototype.Attach = function( el )
{
	if (el.checked == true ) {
		$('idAttachment_list').show();
	} else {
		$('idAttachment_list').hide();
	}
}

JBbyBbs.prototype.Query = function( string )
{
	var tmp = string;
	if (window.encodeURIComponent) {
		tmp = encodeURIComponent(string);
	}
	return tmp;
}

JBbyBbs.prototype.CheckSpecialChar = function( str, specialChar )
{
	var flag = true;
	for(i = 0; i <= str.length; i++) {
		ch = str.charAt(i);
		for(j = 0; j < specialChar.length; j++) {
			if(ch == specialChar.charAt(j)) {
				flag = false;
				break;
			}
		}
		if(flag == false)
			break;
	}
	return flag;
}

JBbyBbs.prototype.Search = function( frm )
{
	var exclude_sp_char = "~`!@#$%^&*()_+=|\\<>.?{}[]:;\"'";
	if (frm.string.value == "")	{
		alert("검색어를 입력하세요");
		frm.string.focus();
		return false;
	}

	if (this.CheckSpecialChar(frm.string.value, exclude_sp_char) == false) {
		alert("제외단어에는 특수문자(" + exclude_sp_char + ")를 입력하실 수 없습니다.");
		frm.string.focus();
		return false;
	}

	return true;
}
//-->