function cRichTextEditor(){
this.emwindow = new Array;
this.editor = "body_1";
this.table = "";
this.id = "1";
this.saveFlag = 0;
this.signatures = false;
this.replyController = false;
this.newImageId = false;
this.plain = new Array;
this.editorReady = true;
}
// This code was written by Tyler Akins and has been placed in the
// public domain. It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf(" chrome/") >= 0 || ua.indexOf(" firefox/") >= 0 || ua.indexOf(' gecko/') >= 0) {
var StringMaker = function () {
this.str = "";
this.length = 0;
this.append = function (s) {
this.str += s;
this.length += s.length;
}
this.prepend = function (s) {
this.str = s + this.str;
this.length += s.length;
}
this.toString = function () {
return this.str;
}
}
} else {
var StringMaker = function () {
this.parts = [];
this.length = 0;
this.append = function (s) {
this.parts.push(s);
this.length += s.length;
}
this.prepend = function (s) {
this.parts.unshift(s);
this.length += s.length;
}
this.toString = function () {
return this.parts.join('');
}
}
}
cRichTextEditor.prototype.fromJSON = function( value )
{
return (new Function( "return " + this.decode64( value )))();
}
cRichTextEditor.prototype.decode64 = function(input) {
if( typeof input === "undefined" ) return '';
var output = new StringMaker();
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output.append(String.fromCharCode(chr1));
if (enc3 != 64) {
output.append(String.fromCharCode(chr2));
}
if (enc4 != 64) {
output.append(String.fromCharCode(chr3));
}
}
return output.toString();
}
cRichTextEditor.prototype.loadEditor = function(ID) {
var parentDiv = document.getElementById("body_position_" + ID);
var pObj = "body_" + ID;
var textArea = document.createElement("TEXTAREA");
textArea.id = pObj;
textArea.style.width = '100%';
parentDiv.appendChild(textArea);
RichTextEditor.plain[ID] = false;
if(preferences.plain_text_editor == 1)
{
RichTextEditor.plain[ID] = true;
RichTextEditor.editorReady = true;
}
else
RichTextEditor.active(pObj);
}
cRichTextEditor.prototype.getSignaturesOptions = function() {
if(RichTextEditor.signatures !== false)
return RichTextEditor.signatures;
var signatures = this.fromJSON( preferences.signatures );
var signature_types = this.fromJSON( preferences.signature_types );
for( key in signatures )
if( !signature_types[key] )
signatures[key] = signatures[key].replace( /\n/g, "
" );
RichTextEditor.signatures = signatures;
return signatures;
}
cRichTextEditor.prototype.getSignatureDefault = function() {
if(RichTextEditor.signatures === false)
RichTextEditor.signatures = RichTextEditor.getSignaturesOptions();
if(!RichTextEditor.signatures ||
!RichTextEditor.signatures[preferences.signature_default || ""])
{
preferences.use_signature = "0"; //Desabilita o uso da assinatura
return '';
}
return unescape(RichTextEditor.signatures[preferences.signature_default]);
}
cRichTextEditor.prototype.createImage = function(){
if (preferences.auto_save_draft == 1)
{
autosave_time = 200000;
clearTimeout(openTab.autosave_timer[currentTab]);
}
var form = document.getElementById("attachment_window");
if (form == null){
form = document.createElement("DIV");
form.id = "attachment_window";
form.style.visibility = "hidden";
form.style.position = "absolute";
form.style.background = "#eeeeee";
form.style.left = "0px";
form.style.top = "0px";
form.style.width = "0px";
form.style.height = "0px";
document.body.appendChild(form);
}
var form_upload = Element('form_upload');
if (form_upload == null)
form_upload = document.createElement("DIV");
form_upload.id = "form_upload";
form_upload.style.position = "absolute";
form_upload.style.top = "5px";
form_upload.style.left = "5px";
form_upload.name = get_lang("Upload File");
form_upload.style.width = "450px";
form_upload.style.height = "75px";
form_upload.innerHTML = get_lang('Select the desired image file')+':
'+
'
' +
' ' +
'';
form.appendChild(form_upload);
this.showWindow(form);
}
cRichTextEditor.prototype.showWindow = function (div){
if(! div) {
return;
}
if(! this.emwindow[div.id]) {
div.style.width = div.firstChild.style.width;
div.style.height = div.firstChild.style.height;
div.style.zIndex = "10000";
var title = div.firstChild.name;
var wHeight = div.offsetHeight + "px";
var wWidth = div.offsetWidth + "px";
div.style.width = div.offsetWidth - 5;
win = new dJSWin({
id: 'win_'+div.id,
content_id: div.id,
width: wWidth,
height: wHeight,
title_color: '#3978d6',
bg_color: '#eee',
title: title,
title_text_color: 'white',
button_x_img: '../phpgwapi/images/winclose.gif',
border: true});
this.emwindow[div.id] = win;
win.draw();
}
else
win = this.emwindow[div.id];
win.open();
}
cRichTextEditor.prototype.addInputFile = function()
{
//Begin: Verify if the image extension is allowed.
var imgExtensions = new Array("jpeg", "jpg", "gif", "png", "bmp", "xbm", "tiff", "pcx");
var inputFile = document.getElementById('inputFile_img');
if(!inputFile.value) return false;
var fileExtension = inputFile.value.split(".");
fileExtension = fileExtension[(fileExtension.length-1)];
var deniedExtension = true;
for(var i=0; i