/*

    2001-11-14:
        - also check parentElement (mv)

    2001-08-13:
        - bugfix: replace '#' in location.href with '%23' (mv)

*/

function replace(string,text,by) 
{
    if (string.length == 0 || text.length == 0)
        return string;

    var i = string.indexOf(text);
    if (((!i) && (text != string.substring(0,text.length))) || (i == -1))
        return string;

    var newstr = string.substring(0,i) + by;

    if (i + text.length < string.length)
        newstr += replace(string.substring(i + text.length, string.length), text, by);

    return newstr;
}

        
function doclick(e) 
{
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug

    if (targ.parentNode) var pe = targ.parentNode; else if (targ.parentElement) var pe = targ.parentElement;

    if (targ.tagName.toUpperCase() == 'IMG' && pe && pe.tagName.toUpperCase() == 'A') {
        targ = pe;
    }

    if (targ.tagName.toUpperCase() == 'A') {
        if (targ.href && targ.href.indexOf('http://') == 0 && targ.href.indexOf('musicfrom.') == -1) {
            targ.href = '/exitlog.php'
                + '?path=' + escape(replace(location.href, '#', '%23'))
                + '&url=' + escape(replace(targ.href, '#', '%23'));
            /*targ.href = '/exitlog.php'
                + '?path=' + escape(location.href)
                + '&url=' + escape(targ.href);*/
        }
    }
}


if (document.getElementById)
{
    document.onclick = doclick;
}