/*+-------------+----------------------------------------------------------*
 *|        /\   |   University of Bonn                                     *
 *|       |  |  |     Department of Geography                              *
 *|      _|  |_ |     Chair of Cartography                                 *
 *|    _/      \|                                                          *
 *|___|         |                                                          *
 *|             |     Meckenheimer Allee 172                               *
 *|             |     D-53115 Bonn, Germany                                *
 *+-------------+----------------------------------------------------------*/
/**
 * <p><b>Title: WPS Profile</b></p>
 * <p><b>Description:</b> Functions WPS </p>
 *
 * <p><b>Copyright:</b> Copyright (c) 2008</p>
 * <p><b>Institution:</b> University of Bonn, Department of Geography</p>
 * @author Pascal Neis, neis@geographie.uni-bonn.de
 * @version 1.0 2009-01-24
 */
 
//Alles was fr WPS wichtig ist

//**********************************************************

var fensterProfile = null;

		function displayProfile(){

			//if(lonlatRoute.length > 50000){
			//	alert('Sorry, it is not possible to create a RouteProfil! Your Route is too long ...');
			//}
			//else{
	
				if(fensterProfile!=null){
					fensterProfile.close();
					fensterProfile = null;
				}
	
				//Set Window ...
				fensterProfile = window.open (
					"",
					"RouteProfile", // Name des neuen Fensters
					+"toolbar=0" // Toolbar
					+",location=0" // Adress-Leiste
					+",directories=0" // Zusatzleisten
					+",status=0" // Statusleiste
					+",menubar=0" // Men
					+",scrollbars=0" // Scrollbars
					+",resizable=0" // Fenstergrsse vernderbar?
					+",width=470" // Fensterbreite in Pixeln
					+",height=320" // Fensterhhe in Pixeln
					);
				
				if (fensterProfile!=null) {
					fensterProfile.document.open();
				    fensterProfile.document.write('<span class=\"infos\">Please wait a moment! This could take several seconds ...</span>');
				    fensterProfile.document.close();
				}
				else
					alert('Da laeuft was schief! :(');
				
				var data = 'Coords='+lonlatRoute;
				var url = 'php/WPS_Profile.php';
				new OpenLayers.Ajax.Request(url, {  method: 'post',
													parameters: data,
													onComplete: showProfile});
			//}
		}

		function showProfile(response) {
			
			//alert(response.responseText);
			if (response) {
				
				//alert(response.responseText);
								
				var xmlresponse = response.responseXML;
				var errorList = xmlresponse.getElementsByTagName('ServiceExceptionReport');
						
				if(errorList.length > 0){
					alert('Error: '+response.responseText);
				}
				else{
					var values = xmlresponse.getElementsByTagName('ComplexValueReference');
					var url = values[0].getAttribute('ows:reference');
					//alert(url);
					if(url.match('process-not-successful')){
						if(fensterProfile!=null){
							fensterProfile.close();
							fensterProfile = null;
						}
						alert(url.slice(url.indexOf('process-not-successful')+23));
						//alert("Notice: RouteProfiles are only in Germany possible!");
					}
					else
						fensterProfile.location.href = url;
				}
			}
		}
//**********************************************************
