var ie = document.all; // IE Test

// Makes the bookmark button visible on puts in the functionality
function makeBookmarkButton() {

    // Fail safe for bad browsers
    if(!document.getElementById) return false;
    
    // Checks if object exists
    if(!document.getElementById('bookmarkCntrl')) return false;
    
    // Assigns a var and turns on visibility
    var bmk = document.getElementById('bookmarkCntrl');
    bmk.style.visibility = "visible"
    
    // Makes the print function for onclick, onkeypress and href.
    bmk.onclick = Function("bookmarkPage()");
    bmk.onkeypress = Function("bookmarkPage()");
    //bmk.href = "javascript:window.external.AddFavorite(window.href,document.title)";

}

function bookmarkPage() {
    if (ie) {
        window.external.AddFavorite(location.href, document.title);
    } else if (window.sidebar) {
        window.sidebar.addPanel(document.title, location.href, "")
    }  
}
// Makes the print button visible on puts in the functionality
function makePrintButton() {

    // Fail safe for bad browsers
    if(!document.getElementById) return false;
    
    // Checks if object exists
    if(!document.getElementById('printCntrl')) return false;
    
    // Assigns a var and turns on visibility
    var pnt = document.getElementById('printCntrl');
    pnt.style.visibility = "visible"
    
    // Makes the print function for onclick, onkeypress and href.
    pnt.onclick = Function("window.print()");
    pnt.onkeypress = Function("window.print()");
    pnt.href = "javascript:window.print()";

}



// Makes all links with rel='external' open in a new window -------------------------------------
// http://www.sitepoint.com/article/standards-compliant-world

function makeExternalLinks() {
    
    // Fail safe for bad browsers
    if(!document.getElementsByTagName) return false;
    
    // The A tags
    var aTags = document.getElementsByTagName('a'); 
    
    // How many? Helps with loop optimization
    var aTagsLength = aTags.length;
    
    for (var i=0; i < aTagsLength; i++) {
        // The current tag
        var thisTag = aTags[i];                                               
        
        // if it has a href and has the rel 'external', then set its target to _blank
        if (thisTag.getAttribute('href') && thisTag.getAttribute('rel') == "external") {
            thisTag.target = "_blank"; 
        }
    }

    
}

// Gets around the problem of having multiple onload handlers ----------------------------------
// http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
// http://www.quirksmode.org/js/events_advanced.html

function addEvent(obj, evType, fn) { 

    // W3C type of event registration model
    if (obj.addEventListener) { 
        obj.addEventListener(evType, fn, false); 
        return true; 
    // MS event registration model    
    } else if (obj.attachEvent) { 
        var r = obj.attachEvent("on"+evType, fn); 
        return r; 
    // Bad browsers that can't do either
    } else { 
        return false; 
    } 
}

addEvent(window, 'load', makeExternalLinks);
addEvent(window, 'load', makePrintButton);
addEvent(window, 'load', makeBookmarkButton);






