/*
 * Create a button object and set it's attributes:
 *    var MyButton = new buttonConstruct();
 *       MyButton.text   = "View My Page";
 *       MyButton.href   = "javascript:goPage( 'my_page' )";
 *       MyButton.id     = "view_page_button";
 * OR use to create a single button:
 *    buttonConstruct("text", "href", "id", 150, "center|right", 10, 14, 15, "&nbsp; &nbsp;");
 *    - Many will default, so only set the attributes you need.
 *    - Enter 'null' without quotes to skip one.
 * (Use inside of script tags)
 */
// buttonConstruct(text, href, id, width, align, vspace, size, spacer, text_pad)
function buttonConstruct()
{
   this.text;
   this.href;
   this.id;
   this.width    = 1;
   this.align;
   this.vspace;
   this.size;
   this.spacer   = 15;
   this.text_pad = '';
   this.tabindex;

   if(arguments.length > 0)
   {
      this.text     = (arguments[0] == null) ? "REQUIRED"                     : arguments[0];
      this.href     = (arguments[1] == null) ? "javascript:alert('REQUIRED')" : arguments[1];
      this.id       = (arguments[2] == null) ? "ID_" + this.text              : arguments[2];
      this.width    = (arguments[3] == null) ? this.width                     : arguments[3];
      this.align    = (arguments[4] == null) ? this.align                     : arguments[4];
      this.vspace   = (arguments[5] == null) ? this.vspace                    : arguments[5];
      this.size     = (arguments[6] == null) ? this.size                      : arguments[6];
      this.spacer   = (arguments[7] == null) ? this.spacer                    : arguments[7];
      this.text_pad = (arguments[8] == null) ? this.text_pad                  : arguments[8];
      this.tabindex = (arguments[9] == null) ? this.tabindex                  : arguments[9];

      buttonConstructor( this );
   }
}

/*
 * Pass in button objects (see above) to create a row of buttons.
 *    buttonConstructor( MyButton )
 *  (Use inside of script tags)
 */
function buttonConstructor()
{
   var numberOfArgs  = arguments.length;
   var alignHtml     = "";
   var vspacePx      = 5;
   var sizeHtml      = "";
   // If one of the constructs sets one of these attributes, they all will get it.
   for(var ii = 0; ii < numberOfArgs; ii++)
   {
      var button_ii = arguments[ii];
      if(button_ii.align != null)
      {
         alignHtml = ' align="' + button_ii.align + '"';
      }
      if(button_ii.size != null)
      {
         sizeHtml = ' style="font-size: ' + button_ii.size + 'px;"';
      }
      if(button_ii.vspace != null)
      {
         vspacePx = button_ii.vspace;
      }
   }
   document.writeln( '<div><img src="./healthecare/ui/images/spacer.gif" width="1" height="' + vspacePx + '" alt=""></div>' );
   document.writeln(
      '<div' + alignHtml + '>'
    + '   <table cellspacing="0" cellpadding="0" border="0">'
    + '      <tr>' );
   for(var i = 0; i < numberOfArgs; i++)
   {
      var button_i = arguments[i];
      var button_i_htmlId     = (button_i.id == null)       ? '' : ' id="' + button_i.id + '"';
      var button_i_htmlBorder = ( isNetscape4 )             ? '' : ' id="buttonConstructorBorder"';
      var tabindexHtml        = (button_i.tabindex == null) ? '' : ' tabindex="' + button_i.tabindex + '"';
      document.writeln(
        '<td nowrap="yes" class="buttonConstructorBg"' + button_i_htmlBorder + '>'
       + '<div id="buttonConstructorContainer"><a href="' + button_i.href + '"' + button_i_htmlId + ' class="buttonConstructorAnchor"' + sizeHtml + tabindexHtml + '>' + button_i.text_pad + button_i.text + button_i.text_pad + '</a></div>'
       + '<div><img src="./healthecare/ui/images/spacer.gif" width="' + button_i.width + '" height="1" border="0" alt=""></div>'
       +'</td>'
                      );
      if(i+1 < numberOfArgs)
      {
         document.writeln('<td><img src="./healthecare/ui/images/spacer.gif" width="' + button_i.spacer + '" height="1" alt=""></td>');
      }
   }
   document.writeln(
      '      </tr>'
    + '   </table>'
    + '</div>'     );
   document.writeln( '<div><img src="./healthecare/ui/images/spacer.gif" width="1" height="' + vspacePx + '" alt=""></div>' );
}

// Easy access to buttonConstruct & buttonConstructor().
function ezButton(buttonText, buttonHref, buttonId, buttonWidth)
{
   var thisBtn = new buttonConstruct();

   thisBtn.text     = (buttonText  == null) ? "REQUIRED"                     : buttonText;
   thisBtn.href     = (buttonHref  == null) ? "javascript:alert('REQUIRED')" : buttonHref;
   thisBtn.id       = (buttonId    == null) ? "ID_" + thisBtn.text              : buttonId;
   thisBtn.width    = buttonWidth;

   buttonConstructor( thisBtn );
}

// buttonMaker is being fazed out.
// Please use buttonConstruct() & buttonConstructor()
function buttonMaker()
{
   var argCount              = arguments.length;
   var multiBtnArray         = new Array;
   var btnCount              = 0;

   for(var i = 0; i < argCount; i++ )
   {
       // Loop through arguments. Create a new construct for each.
      if( (i+1) % 2 != 0 )
      {
         multiBtnArray[btnCount] = new buttonConstruct();
         multiBtnArray[btnCount].text = arguments[i+1];
         multiBtnArray[btnCount].href = arguments[i];
         btnCount++
      }
   }
// This is clunky; could not get NS4 to work with dynamic code ( eval() ).
   switch(btnCount)
   {
      case 1 :
         buttonConstructor( multiBtnArray[0] );
         break;
      case 2 :
         buttonConstructor( multiBtnArray[0], multiBtnArray[1] );
         break;
      case 3 :
         buttonConstructor( multiBtnArray[0], multiBtnArray[1], multiBtnArray[2] );
         break;
      case 4 :
         buttonConstructor( multiBtnArray[0], multiBtnArray[1], multiBtnArray[2],
                            multiBtnArray[3] );
         break;
      case 5 :
         buttonConstructor( multiBtnArray[0], multiBtnArray[1], multiBtnArray[2],
                            multiBtnArray[3], multiBtnArray[4] );
         break;
      case 6 :
         buttonConstructor( multiBtnArray[0], multiBtnArray[1], multiBtnArray[2],
                            multiBtnArray[3], multiBtnArray[4], multiBtnArray[5] );
         break;
   }
}


// @todo merge this and above into one - base - framework - TBD taglib | js
function buttonMakerLight()
{
   var hrefText;
   var linkText;
   var textSpacer    = ' &nbsp;&nbsp; ';       // Leading and trailing space on button text.
   var btnSpacer     = 15;             // Space between buttons in pixels.
   var argCount      = arguments.length;
   var multiBtnArray = new Array;
   var btnCount      = 0;

   for(var i = 0; i < argCount; i++ )
   {
      // Loop through arguments. Add the next odd and even numbered ones.
      if( (i+1) % 2 != 0 )
      {
          multiBtnArray[btnCount] = new Array(arguments[i], arguments[i+1]);
          btnCount++
      }
   }
    // These are the ends of the buttons, then we set up the table.
    document.writeln('<table cellpadding="0" cellspacing="0" border="0">');
    document.writeln(' <tr>');
    
    // Loop through the button array and build the button.
    for(var j = 0; j < multiBtnArray.length; j++)
    {
      hrefText = multiBtnArray[j][0];
      linkText = textSpacer + multiBtnArray[j][1] + textSpacer;
      document.writeln(' <td> ');
      document.writeln('<table cellpadding="0" cellspacing="0" border="0" background="/healthecare/ui/images/spacer.gif">');
      document.writeln('<tr><td colspan="3" bgcolor="#FFFFFF" height="1"><img src="/healthecare/ui/images/spacer.gif" width="1" height="1" hspace="0" vspace="0"></td></tr>');
      document.writeln('<tr>');
      document.writeln('  <td bgcolor="#FFFFFF"><img src="/healthecare/ui/images/spacer.gif" width="1" height="22"></td>');
      document.writeln('  <td bgcolor="#F4D200" nowrap align="center"><span class="buttonMakerLightOrange">' + linkText.link(hrefText) + '</span></td>');
      document.writeln('  <td bgcolor="#936009"><img src="/healthecare/ui/images/spacer.gif" width="1" height="1"></td>');
      document.writeln('</tr>');
      document.writeln('<tr><td colspan="3" bgcolor="#936009" height="1"><img src="/healthecare/ui/images/spacer.gif" width="1" hspace="0" vspace="0" height="1"></td></tr>');
      document.writeln('</table>');
      document.writeln(' </td> ');
      
      // If there is another button, insert a spacer cell.
      if( (j+1) < multiBtnArray.length )
      {
          document.writeln('  <td><img src="/healthecare/ui/images/spacer.gif" width="' + btnSpacer + '" height="1" alt=""></td>');
      }
       
   }
   // Close the table.
   document.writeln(' </tr>');
   document.writeln('</table>');
}

/* ***** dhTable BEGIN *****
 *  Create Tables with Definity Health style.
 * [] dhType choices       = Tool, Info, Content, tip
 * [] headerText           = Optional Text; Keep it short, it will not wrap.
 * [] headerIcon           = Optional Logo.
 *
 * vvvvvvvvvv USAGE EXAMPLE vvvvvvvvvv
 * <script language="JavaScript1.3" type="text/javascript">
 * dhTableOpen('Tool', 'Help Me Find...', 'DrHospital.gif' );
 * </script>
 *   ***** Content goes here *****
 * <script language="JavaScript1.3" type="text/javascript">
 * dhTableClose('Tool');
 * </script>
 * ^^^^^^^^^^ USAGE EXAMPLE ^^^^^^^^^^
 */
function dhTableOpen(dhType, headerText, headerIcon, cornerSize)
{
   var cornerSize    = ( cornerSize == null || cornerSize == '' ) ? 20 : cornerSize;
   var headerContent = ( headerText == null || headerText == '' ) ? '<img src="/healthecare/ui/images/spacer.gif" width="1" height="1" alt="" />' : '&nbsp;' + headerText;
   if( !(headerIcon == null || headerIcon == '') )
   {  
      headerContent += '<img src="/healthecare/ui/images/dhTable/icons/' + headerIcon + '" hspace="5" vspace="3" align="absbottom" alt="" />';
   }
   var headerStyle   = dhType + 'Heading';
   var borderStyle   = dhType + 'ColorBorder';
   var bgStyle       = dhType + 'ColorBg';

   var htmlChunk     = "";

if (!isNetscape4)
{
   // Container Row1 BEGIN
	htmlChunk += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
   htmlChunk += ' <tr height="' + cornerSize + '">';
	htmlChunk += '  <td nowrap="yes" class="' + borderStyle + '"><div class="' + headerStyle + '">' + headerContent + '</div></td>'
   htmlChunk += ' </tr>';
   // Container Row1 END
   // Container Row2 BEGIN
   htmlChunk += ' <tr>';
   htmlChunk += '  <td class="' + borderStyle + '">';
   // Content space BEGIN
   htmlChunk += '   <table width="100%" border="0" cellspacing="2" cellpadding="0">';
   htmlChunk += '    <tr>';
   htmlChunk += '     <td class="' + bgStyle + '">';
}
else
{
   // Container Row1 BEGIN
	htmlChunk += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
   htmlChunk += ' <tr height="' + cornerSize + '">';
	htmlChunk += '  <td nowrap="yes" class="' + borderStyle + '"><div class="' + headerStyle + '">' + headerContent + '</div></td>'
   htmlChunk += ' </tr>';
   // Container Row1 END
   // Container Row2 BEGIN
   htmlChunk += ' <tr class="' + borderStyle + '">';
   htmlChunk += '  <td class="' + bgStyle + '">';
   // Content space BEGIN

}
   // Continues in dhTableClose()
   document.write(htmlChunk);
}

function dhTableClose(dhType, cornerSize)
{
   var cornerSize    = ( cornerSize == null || cornerSize == '' ) ? 20 : cornerSize;
   var borderStyle   = dhType + 'ColorBorder';
   var bgStyle       = dhType + 'ColorBg';
   var htmlChunk     = "";

if (!isNetscape4)
{
   htmlChunk += '     </td>';
   htmlChunk += '    </tr>';
   htmlChunk += '   </table>';
   // Content space END
	htmlChunk += '  </td>';
	htmlChunk += ' </tr>';
   // Container Row2 END
   // Container Row3 BEGIN
	htmlChunk += ' <tr>';
	htmlChunk += '  <td class="' + borderStyle + '">';
   htmlChunk += '<img src="/healthecare/ui/images/spacer.gif" width="1" height="1" alt="" />';
	htmlChunk += '</td>';
	htmlChunk += ' </tr>';
   htmlChunk += '</table>';
   // Container Row3 END
}
else
{
   htmlChunk += '     </td>';
   htmlChunk += '    </tr>';
   htmlChunk += '   </table>';
}
   document.write(htmlChunk);
}

// Writes "on-page" error message.
function dhError(errorMessage)
{
   dhTip(errorMessage);
}


// Writes "on-page" information message.
function dhAlert( message )
{
   var errorMessageHTML = '<blockquote class="errorMargins">' + message + '</blockquote>';
	dhTableOpen('Error', 'Error Message', 'Error_Icon.gif');
	document.writeln(errorMessageHTML);
	dhTableClose('Error');
}

function dhTip( message )
{
   var messageHTML = '<blockquote class="tipMargins">' + message + '</blockquote>';
	dhTableOpen('Tip', 'Tip', 'icon_tip.gif');
	document.writeln(messageHTML);
	dhTableClose('Tip');
}
// ***** dhTable END *****
