function replaceElementText(doc, elem, newText)
{
//Define a new element range and set it up
//to represent the contents of the element.
var er = new ElementRange();
er.beg.parent = er.end.parent = elem;
er.beg.offset = 0;
if(ov(elem.FirstChildElement))
{
er.beg.child = elem.FirstChildElement;
er.end.offset = 0;
}
else er.end.offset = Constants.FV_OBJ_END_OFFSET;
//Set the element range in the document and
//execute Clear() to delete the current element contents.
doc.ElementSelection = er;
doc.Clear(0);
//The insertion point will now be at the beginning of
//the empty element. Execute AddText() to insert the
//new text.
doc.AddText(doc.TextSelection.beg, newText);
}