/*
   Creates a word from the red green and blue bytes.
*/
function rgbWord
(
   ucRed  ,
   ucGreen,
   ucBlue
)
{
   return  (ucRed << 16 | ucGreen << 8 | ucBlue);
}


/*
   Convert a decimal to hex.
*/
function dec2hex
(
   word
)
{
   var  sHexSet     = "0123456789ABCDEF";
   var  sHexString  = "";
   var  sTempString = "";
   var  iCount     = 0;
   var  iRemainder = 0;


   // Divide number by 16 until no possible.

   while (0 != word)
   {
      iRemainder   = word % 16;
      sTempString += sHexSet.charAt(iRemainder);

      word >>= 4;
   }


   // No reverse the tempString

   for (iCount = 5; iCount >= 0; iCount--)
      sHexString += sTempString.charAt (iCount);


   // Return the hex number.

   return (sHexString);

}

/*
   Checks if byte is in byte range 0-255
*/
function inByteRange
(
   byte
)
{
   if ((byte >= 0x00) && (byte <= 0xFF))
      return (true);
   else
      return (false);
}


/*
   Write the string out in different colors.
*/
function blendText
(
   sText       ,  // Text that you want to blend.
   hStartColor ,  // Start color, in HEX. eg.. 0x112233
   hEndColor      // End color, also in hex.
)
{
   var sStringRGB    = "#000000";
   var iTextLen      = sText.length;
   var iCount        = 0;
   var iCharColor    = 0;

   var hStartRed     = hStartColor >> 16;
   var hStartGreen   = (hStartColor & 0x00FF00) >> 8
   var hStartBlue    = hStartColor & 0x0000FF;

   var hEndRed       = hEndColor >> 16;
   var hEndGreen     = (hEndColor & 0x00FF00) >> 8
   var hEndBlue      = hEndColor & 0x0000FF;

   if (iTextLen < 25)
     iTextLen = 22;

   var iIncRed       = Math.floor ((hEndRed   - hStartRed)   / iTextLen);
   var iIncGreen     = Math.floor ((hEndGreen - hStartGreen) / iTextLen);
   var iIncBlue      = Math.floor ((hEndBlue  - hStartBlue)  / iTextLen);



   for (iCount=0; iCount < sText.length; iCount++)
   {
      // Calculate next color.

      if (inByteRange (hStartRed + iIncRed))
         hStartRed += iIncRed;

      if (inByteRange (hStartGreen + iIncRed))
         hStartGreen += iIncGreen;

      if (inByteRange (hStartBlue + iIncRed))
         hStartBlue += iIncBlue;


      // Convert back to hex number.

      iCharColor = dec2hex (rgbWord (hStartRed, hStartGreen, hStartBlue));


      // Leading zeros will have been truncated, so put back if they are needed.

      iCharColor = sStringRGB.substring (0, 6 - iCharColor + 1) + iCharColor;


      // Write the character.

      document.write ("<font color=", iCharColor, ">", sText.charAt (iCount), "</font>");
   }

   return (false);
}

function blendTextPink (txt)
{
   document.write ("<span style='font-weight:bold; font-size:12px;'>");
   blendText (txt, 0xCC3366, 0xEFB9DF);
   document.write ("</span>");
}

function blendTextBlue (txt)
{
   document.write ("<span style='font-weight:bold; font-size:14px;'>");
   blendText (txt, 0x89ADDF, 0x275CA3);
   document.write ("</span>");
}

