$(function() {
 $('#main form').submit(function() {
  var $rows = $('p:not(.submit), fieldset fieldset', this),
  first = true,
  hasError = false;
  $rows.each(function() {
   var simple = $(this).is('p'),
   $input = simple ? $(':input', this) : $(':input', this),
   $label = simple ? $('label', this) : $('legend span', this),
   required = $label.find('em').length,
   error = false;
   $(this).removeClass('error');
   $label.find('strong').remove();
   if (required && $input.is(':text') && $.trim($input.val()) === '') {
    error = 'Dit veld is vereist.';
   } else if (required && $input.is('select') && $input.val() === '') {
    error = 'Maak een keuze.';
   } else if (required && ($input.is(':checkbox') && $input.length == 1 && !($input.is(':checked')))) {
    error = 'Dit is vereist';
   } else if (required && ($input.is(':radio') || $input.is(':checkbox')) && !($input.is(':checked'))) {
    error = 'Maak een keuze.';
   } else if ($input.hasClass('email') && $input.val().indexOf('@') == -1) {
    error = 'Controleer het e-mailadres.';
   } else if (required && $input.is('textarea') && $.trim($input.val()) === '') {
    error = 'Dit veld is vereist.';
   }
   if (error) {
    hasError = true;
    $(this).addClass('error');
    $label.append('<strong>' + error + '</strong>');
    if (first) {
     $input.focus();
     first = false;
    }
   }
  });
  if (hasError) {
   return false;
  }
 });
 $('#main .youtube').each(function() {
  var id = $(this).attr('id')
  swfobject.embedSWF('http://www.youtube.com/v/' + id.substring(8) + '&fs=1', id, '427', '334', '6', null, null, {allowfullscreen: true});
 });
});