<%@ Page Language="c#" AutoEventWireup="false" ValidateRequest="false" Inherits="net.ivoa.tools.TableImport" %>

<%@ Register TagPrefix="uc1" TagName="Trailer" Src="Trailer.ascx" %>
<%@ Register TagPrefix="uc2" TagName="Header" Src="top.ascx" %>
<%@ Import Namespace="edu.jhu.Cas.Util" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Table Import</title>
    <style type="text/css">
    legend{
    font-weight:bold;
    }
    </style>
    <link href="cjobs.css" rel="stylesheet" />
</head>
<body>
    <uc2:Header ID="Header" runat="server" />
    <div style="width: 510">
        <form id="ImportTable" method="post" runat="server" enctype="multipart/form-data">
            <h1>
                Table Import</h1>
            <div>
                <ul style="margin: 0 0 0 0;">
                    <li>Copy/Paste data (all formats) may not exceed <b>
                        <%=MAX_PASTE_CHARS %>
                        characters </b>.</li>
                    <li>VOTable and DataSet files may not exceed <b>
                        <%=MaxSize / 1024 %>
                        kB</b>. </li>
                    <li>CSV (ASCII Comma-Separated Values) files may not exceed <b>
                        <%=MaxSize / 1024 %>
                        kB</b>. </li>
                    <li>First line <b>must</b> have column names, optionally with "#" as first character.
                    </li>
                    <li>If importing into an existing table, column order in the table to be imported must
                        match mydb table column order. </li>
                </ul>
            </div>
            <br />
            <div id="initPane" <%if (!showinit) { %> style="display: block" <%}%>>
                <fieldset>
                    <legend>Import into...<span style="width:10px">&nbsp;</span>
                        <select id="tableTypeDDL" name="tableTypeDDL" onchange="setTableType();">
                            <option value="0">New Table</option>
                            <option value="1">Existing Table</option>
                        </select>
                    </legend>
                    <div id="newTable" style="display:none;">
                        <input type="text" name="NameBox" id="NameBox" style="width: 100%" value="<%=tableName %>" />
                    </div>
                    <div id="exTable" style="display:none;">
                        <select id="tnameDDL" name="tnameDDL">
                            <%foreach (string t in tables) { %>
                            <option value="<%=t %>">
                                <%=t %>
                            </option>
                            <%} %>
                        </select>
                    </div>
                </fieldset>
                <fieldset>
                    <legend>Format</legend>
                    <select id="DataType" name="DataType">
                        <option value="0">Comma/Space/Tab Separated</option>
                        <option value="1">VOTable XML</option>
                        <option value="2">MS DataSet XML</option>
                    </select>
                    <%if (enableFormatType) {%>
                    <div>
                        <input class="clean" type="radio" id="nofType" name="formatType" value="0" onclick="resetFType();"
                            checked="checked" />Import my table as-is
                        <br />
                        <input class="clean" type="radio" id="fType" name="formatType" value="1" onclick="resetFType();" />Automatically
                        format my table for XMatch
                    </div>
                    <%}%>
                    <div id="ftypeBox" style="display: none">
                        <fieldset>
                            <legend>Specify Format</legend>
                            <select id="DataFormat" name="DataFormat">
                                <option value="3">RA/DEC in Degrees</option>
                                <option value="1">Single Column RA/DEC in H/M/S</option>
                                <option value="2">Three Column RA/DEC in H/M/S</option>
                                <option value="0">X/Y/Z</option>
                            </select>
                            <br />
                            <p>
                                Sigma:&nbsp;<input type="text" id="sigmaBox" name="sigmaBox" size="5" />
                                arcsec (approximate accuracy of upload)</p>
                        </fieldset>
                    </div>
                </fieldset>
                <fieldset>
                    <legend>Data Type</legend>
                    <input class="clean" type="radio" id="cpType" name="importType" value="0" onclick="resetType();" />Copy
                    & paste import<br />
                    <input class="clean" type="radio" id="ftpType" name="importType" value="1" checked="checked"
                        onclick="resetType();" />File import
                    <div>
                        <div id="cpBox" style="display: none;">
                            <fieldset>
                                <legend>Data</legend>
                                <textarea id="DataBox" name="DataBox" textmode="MultiLine" rows="" cols="" style="width: 100%;
                                    height: 200" /></textarea>
                            </fieldset>
                        </div>
                        <div id="ftpBox" style="display: none;">
                            <fieldset>
                                <legend>File Name</legend>
                                <input type="file" size="60" id="httpBox" runat="server" name="httpBox" />
                            </fieldset>
                        </div>
                    </div>
                </fieldset>
            </div>
            <p class="message">
                <%=message%>
            </p>
            <div style="margin-top:5">
                <input type="submit" value="Import" id="ImportButton" /></div>
        </form>
    </div>

    <script type="text/javascript">
resetType();
resetFType();
setTableType();
function resetType(){
	var cpType = document.getElementById('cpType').checked;
	if(cpType){
		document.getElementById('cpBox').style.display = 'block';
		document.getElementById('ftpBox').style.display = 'none';
	}else{
		document.getElementById('ftpBox').style.display = 'block';
		document.getElementById('cpBox').style.display = 'none';
	}
}
function resetFType(){
    if(document.getElementById('fType')){
	    var fType = document.getElementById('fType').checked;
	    if(fType) document.getElementById('ftypeBox').style.display = 'block';
	    else document.getElementById('ftypeBox').style.display = 'none';
	}
}
function setTableType(){
    var ttddl = document.getElementById('tableTypeDDL');
    switch(ttddl.selectedIndex){
        case 0:
            document.getElementById('newTable').style.display = 'block';
            document.getElementById('exTable').style.display = 'none';
        break;
        case 1:
        document.getElementById('newTable').style.display = 'none';
            document.getElementById('exTable').style.display = 'block';
        break;
    }
}
    </script>

    <uc1:Trailer ID="Trailer1" runat="server" cvsTag="$Name$" cvsRev="$Revision: 142439 $">
    </uc1:Trailer>
</body>
</html>
