To start with, you've a mess of single and double quotes. For example, you have:
echo "<script type='text/javascript' language="'javascript'">
This will print
<script type="text/javascript" language="
Then it will hit 'javascript' (with the single quotes and not context. An error!!!
afterwards it will start at
"> .......
You've got to get control of your single and double quotes. Your echo'd javascript is 'broken'. Also, the "language='javascript" is not even needed for anything - at least I've never used it like you have!
You should go over your entire code for the over-use and misuse of single and double quotes.