$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = 0;
  });
};

function submitForm(obj) {
	var form1 = $(obj).parents()
										.map(function () {if(this.tagName == "FORM") return this;})
										.get();
	var setalert = 0;
	var requiredelements = $(form1).find("input, select, textarea");
	$(requiredelements).each(function () {
		if($(this).hasClass("required") && $(this).val() == "" && !setalert) {
			alert($(this).attr("title") + " wird benötigt.");
			setalert = 1;
		}
	});
	if(!setalert) $(form1).submit();
}

function resetForm(obj) {
	var form1 = $(obj).parents()
										.map(function () {if(this.tagName == "FORM") return this;})
										.get();
	$(form1).clearForm();
}
