(function($, undefined) {
	var valForm = {
		jqFormInpPflicht: function(el) {
				return !!jQuery.trim($(el).val());
			},
		jqFormInpEmail: function(el) {
				return !!$(el).val().match(/^[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\.[A-Za-z]{2,}$/);
			},
		jqFormInpAnz: function(el) {
				return !!($(el).val().match(/^[0-9]{1,2}$/) && parseInt($(el).val(), 10) > 0);
			},
		jqFormInpErm: function(el) {
				return !!($(el).val() === '' || $(el).val().match(/^[0-9]{1,2}$/) && parseInt($(el).val(), 10) <= parseInt($('.jqFormInpAnz').val(), 10));
			}
		};
	function checkForm() {
		var cl = valForm[$(this).attr('class')];
		if (cl) {
			this.ok = cl(this, valForm);
			$(this).css('background-color', this.ok ? 'white' : '#fcc');
		}
		else {
			this.ok = true; // wenn keine Funktion existiert: alles ok
		}
	}
	$.retZuord = {};
	$(document).ready(function()	{
		var checkRet = function(event) {
			if (event.which == 13) {
			  event.stopImmediatePropagation();
			  event.preventDefault();
			  if (event.type == 'keyup' && $.retZuord[this.id]) {
			  	  $($.retZuord[this.id]).click();
			  }
			}
		}
		$('input.showInfo').mouseover(function() {$(this).attr('src', 'fileadmin/icons/info_h.gif'); });
		$('input.showInfo').mouseout(function() {$(this).attr('src', 'fileadmin/icons/info.gif'); });
		$('input.showClose').mouseover(function() {$(this).attr('src', 'fileadmin/icons/close_h.gif'); });
		$('input.showClose').mouseout(function() {$(this).attr('src', 'fileadmin/icons/close.gif'); });
		$('input').keydown(checkRet).keypress(checkRet).keyup(checkRet);
		$('.jqedFormSubmit .submitBut').click(function(event) {
				var n = $(this).attr('name').match(/^jqedForm\[([0-9]+)\]$/);
				var err = false;
				if (n && (n = n[1])) {
					var inp = $(this).parents('.jqedForm').find('[name^=jqed-' + n + '][class^=jqFormInp]');
					inp.each(function() {
							checkForm();
							err = err || !this.ok;
						});
				}
				if (err) {
					$('#jqedFormErr-' + n).show();
					inp.keydown(function() {$('#jqedFormErr-' + n).hide();});
					event.stopImmediatePropagation();
					event.preventDefault();
					return false;
				}
				return true;
			});
		$('[class^=jqFormInp]').each(checkForm).keyup(checkForm).focusout(checkForm);
		$('.feedback').not(':hidden').each(function() {
				$(this).hide();
				var t = $(this).attr('id').replace('back', 'backModal');
				$('#' + t).dialog({modal:true, width: 450});
			});
	});
	
	window.$ = jQuery;

	var lastId = '';

	window.showInfo = function(id) {
		if (lastId) {
			hideInfo(lastId);
		}
		lastId = id;
		$('#'+id).show();
		$('#'+id+'close').show();
		$('#'+id+'hint').hide();
	};
	window.hideInfo = function(id) {
		lastId = '';
		$('#'+id).hide();
		$('#'+id+'close').hide();
		$('#'+id+'hint').show();
	};

})(jQuery);

