/*
 * Copyright 2004 Outerthought bvba and Schaubroeck nv
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function showQueryInfoPopup(info) {
    var infoWindow = window.open("", "",
			      "toolbar=no,menubar=no,personalbar=no,width=400,height=200,left=20,top=40" +
			      ",scrollbars=yes,resizable=yes");

    var doc = infoWindow.document;
    doc.open();
    doc.write("<html><head><title>Query Info</title><body>");


    var writeParam = function(title, value) {
      doc.write("<b>" + title + ":</b> ");
      if (value != null && value != "")
        doc.write(value);
      else
        doc.write("N/A");
      doc.write("<br/>");
    }

    writeParam("Query", info.query);
    writeParam("Extra condition", info.extraCondition);
    writeParam("Parse and prepare time", formatTiming(info.parseAndPrepareTime));
    writeParam("Fulltext query time", formatTiming(info.fullTextQueryTime));
    writeParam("RDBMS query time", formatTiming(info.rdbmsQueryTime));
    writeParam("Merge time", formatTiming(info.mergeTime));
    writeParam("ACL filter time", formatTiming(info.aclFilterTime));
    writeParam("Sort time", formatTiming(info.sortTime));
    writeParam("Output creation time", formatTiming(info.outputGenerationTime));

    doc.write("</body></html>");
    doc.close();
}

function formatTiming(time) {
  if (time == null || time == "")
    return "";
  return (time / 1000).toFixed(3) + " s";
}

function showHelpPopup(helpDiv) {
    var helpWindow = window.open("", "",
			      "toolbar=no,menubar=no,personalbar=no,width=400,height=200,left=20,top=40" +
			      ",scrollbars=yes,resizable=yes");

    var doc = helpWindow.document;
    doc.open();
    doc.write("<html><body>");
    doc.write(helpDiv.innerHTML);
    doc.write("</body></html>");
    doc.close();
}


function showDocumentInfoPopup(urlPrefix, docName, docId, version, versionCount, versionCreated, versionState,
                               versionStateModified, docOwner, documentPath) {

    var url = urlPrefix + "/docInfo?";
    url += "name=" + encodeURIComponent(docName);
    url += "&id=" + encodeURIComponent(docId);
    url += "&version=" + encodeURIComponent(version);
    url += "&version=" + encodeURIComponent(version);
    url += "&versionCount=" + encodeURIComponent(versionCount);
    url += "&versionCreated=" + encodeURIComponent(versionCreated);
    url += "&versionState=" + encodeURIComponent(versionState);
    url += "&versionStateModified=" + encodeURIComponent(versionStateModified);
    url += "&docOwner=" + encodeURIComponent(docOwner);
    url += "&docPath=" + encodeURIComponent(documentPath);

    var infoWindow = window.open(url, "",
			      "toolbar=no,menubar=no,personalbar=no,width=700,height=300,left=20,top=40" +
			      ",scrollbars=yes,resizable=yes");
}
