﻿
// This functions opeen all rel links in a new window - Belchior Palma / bpalma@ciandt.com
//******************************************************************************
// W3C  are not accept the atribute "target" in links (tag <a>) in doctypes XHTML 1.0 Strict
// this function to do all links with  rel="external" in main link, open in a new window
// EXEMPLE:
//******************************************************************************
//<a href="index.php" title="External Link" rel="external"> 

var url1,title1="";


function openPopup(){
    var windowLink="disclaimer.aspx?url="+url1;
    var windowTitle=title1;
    var windowParam= "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=670,height=500";
        window.open(windowLink);
}

function openPopupOB(){
    var windowLink="disclaimerob.aspx?url="+url1;
    var windowTitle=title1;
    var windowParam= "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=670,height=500";
        window.open(windowLink);
}


function openNewWindow(url){            
        var windowLink=""+url;
        var windowTitle=title1;
        var windowParam= "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=670,height=500";
            window.open(windowLink);
    }


function createExternalLinks() {
    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') { // <-- It´s necessary insert rel="external" in the link
                /*anchor.target = '_blank';*/
                var title = anchor.title
                           /*                  "Du lämnar mcneilab.se och kommer automatiskt till "+
                                            anchor.title + 
                                            ".  Om webbplatsen inte visas efter någon sekund, välj länken för att gå direkt till webbplatsen: \n"+
                                            anchor.getAttribute("href")+ 
                                            "\nDenna länk tar dig till en webbplats där denna "+
                                            anchor.getAttribute("href")+ 
                                            " inte gäller."+
                                            "\nVi rekommenderar att du läser integritetspolicyn för varje webbplats du besöker.";
                                            // <-- Attribute 'title'
                                            */
                
                anchor.title = title;
                var url = anchor.getAttribute("href");
                anchor.href="#";
                title1=title;
                url1=url;
                if( anchor.attachEvent ){
                  anchor.attachEvent('onclick', openPopup);
                   
                } else {
                   anchor.setAttribute('onclick', "javascript:window.open('disclaimer.aspx?url="+url+"','"+anchor.title+"','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=670,height=500');"); 
                }
               // anchor.setAttribute("onClick","javascript:window.open('disclaimer.aspx?url="+url+"','"+anchor.title+"','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=670,height=500');");
            }
            else if(anchor.getAttribute("href") && anchor.getAttribute('rel')=='externalob') { // <-- It´s necessary insert rel="external" in the link
                /*anchor.target = '_blank';*/
                var title = anchor.title
                           /*                  "Du lämnar mcneilab.se och kommer automatiskt till "+
                                            anchor.title + 
                                            ".  Om webbplatsen inte visas efter någon sekund, välj länken för att gå direkt till webbplatsen: \n"+
                                            anchor.getAttribute("href")+ 
                                            "\nDenna länk tar dig till en webbplats där denna "+
                                            anchor.getAttribute("href")+ 
                                            " inte gäller."+
                                            "\nVi rekommenderar att du läser integritetspolicyn för varje webbplats du besöker.";
                                            // <-- Attribute 'title'
                                            */
                
                anchor.title = title;
                var url = anchor.getAttribute("href");
                anchor.href="#";
                title1=title;
                url1=url;
                if( anchor.attachEvent ){
                  anchor.attachEvent('onclick', openPopupOB);
                   
                } else {
                   anchor.setAttribute('onclick', "javascript:window.open('disclaimerob.aspx?url="+url+"','"+anchor.title+"','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=670,height=500');"); 
                }
               // anchor.setAttribute("onClick","javascript:window.open('disclaimer.aspx?url="+url+"','"+anchor.title+"','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=670,height=500');");
            }
        }
    }
}

function createNewWindow() {
    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')=='newWindow') { // <-- It´s necessary insert rel="external" in the link
                /*anchor.target = '_blank';*/
                var title = anchor.title
                           /*                  "Du lämnar mcneilab.se och kommer automatiskt till "+
                                            anchor.title + 
                                            ".  Om webbplatsen inte visas efter någon sekund, välj länken för att gå direkt till webbplatsen: \n"+
                                            anchor.getAttribute("href")+ 
                                            "\nDenna länk tar dig till en webbplats där denna "+
                                            anchor.getAttribute("href")+ 
                                            " inte gäller."+
                                            "\nVi rekommenderar att du läser integritetspolicyn för varje webbplats du besöker.";
                                            // <-- Attribute 'title'
                                            */
                
                anchor.title = title;
                var url = anchor.getAttribute("href");                         
                               
                     
                if( anchor.attachEvent ){                  
                    anchor.setAttribute("target","_blank");                
                  // anchor.attachEvent('onclick', function(){window.open(url);});
                 
                } else {
                   anchor.href="#";
                   anchor.setAttribute('onclick', "javascript:window.open('"+url+"','"+anchor.title+"','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=670,height=500');");                    
                }
               
            }
        }
    }
}
// this function call all arguments in this document
function init() {
	createExternalLinks();
	createNewWindow();
}


//........................................................................
//........................................................................
/* Load function  - compatible with all browsers*/

function addEvent(obj, evType, fn){
    if(obj.addEventListener){
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent('on'+evType, fn);
        return r;
    } else {
        return false;
    }
}

addEvent(window, "load", init);


