// JavaScript Document - attaches icons to .pdf links, .doc links, and links that open to a new browser window

 linkIcons = function() {
    var links = document.getElementsByTagName("a");
    for (i=0; i<links.length; i++) {
      var currentLink = links[i];
      var images = currentLink.getElementsByTagName("img");
      if (images.length == 0 && currentLink.href.indexOf('.pdf') != -1) {
        var newImg=document.createElement('img');
        newImg.setAttribute('src','/crm/performance/images/pdf.png');
        currentLink.appendChild(newImg);
	  }
      if (images.length == 0 && currentLink.href.indexOf('.doc') != -1) {
        var newImg=document.createElement('img');
        newImg.setAttribute('src','/crm/performance/images/doc.png');
        currentLink.appendChild(newImg);
      }
      if (images.length == 0 && currentLink.target == "_blank") {
        var newImg=document.createElement('img');
        newImg.setAttribute('src','/crm/performance/images/new_window.png');
        currentLink.appendChild(newImg);
      }
    }
  }

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

  addLoadEvent(linkIcons);