var BbsMgr = {
script : G_TOP_DIR + "/kr/src/board.php",
isSended : false,
voteMgr : null,
addParam : function () {
var q = location.search.substr(1).split('&');
var r = "";
for (var i = 0; i < q.length; i++){
var v = q[i].split('=');
if (Common.inArray(v[0], ['s', 'c', 'p', 'f', 'q'])) {
r += "&" + v[0] + "=" + v[1];
}
}
return r;
},
linkImage : function (w, h) {
var objContents = $('_contents_');
if (objContents) {
var objImg = objContents.getElementsBySelector('img');
objImg.each (function (obj, i) {
if ((w > 0 && obj.width >= w) || (h > 0 && obj.height >= h)) {
var rs = Common.imgResize(obj.width, obj.height, w, h);
try {
obj.replace('');
} catch (e) {
obj.replace('');
}
}
}.bind(this));
}
},
changePlayer : function (w, h) {
var objContents = $('_contents_');
var objLoadings = $('_loadings_');
if (objContents) {
var objTag = objContents.getElementsBySelector('object', 'embed');
var objTpl = new Template('
');
objTag.each (function (obj, i) {
var s = null;
$A(obj.childNodes).each (function(child, j) {
if (Common.inArray(Common.strToLower(child.getAttribute('name')), ['movie', 'src'])) {
s = child.getAttribute('value');
return;
}
}.bind(this));
if (!s) {
s = obj.getAttribute('src');
}
obj.replace(objTpl.evaluate({w : w, h : h, s : s}));
}.bind(this));
if (objLoadings) {
objLoadings.hide();
objContents.show();
}
}
},
getPass : function (a, n, r, s) {
var objLayer;
objLayer = new Layer(230, 100, ''
+ '
Æнº¿öµå¸¦ ÀÔ·ÂÇϼ¼¿ä
'
+ '
'
+ '
'
+ '
');
objLayer.open(function () {
$('_cncl_').observe('click', function () { objLayer.close(); });
$('_send_').observe('click', function () { this.actPass(a, n, r, s, objLayer); }.bind(this));
$('_pswd_').focus();
Event.observe($('_pswd_'), 'keypress', function (event) {
var e = event ? event : window.event;
if (e.keyCode == 13) {
this.actPass(a, n, r, s, objLayer);
}
}.bind(this));
}.bind(this));
},
actPass : function (a, n, r, s, objLayer) {
var objPass = $('_pswd_');
if (objPass.value == "") {
window.alert("Æнº¿öµå¸¦ ÀÔ·ÂÇϼ¼¿ä.");
objPass.focus();
return;
}
switch (a) {
case "main" :
var v = this.delPost(n, s, objPass.value);
if (v) {
objLayer.close();
location.replace(v);
}
break;
case "memo" :
var v = this.delMemo(n, r, s, objPass.value);
if (v) {
objLayer.close();
new Effect.Appear('memo' + n, {duration : 1.0, from : 1, to : 0, afterFinish : function () { Element.remove('memo' + n); }});
}
break;
case "view" :
var v = this.setPass(n, r, s, objPass.value);
if (v) {
objLayer.close();
location.href = v;
}
break;
}
},
setPass : function (n, r, s, pass) {
var returnValue;
new Ajax.Request(this.script, {
method : "post",
asynchronous : false,
contentType : "application/x-www-form-urlencoded",
encoding : "euc-kr",
parameters : {"n" : n, "r" : r, "a" : "view", "m" : "pass", "s" : s, "pass" : encodeURIComponent(pass)},
onSuccess : function (xmlHttp) {
try {
var msg = xmlHttp.responseText.evalJSON();
if (msg.result == "SUCCESS") {
returnValue = "?n=" + n + "&m=view" + this.addParam();
} else if (msg.result == "FAIL") {
window.alert(decodeURIComponent(msg.message));
} else {
window.alert("À¯È¿ÇÏÁö ¾ÊÀº °á°úÄÚµåÀÔ´Ï´Ù.");
}
} catch (e) {
window.alert(xmlHttp.responseText);
}
}.bind(this)
});
return returnValue;
},
addVote : function (obj) {
var cnt = parseInt($('votes').value) + 1;
var tpl = new Template(' Ãë¼Ò
');
$(obj).insert(tpl.evaluate({i : cnt}));
$('votes').value = cnt;
},
setPost : function () {
if ($('title').value == "") {
window.alert("Á¦¸ñÀ» ÀÔ·ÂÇϼ¼¿ä.");
$('title').focus();
return false;
}
try {
if ($('name').value == "") {
window.alert("À̸§À» ÀÔ·ÂÇϼ¼¿ä.");
$('name').focus();
return false;
}
} catch (e) {
}
try {
if ($('pass').value == "") {
window.alert("Æнº¿öµå¸¦ ÀÔ·ÂÇϼ¼¿ä.");
$('pass').focus();
return false;
}
} catch (e) {
}
try {
if ($('email').value == "") {
window.alert("À̸ÞÀÏÀ» ÀÔ·ÂÇϼ¼¿ä.");
$('email').focus();
return false;
}
} catch (e) {
}
try {
var objBodyTexts = $('body');
var objEditorDiv = $('_e_div_body_');
var objEditorTxt = $('_e_txt_body_');
var objEditorVse = $('_e_vse_body_');
if (objEditorDiv) {
if (objEditorVse.checked == true) {
objBodyTexts.value = objEditorTxt.value;
} else {
objBodyTexts.value = objEditorDiv.contentWindow.document.body.innerHTML;
}
}
if (objBodyTexts.value == "") {
window.alert("³»¿ëÀ» ÀÔ·ÂÇϼ¼¿ä.");
if (!objEditorDiv) {
objBodyTexts.focus();
} else {
if (objEditorVse.checked == false) {
objEditorDiv.contentWindow.focus();
} else {
objEditorTxt.focus();
}
}
return false;
}
} catch (e) {
}
try {
if (/^[0-9]{8}$/.test($('staDate').value) == false) {
window.alert("½ÃÀÛÀÏÀ» YYYYMMDDÇüÅ·ΠÀÔ·ÂÇϼ¼¿ä.");
return false;
} else if (/^[0-9]{8}$/.test($('endDate').value) == false) {
window.alert("Á¾·áÀÏÀ» YYYYMMDDÇüÅ·ΠÀÔ·ÂÇϼ¼¿ä.");
return false;
}
for (var i = 1; i <= parseInt($('votes').value); i++) {
try {
if ($('_vote_is_del_' + i + '_').checked == false) {
if (/^[0-9]+$/.test($('_vote_sort_' + i + '_').value) == false) {
window.alert(i + "¹ø° ¼³¹® ¾ÆÀÌÅÛÀÇ Á¤·Ä ¼ø¼¸¦ ¼ýÀÚ·Î ÀÔ·ÂÇϼ¼¿ä.");
$('_vote_sort_' + i + '_').focus();
return false;
} else if ($('_vote_title_' + i + '_').value == "") {
window.alert(i + "¹ø° ¼³¹® ¾ÆÀÌÅÛÀ» ÀÔ·ÂÇϼ¼¿ä.");
$('_vote_title_' + i + '_').focus();
return false;
}
}
} catch (e) {
}
}
if ($('type') && Common.radio(Form.getInputs('save', 'radio', 'type')) == false) {
window.alert("Âü¿©À¯ÇüÀ» ¼±ÅÃÇϼ¼¿ä.");
return false;
}
} catch (e) {
}
if (this.isSended == false) {
var body = $$('body')[0];
var size = [body.clientWidth, body.clientHeight];
body.appendChild(Builder.node('div', {id : 'sbmsg', style : 'left:' + ((size[0] - 300) / 2) + 'px; top:' + (((size[1] - 50) / 2) + body.scrollTop) + '; width:300px; height:50px;'}, 'Àü¼ÛÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·Á ÁÖ¼¼¿ä.'));
this.isSended = true;
return true;
} else {
window.alert("Àü¼ÛÁßÀÔ´Ï´Ù, Àá½Ã¸¸ ±â´Ù·Á ÁÖ¼¼¿ä.");
return false;
}
},
delPost : function (n, s, pass) {
var returnValue;
if (confirm("¼±ÅÃÇϽŠ°Ô½Ã¹°À» »èÁ¦ÇϽðڽÀ´Ï±î?") == false) {
return;
}
new Ajax.Request(this.script, {
method : "post",
asynchronous : false,
contentType : "application/x-www-form-urlencoded",
encoding : "euc-kr",
parameters : {"n" : n, "a" : "main", "m" : "delete", "s" : s, "pass" : (pass ? encodeURIComponent(pass) : "")},
onSuccess : function (xmlHttp) {
try {
var msg = xmlHttp.responseText.evalJSON();
if (msg.result == "SUCCESS") {
returnValue = "?m=list" + this.addParam();
} else if (msg.result == "FAIL") {
window.alert(decodeURIComponent(msg.message));
} else {
window.alert("À¯È¿ÇÏÁö ¾ÊÀº °á°úÄÚµåÀÔ´Ï´Ù.");
}
} catch (e) {
window.alert(xmlHttp.responseText);
}
}.bind(this)
});
if (pass) {
return returnValue;
} else if (returnValue) {
location.replace(returnValue);
}
},
setMemo : function (user, able) {
if (user == 0 && able == "N") {
window.alert("·Î±×ÀÎÀÌ ÇÊ¿äÇÕ´Ï´Ù.");
return;
} else if (able == "N") {
window.alert("ÄÚ¸àÆ®¸¦ ÀÛ¼ºÇÒ ¼ö ÀÖ´Â ±ÇÇÑÀÌ ¾ø½À´Ï´Ù.");
return;
}
var objName = $('name');
var objPass = $('pass');
var objBody = $('body');
try {
if (objName.value == "") {
window.alert("À̸§À» ÀÔ·ÂÇϼ¼¿ä.");
objName.focus();
return;
} else if (objPass.value == "") {
window.alert("Æнº¿öµå¸¦ ÀÔ·ÂÇϼ¼¿ä.");
objPass.focus();
return;
}
} catch (e) {
}
if (objBody.value == "") {
window.alert("³»¿ëÀ» ÀÔ·ÂÇϼ¼¿ä.");
objBody.focus();
return;
} else if (objBody.value.length > 1000) {
window.alert("1,000ÀÚ ±îÁö ÀÔ´Ï´Ù.");
objBody.value = objBody.value.truncate(1000, "");
objBody.focus();
return;
}
new Ajax.Request(this.script, {
method : "post",
asynchronous : false,
contentType : "application/x-www-form-urlencoded",
encoding : "euc-kr",
parameters : {"r" : $('r').value, "m" : "memo", "s" : $('s').value, "name" : encodeURIComponent(objName.value), "pass" : encodeURIComponent(objPass.value), "body" : encodeURIComponent(objBody.value)},
onSuccess : function (xmlHttp) {
try {
var msg = xmlHttp.responseText.evalJSON();
if (msg.result == "SUCCESS") {
this.addMemo(msg, user);
} else if (msg.result == "FAIL") {
window.alert(decodeURIComponent(msg.message));
} else {
window.alert("À¯È¿ÇÏÁö ¾ÊÀº °á°úÄÚµåÀÔ´Ï´Ù.");
}
} catch (e) {
window.alert(xmlHttp.responseText);
}
}.bind(this)
});
},
addMemo : function (msg, user) {
var tpl = new Template('#{name}
#{body}
[#{date}]
');
var n = msg.seq;
var d = msg.date;
var r = $('r').value;
var s = $('s').value;
$('memo').insert(tpl.evaluate({
mseq : n,
name : $('name').value,
body : $('body').value.replace(/\"),
date : d,
link : user > 0 ? 'javascript:BbsMgr.delMemo(' + n + ', ' + r + ', \'' + s + '\');' : 'javascript:BbsMgr.getPass(\'memo\', ' + n + ', ' + r + ', \'' + s + '\');',
path : G_SVR_IMAGE + '/btn/delete.gif'
}));
$('pass').value = user > 0 ? '0000' : '';
$('body').value = '';
new Effect.Appear('memo' + n, {duration : 1.0});
},
delMemo : function (n, r, s, pass) {
var returnValue = false;
if (confirm("¼±ÅÃÇϽŠÄÚ¸àÆ®¸¦ »èÁ¦ÇϽðڽÀ´Ï±î?") == false) {
return;
}
new Ajax.Request(this.script, {
method : "post",
asynchronous : false,
contentType : "application/x-www-form-urlencoded",
encoding : "euc-kr",
parameters : {"n" : n, "r" : r, "a" : "memo", "m" : "delete", "s" : s, "pass" : (pass ? encodeURIComponent(pass) : "")},
onSuccess : function (xmlHttp) {
try {
var msg = xmlHttp.responseText.evalJSON();
if (msg.result == "SUCCESS") {
returnValue = true;
} else if (msg.result == "FAIL") {
window.alert(decodeURIComponent(msg.message));
} else {
window.alert("À¯È¿ÇÏÁö ¾ÊÀº °á°úÄÚµåÀÔ´Ï´Ù.");
}
} catch (e) {
window.alert(xmlHttp.responseText);
}
}.bind(this)
});
if (pass) {
return returnValue;
} else if (returnValue) {
new Effect.Appear('memo' + n, {duration : 1.0, from : 1, to : 0, afterFinish : function () { Element.remove('memo' + n); }});
}
},
setNotice : function (n, s) {
new Ajax.Request(this.script, {
method : "post",
asynchronous : false,
contentType : "application/x-www-form-urlencoded",
encoding : "euc-kr",
parameters : {"n" : n, "m" : "notice", "s" : s},
onSuccess : function (xmlHttp) {
try {
var msg = xmlHttp.responseText.evalJSON();
if (msg.result == "SUCCESS") {
location.reload();
} else if (msg.result == "FAIL") {
window.alert(decodeURIComponent(msg.message));
} else {
window.alert("À¯È¿ÇÏÁö ¾ÊÀº °á°úÄÚµåÀÔ´Ï´Ù.");
}
} catch (e) {
window.alert(xmlHttp.responseText);
}
}.bind(this)
});
},
setReads : function (n) {
new Ajax.Request(this.script, {method : "post", asynchronous : true, parameters : {"n" : n, "m" : "reads"}});
},
setVote : function (refcIdx, vType) {
var seq = Common.radio(Form.getInputs('_vote_', 'radio', '_v_'), 1);
if (!seq) {
window.alert("¼³¹®À» üũÇϼ¼¿ä.");
return;
}
this.setLogs(refcIdx, seq, vType, 'V', 1, 'C');
},
setLogs : function (refcIdx, voteIdx, vType, lType, votes, aType) {
new Ajax.Request(this.script, {
method : "post",
asynchronous : true,
contentType : "application/x-www-form-urlencoded",
encoding : "euc-kr",
parameters : {"n" : voteIdx, "r" : refcIdx, "m" : "logs", "vType" : vType, "lType" : lType, "votes" : votes},
onSuccess : function (xmlHttp) {
try {
var msg = xmlHttp.responseText.evalJSON();
if (msg.result == "SUCCESS") {
this.actLogs(voteIdx, votes, aType);
} else if (msg.result == "FAIL") {
window.alert(decodeURIComponent(msg.message));
} else {
window.alert("À¯È¿ÇÏÁö ¾ÊÀº °á°úÄÚµåÀÔ´Ï´Ù.");
}
} catch (e) {
window.alert(xmlHttp.responseText);
}
}.bind(this)
});
},
actLogs : function (n, v, m) {
switch (m) {
case "A" :
window.alert("ÃßõÀÌ ¿Ï·áµÇ¾ú½À´Ï´Ù.");
location.reload();
break;
case "B" :
window.alert("ÃßõÀÌ ¿Ï·áµÇ¾ú½À´Ï´Ù.");
$("_votes_").update(parseInt($("_votes_").innerHTML) + v);
break;
case "C" :
window.alert("¼³¹® Âü¿©°¡ ¿Ï·áµÇ¾ú½À´Ï´Ù.");
if (this.voteMgr) {
this.voteMgr.lists[Common.radio(Form.getInputs('_vote_', 'radio', '_v_'), 3, n)].votes += v;
this.voteMgr.votes += v;
this.voteMgr.getResult();
}
break;
}
},
getLatest : function (id, limit, obj, tpl, len) {
new Ajax.Request(this.script, {
method : "get",
asynchronous : true,
contentType : "application/x-www-form-urlencoded",
encoding : "euc-kr",
parameters : {"m" : "latest", "s" : id, "p" : limit},
onSuccess : function (xmlHttp) {
var objMsg = xmlHttp.responseText.evalJSON();
var objTpl = new Template(tpl);
var objRes = [];
objMsg.each (function (data, i) {
objRes[i] = objTpl.evaluate({
id : data.id,
seq : data.seq,
title : Common.strCut(decodeURIComponent(data.title), len),
date : data.date,
isNew : data.isNew == "Y" ? " " : ""
});
}.bind(this));
$(obj).update(objRes.join("\n"));
}.bind(this)
});
},
viewBody : function (n) {
$$('body')[0].getElementsBySelector("tr", "span").findAll(function (s) {
if (s.id == '_' + n + '_') {
if (s.tagName.toLowerCase() == "span") {
$(s).style.fontWeight = 'bold';
return;
}
if (!$(s).visible()) {
this.setReads(n);
}
$(s).show();
} else if (s.id.match(/^[\_0-9\_]/g)) {
if (s.tagName.toLowerCase() == "span") {
$(s).style.fontWeight = '';
return;
}
$(s).hide();
}
}.bind(this));
},
goLogin : function (s) {
Common.openWin(this.script + "?m=login&s=" + s, '_login_', 350, 147);
},
goLogout : function (s) {
new Ajax.Request(this.script, {
method : "post",
asynchronous : false,
contentType : "application/x-www-form-urlencoded",
encoding : "euc-kr",
parameters : {"m" : "logout", "s" : s},
onSuccess : function (xmlHttp) {
location.reload();
}.bind(this)
});
},
goLogoutinquiry : function (s) {
new Ajax.Request(this.script, {
method : "post",
asynchronous : false,
contentType : "application/x-www-form-urlencoded",
encoding : "euc-kr",
parameters : {"m" : "logout", "s" : s},
onSuccess : function (xmlHttp) {
location.href="inquiry.php";
}.bind(this)
});
},
setLogin : function () {
var objID = $('id');
if (!objID.value) {
window.alert("¾ÆÀ̵𸦠ÀÔ·ÂÇϼ¼¿ä.");
objID.focus();
return false;
} else if (objID.value.match(/[^a-z0-9]/g)) {
window.alert("¾ÆÀ̵𸦠¿µ(¼Ò)¹®+¼ýÀÚ·Î ÀÔ·ÂÇϼ¼¿ä.");
objID.value = "";
objID.focus();
return false;
} else if (!$('pass').value) {
window.alert("Æнº¿öµå¸¦ ÀÔ·ÂÇϼ¼¿ä.");
$('pass').focus();
return false;
}
if (this.isSended == false) {
var body = $$('body')[0];
var size = [body.clientWidth, body.clientHeight];
body.appendChild(Builder.node('div', {id : 'sbmsg', style : 'left:' + ((size[0] - 300) / 2) + 'px; top:' + (((size[1] - 50) / 2) + body.scrollTop) + '; width:300px; height:50px;'}, 'Àü¼ÛÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·Á ÁÖ¼¼¿ä.'));
this.isSended = true;
return true;
} else {
window.alert("Àü¼ÛÁßÀÔ´Ï´Ù, Àá½Ã¸¸ ±â´Ù·Á ÁÖ¼¼¿ä.");
return false;
}
}
}
var VoteMgr = Class.create();
VoteMgr.prototype = {
count : 0,
votes : 0,
lists : null,
initialize : function (count, votes) {
this.count = count ? count : 0;
this.votes = votes ? votes : 0;
this.lists = new Array(count);
if (votes >= 0) {
for (var i = 0; i < count; i++) {
this.lists[i] = {'id' : '_graph_' + i + '_', 'votes' : parseInt($('_cnt_' + i + '_').innerHTML)};
}
}
},
getResult : function () {
$('_votes_').update(this.votes);
this.lists.each (function (obj, i) {
$('_cnt_' + i + '_').update(obj.votes);
$('_per_' + i + '_').update(obj.votes > 0 ? Math.round((obj.votes / this.votes) * 100) : 0);
$('_graph_' + i + '_').setStyle({width : '100px'});
if (this.votes == 0) {
$('_result_' + i + '_').hide();
} else {
$('_result_' + i + '_').show();
this.setBar(i, obj.votes);
}
}.bind(this));
},
setBar : function (i, v) {
var per = v > 0 ? Math.round((v / this.votes) * 100) : 0;
var sfm = 100;
new Effect.Scale('_graph_' + i + '_',
1,
{
scaleY : false,
scaleFrom : sfm,
duration : 0.6,
afterFinish : function () { new Effect.Scale('_graph_' + i + '_', per * sfm, {scaleY : false, scaleFrom : 1, duration : 0.8}); }
});
}
}
if ($A(document.getElementsByTagName("script")).findAll(function (s) {
return (s.src && s.src.match(/layer\.js/));
}) == '') {
document.write('<' + 'script language="javascript" src="' + G_TOP_DIR + '/common/module/layer/js/layer.js"><' + '/script>');
}