Javascript function needed to capitalize lastnames!

I need a javascript function which converts lastnames to correct capitalization.

For instance when I have a textfield called lastname and type in the name van helsing and leave the field it will be converted to for instance van Helsing.

Things to consider are :

I have a list of prefixes which need to checked upon so it will have to be included in the javascript function so I can easily add or remove items from the list and the function still has to work without too much hassle. (array,...)

Note that in some cases a little bit smarter programming is required because the '-' symbol is sometimes used.
Helsing-Jones
Helsing-de Jones
...
de Helsing-Jones
de Helsing-van Jones

de Helsing-Vanakker (note that the van here is not a prefix so please include things like this in your checks)

Also there are fields on my form which hold the how to address a person in a letter for instance which have a different set of rules

Rules here are that with this field : If nothing precedes the prefixes then only the first prefix gets a capital letter and ofcourse the lastname itself. (Dear mr Van Helsing)
When however something does precede the suffixes all prefixes remain small. (Dear mr Jones van Helsing)

I will include a short snippet of code so you can sorta see how it is supposed to work...I say sorta see cause this function doesnt work correct all the times the way I have described above.