<%-- $HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/apps/igeoportal-standard/branches/2.5_testing/modules/gazetteer/gaz_a.jsp $
 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
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="org.deegree.i18n.Messages" %>
<%@ page import="java.util.Locale" %>
<%
    Locale loc = request.getLocale();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta name="author" content="Judit Mays, lat/lon GmbH">
        <meta name="KeyWords" content="deegree iGeoPortal lat/lon" />
        <title>deegree WFS Gazetteer</title>
        <link href="../../css/deegree.css" rel="stylesheet" type="text/css" />
		<style type="text/css">
		<!--
			.sel {width: 200px;}
		-->
		</style>
        <script LANGUAGE="JavaScript1.2" TYPE="text/javascript">
		<!-- 

		var ifdocument = null;
        var type = null;
        var identifier = null;

		function clearList(listID) {
		    var list = document.getElementById( listID );
		    if ( list == null ) {
		    	return;
		    }
		    var ops = list.childNodes;
		    for ( var i = ops.length-1; i > 0; i-- ) {
		        list.removeChild( ops[i] );
		    }
		}
	
		function setMessage( mesg ) {
		    var el = document.getElementById('messageline');
		    var els = el.childNodes;
		    for ( i = 0; i < els.length; i++ ) {
		        el.removeChild( els[i] );
		    }
		    var t = document.createTextNode(mesg);
		    el.appendChild(t)
		}
		
		function createRPC( moduleName, featuretype, querytemplate, filterproperties, resultFormat, methodName ) {
			var s = '<?xml version="1.0" encoding="UTF-8"?>'+
	    		'<methodCall><methodName>' + methodName + '</methodName>'+
				'<params><param><value><struct>' +
	        		'<member><name>MODULE</name><value><string>' + moduleName + '</string></value></member>' +
	   		    	'<member><name>FEATURETYPES</name><value><string>' + featuretype + '</string></value></member>' +
		   		    '<member><name>QUERYTEMPLATE</name><value><string>' + querytemplate + '</string></value></member>' +
	   			    '<member><name>FILTERPROPERTIES</name><value><string><![CDATA[' + filterproperties + ']]></string></value></member>' +
	        		'<member><name>RESULTFORMAT</name><value><string>' + resultFormat + '</string></value></member>' + 
				'</struct></value></param></params></methodCall>';
				// s = encodeURIComponent(s); // Don't use this! encodeUriComponent(s) does not work for umlaute! 
			return s;
		}
		
		function getList( module, featureType, template ) {
			if ( featureType == 'app:Counties' ) {
			    clearList("countyID");
			    clearList("municipalityID");
			}
			var filterprop = '{IDENTIFIER=XXX}'; // '{key1=value1}{key2=value2}{...}'
		    var s = createRPC( module, featureType, template, filterprop, 'FEATURECOLLECTION', 'wfs:gazetteer' );
		    var tmp = window.location.href.split('/');

		    setMessage('Searching for counties...');
		    ifdocument.forms[0].action = tmp[0] +  '//' + tmp[2]  +  '/' + tmp[3]+ '/control?rpc='  + s;
		    //ifdocument.forms[0].action = tmp[0] +  '//' + tmp[2]  + '/control?rpc='  + s;
		    ifdocument.forms[0].submit();
		}
		
		function selectCounty( list, module, featureType, template ) {
            clearList("municipalityID");
            var idx = list.selectedIndex;
            var value = list.options[idx].value;
            var tmp = value.split('|');
            identifier = tmp[0];
            type = 'app:Counties';		    
		    
		    setMessage( 'Loading municipalities ... ' );
		    var s = createRPC( module, featureType, template, '{sourceValue='+tmp[0]+'}', 'FEATURECOLLECTION', 'wfs:gazetteer' );
		    var tmp = window.location.href.split('/');
		    ifdocument.forms[0].action = tmp[0] +  '//' + tmp[2]  +  '/' + tmp[3]+ '/control?rpc='  + s;
		    //ifdocument.forms[0].action = tmp[0] +  '//' + tmp[2]  + '/control?rpc='  + s;
		    ifdocument.forms[0].submit();
		}
	    
	    function selectFinal( list, tp ) {
	        var idx = list.selectedIndex;
	        var value = list.options[idx].value;
	        var tmp = value.split('|');
	        identifier = tmp[0];
	        type = tp;
	    }
	    
	    function take( module ) {
	        if ( identifier == null || identifier.indexOf( '...' ) > -1 ) {
                alert( "no valid selection for zooming" );
                return;
            }
			if ( "app:Counties" == type  ) {
				template = "countyMapTemplate";
			} else if ( "app:Municipalities" == type ) {
				template = "municipalityMapTemplate";			
			}
	        var s = createRPC( module, type, template, '{IDENTIFIER='+identifier+'}', 'FEATURECOLLECTION', 'wfs:take' );
	        var tmp = window.location.href.split('/');
	        ifdocument.forms[0].action = tmp[0] +  '//' + tmp[2] + '/' + tmp[3]+ '/control?rpc='  + s;
	        //ifdocument.forms[0].action = tmp[0] +  '//' + tmp[2]  + '/control?rpc='  + s;
	        ifdocument.forms[0].submit();
	    }
		-->
		</script>
	</head>
    <body class="gaz9 pGazFlavor" onload="getList( 'GazModule', 'app:Counties', 'countyTemplate' );">
	    <iframe src="./gaz_if.jsp" width="0" height="0" name="gazetteer" id="gazetteer" frameborder="0" marginheight="0" marginwidth="0"></iframe>
	    <table>
	        <tbody>
	            <tr>
	                <td><b>Counties</b></td>
	            </tr>
	            <tr>
	                <td>
	                    <select class="sel" name="County" id="countyID" onchange="selectCounty( this, 'GazModule', 'app:Municipalities', 'municipalityTemplate' );" >
	                        <option value="... select">... select</option>
	                    </select>
	                </td>
	            </tr>
	            <tr>
	                <td><b>Municipalities</b></td>
	            </tr>
	            <tr>
	                <td>
	                    <select class="sel" name="MunicipalityName" id="municipalityID" size="1" onchange="selectFinal( this, 'app:Municipalities' ); ">
	                        <option value="... select">... select a county first</option>
	                    </select>
	                </td>
	            </tr>
	            <tr>
	                <td><p class="gaz9" id="messageline">&nbsp;</p></td>
	            </tr>
	            <tr>
	                <td><a href="javascript:take( 'GazModule' );" style="width:100px" class="buttonArea"><%=Messages.get( loc, "IGEO_STD_BTN_ZOOMTO" ) %></a></td>
	            </tr>
	        </tbody>
	    </table>
	</body>
</html>
