﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Html Preview </title>
    <script src="Scripts/jquery1.8.3.js" type="text/javascript"></script>
    <script src="../../../ClientGlobalContext.js.aspx"></script>
    <script language="javascript" type="text/javascript">
        window.onload = function () {
            var reportTable = "<table id=ReportSchedulerTable>" +
                             "<tr><th>Sr. No.</th><th>Link</th><th>Account Name</th><th>Main Phone</th><th>Address 1: City</th><th>Primary Contact</th><th>E-mail (Primary Contact)</th></tr>" +
                             "<tr><td class=datacellEven>1</td>" +
                             "<td class=datacellEven><a href='#' onclick=window.open('http://www.iotap.com/','targetWindow','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes'); return false; >Link</a></td>" +
                             "<td class=datacellEven>Account 1</td><td class=datacellEven>XXX-XXX-XXXX</td><td class=datacellEven>City1</td><td class=datacellEven>Contact1</td>" +
                             "<td class=datacellEven>contact1@email.com</td></tr>" +
                             "<tr><td class=datacellOdd>2</td>" +
                             "<td class=datacellOdd><a href='#' onclick=window.open('http://www.iotap.com/','targetWindow','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes'); return false;>Link</a></td>" +
                             "<td class=datacellOdd>Account 2</td><td class=datacellOdd>XXX-XXX-XXXX</td><td class=datacellOdd>City2</td><td class=datacellOdd>Contact2</td>" +
                             "<td class=datacellOdd>contact2@email.com</td></tr>" +
                             "<tr><td class=datacellEven>3</td>" +
                             "<td class=datacellEven><a href='#' onclick=window.open('http://www.iotap.com/','targetWindow','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes'); return false;>Link</a></td>" +
                             "<td class=datacellEven>Account 3</td><td class=datacellEven>XXX-XXX-XXXX</td><td class=datacellEven>City3</td><td class=datacellEven>Contact3</td>" +
                             "<td class=datacellEven>contact3@email.com</td></tr>" +
                             "<tr><td class=datacellOdd>4</td>" +
                             "<td class=datacellOdd><a href='#' onclick=window.open('http://www.iotap.com/','targetWindow','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes'); return false;>Link</a></td>" +
                             "<td class=datacellOdd>Account 4</td><td class=datacellOdd>XXX-XXX-XXXX</td><td class=datacellOdd>City4</td><td class=datacellOdd>Contact4</td>" +
                             "<td class=datacellOdd>contact4@email.com</td></tr>" +
                             "<tr><td class=datacellEven>5</td>" +
                             "<td class=datacellEven><a href='#' onclick=window.open('http://www.iotap.com/','targetWindow','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes'); return false;>Link</a></td>" +
                             "<td class=datacellEven>Account 5</td><td class=datacellEven>XXX-XXX-XXXX</td><td class=datacellEven>City5</td><td class=datacellEven>Contact5</td>" +
                             "<td class=datacellEven>contact5@email.com</td></tr>" +
                             "</table>";

            //var reportStyle = window.opener.document.getElementById('iotap_reporttablestyle').value;
            //var reportBody = window.opener.document.getElementById('iotap_htmltemplate').value;
            var reportStyle = window.opener.Xrm.Page.getAttribute("iotap_reporttablestyle").getValue();
            var reportBody = window.opener.Xrm.Page.getAttribute("iotap_htmltemplate").getValue();
            
            // If browser is mozila reportstyle & reportbody may be undefined
            if (typeof reportStyle == "undefined") {
                reportStyle = $("#iotap_reporttablestyle", window.opener.document).attr("title");
                reportBody = $("#iotap_htmltemplate", window.opener.document).attr("title");
            }

            var dt = new Date();

            reportBody = reportBody.indexOf("{ReportTableStyle}") > -1 ? reportBody.replace("{ReportTableStyle}", reportStyle) : reportBody;
            reportBody = reportBody.indexOf("{ReportName}") > -1 ? reportBody.replace("{ReportName}", "Preview") : reportBody;
            reportBody = reportBody.indexOf("{ReportDate}") > -1 ? reportBody.replace("{ReportDate}", (dt.getMonth() + 1 + "/" + dt.getDate() + "/" + dt.getFullYear() + " " + dt.toLocaleTimeString())) : reportBody;
            reportBody = reportBody.indexOf("{ReportOwner}") > -1 ? reportBody.replace("{ReportOwner}", "User") : reportBody;
            reportBody = reportBody.indexOf("{ReportComment}") > -1 ? reportBody.replace("{ReportComment}", "Comment lines") : reportBody;
            reportBody = reportBody.indexOf("{ReportTable}") > -1 ? reportBody.replace("{ReportTable}", reportTable) : reportBody;

            $("#lblHtmlPreview").html(reportBody);
        }
    </script>
</head>
<body>
    <div id="lblHtmlPreview">
    </div>
</body>
</html>
