/*
 * Generated by the Jasper component of Apache Tomcat
 * Version: Apache Tomcat/7.0.27
 * Generated at: 2014-05-12 06:10:29 UTC
 * Note: The last modified time of this file was set to
 *       the last modified time of the source file after
 *       generation to assist with modification tracking.
 */
package org.apache.jsp.WEB_002dINF.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class searchResult_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
  }

  public void _jspDestroy() {
  }

  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException, javax.servlet.ServletException {

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\n');
      out.write('\n');
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "/WEB-INF/jsp/header.jsp", out, false);
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("<script type=\"text/javascript\">\n");
      out.write("    var dataTable;\n");
      out.write("    // puts query string parameters in a object using Jquery bbq plugin\n");
      out.write("    // (https://github.com/cowboy/jquery-bbq)\n");
      out.write("    var urlParams = $.deparam.querystring();\n");
      out.write("\n");
      out.write("    $(function() {\n");
      out.write("\n");
      out.write("        $('#sdfDownloadLink a').attr('href','downloadHits?structure=' + urlParams['structure']\n");
      out.write("            + '&cas=' + urlParams['cas']+ '&compoundName=' + urlParams['compoundName']\n");
      out.write("            + '&compoundDescription=' + urlParams['compoundDescription']);\n");
      out.write("\n");
      out.write("        $('#dataTable').delegate('td img', 'click', function() {\n");
      out.write("            alert($(this).attr('alt'));\n");
      out.write("        });\n");
      out.write("\n");
      out.write("        var displayStart = 0;\n");
      out.write("        var displayLength = 4;\n");
      out.write("\n");
      out.write("        var scrollY = \"700\";\n");
      out.write("        if (screen.height<=768){\n");
      out.write("            displayLength = 3;\n");
      out.write("            scrollY = \"550\";\n");
      out.write("        }\n");
      out.write("\n");
      out.write("        if ($.bbq.getState('iDisplayStart')){\n");
      out.write("            displayStart = $.bbq.getState('iDisplayStart', true);\n");
      out.write("        }\n");
      out.write("\n");
      out.write("        dataTable = $('#dataTable').dataTable( {\n");
      out.write("            //\"sDom\": 'l<\"toolbar\">rtip',\n");
      out.write("            \"bProcessing\": true,\n");
      out.write("            \"bServerSide\": true,\n");
      out.write("            \"sAjaxSource\": \"/MDFSimpleWebApp/compound/search\",\n");
      out.write("            \"sAjaxDataProp\": \"aaData\",\n");
      out.write("            \"bLengthChange\": false,\n");
      out.write("            \"sScrollY\": scrollY,\n");
      out.write("            \"iDisplayLength\": displayLength,\n");
      out.write("            \"iDisplayStart\": displayStart,\n");
      out.write("            \"sPaginationType\": \"full_numbers\",\n");
      out.write("            \"bSort\": false,\n");
      out.write("            \"bFilter\": false,\n");
      out.write("            \"bAutoWidth\": false,\n");
      out.write("            \"aoColumns\": [\n");
      out.write("                {\n");
      out.write("                    \"sTitle\" : \"Structure\",\n");
      out.write("                    \"mData\": \"structure\",\n");
      out.write("                    \"bSearchable\": false,\n");
      out.write("                    \"bSortable\": false,\n");
      out.write("                    \"sWidth\": \"400px\",\n");
      out.write("                    \"fnRender\": function ( oObj ) {\n");
      out.write("                        if (oObj.aData['id'] != ''){\n");
      out.write("                            var smiles = oObj.aData['smiles'];\n");
      out.write("                            var html;\n");
      out.write("                            if(urlParams['structure']){\n");
      out.write("                            html = '<img alt=\"' + smiles\n");
      out.write("                                + '\" src=\"/MDFSimpleWebApp/compound/'\n");
      out.write("                                + oObj.aData['id'] + '/render/highlight/' + urlParams['structure'] +'\"/>';\n");
      out.write("                            } else {\n");
      out.write("                                html = '<img alt=\"' + smiles\n");
      out.write("                                + '\" src=\"/MDFSimpleWebApp/compound/'\n");
      out.write("                                + oObj.aData['id'] + '/render/\"/>';\n");
      out.write("                            }\n");
      out.write("                            return html;\n");
      out.write("                        } else {\n");
      out.write("                            return '';\n");
      out.write("                        }\n");
      out.write("                    }\n");
      out.write("                },\n");
      out.write("                {\n");
      out.write("                    \"sTitle\" : \"Compound Name\",\n");
      out.write("                    \"mDataProp\": \"compoundName\",\n");
      out.write("                    \"bSearchable\": true,\n");
      out.write("                    \"bSortable\": true,\n");
      out.write("                    \"sWidth\": \"200px\",\n");
      out.write("                    \"fnRender\": function ( oObj ) {\n");
      out.write("                        if (oObj.aData['compoundName'] != ''){\n");
      out.write("                            var html = '<a href=\"/MDFSimpleWebApp/compound/'\n");
      out.write("                                + oObj.aData['id'] + '/\">'\n");
      out.write("                                + oObj.aData['compoundName'] + '</a>';\n");
      out.write("                            return html;\n");
      out.write("                        } else {\n");
      out.write("                            return '';\n");
      out.write("                        }\n");
      out.write("                    }\n");
      out.write("                },\n");
      out.write("                {\n");
      out.write("                    \"sTitle\" : \"CAS\",\n");
      out.write("                    \"mData\": \"cas\", \"bSearchable\": true,\n");
      out.write("                    \"bSortable\": true,\n");
      out.write("                    \"sWidth\": \"50px\"\n");
      out.write("                }\n");
      out.write("            ],\n");
      out.write("            \"fnServerData\": function ( sSource, aoData, fnCallback ) {\n");
      out.write("                /* Add all request parameters to the AJAX call\n");
      out.write("                 * iDisplayStart and iDisplayLength are handeled by datatables\n");
      out.write("                 * -> do not forward them\n");
      out.write("                 */\n");
      out.write("                for (var key in urlParams){\n");
      out.write("                    if(key != \"iDisplayStart\" && key != \"iDisplayLength\"){\n");
      out.write("                        aoData.push( { \"name\": key, \"value\": urlParams[key] } );\n");
      out.write("                    }\n");
      out.write("                }\n");
      out.write("\n");
      out.write("                $.ajax( {\n");
      out.write("                    \"dataType\": 'json',\n");
      out.write("                    \"type\": \"GET\",\n");
      out.write("                    \"url\": sSource,\n");
      out.write("                    \"data\": aoData,\n");
      out.write("                    \"cache\": true,\n");
      out.write("                    \"success\": function(data){\n");
      out.write("                        fnServerSideCallback(data);\n");
      out.write("                        fnCallback(data); // draw the table\n");
      out.write("                    },\n");
      out.write("                    \"error\": function(jqXHR, textStatus, errorThrown){\n");
      out.write("                        var errorText = errorThrown + \": \" + jqXHR.responseText;\n");
      out.write("                        $('#footWide').before('<div class=\"error\">' + errorText + '</div>');\n");
      out.write("                    }\n");
      out.write("                } );\n");
      out.write("            }\n");
      out.write("        } );\n");
      out.write("    } );\n");
      out.write("\n");
      out.write("    function fnServerSideCallback(data) {\n");
      out.write("        $('#hitsFound').text(\"Hits Found: \" + data.iTotalDisplayRecords);\n");
      out.write("        $('#totalRecords').text(\"Total Records: \" + data.iTotalRecords);\n");
      out.write("        buildSmiles(data);\n");
      out.write("    }\n");
      out.write("\n");
      out.write("    function buildSmiles(data) {\n");
      out.write("        var aaData = data.aaData;\n");
      out.write("        $.each(aaData, function(index, compound){\n");
      out.write("            var smiles = \"\";\n");
      out.write("            $.each(compound.compositions, function(index, composition){\n");
      out.write("                var chemicalStructure = composition.chemicalStructure;\n");
      out.write("                if (typeof chemicalStructure !== 'object' ){\n");
      out.write("                    chemicalStructure = resolveChemicalStructure(aaData, composition.chemicalStructure);\n");
      out.write("                }\n");
      out.write("                smiles += chemicalStructure.structureData + \".\";\n");
      out.write("            });\n");
      out.write("             smiles =  smiles.substring(0,  smiles.length - 1);\n");
      out.write("            compound[\"smiles\"] = smiles;\n");
      out.write("            compound[\"structure\"] = \"\";\n");
      out.write("        });\n");
      out.write("        return true;\n");
      out.write("    }\n");
      out.write("\n");
      out.write("    function resolveChemicalStructure(aaData, jsonId) {\n");
      out.write("        var result = null;\n");
      out.write("        $.each(aaData, function(index, compound){\n");
      out.write("            $.each(compound.compositions, function(index, composition) {\n");
      out.write("                var chemicalStructure = composition.chemicalStructure;\n");
      out.write("                if (typeof chemicalStructure === 'object' ){\n");
      out.write("                    if (chemicalStructure[\"@id\"] == jsonId){\n");
      out.write("                        result = chemicalStructure;\n");
      out.write("                        return false;\n");
      out.write("                    }\n");
      out.write("                }\n");
      out.write("            });\n");
      out.write("        });\n");
      out.write("        return result;\n");
      out.write("    }\n");
      out.write("</script>\n");
      out.write("<div id=\"toolbar\">\n");
      out.write("    <h1 id=\"hitsFound\">Hits Found:</h1>\n");
      out.write("    <h1 id=\"totalRecords\">Total Records:</h1>\n");
      out.write("    <div id=\"sdfDownloadLink\"><a href=\"\">Download Hits</a></div>\n");
      out.write("</div>\n");
      out.write("<table id=\"dataTable\">\n");
      out.write("    <thead>\n");
      out.write("        <tr>\n");
      out.write("            <th>Structure</th>\n");
      out.write("            <th>Compound Name</th>\n");
      out.write("            <th>CAS</th>\n");
      out.write("        </tr>\n");
      out.write("    </thead>\n");
      out.write("    <tbody>\n");
      out.write("    </tbody>\n");
      out.write("</table>\n");
      out.write("\n");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "/WEB-INF/jsp/footer.jsp", out, false);
      out.write('\n');
    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
