Yes you can put PHP anywhere in this code.
Javascript and PHP are totally independent. When the server processes the PHP script the user receives a static page. Something exactly like a simple HTML page.
for example you have this code in your script:
if(cookiesEnabled) document.write("Cookies Are Enabled!")
else document.write("Cookies Are Disabled!")
if you rewrite it to:
if(cookiesEnabled) document.write("<?php echo "Chocolate "; ?>Cookies Are Enabled!")
else document.write("Cookies Are Disabled!")
the page the user will receive will always have this:
if(cookiesEnabled) document.write("Chocolate Cookies Are Enabled!")
else document.write("Cookies Are Disabled!")