// $Id: pdf.js,v 1.3 2004/03/09 13:56:54 powem Exp $

// find pdf links on a page and add an onclick event to them
// Mon 3/8/04

/* this script dynamically adds onClick events to links on the
 * page.  it does this by looping through the document.links array
 * and checking for links to .pdf files.  any link to a .pdf that
 * doesn't already have an onclick event has one assigned to it.
 * 
 * the event calls a function that assigns the pathname of the link
 * to the URL (DCS.dcsuri) and the text of the link (the descriptive
 * text that appears on the page) to the page title (WT.ti).
 *
 * then, the dcsMultiTrack() function is called.
 *
 * the code has to be loaded at the bottom of the page, after the links 
 * array has been filled.  any links that load after the code runs will
 * not be in the array and will not be checked.  other than that, 
 * nothing bad will happen.
 *
 */

findPDF();
findDOC();
findPPT();
findXLS();
findZIP();

function findPDF(){

	var l = document.links;

	function check(){
		var dest = "/" + this.pathname;
		var title = this.firstChild.data;
		dcsMultiTrack('DCS.dcsuri',dest,'WT.ti',title);
	}

	for (i = 0; i < l.length; i++){
		if(l[i].pathname.match(/\.pdf/)){
			if(!l[i].onclick){
				l[i].onclick=check;
			}
		}
	}
} // end findPDF

function findDOC(){

	var l = document.links;

	function check(){
		var dest = this.pathname;
		var title = this.firstChild.data;
		dcsMultiTrack('DCS.dcsuri',dest,'WT.ti',title);
	}

	for (i = 0; i < l.length; i++){
		if(l[i].pathname.match(/\.doc/)){
			if(!l[i].onclick){
				l[i].onclick=check;
			}
		}
	}
} //end findDOC

function findXLS(){

	var l = document.links;

	function check(){
		var dest = this.pathname;
		var title = this.firstChild.data;
		dcsMultiTrack('DCS.dcsuri',dest,'WT.ti',title);
	}

	for (i = 0; i < l.length; i++){
		if(l[i].pathname.match(/\.xls/)){
			if(!l[i].onclick){
				l[i].onclick=check;
			}
		}
	}
} // end findXLS


function findPPT(){

	var l = document.links;

	function check(){
		var dest = this.pathname;
		var title = this.firstChild.data;
		dcsMultiTrack('DCS.dcsuri',dest,'WT.ti',title);
	}

	for (i = 0; i < l.length; i++){
		if(l[i].pathname.match(/\.ppt/)){
			if(!l[i].onclick){
				l[i].onclick=check;
			}
		}
	}
} // end findPPT

function findZIP(){

	var l = document.links;

	function check(){
		var dest = this.pathname;
		var title = this.firstChild.data;
		dcsMultiTrack('DCS.dcsuri',dest,'WT.ti',title);
	}

	for (i = 0; i < l.length; i++){
		if(l[i].pathname.match(/\.zip/)){
			if(!l[i].onclick){
				l[i].onclick=check;
			}
		}
	}
} // end findZIP

function findEXE(){

	var l = document.links;

	function check(){
		var dest = this.pathname;
		var title = this.firstChild.data;
		dcsMultiTrack('DCS.dcsuri',dest,'WT.ti',title);
	}

	for (i = 0; i < l.length; i++){
		if(l[i].pathname.match(/\.exe/)){
			if(!l[i].onclick){
				l[i].onclick=check;
			}
		}
	}
} // end findEXE
