/**
 * @author Gregor Aisch
 * @publisher webvariants GbR
 * @website http://www.webvariants.de/
 * @contact info - webvariants - de
 * 
 * This script uses the prototype library. It must be loaded before this file is loaded.
 * You can find prototype from http://www.prototypejs.org/
 */

if (Prototype.Version) {
	document.observe('dom:loaded', function() {
		if ($('routeResults')) {
			$('routeResults').hide();
			
			if ($('fromAdress') && $('toAdress') && $('show_route') && wv15_map) {
				$('show_route').observe('click', function() {
			
					$('routeResults').innerHTML = '<h2>Anfahrtsbeschreibung:</h2>';
					$('status').update('<p>Die Route wird berechnet...</p>');
					
					var extractValue = function(element) {
						if (element.value) {
							return element.value;
						} else if (element.options) {
							return element.options[element.selectedIndex].value;
						} else if (element.innerHTML) {
							return element.innerHTML;
						}
					}
					
					var fromAdress = extractValue($('fromAdress'));
					var toAdress = extractValue($('toAdress'));
	
					if (fromAdress && toAdress) wv15_map.showRoute(fromAdress, toAdress, $('routeResults'), $('status'), function() {
						$('row1').style.height = parseInt($('routeResults').offsetHeight + 140)+'px';
					});
					
					//window.alert("from: "+fromAdress+" to: "+toAdress);
				});
			}
		}
	});
}

