sorry to take so long to get back to you...
the problem i see is the php language declaration at lines 536 and 544
all php language calls should be made with either
'<?' or '<?php'
what you show is
<script language='php'> as if you are trying to call the code on the client side...which won't work...
try changing those calls to either of the examples I've shown above...
hth