A: 

Check the html for any unclosed tags. The error you are getting usually points that way.

Colin
A: 

Modifying the application.master (or any files in the "12 hive") isn't recommended as it makes your installation unsupported. It also means the changes affect every web application used by SharePoint (which may be OK if you only have one). There are other options, all of which are described in this SharePoint Magazine article.

Alternative approach

You could also not modify the application.master file at all. It contains this delegate control tag:

<SharePoint:DelegateControl runat="server"
    ControlId="AdditionalPageHead"
    AllowMultipleControls="true"/>

Therefore a delegate control feature could be used to programmatically disable or hide SharePoint's default navigation and replace it with your own. The elements.xml would look something like:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
    <Control
     ControlClass="YourAssembly.YourClass"
     ControlAssembly="YourAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx"
     Id="AdditionalPageHead"
     Sequence="1" />
</Elements>

This option gives flexibility to activate the feature in only the necessary locations, as well as keeps your application.master intact without needing low-level HTTP modules.

Alex Angas
A: 

Firstly don’t modify out of the box files, an Update or SP could overwrite it. Use Alex’s approach of delegates or if necessary look to the http handler approach. There is a KB article when MS points that the lack of support for modifying the application master can be corrected by creating a new _layouts virtual directory but you are better off with an http handler if you can’t use delegates

Looks like you edited the master page using SharePoint Designer. This commonly breaks files when you save them to disk, though I have heard that the updated version no longer does this (I haven’t had SPD installed on my dev box in over a year). If you open the file in note pad you will see a number of __XXXX attributes these will cause the page to break. You can modify the file in SPD and then do a select all on the text and then cut and past that in to the new file open in notepad/Visual Studio. Though I would recommend using Visual studio to do all your modifications.

By the sound of it you will need to go the HTTP Handler/HTTP Module approach as you want to modify the mark up of the page though you could do something clever with JavaScript in a delegate.

Note if you change the Application.Master page in the layouts folder you SharePoint installation will be in an unsupported state.

JC Vivian