<!-- Make sure user provided value for Attributes.Body -->
<CFIF ParameterExists( Attributes.Body ) is "No">
   <CF_SHOWERR
      ERRORTITLE="Developer Error"
      LEADIN="This program has made an invalid call 
to the custom tag, CF_WRAPTEXT."
      ERRORMSG="When calling CF_WRAPTEXT, 
you must include the BODY attribute, which 
                contains the text to be wrapped"
   >
   </CFABORT>
</CFIF>

<!-- Default nCols to 70 if user hasn't specified it in an attribute -->
<CFSET NCols = Iif( ParameterExists( Attributes.nCols ) 
is "Yes", "Attributes.nCols", DE("70"))>

<CFSET nTxtSize = Len(Attributes.Body)>
<CFSET frmText = ìî>
<CFSET CRLF = Chr(13) & Chr(10)>
<CFIF nTxtSize LTE nCols>
   <!--
      Text isnít as wide as the specified number of columns.
   -->
   <CFSET frmText = Attributes.Body>
<CFELSE>
   <CFSET nSPos = 1>
   <CFLOOP
      CONDITION="True"
   >
      <CFIF nSPos + nCols -1 GTE nTxtSize>
         <CFSET frmText = frmText & Mid(Attributes.Body,nSPos,
nTxtSize-nSPos+1)>
         <CFBREAK>
      <CFELSE>
         <CFSET nPos = nSPos + nCols -1>
         <CFLOOP
            INDEX = "ii"
            FROM  = #nPos#
            TO    = #nSPos#
            STEP  = -1
         >
            <CFIF ( Mid(Attributes.Body,ii,1) is " " )
             OR   ( Mid(Attributes.Body,ii,1) is #CRLF# )>
               <CFSET frmText = frmText & Mid
(Attributes.Body, nSPos, nCols-(nPos-ii)) & #CRLF# >
               <CFSET nSPos = ii + 1 >
               <CFBREAK>
            <CFELSEIF ( ii is nSPos )>
               <!--
                  There wasnít a single break in the current chunk of text.
                  Weíll simply cut of a chunk which is nCols wide 
	      starting at nSPos.
               -->
               <CFSET frmText = frmText & Mid
(Attributes.Body,nSPos,nCols) & #CRLF# >
               <CFSET nSPos = nSPos + nCols>
               <CFBREAK>
            </CFIF>
         </CFLOOP>
      </CFIF>
   </CFLOOP>
</CFIF>
<CFSET Caller.WrappedText = frmText>