If you used some method of indicating which curly brace end belongs to which curly brace start then you would find all programming much easier.
This works for me
<html>
<script type="text/javascript">
function popUp() {
var message1 = "Browser could not start page.";
var message2 = "Browser is now refreshing. Click OK";
var message3 = "Browser could not be refreshed try again?";
var message4 = "Page has loaded succesfully. Click OK to continue on to page";
if(confirm(message1)) {
if(confirm(message2)) {
if(confirm(message3)){
if(confirm(message4)){
// whatever
}<!--endif1-->
}<!--endif2-->
}<!--endif3-->
}<!--endif4-->
}<!--endfunc-->
window.onload = popUp;
</script>
</html>