function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            func();
            oldonload();
        }
    }
}

function winpop(hlink, width, height, sbar) {
    var href;

    if (typeof(hlink) == 'string') {
        href = hlink;
    } else {
        href = hlink.href;
    }

    var top;
    var left;

    if(typeof window.innerWidth == "number") {
        left = Math.round((window.innerWidth - width) / 2);
        top = Math.round((window.innerHeight - height) / 2);
    }
    else if(typeof window.screenTop == "number" && typeof document.documentElement.clientWidth == "number") {
        left = Math.round((document.documentElement.clientWidth - width) / 2);
        top = window.screenTop + 50;
    }
    else {
        left = Math.round((document.body.clientWidth - width) / 2);
        top = 50;
    }

    var popwin = window.open(href, "_blank",
        'height=' + height +
        ',width=' + width +
        ',top=' + top +
        ',left=' + left +
        ',toolbar=0,directories=0,status=0,menubar=0,resizable=1,scrollbars='+sbar);

    popwin.focus();
    return false;
}

function windowLinks() {
    if(!document.getElementsByTagName) {
         return;
    }

    var anchors = document.getElementsByTagName("a"); // grab all links and pop them in an array called 'anchors'
    for (var i = 0; i < anchors.length; i++) {        // start a loop to work our way through
         var anchor = anchors[i];                     // grab the next link & copy it to 'anchor' for working
         var relIndex = anchor.rel;                   // get the value of it's 'REL' attribute
         if (relIndex){                               // does it have a value for REL?...
            var relSplit = relIndex.split("|");
         
            if (relSplit[0] == "external") {       // If the relSplit[0] is 'external'...
                anchor.target = "_blank";           // then set it's 'target' attribute to '_blank'
                if (anchor.className != "") {
                    anchor.className = anchor.className+" external";     // attach a CSS class to it
                } else {
                    anchor.className = "external";
                }
                anchor.title = "Naujame lange: "+ anchor.href;
            } else if (relSplit[0] == "popup") {      // else if relSplit[0] is 'popup'...
                if (anchor.className != "") {
                    anchor.className = anchor.className+" popup";
                } else {
                    anchor.className = "popup";
                }
                
                anchor.popupWidth = relSplit[1];          // set the popup's width
                anchor.popupHeight = relSplit[2];          // set the popup's height
                anchor.scrbar = 0;
                if (relSplit.length == 4)
                {
                    anchor.scrbar = relSplit[3];
                }
                
                anchor.onclick = function() {winpop(this.href,this.popupWidth,this.popupHeight,this.scrbar);return false;};
            }
        }
    }
}

addLoadEvent(function() {
    windowLinks();
});