//$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/apps/igeoportal-standard/branches/2.5_testing/modules/csw/csw_functions_search_result.js $
/*----------------------------------------------------------------------------
 This file is part of deegree, http://deegree.org/
 Copyright (C) 2001-2009 by:
 - Department of Geography, University of Bonn -
 and
 - lat/lon GmbH -

 This library is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the Free
 Software Foundation; either version 2.1 of the License, or (at your option)
 any later version.
 This library is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 details.
 You should have received a copy of the GNU Lesser General Public License
 along with this library; if not, write to the Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 Contact information:

 lat/lon GmbH
 Aennchenstr. 19, 53177 Bonn
 Germany
 http://lat-lon.de/

 Department of Geography, University of Bonn
 Prof. Dr. Klaus Greve
 Postfach 1147, 53001 Bonn
 Germany
 http://www.geographie.uni-bonn.de/deegree/

 e-mail: info@deegree.org
----------------------------------------------------------------------------*/
var id, catalog;
var title, services;
var minx = 0; 
var miny = 0; 
var maxx = 1; 
var maxy = 1; 
var selectedButton;

function createReqRPC( id, catalog, minx, miny, maxx, maxy, functionName ) {
    var s = "<?xml version='1.0' encoding='UTF-8'?><methodCall>" +
        "<methodName>cswClient:" + functionName + "</methodName>" +
        "<params>" +
        "<param><value><struct>" +
            "<member><name>catalog</name><value><string>" + catalog + "</string></value></member>" +
            "<member><name>RPC_IDENTIFIER</name><value><string>" + id + "</string></value></member>" +
            "<member><name>RPC_FORMAT</name><value><string>ISO19115</string></value></member>" +
            "<member><name>RPC_PROTOCOL</name><value><string>POST</string></value></member>" +
            "<member><name>boundingBox</name><value><struct>" +
                "<member><name>minx</name><value><double>" + minx + "</double></value></member>" +
                "<member><name>miny</name><value><double>" + miny + "</double></value></member>" +
                "<member><name>maxx</name><value><double>" + maxx + "</double></value></member>" +
                "<member><name>maxy</name><value><double>" + maxy + "</double></value></member>" +
            "</struct></value></member>" +
        "</struct></value></param>" +
        "</params>" +
        "</methodCall>";
    return s;
}

// (JM) used when a link in search result is hit for the first time
function getMetadata( id, catalog, minx, miny, maxx, maxy, funcName ) {
    req = "control?rpc=" + createReqRPC( id, catalog, minx, miny, maxx, maxy, funcName );
    // in another window
    myFiWindow = window.open( req, "Metadata","width=680,height=400,left=150,top=200,scrollbars=yes,resizable=yes");
    myFiWindow.focus();
    ////setVariableArea(parent.document, req);
    //window.location.replace( req );
}	

// (Stadt Wuppertal Sa 18.09.06) used when a link to a parent element is hit in metadata details 
function getMetadataParent( id, catalog, minx, miny, maxx, maxy, funcName ) {
    req = "control?rpc="+createReqRPC( id, catalog, minx, miny, maxx, maxy, funcName );
    // in the same window
    window.location.replace( req );
}

// (JM ) used when metadata already available (when calling from metadata overview)
function getMetadataDetails() {
    var req = "control?rpc=<?xml version='1.0' encoding='UTF-8'?>" +
              "<methodCall><methodName>cswClient:showMetadataDetails</methodName></methodCall>";
    window.location.replace( req );
}

// (JM) used when metadata already available (when returning form metadata details)
function getMetadataOverview() {
    var req = "control?rpc=<?xml version='1.0' encoding='UTF-8'?>" +
          "<methodCall><methodName>cswClient:showMetadataOverview</methodName></methodCall>";
    window.location.replace( req );
}

// (JM) show next or previous lot of search results
function turnPage( catalog, numberOfMatches, numberOfRecordsReturned, direction ) {
    var req = "control?rpc=<?xml version='1.0' encoding='UTF-8'?>" +
        "<methodCall><methodName>cswClient:turnPage</methodName>" +
        "<params><param><value><struct>" +
            "<member><name>catalog</name><value><string>" + catalog + "</string></value></member>" + 
            "<member><name>RPC_FORMAT</name><value><string>ISO19115</string></value></member>" +
            "<member><name>matches</name><value><int>" + numberOfMatches + "</int></value></member>" + 
            "<member><name>recReturned</name><value><int>" + numberOfRecordsReturned + "</int></value></member>" + 
            "<member><name>direction</name><value><string>" + direction + "</string></value></member>" +
        "</struct></value></param></params>" +
        "</methodCall>";
    window.location.replace( req );
}

// (JM) adds the passed (meta)data set to the shopping cart 
function addToShoppingCart( id, title, catalog, minx, miny, maxx, maxy, services, xslt ) {

    var req = "control?rpc=<?xml version='1.0' encoding='UTF-8'?><methodCall>" +
        "<methodName>cswClient:addToShoppingCart</methodName>" +
        "<params>" +
        "<param><value><struct>" +
            "<member><name>catalog</name><value><string>" + catalog + "</string></value></member>" +
            "<member><name>RPC_IDENTIFIER</name><value><string>" + id + "</string></value></member>" +
            "<member><name>RPC_TITLE</name><value><string>" + title + "</string></value></member>" +
            "<member><name>boundingBox</name><value><struct>" +
                "<member><name>minx</name><value><double>" + minx + "</double></value></member>" +
                "<member><name>miny</name><value><double>" + miny + "</double></value></member>" +
                "<member><name>maxx</name><value><double>" + maxx + "</double></value></member>" +
                "<member><name>maxy</name><value><double>" + maxy + "</double></value></member>" +
            "</struct></value></member>" +
            "<member><name>RPC_XSLT</name><value><string>" + xslt + "</string></value></member>" +
        "</struct></value></param>" +
        "</params></methodCall>";
    window.location.replace( req );
}
