/* Copyright 2005 Acrotect LLC.  All rights reserved. */

function setTarget(id, target) {
    if (document.getElementById) {
        var el = document.getElementById(id);
        if (el) {
            el.target = target;
            return true;
        }
    }
    return false;
}

function useLinkRel() {
    if (document.getElementsByTagName) {
        var anchors = document.getElementsByTagName('a');
        for (var i = 0; i < anchors.length; i++) {
            var anchor = anchors[i];
            if (anchor.getAttribute('href') &&
                  (anchor.getAttribute('rel') == 'external' ||
                   anchor.getAttribute('rel') == 'child' ||
                   anchor.getAttribute('rel') == 'blank')) {
                var target = anchor.getAttribute('title') || 'external';
                target = target.replace(/ /g, '_');

                if (anchor.getAttribute('rel') == 'child') {
                    anchor.onclick = function() {
                        //var x = window.innerWidth ? window.innerWidth :
                        //        document.body.clientWidth ? document.body.clientWidth :
                        //        500;
                        //x = 0.8 * x;
                        var x = 760;
                        var y = window.innerHeight ? window.innerHeight
                                                   : window.screen.availHeight;
                        y = 0.8 * y;
                        var hash = this.href.indexOf('#');
                        var noNav = (this.href.indexOf('?') < 0) ?
                            '?navbar=no' :
                            '&navbar=no';
                        var url = (hash < 0) ?
                            this.href + noNav :
                            this.href.substring(0, hash) + noNav + this.href.substring(hash);
                        window.open(url,
                                    target,
                                    'resizable=yes,scrollbars=yes,width=' + x + ',height=' + y);
                        return false;
                    };
                } else {
                    anchor.target = target;
                }

            }
        }
    }
}

useLinkRel();
