The line that assigns the $value variable:
$value = (is_array($element['#value']) ? $element['#value']['value'] : $element['#value']);
doesn't allow for some CCK types such as the email field, which stores values with the ['email'] key rather than ['value'], e.g. $node->field_email[0]['email'].
I suggest replacing the above line with:
$value = (is_array($element['#value']) ? array_shift($element['#value']) : $element['#value']);
Tim