    jQuery(function($){
      $('form').submit(function(){
        var post_url = this.action;

        $('form').find(':input').each(
          function() {
						if (this.name == undefined) return;

            var dlen = this.name.length;
            if ("[]" != this.name.toString().substring(dlen-2,dlen)) {
              data[this.name] = this.value;
            }
            else {
              if (data[this.name]) {
                data[this.name].push(this.value);
              }
              else {
                data[this.name] = [this.value];
              }
            }
          }
        );

        $('form').find(':checkbox').each(
          function() {
            var checked = "";
            if (this.checked) {
              checked = "on";
            }
            data[this.name] = checked;
          }
        );

				var validator = {
					contact_name: /\w+/,
					contact_names:/\w+/,

					contact_company: /\w+/,
					contact_redaktion:/.*/,
					contact_phone:/\d+/,
					contact_fax:/\d+/,
					             contact_email:/.+@.+/,
					contact_url:/http:\/\/.*\..*/,

					contact_street:/\w+/,
					contact_zipcode:/\d{4,5} \w+/,

					contact_function: /\w+/,
					contact_medium:/\w+/
				};

				var valid = {};

				for (key in data) {
					valid[key] = validator[key] ? validator[key].test(data[key]) : true;
					if (valid[key] == false && key in required) {
						$('.form_error')
							.filter('[id*='+key+']')
								.css({background:'#f66',
											color:'#fff',
											padding:'2px',
											width:'25em'})
								.html('Bitte f&uuml;llen Sie dieses Feld korrekt aus.')
								.show();
					}
					else if (key in required) {
						$('.form_error')
							.filter('[id*='+key+']')
								.hide();
					}
				}

				for (key in valid) {
					if (valid[key] == false && key in required) {
		  	    $("#form_buttons").show();
		  	    $("#loading").hide();
						return false;
					}
				}

												 if (data['form'] != 'Online Application') {
													 $.post(
														 post_url,
														 data,
														 function(result,status) {
                               if (status == 'success') {
                                 $('div.form').html(result);
                                 $('div.form_buttons').html('');
                               }
                               else {
                               }
															 window.setTimeout(function(){$('#TB_closeWindowButton').click()},3000);
														 });

													 return false;
												 }
												 else {
													 return true;
												 }

      });

    });

