//---------------------------------------------------------
// version information
//   this script is called from other scripts
//---------------------------------------------------------
function getDwVersion()
{
  var DW_VERSION = 2.0;
  return DW_VERSION;
}


//---------------------------------------------------------
// main function
//---------------------------------------------------------
function docwrite(text, ctag, ctagAttribute, ptag, ptagAttribute, ptagAttributeValue)
{
  var newText = document.createTextNode(text);  // text to render, e.g. "Hello World" or a variable like sOutput
  var newTag = document.createElement(ctag);     // type of element to wrap text in, e.g. <p> or <span>
  var parentTag = document.getElementById(ptagAttributeValue);  // tag + id combination, e.g. <div id="pageheading">
  var colDivTags = document.getElementsByTagName('div');  // get ALL <div> elements, sort out later


//---------------------------------------------------------
// test purposes only
//---------------------------------------------------------
/*
var sOutput = "Script: docwrite.js" + "\n"
  + "\n" + "text = " + text
  + "\n" + "ctag = " + ctag
  + "\n" + "ctagAttribute = " + ctagAttribute
  + "\n" + "ptag = " + ptag
  + "\n" + "ptagAttribute = " + ptagAttribute
  + "\n" + "ptagAttributeValue = " + ptagAttributeValue;
alert(sOutput);
*/


//---------------------------------------------------------
// check if a class name is used with the child tag
//---------------------------------------------------------
  if (ctagAttribute == null)
  {
    // use the element without appending a class attribute
  }
  else
  {
    // append a class attribute to the element
    alert("ctagAttribute was passed and is not null.");
    var newTagClassName = ctagAttribute;
    newTag.className = newTagClassName;
    //alert(newTag.nodeName + " class=" + newTag.className);
  };


//---------------------------------------------------------
// append the text to the end of the new child tag,
//    probably <p> or <span>
//---------------------------------------------------------
  newTag.appendChild(newText);


//---------------------------------------------------------
// then append the new child tag to the end of the proper
//   parent tag (matching on the parent's class name),
//   probably <div>
//---------------------------------------------------------
  switch (ptagAttribute) {
    case 'class': {
      for (i=0; i<colDivTags.length; i++)
      {
        if (colDivTags[i].className == ptagAttributeValue)
        {
          colDivTags[i].appendChild(newTag);
        }  // end if
      }  // end for
      break;
    }  // end case

    case 'id': {
      parentTag.appendChild(newTag);
      break;
    }  // end case

    case otherwise: {
      alert("else case not defined yet.");
      break;
    }  // end case
  }  // end switch

return;
}  // end function docwrite
