﻿function getBoxHtml(bolImageLeft, strBoxTitle, strBackgroundImageUrl, intBackgroundImageHeight,
                    intLeftColumnWidth, strHeader, intHeaderHeight, arrStrContent, strPdfUrl) {

    var bolImageRight = !bolImageLeft;
    var intTotalBoxWidth = 610;
    var intPdfImageHeight = 20;
    var intPdfImageWidth = 20;

    var bolIncludePdfLink = (strPdfUrl != null && strPdfUrl.length > 0);
    var intContentHeight = intBackgroundImageHeight - intHeaderHeight - ((bolIncludePdfLink) ? (intPdfImageHeight) : (0));
    if (bolImageRight && bolIncludePdfLink) {
        intContentHeight -= intPdfImageHeight;
    }

    var strContent = "";
    for (var i = 0; i < arrStrContent.length; i++) {
        if (arrStrContent[i].substring(0, 5) == "*NOP*") {
            strContent += arrStrContent[i].substring(5);
        }
        else {
            strContent += "<p" + ((bolImageRight) ? (" style=\"margin-left: 0px; padding-left: 0px\"") : ("")) + ">" + arrStrContent[i] + "</p>";
        }
    }
    
    var strBoxHtml = "\
			                    <table width=\"" + intTotalBoxWidth + "px\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\
				                    <tr>\
                                        <td>\
                                            <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\
                                                <tr>\
                                                    <td class=\"BoxTopLeftCorner\"></td>\
                                                    <td class=\"BoxMiddleTop\" style=\"width: " + (Math.round(intTotalBoxWidth / 2)) + "px;\">\
                                                        <div class=\"BoxTitle\">\
                                                            " + strBoxTitle + "\
                                                        </div>\
                                                    </td>\
                                                    <td class=\"BoxMiddleTop\">\
                                                        <div class=\"BoxTitleShadow\" style=\"left: -" + (Math.round(intTotalBoxWidth / 2) - 9) + "px;\">\
                                                            " + strBoxTitle + "\
                                                        </div>\
                                                    </td>\
                                                    <td class=\"BoxTopRightCorner\"></td>\
                                                </tr>\
                                            </table>\
                                        </td>\
				                    </tr>\
				                    <tr>\
                                        <td>\
                                            <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\
                                                <tr>\
                                                    <td class=\"BoxMiddleLeft\"></td>\
                                                    <td style=\"background-image: url(" + strBackgroundImageUrl + "); background-repeat: no-repeat; background-position: bottom; padding: 0px 14px 0px 15px; height: " + intBackgroundImageHeight + "px\" valign=\"top\">\
                                                        <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">\
                                                            <tr>\
                                                                " + ((bolImageLeft) ? ("<td height=\"" + intBackgroundImageHeight + "px\" width=\"" + intLeftColumnWidth + "px\">&nbsp;</td>") : ("")) + "\
                                                                <td valign=\"top\"" + ((bolImageLeft) ? ("") : (" width=\"" + intLeftColumnWidth + "px\"")) + ">\
                                                                    <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">\
                                                                        <tr>\
                                                                            <td valign=\"bottom\" height=\"" + intHeaderHeight + "px\">\
                                                                                <p style=\"font-size: 12px; font-weight: bold; color: #FFB522; margin-bottom: 0px; padding-bottom: 0px" + ((!bolImageLeft) ? ("; margin-left: 0px; padding-left: 0px") : ("")) + "\">" + strHeader + "</p>\
                                                                            </td>\
                                                                        </tr>\
                                                                        <tr>\
                                                                            <td valign=\"top\" height=\"" + intContentHeight + "px\">\
                                                                                " + strContent + "\
                                                                            </td>\
                                                                        </tr>\
                                                                        " +
                                                                        ((!bolIncludePdfLink || bolImageRight) ? ("") :
                                                                            ("<tr>\
                                                                                  <td height=\"" + intPdfImageHeight + "px\" valign=\"bottom\" align=\"right\">\
                                                                                      <a href=\"" + strPdfUrl + "\" target=\"_blank\" onfocus=\"if (this.blur) this.blur()\">\
                                                                                          <img src=\"images/Blank.gif\" width=\"" + intPdfImageWidth + "\" height=\"" + intPdfImageHeight + "\" border=\"0\" hspace=\"2\" />\
                                                                                      </a> \
                                                                                  </td>\
                                                                              </tr>"
                                                                             )) + "\
                                                                    </table>\
                                                                </td>\
                                                                " + ((!bolImageLeft) ? ("<td height=\"" + (intBackgroundImageHeight - ((bolIncludePdfLink && !bolImageLeft) ? (intPdfImageHeight) : (0))) + "px\">&nbsp;</td>") : ("")) + "\
                                                            </tr>\
                                                            " +
                                                            ((!bolIncludePdfLink || bolImageLeft) ? ("") :
                                                                ("<tr>\
                                                                      <td colspan=\"2\" height=\"" + intPdfImageHeight + "px\" valign=\"bottom\" align=\"right\">\
                                                                          <a href=\"" + strPdfUrl + "\" target=\"_blank\" onfocus=\"if (this.blur) this.blur()\">\
                                                                              <img src=\"images/Blank.gif\" width=\"" + intPdfImageWidth + "\" height=\"" + intPdfImageHeight + "\" border=\"0\" hspace=\"2\" />\
                                                                          </a> \
                                                                      </td>\
                                                                  </tr>"
                                                                 )) + "\
                                                        </table>\
                                                    </td>\
                                                    <td class=\"BoxMiddleRight\"></td>\
                                                </tr>\
                                            </table>\
                                        </td>\
				                    </tr>\
				                    <tr> \
                                        <td>\
                                            <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\
                                                <tr>\
                                                    <td class=\"BoxBottomLeftCorner\"></td>\
                                                    <td class=\"BoxMiddleBottom\">&nbsp;</td>\
                                                    <td class=\"BoxBottomRightCorner\"></td>\
                                                </tr>\
                                            </table>\
                                        </td>\
				                    </tr>\
			                    </table>\
			                ";
    return strBoxHtml;
}

