javascript for publish function.

Needs to be enhanced (see comments in file).