/**
* xmachina external link modifier (popup pre-site)
* @version 0.3
* @package Abbott Humira
* @copyright 2008 xmachina Gmbh, cw.
* @license Alle Rechte vorbehalten. All rights reserved.
* Oficial website: http://www.xmachina.de
* -------------------------------------------
* Mofifies all external links to open a popup window, showing 
* a generell corporate statement about external links.
* Creator: cw
* Email: deus@xmachina.de
*/


// config ( all )

    // host
        var exceptionHosts = new Array( 'humira-2009.stage.xmachina.de','humira-2009.dev.xmachina.de','humira-2009.xmachina.de','humira.dev.xmachina.de','humira-dev.xmachina.de', 'humira-relaunch.xmachina.de', 'www.abbott.de', 'www.humira.de', 'www.abbott-care.de', 'poll.abbott-care.de' );

    // language
        var liabilityStatement = 'Sie haben einen externen Link gew&auml;hlt. Wenn Sie auf "Weiter" klicken, verlassen Sie die Homepage von Abbott GmbH & Co. KG. Bitte beachten Sie, dass die Abbott GmbH & Co. KG f&uuml;r den Inhalt der verlinkten Seite nicht verantwortlich ist.';
        // var langStatement = '';
        var confirmRequest = 'Wollen Sie die externe Seite betreten?';
        var no = 'nein';
        var yes = 'ja';
        var confirmTitle = 'Externer Link';
        
    // document locations
            // var stylesheetUrl = 'externalLinkNotification.css';
            // var scriptUrl = 'externalLinkNotification.js';


// config ( popup )

    // dimension
        // notice
        var winw = 300;
        var winh = 350;
    
        // target
        var targetWidth = 1024;
        var targetHeight = 768;
            
    // position
        var screenw = screen.availWidth;
        var screenh = screen.availHeight;
        
        // notice
        var pre_posx = (screenw / 2) - (winw / 2);
        var pre_posy = (screenh / 2) - (winh / 2);
        
        // target
        var targetLeft = (screenw / 2) - (targetWidth / 2);
        var targetTop = (screenh / 2) - (targetHeight / 2);


// main function

    function main () {

        // process
            if ( document.links ) {

                for ( var i = 0; i < document.links.length; ++i ) {
                   
                    var current = document.links[i];
                    
                    // check for external href
                        var isExternal = true;
                        
                        for ( var j = 0; j < exceptionHosts.length; ++j ) {

                            if ( current.hostname == exceptionHosts[j] ) {
                                    isExternal = false;
                            }
                        }  
                    
                    // check for protocol (no mailto)
                        if ( current.protocol != 'http:' ) {
                                isExternal = false;
                        }
                    
                    // attach onclick event
                        if ( isExternal == true ) {
                        
                            current.addEventListener?current.addEventListener("click", showLinkNotification, false):current.attachEvent("onclick", showLinkNotification);
                        }
                }
            }
    }
    

// helper functions

    // popup function
        function showLinkNotification (e) {
        
            // prevent default (open href)
                e.preventDefault?(e.preventDefault()):(e.returnValue=false);
            
            // get crossbrowser event target element ( srcElement )
                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) // defeat Safari bug
                    targ = targ.parentNode;
            
            // fix linked images
                if ( targ.tagName == 'IMG' ) {
                    targ = targ.parentNode;
                }
            
            // get targetUrl
                var targetUrl = targ.href;

            // build popup
                    
                NotificationWin = window.open( '', 'NotificationWin', 'width='+winw+', height='+winh+', left='+pre_posx+', top='+pre_posy+', resizable=yes ' );
                NotificationWin.document.write('<html>');
                NotificationWin.document.write('    <head>');
                NotificationWin.document.write('          <link rel="stylesheet" href="'+ stylesheetUrl +'" type="text/css" />');
                NotificationWin.document.write('    </head>');
                NotificationWin.document.write('    <body>');
                NotificationWin.document.write('        <div class="linkNotification">');
                NotificationWin.document.write('            <p class="title">'+confirmTitle+'</p>');
                NotificationWin.document.write('            <p>'+liabilityStatement+'</p>');
                NotificationWin.document.write('            <p class="title_confirm">'+confirmRequest+'</p>');
                NotificationWin.document.write('            <p class="url">'+targetUrl+'</p>');
                NotificationWin.document.write('            <p class="confirm">[ <a onclick="window.open( \''+ targetUrl +'\', \'targetWin\', \'resizable=yes, scrollbars=yes , width='+targetWidth+', height='+targetHeight+', left='+targetLeft+', top='+targetTop+' \' ); self.close(); return false;" target="_blank" href="'+ targetUrl +'">'+ yes +'</a> ] [ <a class="maincontentlink" href="javascript:self.close()">'+ no +'</a> ]</p>');
                NotificationWin.document.write('        </div>');
                NotificationWin.document.write('    </body>');
                NotificationWin.document.write('</html>');
                NotificationWin.document.close();
                NotificationWin.focus();
        }
  
  
// start main function onload  
    window.addEventListener?window.addEventListener("load", main, false):window.attachEvent("onload", main);
    