--- form.class.php.org	2007-02-19 12:21:26.000000000 +0100
+++ form.class.php	2007-02-19 13:14:04.000000000 +0100
@@ -96,12 +96,13 @@
       case 'input':
       case 'text':
 		$str .= '<tr>';
-		$str .= '<td>'.$value['name'].'</td>';
 		if( ereg( 'readonly', $value['attrs'] ) ) {
+		  $str .= '<td><label>'.$value['name'].'</label></td>';
 		  $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($value['value']).'</p><input name="'
 			.$key.'" type="hidden" value="'.MySmarty::htmlentities($value['value']).'" /></td>';
 		} else {
-		  $str .= '<td><input name="'.$key.'" type="'.$value['type'].'" value="'.MySmarty::htmlentities($value['value']).'" '
+		  $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>';
+		  $str .= '<td><input name="'.$key.'" id="'.$key.'" type="'.$value['type'].'" value="'.MySmarty::htmlentities($value['value']).'" '
 			.MySmarty::htmlentities($value['attrs']).' size="'.$size.'" /></td>';
 		}
 		$str .= '<td>'.KolabForm::comment_helper($value).'</td>';
@@ -109,7 +110,6 @@
 		break;
 	  case 'email':
 		$str .= '<tr>';
-		$str .= '<td>'.$value['name'].'</td>';
 		if( strpos($value['value'],'@')===false ) {
 		  $uname = $value['value'];
 		  $domain = '';
@@ -117,17 +117,19 @@
 		  list($uname,$domain) = split('@',$value['value']);
 		}
 		if( ereg( 'readonly', $value['attrs'] ) ) {
+		  $str .= '<td><label>'.$value['name'].'</label></td>';
 		  $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($value['value']).'</p><input name="user_'.$key.'" type="hidden" value="'.
 			MySmarty::htmlentities($uname).'" /><input name="domain_'.$key.'" type="hidden" value="'.
 			MySmarty::htmlentities($domain).'" /></td>';
 		} else {
-		  $str .= '<td><input name="user_'.$key.'" type="text" value="'.MySmarty::htmlentities($uname).'" '
+		  $str .= '<td><label for="user_'.$key.'">'.$value['name'].'</label></td>';
+		  $str .= '<td><input name="user_'.$key.'" id="user_'.$key.'" type="text" value="'.MySmarty::htmlentities($uname).'" '
 			.$value['attrs'].' size="'.($size-40).'" />';
 		  if( count($value['domains']) == 1 ) {
 			$str .= '<input name="domain_'.$key.'" type="hidden" value="'.MySmarty::htmlentities($value['domains'][0]).'" />';
 			$str .= '<span class="ctrl">@'.MySmarty::htmlentities($value['domains'][0]).'</span></td>';
 		  } else {
-			$str .= '@<select name="domain_'.$key.'" '.$value['attrs']." >\n";
+			$str .= '<label for="domain_'.$key.'">@</label><select name="domain_'.$key.'" id="domain_'.$key.'" '.$value['attrs']." >\n";
 			foreach( $value['domains'] as $dom ) {
 			  if( $dom == $domain ) $s = 'selected';
 			  else $s = '';
@@ -149,29 +151,31 @@
 		break;
       case 'textarea':
 		$str .= '<tr>';
-		$str .= '<td>'.$value['name'].'</td>';
 		if( ereg( 'readonly', $value['attrs'] ) ) {
+		  $str .= '<td><label>'.$value['name'].'</label></td>';
 		  $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($value['value']).'</p></td>';
 		} else {
-		  $str .= '<td><textarea name="'.$key.'" rows="5" cols="'.$size.'" '.$value['attrs'].' onkeypress="javascript:textareakeypress()">'.MySmarty::htmlentities($value['value']).'</textarea></td>';
+		  $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>';
+		  $str .= '<td><textarea name="'.$key.'" id="'.$key.'" rows="5" cols="'.$size.'" '.$value['attrs'].' onkeypress="javascript:textareakeypress()">'.MySmarty::htmlentities($value['value']).'</textarea></td>';
 		}
 		$str .= '<td>'.KolabForm::comment_helper($value).'</td>';
 		$str .= '</tr>'."\n";
 		break;	
       case 'checkbox':
 		$str .= '<tr>';
-		$str .= '<td>'.$value['name'].'</td>';
 		if( ereg( 'readonly', $value['attrs'] ) ) {
+		  $str .= '<td><label>'.$value['name'].'</label></td>';
 		  $str .= '<td><span class="ctrl">'.($value['value']?_('Yes'):_('No')).'</span></td>';
 		} else {
-		  $str .= '<td><input name="'.$key.'" type="'.$value['type'].'" value="on" '.($value['value']?'checked':'').' '.$value['attrs'].' /></td>';
+		  $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>';
+		  $str .= '<td><input name="'.$key.'" id="'.$key.'" type="'.$value['type'].'" value="on" '.($value['value']?'checked':'').' '.$value['attrs'].' /></td>';
 		}
         $str .= '<td>'.KolabForm::comment_helper($value).'</td>';
 		$str .= '</tr>'."\n";
 		break;	
 	  case 'checklist':
 		$str .= '<tr>';
-		$str .= '<td>'.$value['name'].'</td>';
+		$str .= '<td><label>'.$value['name'].'</label></td>';
 		if( ereg( 'readonly', $value['attrs'] ) ) {
 		  $str .= '<td><span class="ctrl">'.(join('<br/>',$value['options'])).'</span></td>';
 		} else {
@@ -190,12 +194,13 @@
 		break;			
 	  case 'select':
 		$str .= '<tr>';
-		$str .= '<td>'.$value['name'].'</td>';
 		if( ereg( 'readonly', $value['attrs'] ) ) {
+		  $str .= '<td><label>'.$value['name'].'</label></td>';
 		  $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($value['options'][$value['value']]).
 			'<input type="hidden" name="'.$key.'" value="'.MySmarty::htmlentities($value['value']).'" /></p></td>';
 		} else {
-		  $str .= '<td><select name="'.$key.'" '.$value['attrs'].' >'."\n";
+		  $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>';
+		  $str .= '<td><select name="'.$key.'" id="'.$key.'" '.$value['attrs'].' >'."\n";
 
 		  for( $i = 0; $i < count($value['options']); ++$i) {
 			if( $i == $value['value'] ) $s = 'selected';
@@ -210,15 +215,16 @@
 		break;
 	  case 'foldertypeselect':
 		$str .= '<tr>';
-		$str .= '<td>'.$value['name'].'</td>';
                 $entries = array ( '' => _('Unspecified'), 'mail' => _('Mails'), 'task' => _('Tasks'), 
 								   'journal' => _('Journals'), 'event' => _('Events'), 
 								   'contact' => _('Contacts'), 'note' => _('Notes'));
 		if( ereg( 'readonly', $value['attrs'] ) ) {
+		  $str .= '<td><label>'.$value['name'].'</label></td>';
 		  $str .= '<td><p class="ctrl">'.MySmarty::htmlentities($entries[$value['value']]).
 			'<input type="hidden" name="'.$key.'" value="'.MySmarty::htmlentities($value['value']).'" /></p></td>';
 		} else {
-		  $str .= '<td><select name="'.$key.'" '.$value['attrs'].' >'."\n";
+		  $str .= '<td><label for="'.$key.'">'.$value['name'].'</label></td>';
+		  $str .= '<td><select name="'.$key.'" id="'.$key.'" '.$value['attrs'].' >'."\n";
 		  foreach ($entries as $id => $title) {
 		  	if ( $value['value'] == $id )
 				$s = 'selected';
@@ -235,11 +241,12 @@
 		break;
       case 'aclselect': // Special Kolab entry for ACLs
 		$str .= '<tr>';
-		$str .= '<td>'.$value['name'].'</td>';
 		if( ereg( 'readonly', $value['attrs'] ) ) {
+		  $str .= '<td><label>'.$value['name'].'</label></td>';
 		  if( $value['user'] ) $str .= '<td><span class="ctrl">'.MySmarty::htmlentities($value['user']).'</span> <span class="ctrl">'.$value['perm'].'</span></td>';
 		} else {
-		  $str .= '<td><input name="user_'.$key.'" type="'.$value['type'].'" size="'.($size-15).'" value="'
+		  $str .= '<td><label for="user_'.$key.'">'.$value['name'].'</label></td>';
+		  $str .= '<td><input name="user_'.$key.'" id="user_'.$key.'" type="'.$value['type'].'" size="'.($size-15).'" value="'
 			.MySmarty::htmlentities($value['user']).'" '.$value['attrs'].' />';
 		  $str .= '<select name="perm_'.$key.'">'."\n";
 		  if( $value['perm'] ) $selected_perm = $value['perm'];
@@ -268,7 +275,7 @@
 		debug("resourcepolicy");
 		$ro = ereg( 'readonly', $value['attrs'] );
 		$str .= '<tr>';
-		$str .= '<td>'.$value['name'].'</td>';
+		$str .= '<td><label>'.$value['name'].'</label></td>';
 		$str .= '<td>';
 		$str .= '<table>';
 		$i = 0;
