if (typeof oForumForm != "object")
var oForumForm = {};
var MessageMax = 64000;
function quoteMessageEx(author, mid)
{
if (typeof document.forms["REPLIER"] != "object" || document.forms["REPLIER"] == null)
return false;
init_form(document.forms["REPLIER"]);
oForumForm[document.forms["REPLIER"].id].quote(author, mid);
}
function CreatePalette()
{
if (oForumForm['PALETTE'])
return oForumForm['PALETTE'];
var color_range = {0 : "00", 1 : "33", 2 : "66", 3 : "99", 4 : "BB", 5 : "FF"};
var rgb = {'R' : 0, 'G' : 0, 'B' : 0, 'color' : ''};
var oDiv = document.body.appendChild(document.createElement("DIV"));
oDiv.id = 'palette';
oDiv.className = 'palette';
oDiv.style.position = 'absolute';
oDiv.style.width = '199px';
oDiv.style.height = '133px';
oDiv.style.border = 'none';
oDiv.style.visibility = 'hidden';
var table = document.createElement("TABLE");
table.className = 'palette';
var tbody = table.appendChild(document.createElement('TBODY'));
for (var ii = 0; ii < 216; ii++)
{
if (ii%18 == 0)
var row = tbody.appendChild(document.createElement('TR'));
rgb['R'] = ii%6; rgb['G'] = Math.round(ii/36)%6; rgb['B'] = Math.round(ii/6)%6;
rgb['color'] = '' + color_range[rgb['R']] + '' + color_range[rgb['G']] + '' + color_range[rgb['B']];
var cell = row.appendChild(document.createElement('TD'));
var img = cell.appendChild(document.createElement('IMG'));
img.src = '/bitrix/components/bitrix/forum.post_form/templates/.default/images/bbcode/empty_for_ie.gif';
cell.id = 'color_' + rgb['color'];
cell.style.backgroundColor = '#' + rgb['color'];
cell.onmousedown = function(e){
e = (jsUtils.IsIE() || !e ? window.event : e);
jsUtils.PreventDefault(e);
window.color_palette = '#' + this.id.replace('color_', '');}
}
oDiv.appendChild(table);
oForumForm['PALETTE'] = oDiv;
return oForumForm['PALETTE'];
}
/* Form functions */
function init_form(form)
{
if (typeof(form) != "object")
return false;
if (!oForumForm[form.id] || typeof(oForumForm[form.id]) != "object")
{
oForumForm[form.id] = new PostForm(form);
oForumForm[form.id].Init(form);
oForumForm[form.id].onkeydown = function(e){};
oForumForm[form.id].onmouseover = function(e){};
}
return;
}
function PostForm()
{
this.real_tags = {};
this.form = false;
this.stack = [];
this.tags = {
"B" : "simple_tag",
"I" : "simple_tag",
"U" : "simple_tag",
"S" : "simple_tag",
"CODE" : "simple_tag",
"QUOTE" : "simple_tag",
"COLOR" : "simple_tag",
"FONT" : "simple_tag",
"SIZE" : "simple_tag",
"PALETTE" : "show_palette",
"URL" : "tag_url",
"IMG" : "tag_image",
"LIST" : "tag_list",
"VIDEO" : "tag_video",
"TRANSLIT" : "translit",
"SMILES_DINAMIC" : "show_smiles_dinamic",
"SMILES_STATIC" : "show_smiles_static"};
this.template = '
';
this.item_template = '#TITLE##BODY#
';
this.additional_params = {"translit" : 0};
this.oCursor = {"text" : "", "start" : 0, "end" : 0};
this.nav = 'none';
var t = this;
this.popupMenu = false;
this.bTranslited = false;
this.active = null;
this.Init = function(form)
{
if (this.form)
return true;
if (typeof(form) != "object" || typeof(form["POST_MESSAGE"]) != "object")
return false;
this.form = form;
/* Simple tags */
var oDivs = this.form.getElementsByTagName('A');
if (oDivs && oDivs.length > 0)
{
for (var ii = 0; ii < oDivs.length; ii++)
{
if (!(oDivs[ii] && oDivs[ii].id && oDivs[ii].id.substring(0, 5) == "form_"))
continue;
oDiv = oDivs[ii];
if (!oDiv.id || oDiv.name == "smiles")
continue;
id = oDiv.id.substring(5).toUpperCase();
oDiv.onclick = oDiv.onmousedown = function(e){
e = (jsUtils.IsIE() || !e ? window.event : e);
jsUtils.PreventDefault(e);
if (e.type == 'mousedown' && jsUtils.IsOpera())
{
t.saveSelection = t.GetSelection();
}
if (e.type == 'click')
{
t.format_text(this, e);
t.saveSelection = false;
}
}
oDiv.onmouseover = function(){this.className += ' marked';};
oDiv.onmouseout = function(){this.className = this.className.replace(/marked/, '').replace(' ', ' ');};
if (jsUtils.IsOpera() && oDiv.title)
oDiv.title = oDiv.title.replace(/\(alt+([^)])+\)/gi, '');
this.real_tags[id] = oDiv;
}
}
if (this.form['FONT'])
{
this.form['FONT'].onmousedown = function(e){t.saveSelection = t.GetSelection();};
this.form['FONT'].onchange = function(e){t.format_text(this, e)};
this.form['FONT'].onmouseover = function(){this.className += ' marked';};
this.form['FONT'].onmouseout = function(){this.className = this.className.replace(/marked/, '').replace(' ', ' ');};
}
// Smiles
var image = this.form.getElementsByTagName("img");
if (image && image.length > 0)
{
for (var ii = 0; ii < image.length; ii++ )
{
if (image[ii].className == "smiles" || image[ii].className == "smiles-list")
{
image[ii].onclick = image[ii].onmousedown = function(e){
e = (jsUtils.IsIE() || !e ? window.event : e);
jsUtils.PreventDefault(e);
if (e.type == 'click')
{
t.emoticon(this);
}
}
// this.real_tags["SMILES"] = true;
}
}
}
this.form["POST_MESSAGE"].onkeyup = t.check_keyup;
this.form["POST_MESSAGE"].onkeypress = t.check_ctrl_enter;
this.form["POST_MESSAGE"].onfocus = function(e){this.hasfocus = true};
this.form["POST_MESSAGE"].onblur = function(e){this.hasfocus = false;};
this.template = this.template.replace(/\#FORM_ID\#/g, this.form.id);
return true;
},
this.check_submit = function(e, action, id)
{
e = (jsUtils.IsIE() || !e ? window.event : e);
if (e)
jsUtils.PreventDefault(e);
id = (id == false ? t.active : id);
var close = true;
if (action == 'OK')
{
close = t["tag_" + id]('format_text');
}
if (close)
t.Hide();
},
this.check_keypress = function(e)
{
if(!e) e = window.event
if(!e) return false;
if(e.keyCode == 27)
t.check_submit(false, 'C', false);
return;
},
this.check_keyup = function(e)
{
if(!e) e = window.event
if(!e) return;
if(!e.altKey) return;
if(e.keyCode == 73)
t.format_text({'id' : 'form_i', 'value' : ''}, e);
else if(e.keyCode == 85)
t.format_text({'id' : 'form_u', 'value' : ''}, e);
else if(e.keyCode == 66)
t.format_text({'id' : 'form_b', 'value' : ''}, e);
else if(e.keyCode == 81)
t.format_text({'id' : 'form_quote', 'value' : ''}, e);
else if(e.keyCode == 80)
t.format_text({'id' : 'form_code', 'value' : ''}, e);
else if(e.keyCode == 71)
t.tag_image();
else if(e.keyCode == 72)
t.tag_url(true);
else if(e.keyCode == 76)
t.tag_list();
},
this.check_ctrl_enter = function(e)
{
if(!e)
e = window.event;
if((e.keyCode == 13 || e.keyCode == 10) && e.ctrlKey && ValidateForm(t.form))
t.form.submit();
return;
},
this.GetSelection = function()
{
if (this.form["POST_MESSAGE"].hasfocus == true && typeof(this.form["POST_MESSAGE"].selectionStart) != 'undefined')
{
return this.form["POST_MESSAGE"].value.substr(this.form["POST_MESSAGE"].selectionStart,
this.form["POST_MESSAGE"].selectionEnd - this.form["POST_MESSAGE"].selectionStart);
}
else if (this.saveSelection)
{
return this.saveSelection;
}
else if (document.selection && document.selection.createRange)
{
return document.selection.createRange().text;
}
else if (window.getSelection)
{
return window.getSelection() + '';
}
else
{
return false;
}
},
this.Show = function(id, data)
{
if (!data)
return false;
var oDiv = document.getElementById('forum_popup_' + this.form.id + '_post_form');
if (!oDiv)
{
oDiv = document.body.appendChild(document.createElement("DIV"));
oDiv.id = 'forum_popup_' + this.form.id + '_post_form';
}
oDiv.style.visible = 'hidden';
oDiv.className = "forum-popup-postform";
oDiv.style.position = 'absolute';
oDiv.innerHTML = data;
jsUtils.addEvent(document, "keypress", t.check_keypress);
var res = jsUtils.GetWindowSize();
var pos = {};
if (t.active != id)
{
this.Hide();
t.active = id;
pos['top'] = parseInt(res["scrollTop"] + res["innerHeight"]/2 - oDiv.offsetHeight/2);
pos['left'] = parseInt(res["scrollLeft"] + res["innerWidth"]/2 - oDiv.offsetWidth/2);
FJCFloatDiv.Show(oDiv, pos["left"], pos["top"], false, true, true);
}
return false;
},
this.Hide = function()
{
if (t.active == null)
return false;
t.active = null;
var oDiv = document.getElementById('forum_popup_' + t.form.id + '_post_form');
FJCFloatDiv.Close(oDiv);
jsUtils.removeEvent(document, "keypress", t.check_keypress);
return false;
},
this.Insert = function (ibTag, ibClsTag, postText)
{
ibTag = (ibTag && ibTag.length > 0 ? ibTag : "");
ibClsTag = (ibClsTag && ibClsTag.length > 0 ? ibClsTag : "");
postText = (postText && postText.length > 0 ? postText : "");
if (ibTag.length <= 0 && ibClsTag.length <= 0 && postText.length <= 0)
return true;
var bReplaceText = (!postText ? false : true);
var sSelectionText = this.GetSelection();
if (!this.form["POST_MESSAGE"].hasfocus)
{
this.form["POST_MESSAGE"].focus();
}
var isSelect = (sSelectionText ? 'select' : bReplaceText ? 'after' : 'in');
if (bReplaceText)
postText = ibTag + postText + ibClsTag;
else if (sSelectionText)
postText = ibTag + sSelectionText + ibClsTag;
else
postText = ibTag + ibClsTag;
if (typeof(this.form["POST_MESSAGE"].selectionStart) != 'undefined')
{
var currentScroll = this.form["POST_MESSAGE"].scrollTop;
var selection = {
"start" : this.form["POST_MESSAGE"].selectionStart,
"end" : this.form["POST_MESSAGE"].selectionEnd};
this.form["POST_MESSAGE"].value = this.form["POST_MESSAGE"].value.substr(0, selection["start"]) +
postText + this.form["POST_MESSAGE"].value.substr(selection["end"]);
if (isSelect == 'select')
{
this.form["POST_MESSAGE"].selectionStart = selection["start"];
this.form["POST_MESSAGE"].selectionEnd = selection["start"] + postText.length;
}
else if (isSelect == 'in')
{
this.form["POST_MESSAGE"].selectionStart = selection["start"] + ibTag.length;
this.form["POST_MESSAGE"].selectionEnd = selection["start"] + ibTag.length;
}
else
{
this.form["POST_MESSAGE"].selectionStart = selection["start"] + postText.length;
this.form["POST_MESSAGE"].selectionEnd = selection["start"] + postText.length;
}
this.form["POST_MESSAGE"].scrollTop = currentScroll;
}
else if (document.selection && document.selection.createRange)
{
var sel = document.selection.createRange();
var selection_copy = sel.duplicate();
postText = postText.replace(/\r?\n/g, '\r\n');
sel.text = postText;
sel.setEndPoint('StartToStart', selection_copy);
sel.setEndPoint('EndToEnd', selection_copy);
if (isSelect == 'select')
{
sel.collapse(true);
postText = postText.replace(/\r\n/g, '1');
sel.moveEnd('character', postText.length);
}
else if (isSelect == 'in')
{
sel.collapse(false);
sel.moveEnd('character', ibTag.length);
sel.collapse(false);
}
else
{
sel.collapse(false);
sel.moveEnd('character', postText.length);
sel.collapse(false);
}
sel.select();
}
else
{
// failed - just stuff it at the end of the message
this.form["POST_MESSAGE"].value += text;
}
return true;
},
this.format_text = function(oObj, e)
{
e = (jsUtils.IsIE() || !e ? window.event : e);
jsUtils.PreventDefault(e);
if (!oObj || !oObj.id)
return false;
var id = oObj.id.substring(5).toUpperCase();
if (this.tags[id] == 'simple_tag')
{
var tag_start = tag_name = id;
if (tag_name == 'FONT' || tag_name == 'COLOR')
tag_start += "=" + oObj.value;
if ((!jsUtils.in_array(tag_name, this.stack) || this.GetSelection()) &&
!(tag_name == 'FONT' && oObj.value == 'none'))
{
if (!this.Insert("[" + tag_start + "]", "[/" + tag_name + "]"))
{
this.stack.push(tag_name);
if (this.real_tags[id])
this.real_tags[id].className += ' opened';
}
}
else
{
var res = false;
while (res = this.stack.pop())
{
this.Insert("[/" + res + "]", "");
if (this.real_tags[res])
this.real_tags[res].className = this.real_tags[res].className.replace(/opened/, '').replace(' ', ' ');
if (res == tag_name)
break;
}
}
}
else if (this.tags[id] == 'show_palette')
{
this.show_palette(oObj);
}
else if (this.tags[id] == 'show_smiles_dinamic')
{
this.show_smiles_dinamic(oObj);
}
else if (this.tags[id] == 'show_smiles_static')
{
this.show_smiles_static(oObj);
}
else if (this.tags[id] == 'translit')
{
res = this.translit();
if (this.real_tags[id])
{
if (res)
this.real_tags[id].className += ' opened translited';
else
this.real_tags[id].className = this.real_tags[id].className.replace(/opened/, '').replace(/translited/, '').replace(' ', ' ');
}
}
else if (this.tags[id])
{
this[this.tags[id]](true);
}
},
this.emoticon = function(element)
{
this.Insert(" ", " ", element.alt);
},
this.tag_image = function()
{
var FoundErrors = '';
var need_loop = true;
var oFields = {
"URL" : {
"text" : oText['enter_image'],
"default" : "http://",
"error" : oErrors['no_url'],
"value" : ""}};
var selection = t.GetSelection();
if (selection != false && selection.search(/^(http|https|news|ftp|aim|mailto)\:\/\//gi) > -1)
{
oFields["URL"]["default"] = selection;
}
else
{
selection = false;
}
for (var ii in oFields)
{
need_loop = true;
do
{
var res = prompt(oFields[ii]["text"], oFields[ii]["default"]);
if (res == null)
{
need_loop = false;
return false;
}
else if (res.length <= 0)
{
alert("Error! " + oFields[ii]["error"]);
}
else
{
oFields[ii]["value"] = res;
need_loop = false;
}
}
while(need_loop);
}
this.Insert("[IMG]", "[/IMG]", oFields["URL"]["value"]);
},
this.tag_video = function(action)
{
action = (action == 'format_text' ? 'format_text' : 'show_data');
var sError = "";
var path = "";
var selection = t.GetSelection();
if (selection != false && selection.search(/^(http|https|news|ftp|aim|mailto)\:\/\//gi) > -1)
path = selection.replace(/[\<\>]/gi, "");
var sBody = "";
if (action == 'format_text')
{
var form = false;
for(var ii in document.forms)
{
if (document.forms[ii].name == 'forum_video_form')
form = document.forms[ii];
}
if (!form)
return true;
var width = parseInt(form["width"].value);
var height = parseInt(form["height"].value);
var path = form["path"].value;
var preview = form["preview"].value;
if (path.length <= 0)
{
action = 'show_data';
sBody = "" + oErrors['no_path'] + "
";
}
}
if (action == 'show_data')
{
sBody = sBody +
this.item_template.replace(/\#TITLE\#/g, oText["path"]).replace(/\#BODY\#/g, '') +
this.item_template.replace(/\#TITLE\#/g, oText["preview"]).replace(/\#BODY\#/g, '') +
this.item_template.replace(/\#TITLE\#/g, oText["width"]).replace(/\#BODY\#/g, '') +
this.item_template.replace(/\#TITLE\#/g, oText["height"]).replace(/\#BODY\#/g, '');
var sData = this.template.replace(/\#ID\#/g, "video").replace(/\#TITLE\#/g, oText["video"]).replace(/\#BODY\#/g, sBody);
this.Show('video', sData);
return false;
}
this.Insert("[VIDEO WIDTH=" + width + " HEIGHT=" + height +
(preview.length > 0 ? ' PREVIEW="' + preview + '"' : '') + "]", "[/VIDEO]", path);
return true;
},
this.tag_list = function()
{
var thelist = "";
var need_loop = true;
do
{
var res = prompt(oText['list_prompt'], "");
if (res == null)
{
need_loop = false;
}
else if (res.replace(/^\s\s*/, '').replace(/\s\s*$/, '').length <= 0)
{
need_loop = false;
}
else
{
thelist = thelist + "[*]" + res + "\n";
}
}
while(need_loop);
if (thelist.length > 0)
{
this.Insert("[LIST]\n", "[/LIST]\n", thelist);
}
},
this.closeall = function()
{
var res = false;
while(res = this.stack.pop())
{
this.Insert("[/" + res + "]", "");
if (this.real_tags[res])
this.real_tags[res].className = this.real_tags[res].className.replace(/opened/, '').replace(' ', ' ');
}
},
this.tag_url = function()
{
var FoundErrors = '';
var need_loop = true;
var oFields = {
"URL" : {
"text" : oText['enter_url'],
"default" : "http://",
"error" : oErrors['no_url'],
"value" : ""},
"TITLE" : {
"text" : oText['enter_url_name'],
"default" : "My Webpage",
"error" : oErrors['no_title'],
"value" : ""}};
var selection = t.GetSelection();
if (selection != false)
{
if (selection.search(/^(http|https|news|ftp|aim|mailto)\:\/\//gi) > -1)
{
oFields["URL"]["default"] = selection;
}
else
{
oFields["TITLE"]["default"] = selection;
}
}
for (var ii in oFields)
{
need_loop = true;
do
{
var res = prompt(oFields[ii]["text"], oFields[ii]["default"]);
if (res == null)
{
need_loop = false;
return false;
}
else if (res.length <= 0)
{
alert("Error! " + oFields[ii]["error"]);
}
else
{
oFields[ii]["value"] = res;
need_loop = false;
}
}
while(need_loop);
}
this.Insert("[URL=" + oFields["URL"]["value"] + "]", "[/URL]", oFields["TITLE"]["value"]);
return false;
},
this.translit = function()
{
var i = 0;
var textbody = this.form['POST_MESSAGE'].value;
var selection = this.GetSelection();
if (selection != false)
{
textbody = selection;
}
if (this.bTranslited == false)
{
for (i=0; i 0)
{
var message = document.getElementById(mid);
if (typeof(message) == "object" && message)
{
selection = message.innerHTML;
selection = selection.replace(/\
/gi, "\n").replace(/\