 // Esta información corresponde al archivo Dhtmled.js
 // DHTML Editing Component Constants for JavaScript
 //
 // Command IDs
 //
 DECMD_BOLD =                      5000
 DECMD_COPY =                      5002
 DECMD_CUT =                       5003
 DECMD_DELETE =                    5004
 DECMD_DELETECELLS =               5005
 DECMD_DELETECOLS =                5006
 DECMD_DELETEROWS =                5007
 DECMD_FINDTEXT =                  5008
 DECMD_FONT =                      5009
 DECMD_GETBACKCOLOR =              5010
 DECMD_GETBLOCKFMT =               5011
 DECMD_GETBLOCKFMTNAMES =          5012
 DECMD_GETFONTNAME =               5013
 DECMD_GETFONTSIZE =               5014
 DECMD_GETFORECOLOR =              5015
 DECMD_HYPERLINK =                 5016
 DECMD_IMAGE =                     5017
 DECMD_INDENT =                    5018
 DECMD_INSERTCELL =                5019
 DECMD_INSERTCOL =                 5020
 DECMD_INSERTROW =                 5021
 DECMD_INSERTTABLE =               5022
 DECMD_ITALIC =                    5023
 DECMD_JUSTIFYCENTER =             5024
 DECMD_JUSTIFYLEFT =               5025
 DECMD_JUSTIFYRIGHT =              5026
 DECMD_LOCK_ELEMENT =              5027
 DECMD_MAKE_ABSOLUTE =             5028
 DECMD_MERGECELLS =                5029
 DECMD_ORDERLIST =                 5030
 DECMD_OUTDENT =                   5031
 DECMD_PASTE =                     5032
 DECMD_REDO =                      5033
 DECMD_REMOVEFORMAT =              5034
 DECMD_SELECTALL =                 5035
 DECMD_SEND_BACKWARD =             5036
 DECMD_BRING_FORWARD =             5037
 DECMD_SEND_BELOW_TEXT =           5038
 DECMD_BRING_ABOVE_TEXT =          5039
 DECMD_SEND_TO_BACK =              5040
 DECMD_BRING_TO_FRONT =            5041
 DECMD_SETBACKCOLOR =              5042
 DECMD_SETBLOCKFMT =               5043
 DECMD_SETFONTNAME =               5044
 DECMD_SETFONTSIZE =               5045
 DECMD_SETFORECOLOR =              5046
 DECMD_SPLITCELL =                 5047
 DECMD_UNDERLINE =                 5048
 DECMD_UNDO =                      5049
 DECMD_UNLINK =                    5050
 DECMD_UNORDERLIST =               5051
 DECMD_PROPERTIES =                5052

 //
 // Enums
 //

 // OLECMDEXECOPT
 OLECMDEXECOPT_DODEFAULT =         0
 OLECMDEXECOPT_PROMPTUSER =        1
 OLECMDEXECOPT_DONTPROMPTUSER =    2


 var obj_editor = 0 ;
 // Per canvis de gifs a la barra d'icones:
 function canvi_imatge(nom_img,graf){
   document.images[nom_img].src = graf;
   return true;
 }


 function MakeArray(n) {
   this.length=n
   for(var j=1; j<=n; j++){
     this[n]=0
   }
   return this
 }


//--------------------------------------------
// the following functions were
// inserted by Frits Scholten
// GetThere 2003
//--------------------------------------------

 // default content
 function set_content(name, content) {
	if (document[name]) {
   		obj_editor = eval( "document."+name);
   		obj_editor.DocumentHTML = '<font face=sans-serif size=2 >'+content+'</font>';
	}
 }

 editor_names = new Array();
 function add_editor_name(name) {
 	editor_names[editor_names.length] = name;
 }

 editor_configs = new Array();
 function add_config_name(name) {
 	editor_configs[editor_configs.length] = name;
 }

 // construct editor
 function create_editor(name, config, conf_name) {
     var hidden_var = name.substring(0,name.indexOf("_obj"));
     var action_name = "";
     var img_name = "";
     var img_url = "";
     var img_url_focus = "";
     var alt_text = "";
     var is_button = 0;

     var editor_height = "150";
     var editor_width = "500";

     add_editor_name(hidden_var);
     add_config_name(conf_name);

     if (config.height && config.height != '') {
     	editor_height = config.height;
     }
     if (config.width && config.width != '') {
     	editor_width = config.width;
     }

     document.write('<TABLE border="0" cellPadding="0" cellSpacing="0">\n');
     document.write('  <input type="hidden" name="'+hidden_var+'">\n');
     document.write('  <TR><TD>\n');
     document.write('      <TABLE border="0" cellPadding="0" cellSpacing="0">\n');
     document.write('      <TR>\n');

     // check config toolbars and insert the buttons
     for (var index = 0; index < config.toolbar.length; index++) {
	is_button = 0;
	// bold
	if (config.toolbar[index].toLowerCase() == 'bold' ) {
		action_name = "do_bold()";
		img_name = "img_bold";
		img_url = "img/bold.gif";
		img_url_focus = "img/bold.gif";
		alt_text = "Vet";
		is_button = 1;
	}
	// italics
	if (config.toolbar[index].toLowerCase() == 'italic' ) {
		action_name = "do_italic()";
		img_name = "img_italic";
		img_url = "img/italic.gif";
		img_url_focus = "img/italic.gif";
		alt_text = "Cursief";
		is_button = 1;
	}
	// underline
	if (config.toolbar[index].toLowerCase() == 'underline' ) {
		action_name = "do_underline()";
		img_name = "img_under";
		img_url = "img/underline.gif";
		img_url_focus = "img/underline.gif";
		alt_text = "Onderstreept";
		is_button = 1;
	}
	// special chars
/*
	if (config.toolbar[index].toLowerCase() == 'specialchars' ) {
		action_name = "do_specialchars()";
		img_name = "img_special";
		img_url = "img/charmap.gif";
		img_url_focus = "img/charmap.gif";
		alt_text = "Speciale tekens";
		is_button = 1;
	}
*/
	// new line break
	if (config.toolbar[index].toLowerCase() == 'newline' ) {
		action_name = "do_newline()";
		img_name = "img_newline";
		img_url = "img/undo.gif";
		img_url_focus = "img/undo.gif";
		alt_text = "Regelovergang";
		is_button = 1;
	}
	// uppercase
	if (config.toolbar[index].toLowerCase() == 'uppercase' ) {
		action_name = "do_uppercase()";
		img_name = "img_uppercase";
		img_url = "img/uppercase.gif";
		img_url_focus = "img/uppercase.gif";
		alt_text = "HOOFDLETTERS";
		is_button = 1;
	}
	// lowercase
	if (config.toolbar[index].toLowerCase() == 'lowercase' ) {
		action_name = "do_lowercase()";
		img_name = "img_lowercase";
		img_url = "img/lowercase.gif";
		img_url_focus = "img/lowercase.gif";
		alt_text = "kleine letters";
		is_button = 1;
	}
        // superscript
        if (config.toolbar[index].toLowerCase() == 'superscript' ) {
                action_name = "do_superscript()";
                img_name = "img_superscript";
                img_url = "img/sup.gif";
                img_url_focus = "img/sup.gif";
                alt_text = "Superscript";
                is_button = 1;
        }
        // euro sign
        if (config.toolbar[index].toLowerCase() == 'euro' ) {
                action_name = "do_eurosign()";
                img_name = "img_eurosign";
                img_url = "img/euro.gif";
                img_url_focus = "img/euro.gif";
                alt_text = "Euro teken";
                is_button = 1;
        }
	// separator
//	if (config.toolbar[index].toLowerCase() == 'separator' ) {
//	 	document.write('  <TD valign="center" bgcolor="silver"><IMG align="absMiddle" border="0" src=\'img/separator.gif\'> </TD>');
//	}
//	// counter
//	if (config.toolbar[index].toLowerCase() == 'counter' ) {
//	 	document.write('  <TD valign="center"> aantal karakters:</TD>');
//	 	document.write('  <TD valign="center"><input type="text" size="4" name="'+hidden_var+'_counter" onFocus="count_chars(this,\''+name+'\', '+conf_name+');"> </TD>');
//	}


	// write button
     	if (is_button == 1) {
    		document.write('  <TD valign="center" >&nbsp;&nbsp;<a href="#" onclick="init('+name+'); '+action_name+'; return false;"');
     		document.write('onmouseout="canvi_imatge(\''+img_name+'\',\''+img_url+'\');"');
     		document.write('onmouseover="canvi_imatge(\''+img_name+'\',\''+img_url_focus+'\');">');
     		document.write('<IMG align="absMiddle" alt="'+alt_text+'" border="0" name="'+img_name+'" src="'+img_url+'"></A> &nbsp;&nbsp;</TD>\n');
     		document.write('  </TD>\n');
     	}
     }
     document.write('      <TR>\n');
     document.write('      </TABLE>\n');
     document.write('  </TD></TR>\n');
     document.write('</TABLE>\n');
 }

 // bold
 function do_bold(){
   obj_editor.ExecCommand(DECMD_BOLD,OLECMDEXECOPT_DODEFAULT);
   return false;
 }

 // cursief
 function do_italic() {
   obj_editor.ExecCommand(DECMD_ITALIC,OLECMDEXECOPT_DODEFAULT);
 }

 // onderstreept
 function do_underline() {
   obj_editor.ExecCommand(DECMD_UNDERLINE,OLECMDEXECOPT_DODEFAULT);
 }

 // superscript
 function do_superscript() {
    var sel = obj_editor.DOM.selection;
    var range = sel.createRange();
    if (range.text != "") {
      	var tekst = range.htmlText;
      	var check_tekst = tekst.toLowerCase();
        if (check_tekst.indexOf("<sup>") >= 0) {
		tekst = tekst.replace(/<sup>/g, '');
		tekst = tekst.replace(/<SUP>/g, '');
		tekst = tekst.replace(/<\/sup>/g, '');
		tekst = tekst.replace(/<\/SUP>/g, '');
	} else {
      		tekst = "<SUP>" + tekst + "</SUP>";
      	}
      	range.pasteHTML( tekst );
    }
 }


 // special characters
 function do_specialchars() {
   var specialChar = "";
   var value = showModalDialog("popups/chartabel.html",
                specialChar,      // str or obj specified here can be read from dialog as "window.dialogArguments"
                "resizable: yes; help: no; status: no; scroll: no; ");
   if (value) {
	editor_insertHTML(value);
   }
 }

 // euro sign
 function do_eurosign() {
    editor_insertHTML('&euro;');
 }

 // new line
 function do_newline() {
 	var sel = obj_editor.DOM.selection; // get selected text, or when empty get insertion point
        var range = sel.createRange();
        range.pasteHTML("<BR>");

	//var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
	//if (win_ie_ver < 5.5) {
	        range.pasteHTML("<SPAN></SPAN>");
	//}

	//obj_editor.refresh();
        obj_editor.focus();
        return;
 }

 // upper case
 function do_uppercase() {
    var sel = obj_editor.DOM.selection;
    var range = sel.createRange();
    if (range.text != "") {
      var text = range.htmlText.toUpperCase();
      range.pasteHTML( text );
    }
 }

 // lower case
 function do_lowercase() {
    var sel = obj_editor.DOM.selection;
    var range = sel.createRange();
    if (range.text != "") {
      var text = range.htmlText.toLowerCase();
      range.pasteHTML( text );
    }
 }

 // insert HTML
 function editor_insertHTML(value) {
 	var sel = obj_editor.DOM.selection; // get selected text, or when empty get insertion point
        var range = sel.createRange();
        range.pasteHTML(value);
        obj_editor.focus();
        return;
 }

 function filter_output(editor_obj, config) {
    var obj_ed = eval("document." + editor_obj);
    var contents = obj_ed.DOM.body.innerHTML;
    if (contents.toLowerCase() == '<p>&nbsp;</p>') { contents = ""; }
    contents = contents.replace(/&lt;/g, '<');
    contents = contents.replace(/&gt;/g, '>');
    for (var index = 0; index < config.allowed_tags.length; index++) {
    	if ( config.allowed_tags[index].toLowerCase() == 'strong') {
        	contents = contents.replace(/<strong>/g, '@@strong@@');
        	contents = contents.replace(/<STRONG>/g, '@@strong@@');
        	contents = contents.replace(/<\/strong>/g, '@@/strong@@');
        	contents = contents.replace(/<\/STRONG>/g, '@@/strong@@');
	}
    	if ( config.allowed_tags[index].toLowerCase() == 'em') {
        	contents = contents.replace(/<em>/g, '@@em@@');
        	contents = contents.replace(/<EM>/g, '@@em@@');
        	contents = contents.replace(/<\/em>/g, '@@/em@@');
        	contents = contents.replace(/<\/EM>/g, '@@/em@@');
	}
    	if ( config.allowed_tags[index].toLowerCase() == 'u') {
        	contents = contents.replace(/<u>/g, '@@u@@');
        	contents = contents.replace(/<U>/g, '@@u@@');
        	contents = contents.replace(/<\/u>/g, '@@/u@@');
        	contents = contents.replace(/<\/U>/g, '@@/u@@');
	}
    	if ( config.allowed_tags[index].toLowerCase() == 'sup') {
        	contents = contents.replace(/<sup>/g, '@@sup@@');
        	contents = contents.replace(/<SUP>/g, '@@sup@@');
        	contents = contents.replace(/<\/sup>/g, '@@/sup@@');
        	contents = contents.replace(/<\/SUP>/g, '@@/sup@@');
	}
    }
    contents = contents.replace(/<br>/g, '@@br@@');
    contents = contents.replace(/<BR>/g, '@@br@@');
    contents = contents.replace(/<br\/>/g, '@@br@@');
    contents = contents.replace(/<BR\/>/g, '@@br@@');
    contents = contents.replace(/<[^>]*>/g, '');
	// 'STRONG' -> bold
       	contents = contents.replace(/@@strong@@/g, '<STRONG>');
       	contents = contents.replace(/@@\/strong@@/g, '</STRONG>');
	// 'EM' -> italic
        contents = contents.replace(/@@em@@/g, '<EM>');
        contents = contents.replace(/@@\/em@@/g, '</EM>');
	// 'U' -> underline
        contents = contents.replace(/@@u@@/g, '<U>');
        contents = contents.replace(/@@\/u@@/g, '</U>');
	// 'SUP' -> superscript
        contents = contents.replace(/@@sup@@/g, '<SUP>');
        contents = contents.replace(/@@\/sup@@/g, '</SUP>');
	// 'BR'
        contents = contents.replace(/@@br@@/g, '<BR/>');
    // remove HTML comments
    contents = contents.replace(/<!--.*-->/, '');
    // remove nextlines from output (if requested)
    if (config.replaceNextlines) {
      contents = contents.replace(/\r\n/g, ' ');
      contents = contents.replace(/\n/g, ' ');
      contents = contents.replace(/\r/g, ' ');
    }

    // remove &nbsp;'s from output
    contents = contents.replace(/&nbsp;/g, ' ');
    contents = contents.replace(/&amp;nbsp;/g, ' ');
    contents = contents.replace(/¤/g, '&euro;');
    // update output with filtered content
    return contents;
  }


// submit editors - put contents in form variables
function submitEditors(thisForm) {
	for (var index = 0; index < editor_names.length; index++) {
	    var content_obj = eval( "document." + thisForm.name + "." + editor_names[index] );
	    var conf_obj = eval( editor_configs[index] );
	    content_obj.value = filter_output( editor_names[index] + "_obj", conf_obj );
	}
 return true;
}

function count_chars(thisElement, editor_obj, config) {
	//alert ("count_chars");
    	var obj_ed = eval("document." + editor_obj);
	var contents = obj_ed.DOM.body.innerHTML;

    	// remove all HTML tags
    	contents = contents.replace(/<[^>]*>/g, '');

    	//contents = contents.replace(/<p>/g, '<br>');
    	//contents = contents.replace(/</p>/g, '');

	//var contents = filter_output(editor_obj, config);
	thisElement.value = contents.length;
}


function init(name) {
	// set editor
	obj_editor = name;
}
