// MutableText applet functions

var MT_code = "MutableText.class";
var MT_codebase = "/scripts/mutable_text";

// parameters the user is encouraged to set
var MT_text = "";
var MT_bgcolor = "#FFFFFF";
var MT_fgcolor = "#000000";
var MT_font = "Serif-16";
var MT_align = "center";
var MT_height = "18";
var MT_charwidth = "20";

// after setting the parameters you wish to use (or accepting the defaults), call this function to insert a field
function MT_insertField(fieldName)
{
  document.write('<applet codebase="' + MT_codebase + '" code="' + MT_code + '" width="'+(8*MT_charwidth)+'" height="'+MT_height+'" name="'+fieldName+'">');
    document.write('<param name="text" value="'+MT_text+'">');
    document.write('<param name="bgcolor" value="'+MT_bgcolor+'">');
    document.write('<param name="fgcolor" value="'+MT_fgcolor+'">');
    document.write('<param name="font" value="'+MT_font+'">');
    document.write('<param name="align" value="'+MT_align+'">');
    document.write('<input type="text" name="'+fieldName+'" value="'+MT_text+'" size="'+MT_charwidth+'">');
  document.write('</applet>');
}

// get the text from an MT field
function MT_getText(formName, fieldName)
{
  var theField;
  
  if ((theField = eval("document."+fieldName)) != null) {
    return theField.getText();
  } else if ((theField = eval("document."+formName+"."+fieldName)) != null) {
    if (theField.toString().substring(0,11) != "MutableText") {
      return theField.value;
    } else {
      return theField.getText();
    }
  }
  
  // field or applet was not found, return null
  return null;
}

// set the text of an MT field
function MT_setText(formName, fieldName, val)
{
  var theField;
  
  if ((theField = eval("document."+fieldName)) != null) {
    theField.setText(val);
  } else if ((theField = eval("document."+formName+"."+fieldName)) != null) {
    if (theField.toString().substring(0,11) != "MutableText") {
      theField.value = val;
    } else {
      theField.setText(val);
    }
  }
}
