$(document).ready(function(){
	
	inFieldLabels('#0f3464', '#97acc6');

});

// Platziert Form-Labels über den Input-Feldern
function inFieldLabels(darkColor, lightColor)
{
	$error = false;
	
	// do something with each matching input
	$('.infield-labels').find('input').each(function(){

		// get name of input for later reference
		var input_name = $(this).attr('name');
		
		
		// do something with each matching label
		$(this).parent().find('label').each(function(){
			// but only for the one matching the input-name
						
			// Modifikation für Typo3 Extension Formhandler
			var formfor = $(this).attr('for');
			var formforhandler = "formhandler["+formfor+"]";
			if (formforhandler == input_name){
			//if ($(this).attr('for') == input_name){
			
				// set counter to zero (for later use)
				var c = 0;
				// get inner HTML (text) of label tag
				var label = $(this).text();
				// get "label-referenced" (for="foobar") input 
				var input = $(this).parent().find('input[name='+input_name+']');

				// apply label-text as input value
								
				// only paste label if field was empty on load
				if (input.val() == ""){
					input.val(label);
				}
				
				// remove label element from dom
				$(this).remove();				
				
				// listen for focus
				input.bind('focus', function(){
				
					// listen for keyboard input; but only once (use counter here)
					$(this).bind('keypress', function(){
						c++;
						if (c == 1 
							&& $(this).val() == label){
							// if user starts typing color is set to dark and placeholder removed
							$(this).css({ "color": darkColor });
							$(this).val('');
						}
					});
					
					if ($(this).val() == label){
						// if there is a focus on default label use light color
						$(this).css({ "color": lightColor });
					} else {
						// oposite
						$(this).css({ "color": darkColor });
					}
				
				// listen for blur
				}).bind('blur', function(){
					// set counter to zero again
					c = 0;
					if ($(this).val().length == 0){
						// if input was left empty but back default value
						$(this).val(label);
					}
					// and finaly use dark color again
					$(this).css({ "color": darkColor });
				});
				

			// Modifikation für Typo3 Extension Formhandler
			// Löscht die Feld-Werte (urspr. Label) vor dem Senden, damit die Validation funktioniert
			$('#submit').click(function() {
 				if (input.val() == label){
					input.val("");
				}
			});	

			}
		});
		
	})

	
// do something with each matching textarea
	$('.infield-labels').find('textarea').each(function(){

		// get name of input for later reference
		var input_name = $(this).attr('name');
		
		// do something with each matching label
		$(this).parent().find('label').each(function(){
			// but only for the one matching the input-name
			
			// Modifikation für Typo3 Extension Formhandler
			var formfor = $(this).attr('for');
			var formforhandler = "formhandler["+formfor+"]";
			if (formforhandler == input_name){
			
			//if ($(this).attr('for') == input_name){
			
				// set counter to zero (for later use)
				var c = 0;
				// get inner HTML (text) of label tag
				var label = $(this).text();
				// get "label-referenced" (for="foobar") input 
				var input = $(this).parent().find('textarea[name='+input_name+']');
				// apply label-text as input value
				// only paste label if field was empty on load
				if (input.val() == ""){
					input.val(label);
				}
				
				// remove label element from dom
				$(this).remove();				
				
				// listen for focus
				input.bind('focus', function(){
				
					// listen for keyboard input; but only once (use counter here)
					$(this).bind('keypress', function(){
						c++;
						if (c == 1 
							&& $(this).val() == label){
							// if user starts typing color is set to dark and placeholder removed
							$(this).css({ "color": darkColor });
							$(this).val('');
						}
					});
					
					if ($(this).val() == label){
						// if there is a focus on default label use light color
						$(this).css({ "color": lightColor });
					} else {
						// oposite
						$(this).css({ "color": darkColor });
					}
				
				// listen for blur
				}).bind('blur', function(){
					// set counter to zero again
					c = 0;
					if ($(this).val().length == 0){
						// if input was left empty but back default value
						$(this).val(label);
					}
					// and finaly use dark color again
					$(this).css({ "color": darkColor });
				});
				
			// Modifikation für Typo3 Extension Formhandler
			// Löscht die Feld-Werte (urspr. Label) vor dem Senden, damit die Validation funktioniert
			$('#submit').click(function() {
 				if (input.val() == label){
					input.val("");
				}
			});
				
			}
		});
	})
	
	

/*
// Alert ausgeben, wenn ein element mit class="error" gefunden wurde
// error-class muss erste aufglistete class im Attribut sein!
$('.infield-labels').find('.error').each(function(){
		var input_class = $(this).attr('class');
		if (input_class == 'error') {$error = true};
})
if ($error == true) {alert ('Bitte alle Pflichtfelder ausfüllen!')};
*/


}





	
	// Google Maps API V3
  function mapinitialize() {
    var myLatlng = new google.maps.LatLng(52.73620721,13.17603528);
    var myOptions = {
      zoom: 9,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    var marker = new google.maps.Marker({
        position: myLatlng, 
        map: map,
        title:"Standort Grunske bei Google Maps"
    });
	
	google.maps.event.addListener(marker, 'click', function() {
  		window.open('http://maps.google.de/maps?q=Grunske+Veltener+Stra%C3%9Fe+32+16515+Oranienburg+%2F+OT+Germendorf+&hl=de&ie=UTF8&ll=52.769539,13.20694&spn=0.202316,0.409927&sll=52.791933,13.322808&sspn=0.259099,0.626907&vpsrc=6&hq=Grunske+Veltener+Stra%C3%9Fe+32+16515+Oranienburg+%2F+OT&hnear=Oranienburg,+Oberhavel,+Brandenburg&t=m&z=11&iwloc=A', 'Google Maps', 'width=980,height=580,resizable=yes');
	});
 }
  
  
