/**
* retargetOuterLink (c) 2006 http://www.marcomoser.it
*
* @author       Marco Moser <marco@marcomoser.it>
* @version      18/3/2006 init
*
* redefine out-of-this-site anchors (<a href...>) with a different class and a different window
* skip javascript: and xxx.mysite.xx
*
* @param className null or the class to replace with ('myclass') or add to (if begin with a space ' outerclass')
* @param target null or the new target window ('_blank' or 'mywindow')
*
* example:
    <style type="text/css">
    .outlink { color: red; }
    </style>
    <script type="text/javascript" src="<?=$ub?>skins/commons/retarget.js"></script>
    <script type="text/javascript">
    window.onload=function() { retargetOuterLink(' outlink','_blank') }
    </script>
*/
function retargetOuterLink(className,target)
{
    // javascript: or http://www.xxx.yy
    var reskip = new RegExp('^\s*(javascript:|.{0,8}'+window.location['hostname']+')','i');
    var alist = document.getElementsByTagName('a');
    for(var ii=0; ii<alist.length; ii++)
    {
        if (!alist[ii].href.match(reskip))
        {
            if (className)
            {
                if (className.charAt(0)==' ') alist[ii].className+=className;   // add
                else alist[ii].className=className;     // replace
            }
            if (target)
            {
                if (!alist[ii].target) alist[ii].target=target;  // replace
            }
        }
    }
}

