/*
 * Werte von Elementen mit default-Value werden onFocus gelöscht und onBlur,
 * falls nichts anderes eingegeben wurde, wieder eingfügt.  
 */
$(document).ready(function() {
	$('.ui-usersense').focus(function() {

		if ( 'password' == $(this).attr('type') ) {
			if ( 'password' == $(this).val() ) {
				$(this).val("");
			}
			return;
		}

		if(!$(this).data("value")) {
			$(this).data("value", $(this).val());
		}

		if($(this).val() === $(this).data("value")) {
			$(this).val("");
		}
	});

	$('.ui-usersense').blur(function() {
		if ( 'password' == $(this).attr('type') ) {
			if ( 0 < $(this).val().length ) {
				return;
			}

			$(this).val('password'); return; 
		}

		if(!$(this).val() || 1 > $(this).val().length) {
			$(this).val($(this).data("value"));
		}
	});

	$('form').submit(function() {
		$(this).find('.ui-usersense').each(function(i) {
			if ( 'password' == $(this).attr('type') ) {
				return;
			}

			if($(this).data("value")) {
				$(this).data("value", $(this).val());
			}
			if($(this).value == $(this).data("value")) {
				$(this).val("");
			}
		})
	});
});

/**
 * Inhalt eines Textfelds markieren OnFocus
 */
$(function() {
	$('.ui-search').each(function() {
		var $input = $(this);
		$input.focus(function() {
			this.select();
		});
	});
});


