Before I dig into the functions, I wanted to suggest you read up on the User Defined Functions (UDF) in the FAQs.

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

How to write a UDF -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=82017#Post82017

All of FAQs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=5&page=1