﻿function init() {

    links();
}

function links() {

    var hyperlinks = document.getElementsByTagName('a');

    // parse all links, check for condition, make open in new window
    for (var i = 0; i < hyperlinks.length; i++) {
        if (checkExternalLink(hyperlinks[i]) || checkFileLink(hyperlinks[i]))
            hyperlinks[i].target = "_blank";
        //		hyperlinks[i].onclick = "window.open(this.href); return false;";
    }
}

function changeLargeImage(link) {
    // receives link's href, changes largeimage, return false disables link
    document.getElementById('largeimage').getElementsByTagName('img')[0].src = link.href;

    // if JS off, link executes normally
}

function checkExternalLink(a) {

    // checks beginning for http, indicating absolute link
    if (a.getAttribute('href', 2).substring(0, 7) == "http://") // second parameter for getAttribute for IE bug
        return true;
    else
        return false;
}

function checkFileLink(a) {

    // checks last three characters
    var extension = a.href.substring(a.href.length - 3);

    if (extension == "doc" || extension == "pdf")
        return true;
    else
        return false;
}
