//*************************************************************************************
// File : mf_setanchortargettype.js
// Version : 1.0
// Requires : mf_domLibrary_0.1.js
// Author : Kyle Weems (ksw)
// Origin : mindfly.com
// Created : April 22, 2008
// Modified : April 22, 2008
// Purpose : Adds a value to the target attribute of all anchors, or if the linkFilter is used, to only the 
// anchors that contain the linkFilter value in their href attributes.
//*************************************************************************************

// Version History (only for changes of at least 0.0.1 in version number)
// ===============
// Version 1.0 (04/22/2008) - Basic functionality completed.


//=============================================================================================
// setAnchorTargetType( targetType, linkFilter)
//=============================================================================================
// Add the string of targetType to all anchors' target attributes. If the overloaded linkFilter variable is given a 
// string value, then the targetType value will only be added to anchors on the page that contain the value of 
// linkFilter in their href attribute.
function setAnchorTargetType(targetType, linkFilter)
{
	// Get a collection of all anchors in the body
	var anchorList = document.getElementsByTagName('a');
	// If there's at least one anchor...
	if(anchorList.length > 0)
	{
		// loop through the anchors
		for(i=0;i<anchorList.length;i++)
		{
			// If there's a value for linkFilter...
			if(linkFilter)
			{
				// Check if the anchor has a href attribute with '.pdf' in it...
				if(anchorList[i].getAttribute('href') && anchorList[i].getAttribute('href').match(linkFilter))
				{
					// Add the attribute 'target' with the value '_blank' to the anchor.
					anchorList[i].setAttribute('target',targetType);
				} // end if
			}
			// Otherwise...
			else
			{
				// Add the attribute 'target' with the value '_blank' to the anchor.
				anchorList[i].setAttribute('target',targetType);
			}
		} // end for loop
	} // end if
} // end of function addTargetToPDFAnchors()

function setTargetBlanktoPDFAnchors()
{
	setAnchorTargetType('_blank','.pdf')
}

addLoadEvent(setTargetBlanktoPDFAnchors);