//$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/apps/igeoportal-standard/branches/2.5_testing/modules/csw/csw_functions_shop.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
----------------------------------------------------------------------------*/

function performDelete() {
    var req = "control?rpc=<?xml version='1.0' encoding='UTF-8'?><methodCall>" +
              "<methodName>cswClient:deleteFromShoppingCart</methodName>" +
              "<params>";
    var cnt = 0;
    for ( var i = 0; i < document.forms['auswahlform'].elements.length; i++ ) {
        if ( document.forms['auswahlform'].elements[i].type == 'checkbox' ) {
            if ( document.forms['auswahlform'].elements[i].checked == true ) {
                cnt++;
                var s = document.forms['auswahlform'].elements[i].name.split(":");              
                req += "<param><value><struct>"+
                    "<member><name>RPC_IDENTIFIER</name><value><string>" + s[0] + "</string></value></member>" +    
                    "<member><name>catalog</name><value><string>" + s[1] + "</string></value></member>" +
                    "<member><name>RPC_TITLE</name><value><string>" + s[2] + "</string></value></member>" +
                    "</struct></value></param>";
            }
        }
    }
    req += "</params></methodCall>";
    if ( cnt > 0 ) {
        window.location.replace( req );
    } else {
        alert( "Please choose at least one item!" );
    }
}

function performDeleteAll() {
    var req = "control?rpc=<?xml version='1.0' encoding='UTF-8'?><methodCall>" +
              "<methodName>cswClient:deleteFromShoppingCart</methodName>" +
              "<params>";
    var cnt = 0;
    for ( var i = 0; i < document.forms['auswahlform'].elements.length; i++ ) {
        if ( document.forms['auswahlform'].elements[i].type == 'checkbox' ) {
            cnt++;
            var s = document.forms['auswahlform'].elements[i].name.split(":");
            req += "<param><value><struct>" +
                "<member><name>RPC_IDENTIFIER</name><value><string>" + s[0] + "</string></value></member>" +    
                "<member><name>catalog</name><value><string>" + s[1] + "</string></value></member>" +
                "<member><name>RPC_TITLE</name><value><string>" + s[2] + "</string></value></member>" +
                "</struct></value></param>";
        }
    }
    req += "</params></methodCall>";
    if ( cnt > 0 ) {
        window.location.replace( req );
    }
}

function displayMap() {
    var sessionId = null;
    var vSessionKeeper = parent.opener.parent.controller.vSessionKeeper;
    
    if ( vSessionKeeper != null ) {
        sessionId = vSessionKeeper.id;
        if ( sessionId == null ) {
            alert( "Please log in first!" );
            return;
        }
    }

    var contextName = prompt("Please insert a name for the new context: ", "" );
    if ( contextName == "" ) {
        var tmp = new Date().getTime();
        contextName = "context_"+tmp;
    }
    if ( contextName == null ) {
        alert( "Loading was aborted by user request." );
    } else {
        var req = "control?rpc=<?xml version='1.0' encoding='UTF-8'?><methodCall>" +
                 "<methodName>cswClient:displayMap</methodName><params>" +
                 "<param><value><struct>" +
                     "<member><name>SESSION_ID</name><value><string>" + sessionId + "</string></value></member>" +
                     "<member><name>CONTEXT_NAME</name><value><string>" + contextName + "</string></value></member>" +
                 "</struct></value></param>";
        var cnt = 0;
        for ( var i = 0; i < document.forms['auswahlform'].elements.length; i++ ) {
            if ( document.forms['auswahlform'].elements[i].type == 'checkbox' ) {
                if ( document.forms['auswahlform'].elements[i].checked == true ) {
                    cnt++;
                    var s = document.forms['auswahlform'].elements[i].name;
                    var tmp = s.split(":");
                    
                    req += "<param><value><struct>" +
                                "<member><name>RPC_IDENTIFIER</name><value><string>" + tmp[0] + "</string></value></member>" +
                                "<member><name>catalog</name><value><string>" + tmp[1] + "</string></value></member>" +
                                "<member><name>RPC_TITLE</name><value><string>" + tmp[2] + "</string></value></member>";
                    
                    if ( document.forms['auswahlform'].elements["BBOX:"+s] != null ) {
                        var bbox = document.forms['auswahlform'].elements["BBOX:"+s].value.split(",");    
                        req += "<member><name>boundingBox</name><value><struct>" +
                                    "<member><name>minx</name><value><double>" + bbox[0] + "</double></value></member>" +
                                    "<member><name>miny</name><value><double>" + bbox[1] + "</double></value></member>" +
                                    "<member><name>maxx</name><value><double>" + bbox[2] + "</double></value></member>" +
                                    "<member><name>maxy</name><value><double>" + bbox[3] + "</double></value></member>" +
                               "</struct></value></member>"
                    }                        
                    req += "</struct></value></param>";
                }
            }
        }
        req += "</params></methodCall>";
        if ( cnt > 0 ) {
            window.location.replace( req );
        } else {
            alert( "Please choose at least one item!" );
        }
    }
}

/*
function performDownload() {
    var req= "control?rpc=<?xml version='1.0' encoding='UTF-8'?><methodCall>" +
              "<methodName>cswClient:download</methodName><params>";
    var cnt = 0;
    for ( var i = 0; i < document.forms['auswahlform'].elements.length; i++ ) {
        if ( document.forms['auswahlform'].elements[i].type == 'checkbox' ) {
            if ( document.forms['auswahlform'].elements[i].checked == true ) {
                cnt++;
                var s = document.forms['auswahlform'].elements[i].name;
                var tmp = s.split(":");
                
                req += "<param><value><struct>" +
                    "<member><name>RPC_IDENTIFIER</name><value><string>" + tmp[0] + "</string></value></member>" +
                    "<member><name>catalog</name><value><string>" + tmp[1] + "</string></value></member>" +
                    "<member><name>RPC_TITLE</name><value><string>" + tmp[2] + "</string></value></member>";
                
                if ( document.forms['auswahlform'].elements["BBOX:"+s] != null ) {
                    var bbox = document.forms['auswahlform'].elements["BBOX:"+s].value.split(",");    
                    req += "<member><name>boundingBox</name><value><struct>" +
                                "<member><name>minx</name><value><double>" + bbox[0] + "</double></value></member>" +
                                "<member><name>miny</name><value><double>" + bbox[1] + "</double></value></member>" +
                                "<member><name>maxx</name><value><double>" + bbox[2] + "</double></value></member>" +
                                "<member><name>maxy</name><value><double>" + bbox[3] + "</double></value></member>" +
                           "</struct></value></member>"
                }
                req += "</struct></value></param>";
            }
        }
    }
    req = req + "</params></methodCall>";
    if ( cnt > 0 ) {
        window.location.replace( req );
    }
    if ( cnt == 0 ) {
        alert( "Please choose at least one item!" );
    }
}

function doOrder() {
    var req= "cswClient?rpc=<?xml version='1.0' encoding='UTF-8'?><methodCall>" +
              "<methodName>catalogClient:orderData</methodName>";
    req = req + "</methodCall>";
    //window.location.replace( req );
    document.auswahlform.method = "POST";
    document.auswahlform.action = req;
    document.auswahlform.submit();

}
*/

