// texteditor control functions

// generates and returns the HTML code for the control
function texteditorControlGenerageHtml( formId, controlDescription )
{
  var output = "";
  
  if ( controlDescription['caption'] )
    output += controlDescription['caption'];
  
  var internalControlId = getInternalControlId( formId, controlDescription );
  var checkboxControlId = getInternalControlId( formId, controlDescription )+"ModeCheckbox";
  
  output += 
    "<div class=\"checkboxinput\"><label for=\""+checkboxControlId+"\"><input id=\""+checkboxControlId+"\" type=\"checkbox\" onclick=\"javascript: texteditorControlSetEditMode('"+internalControlId+"', this.checked)\">Use WYSWYG</label></div>" +
    "<div class=\"multilinetextinput\"><iframe src=\"about:blank\" id=\""+internalControlId+"\" value=\"\" "+ ( controlDescription['maxLength'] ? "maxlength=\""+ controlDescription['maxLength'] +"\" " : "" ) +"onkeyup=\"javascript: saveControlValue('"+formId+"', '"+controlDescription['id']+"', this.value);\" onblur=\"javascript: saveControlValue('"+formId+"', '"+controlDescription['id']+"', this.value);\" onmouseup=\"javascript: saveControlValue('"+formId+"', '"+controlDescription['id']+"', this.value);\" oninit=\"javascript: texteditorInitEditableIFrame(this); \"></iframe></div>"
  
  return output;
}

// Sets the properties of the control to the ones, set in control description
function texteditorControlPopulateProperties( formId, controlDescription )
{
  textControlPopulateProperties( formId, controlDescription );
}

//   Adds the new texteditor control description to the form, given
// and returns updated form
//   The form must be a valid form
//   If there already is a control with ID, given, it will be replaced
// with new
function texteditorControlAddToForm( id, defaultValue, caption, maxLength )
{
  this.addBaseControl( id, defaultValue );
  
  this['fields'][id]['type'] = 'texteditor';
  this['fields'][id]['caption'] = caption;
  this['fields'][id]['maxLength'] = maxLength;
}

// Internal functions

// switches the texteditor mode from plain text edit and
// WYSWYG mode.
// Is designed to be used internally inside the control
function texteditorControlSetEditMode( controlId, isWyswygMode ) 
{
  var control = obtainElementById( controlId );
  if ( !control )
    return;
    
    texteditorInitEditableIFrame( control ) 
    /*
  var content;
  if (isWyswygMode) 
  {
    content = control.document.body.innerHTML;
    control.document.body.innerText = content;
  } 
  else 
  {
    content = control.document.body.innerText;
    control.document.body.innerHTML = content;
  }
  control.focus();*/
}

// initializes the iframe's edit mode. Pass an iframe object
// Is designed to be used internally inside the control
function texteditorInitEditableIFrame( iFrame ) 
{
  var editableIFrame = createEditableIFrame( iFrame );
}