Another approach would be using CSS3 selectors but they are not supported by Internet Explorer 6 (see: http://www.webdevout.net/browser-support-css#css3selectors):
// external link style
a:link[href^="http://"] {
background-color: #990000;
}
// internal link style
a:link, a:link[href^="http://www.mydomain.com"] {
background-color: #009900;
color: #000000;
}
You would not need to change your links programmatically!
<a href="somelink.htm">some link</a>
<a href="http://www.mydomain.com/anotherlink.htm">another link</a>
... would result in a link with internal link style.
<a href="http://www.otherdomain.com">external link</a>
... would result in a link with external link style.