<%@ Import Namespace="System.Data" %>
<%@ Register TagPrefix="uc1" TagName="Trailer" Src="Trailer.ascx" %>
<%@ Register TagPrefix="uc2" TagName="Header" Src="top.ascx" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="edu.jhu.Cas.Jobs" %>
<%@ Import Namespace="edu.jhu.Cas.Web" %>
<%@ Import Namespace="edu.jhu.Cas.Util" %>
<%@ Import Namespace="System.Web" %>

<%@ Page Language="c#" ValidateRequest="false" AutoEventWireup="false" Inherits="edu.jhu.Cas.Web.SubmitJob"
    EnableViewState="true" EnableViewStateMac="true" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Pragma" content="no-cache" />
    <title>CasJobs</title>
    <link href="cjobs.css" rel="stylesheet" />
<script type="text/javascript" src="scripts/submitjob.js"></script>
    <script type="text/javascript" language="JavaScript">
        var queryIsRunning = false;
        function completeQuery(){   
            if(queryIsRunning){ 
                document.getElementById('message').className = 'happy';
                document.getElementById('message').innerHTML = 'Query complete!';
                showExecButtons();
                setEditorMid();
                queryIsRunning = false;
            }
        }
        function trmenu(){
            if(window.frames['resultPane'].document.body.innerHTML.length < 15)
                document.getElementById('menuRow').style.display = 'none';
            else{
                document.getElementById('menuRow').style.display = '';
                setEditorMid();
            }
        }
    </script>
    <style type="text/css">
        table{
            padding: 0 0 0 0;
            margin: 0 0 0 0;
        }
    </style>
</head>
<body style="padding: 0 0 0 0; margin: 0 0 0 0" onload="initHist();">
    <form name="SubmitJob" id="SubmitJob" action="SubmitJob.aspx" method="post" target="_top"
        style="padding: 0 0 0 0; margin: 0 0 0 0">
        <input type="hidden" id="queue" name="queue" value="1" style="display: none;" />
        <table cellspacing="0" cellpadding="0" id="mostEverything" style="width: 100%; height: 100%">
            <tr>
                <td>
                    <uc2:Header ID="Header" runat="server" />
                </td>
            </tr>
            <tr>
                <td>
                    <table style="width: 100%">
                        <tr>
                            <th class="mover">
                                <a href="#" onmouseover="showqsnode('contextHelpDiv');" onmouseout="hideqsnode();">Context</a></th>
                            <th class="mover" style="white-space: nowrap">
                                <a href="#" onmouseover="showqsnode('tableHelpDiv');" onmouseout="hideqsnode();">Table <span style="font-weight: normal"
                                    size="-2">(optional)</span></a></th>
                            <th class="mover" style="width: 100%">
                                <a href="#" onmouseover="showqsnode('taskNameHelpDiv');" onmouseout="hideqsnode();">Task Name</a></th>
                        </tr>
                        <tr>
                            <%if (SYSTEM.ENABLE_ALT_SOURCES) { %>
                            <td align="center">
                                <select style="width: 100%" name="type" id="typeDDL">
                                    <option>Classic</option>
                                    <option>Cube</option>
                                </select>
                            </td>
                            <%} %>
                            <td align="center">
                                <select name="targest" id="targetDDL">
                                    <%foreach (string s in sList) {%>
                                    <option <%=targisselected(s)%>>
                                        <%=s%>
                                    </option>
                                    <%}%>
                                </select>
                            </td>
                            <td align="center" style="width: 100px">
                                <input type="text" style="width: 100%" id="table" name="table" value="<%=GetUniqueTableName()%>" /></td>
                            <td align="center">
                                <input type="text" name="taskname" style="width: 100%" value="<%=getTaskName()%>" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table id="querypane" cellspacing="1" cellpadding="0" class="bar" style="padding: 0 0 0 0;
                        width: 100%;">
                        <tr>
                            <td style="text-align: center;">
                                <input id="sampCheck" type="button" value="Samples" onclick="toggleSamples();" />
                            </td>
                            <td style="text-align: center;">
                                <input id="histCheck" type="button" value="Recent" onclick="toggleHist();" />
                            </td>
                            <td style="text-align: center;">
                                <input id="clearButton" type="button" onclick="clearQry();" value="Clear" />
                            </td>
                            <td>
                                <div class="footer" style="white-space: nowrap">
                                    &nbsp;Line <span id="rowLabel">1</span>, Col <span id="colLabel">1</span>
                                </div>
                            </td>
                            <td style="padding: 0 5 0 5; width: 25;">
                                <div style="white-space: nowrap" id="timer">
                                </div>
                            </td>
                            <td width="100%">
                                <div class="message" style="text-align: right; padding-right: 5; height: 15px; overflow: hidden;"
                                    onmouseover="cjshowqsM();" onmouseout="cjhideqsM();" id="message">
                                    <%=message%>
                                </div>
                                <div style="visibility: hidden; z-index: 100; position: absolute;" id="mmessage">
                                </div>
                            </td>
                            <td style="text-align: center;">
                                <input type="hidden" id="syntax" name="syntax" value="false" />
                                <input id="syntaxButton" title="Check Query Syntax." type="button" value="Syntax"
                                    onclick="checksyntax()" /></td>
                            <td style="text-align: center;">
                                <input id="planButton" title="Show estimated query plan." type="button" value="Plan"
                                    onclick="getplan();" /></td>
                            <td style="text-align: center;">
                                <input id="quickButton" title="Runs the query instantaneously.  Limited to one minute and 1000 rows."
                                    value="Quick" type="button" onclick="submitQuickQuery();" /></td>
                            <td style="text-align: center">
                                <input id="submitButton" value="Submit" title="Submits your query.  Limitited to size of MyDB and 500 minutes."
                                    type="button" onclick="submitQuery();" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr id="queryRow">
                <td id="queryCell" height="100%" style="padding:0 1 1 0">
                    <textarea onmousedown="hideFloats();"
                        wrap="off" cols="80" onkeyup="setPosition();" onclick="setPosition();" name="sql"
                        id="sql" style="margin: 0 0 0 0;padding:0 0 0 0;width: 100%; height: 100%;"><%=GetQuery()%></textarea></td>
            </tr>
            <tr id="resultsRow" style="display:none;">
                <td id="resultsCell" width="100%" height="65%">
                    <iframe name="resultPane" id="resultPane" height="100%" style="height: 100%; width: 100%"
                        src="output/vodataclean.aspx" frameborder="0" onload="trmenu();" scrolling="auto"></iframe>
                </td>
            </tr>
            <tr id="menuRow">
                <td>
                    <table class="bar" id="windowMenu" cellpadding="0" cellspacing="1" border="0" style="width: 100%;">
                        <tr>
                            <td>
                                <input type="button" value="Plot" onclick="window.open('output/voplot/loadjvt.aspx','plot','');" />
                            </td>
                            <td>
                                <input type="button" value="Save As" onclick="save();" />
                            </td>
                            <td>
                                <select id="ddl">
                                    <option>HTML</option>
                                    <option>CSV</option>
                                    <option>VOTable</option>
                                    <option>DataSet</option>
                                </select>
                            </td>
                            <td width="100%">
                                &nbsp;
                            </td>
                            <td style="padding-right: 5;">
                            </td>
                            <td>
                                <input type="button" value="Query" onclick="maxQuery();" />
                            </td>
                            <td>
                                <input type="button" value="Results" onclick="maxResults();" />
                            </td>
                            <td>
                                <input type="button" value="Both" onclick="setEditorMid();" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="">
                    <uc1:Trailer ID="Trailer1" runat="server" cvsTag="$Name: v3_5_18 $" cvsRev="$Revision: 1.70 $">
                    </uc1:Trailer>
                </td>
            </tr>
        </table>
    </form>
    <form name="svqry" id="Form1" action="output/svqry.aspx" method="post" target="hidden"
        style="display: none;">
        <input type="hidden" name="USQL" id="USQL" value="" />
        <input type="hidden" name="UCONTEXT" id="UCONTEXT" value="" />
    </form>
    <iframe name="hidden" style="display: none"></iframe>
    <input type="hidden" id="wsid" value="<%=wsid%>" />
    <div id="samples" style="position: absolute; display: none; width: 200; vertical-align: text-top;
        overflow: auto; z-index: 100; padding: 2 2 2 2;">
        <div>
            <%=LoadSamples()%>
        </div>
    </div>
    <div id="hist" style="position: absolute; display: none; vertical-align: text-top;
        overflow: auto; z-index: 100; padding: 2 2 2 2;">
    </div>
    <div style="">
        <%=LoadSamplesInfo()%>
    </div>
    <div id="tableHelpDiv" class="qpopH">
        Submitted queries are required to direct their output into a table in MyDB. You
        can do this either by manually specifying 'select into' clause within your query,
        or by letting CasJobs automatically add the table in this field. Default table names
        in this field are usually unique.;
    </div>
    <div id="contextHelpDiv" class="qpopH">
        Your <i>context</i> selection determines in which database
        your query will be run. Even though a context may have multiple queues, every
        queue with the same <i>context</i> name contains identical data.
    </div>
    <div id="taskNameHelpDiv" class="qpopH">
        You can search your job history by taskname, so using a unique value in this field
        can help when searching for a particular job.
    </div>

    <script language="JavaScript" type="text/javascript" src="scripts/cookieMonster.js"></script>
    <script type="text/javascript" src="scripts/qspop.js"></script>
    <script type="text/javascript" src="scripts/urlcoder.js"></script>
    <script type="text/javascript" src="scripts/ajcrp.js"></script>
    <script type="text/javascript">
        resubmit = document.location.href.indexOf("resubmit") > -1;// || document.location.href.indexOf("sql") > -1;
        if(!resubmit)loadSubmitPage();
        window.onunload = saveSubmitPage;
        if(document.getElementById('samples').style.display == 'block')
            document.getElementById('sampCheck').checked = true;
    </script>
</body>
</html>
