function validate() {
	var myform = $('dentistSearchForm');
	k1 = myform['tx_hndentist_pi1[street]'].value;
	k2 = myform['tx_hndentist_pi1[name]'].value;
	k3 = myform['tx_hndentist_pi1[zipcode]'].value;
	
	t=true;

	if ((k1.length>=3) && (k1 != 'Straße')) t=false; 
	if ((k2.length>=3) && (k2 != 'Name')) t=false;
	if ((k3.length>=2) && (k3 != 'Postleitzahl')) t=false;

	if ((t)){
		alert('Bitte geben Sie mindestens 3 Buchstaben bei Name oder Str. ein - bei PLZ mind. 2 Zahlen!');
		return false;
	} 
	if (k1 == 'Straße') $('tx_hndentist_pi1_street').value = ''; 
	if (k2 == 'Name') $('tx_hndentist_pi1_name').value = ''; 
	if (k3 == 'Postleitzahl') $('tx_hndentist_pi1_zipcode').value = ''; 
	return true;
}


function toggleDetailedSearch() {
	if ($('detailedSearchLayer').visible()) {
		new Effect.SlideUp('detailedSearchLayer');
	} else {
		new Effect.SlideDown('detailedSearchLayer');
	}
}

function initInputField(id, defaultValue) {
	Event.observe($(id), 'focus', function() {
	//$(id).onfocus = function() {
//		console.log($(id).value);
		if ($(id).value == defaultValue) {
			$(id).value = '';
		}
	});
	Event.observe($(id), 'blur', function() {
	//$(id).onblur = function() {
		if ($(id).value == '') {
			$(id).value = defaultValue;
		}
	});
}


Event.observe(window, 'load', function() {
	try {
		initInputField('tx_hndentist_pi1_name', 'Name');
		initInputField('tx_hndentist_pi1_street', 'Straße');
		initInputField('tx_hndentist_pi1_zipcode', 'Postleitzahl');
	} catch(E) {
	}
});


var DentistMarker = Class.create();
Object.extend(
	DentistMarker.prototype, {
		initialize: function(uid, lat, lng, html) {
			this.uid = uid;
			this.lat = lat;
			this.lng = lng;
			this.html = html;
		}
	}
);
var myevent;
var centeredMarkerUid=0;
function centerMarker(uid) {
	try {
		
		window.clearTimeout(myevent); 
		
	} catch (E) {
	}
	decenterMarker(centeredMarkerUid);
	
	myevent = window.setTimeout(function() {
		markers.each(function(item) {
			
			if ((item.uid == uid)) {
				//map.panTo( item.getLatLng());
				item.setImage('http://gmaps-samples.googlecode.com/svn/trunk/markers/red/blank.png');
				item.openInfoWindowHtml($('dentistMarkerHtml'+uid).innerHTML);
				centeredMarkerUid = uid;
			}
		});
	}.bind(uid), 100);
}
function decenterMarker(uid) {
	try {
		window.clearTimeout(myevent); 
	} catch (E) {
	}
	markers.each(function(item) {
		if ((item.uid == uid)) {
			item.setImage('http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png');
		}
	});
}


var map;
var markers = new Array();
function initGoogleMap() {
	map = new GMap2($('dentistsGoogleMap'));
	map.setCenter(new GLatLng(50,10), 3);
	map.addControl(new GSmallMapControl());
	
	var bounds = new GLatLngBounds();

	var blueIcon = new GIcon(G_DEFAULT_ICON);
    blueIcon.image = "http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png";
	
	// Set up our GMarkerOptions object
	var markerOptions = { icon:blueIcon, zIndexProcess: myIndexProcessor };	
	
	dentistMarkers.each(function(item) {
		var ll = new GLatLng(item.lat, item.lng)
		var marker = new GMarker(ll, markerOptions);
		GEvent.addListener(marker, 'click', function() {
			centerMarker(item.uid);
			//marker.openInfoWindowHtml(item.html);
		});
		marker.uid = item.uid;
		map.addOverlay(marker);
		bounds.extend(ll);
		markers.push(marker);
	});
	
	map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
}

function initGoogleMapOnLoad() {
	Event.observe(window, 'load', initGoogleMap);
}

function myIndexProcessor(a, b) {
	if (b) {
		return 1000;
	}
	return 1;
}
