<%--
    Document   : AccountRnewalBulkFileUpload
    Created on : Sep 29, 2018, 4:48:59 PM
    Author     : 1004242
--%>


<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Account Renewal Bulk File Upload</title>
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/styles.css?pacs=<%=((new java.util.Date()).getTime())%>"/>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/ButtonAndText.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/info.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <script src="${pageContext.request.contextPath}/js/Calendar.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/chromejs/chrome.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/js/iFrame_killer.js"></script>

    </head>
    <script>
    function sendFileToServer(temp)
        {
        if(temp==1){
        var fileName= document.getElementById("fileChooser").value
        var fileNameSplit=fileName.split('.');
        if(fileNameSplit[1]!="csv"){
            alert("Please choose .csv file only.");
            return;
        }
        else{
            document.forms[0].submit();
            var formUploadMultiPart = document.getElementById("BulkFileIdUpload");
            formUploadMultiPart.action = '/PacsApplication/AccountRewnewBulkServlet';
            formUploadMultiPart.submit();
        }
        }
        else if(temp==2)
            {
                 var formDownloadNormal = document.getElementById("BulkFileIdDownload");
                 formDownloadNormal.action = '/PacsApplication/AccountRewnewBulkServlet';
                 formDownloadNormal.submit();
            }
        else if(temp==3)
            {
                if( BulkFileReport.fileId.value == ""  )
                {
                    alert("Please provide File Id.");
                    BulkFileReport.fileId.focus();
                    return false;
                }
                        var formDownloadReport = document.getElementById("BulkFileReport");
                        formDownloadReport.reportPath.value = "/Reports/bulk_kcc_renewal_report";
                        formDownloadReport.reportName.value = "Bulk KCC Renewal Report";
                        formDownloadReport.DOWNLOAD.value = "P";
                        formDownloadReport.action = '/PacsApplication/ExcelReportServlet';
                        formDownloadReport.submit();
            }
    }

    function toggleDiv(temp)
{
    document.getElementById("errorMessageTag").innerHTML="";
    if(temp == 1 && document.getElementById("FileTypeId").value == 'Def'){
        alert("Please select an option first.");
    }
    else if (temp == 1 && document.getElementById("FileTypeId").value == 'Upload'){
        document.getElementById("UploadDiv").style.display='block';
        document.getElementById("SelectDiv").style.display='none';
    }
    else if(temp == 1 && document.getElementById("FileTypeId").value == 'Download'){
        document.getElementById("ReportDiv").style.display='block';
        document.getElementById("SelectDiv").style.display='none';
    }
    else if(temp==2 ){
        document.getElementById("ReportDiv").style.display='none';
        document.getElementById("SelectDiv").style.display='block';
    }
    else if(temp==3 ){
        document.getElementById("UploadDiv").style.display='none';
        document.getElementById("SelectDiv").style.display='block';
    }
}
     function popup_bulkFile(width, height, fileId) {
            if (window.innerWidth) {
                LeftPosition = (window.innerWidth - width) / 2;
                TopPosition = ((window.innerHeight - height) / 2) - 20;
            }
            else {
                LeftPosition = (parseInt(window.screen.width) - width) / 2;
                TopPosition = ((parseInt(window.screen.height) - height) / 2) - 20;
            }
            attr = 'resizable=yes,scrollbars=yes,width=' + width + ',height=' +
                height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
                TopPosition + '';
            var screenName = "AccountRenewalBulk.jsp";
            var lovKey = "bulkReport";
            popWin = open('${pageContext.request.contextPath}/CommonSearchInfoLOVNew.jsp?fileId=' + fileId + '&screenName=' + screenName + '&lovKey=' + lovKey, 'bulkReport', attr);
            popWin.focus();

        }
        
        // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
            
     </script>
    <body>

        <jsp:include page="MenuHead.jsp" flush="true" />
        <br>
        <fieldset style="border-color: black; background-image: url('/PacsApplication/img/download.jpg'); border-width: 3px">
            <legend style="padding: 8px; border-radius: 20px; background-color: #006600; color: white">Account Renewal Bulk File Upload</legend>
            <center>
                <div id="SelectDiv">
                    <table>
                        <tr>
                            <td>Select Operation</td>
                            <td>
                                <select id="FileTypeId" name="FileType" onchange="toggleDiv(1)">
                                    <option value="Def" selected> --Select-- </option>
                                    <option value="Upload" >Upload Renewal Bulk File</option>
                                    <option value="Download" >Generate Renewal Bulk File Process Report</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </div>
            </center>
            <div id="UploadDiv" style="display:none">
                <form name="BulkFile" id="BulkFileIdUpload" action="" method="post" enctype="multipart/form-data">
                    <center>


                        Select file to upload:
                        <input type="file" name="dataFile" id="fileChooser"/><br/><font color="blue" >*Supported File type: csv</font><br/><br/>
                        <input type="button" value="Upload" id ="FileTypeIdUpload" name="FileType" onclick="sendFileToServer(1)"/>
                        <input type="button" value="Back" id ="BackIdU" name="BackIdUButton" onclick="toggleDiv(3)"/>



                    </center>
                </form>
                <form name="BulkFileSample" id="BulkFileIdDownload" action="" method="post" >


                        <input type="hidden" id="actionId" value="Download" name="actionTag">
                        <input type="button" value="Download Manual Document" id ="FileTypeIdDownload" name="FileType" onclick="sendFileToServer(2)" style="float: right"/>



                </form>
             </div>
             <div id="ReportDiv" style="display:none">
                 <form name="BulkFileReport" id="BulkFileReport" action="" method="post" >
                 <center>
                        <td>File Id:</td>
                        <td><input type="text" name="fileId" id="fileId" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                        <td><input type="button"  value="Search" onclick="javascript:popup_bulkFile(750, 250,document.BulkFileReport.fileId.value);"/></td>
                        <br><br>
                        <input type="button" value="Download Bulk Report" id ="ReportDownload" name="ReportType" onclick="sendFileToServer(3)" style="float: center"/>
                        <input type="button" value="Back" id ="BackIdU" name="BackIdUButton" onclick="toggleDiv(2)"/>

                    <input type="hidden" name="reportPath" value=""/>
                    <input type="hidden" name="reportName" value=""/>
                    <input type="hidden" name="DOWNLOAD" value=""/>
                    </center>
                   </form>
                    <br><br>
             </div>
            <div id="errorMessageTag"style="color: #FF0000;">${errorMessageAccBulk}</div>
        </fieldset>
    </body>
</html>
