$(document).ready(function() {
	// Deobfuscate addresses
	
	$("a[href^=mailto:]").each(function() {
		var addr = $(this).attr("href").substring(7);
		var a = addr.replace(/ \[ät\] /g, "@").replace(/ \[piste\] /g, ".");
		$(this).attr("href", "mailto:" + a);
		for(var i=0;i<addr.length;++i) {
			if(addr[i]!=$(this).text()[i]) { 
				//alert(addr[i] + " " + i); 
				break; 
			}
		}
		if($(this).text()==addr) { $(this).text(a); }
	});
	

	// Sort tables
	$("table.sortable").tablesorter();
	
	/* emulate placeholders for older browsers */
	if(!Modernizr.input.placeholder) {
	$("input[placeholder],textarea[placeholder]")
		.blur(function() {
			if($(this).val()=="") {
				$(this).val($(this).attr("placeholder")).addClass("placeholder");
			}
		})
		.focus(function() {
			if($(this).val()==$(this).attr("placeholder")) {
				$(this).val("").removeClass("placeholder");
			}
		}).blur();
	}	
	
	// Prevent submission of empty forms
	$(":submit.noempty").click(function() {
		var inputs = $(this).closest("form").find("input[type=text],textarea");
		var ok = true;
		inputs.each(function() {
			if($(this).val()==="" || $(this).val() === $(this).attr("placeholder")) {
				ok = false;
				$(this)
					.attr("data-oldborder", $(this).css('border-color'))
					.css('border-color', 'red')
					.one('change', function() {
						$(this).css('border-color', $(this).attr('data-oldborder'));
					});

			}
			return true;
		});
		return ok;
	});	
	
});


