/*
All Contents of this file are Copyright Covenant Eyes 2007 unless otherwise noted.
*/
function AppendLinks(aData, hrefRules)
{	/* Update all anchor tags on a page with additional data */
	if(aData != null)
	{
		linchors = document.getElementsByTagName("a");
		/* Loop through our anchors */
		for(var lincount in linchors)
		{	/* Get the request URI and check for variables already passed. If there is something there, add our additional data to that; if not, create the get variable. */
			tempHref = linchors[lincount].getAttribute("href");
			requestURI = tempHref.substring( (tempHref.lastIndexOf("/") + 1) );
			if(aData.charAt(0) == "?" || aData.charAt(0) == "&") { aData.substring(1); }
			if(requestURI.lastIndexOf("?") != -1) { hrefUpdate = "&" + aData; } else { hrefUpdate = "?" + aData; }

			if(hrefRules != null)
			{	/* If hrefRules is set, only apply the function to those URLs meeting the criteria. */
				modEnd = false;
				for(ruleURI in hrefRules)
				{
					if(tempHref.substring(0, (ruleURI.length)) == ruleURI)
					{	/* If the URL matches the Rule */
						modEnd = hrefRules[ruleURI];
						if ( !modEnd )
						{
							break;
						}
					}
				}
				if(modEnd == true) { linchors[lincount].setAttribute("href", tempHref + hrefUpdate); }
			}
			else
			{	/* No rules are set, apply globally */
				linchors[lincount].setAttribute("href", tempHref + hrefUpdate);
			}
		}
	}
}

function utmLinkHrefs()
{
	if(typeof __utmLinker == 'function')
	{
		links=document.getElementsByTagName("a");
		if(arguments.length>0)
		{
			for(var arg_loop=0; arg_loop<arguments.length; arg_loop++)
			{
				var specificUrl=arguments[arg_loop];
				for(var loop=0; loop<links.length; loop++)
				{
					var link=links[loop];
					if(link.getAttribute("href") && !link.getAttribute("target"))
					{
						if(link.getAttribute("href").substr(0,specificUrl.length) == specificUrl)
						{
							link.setAttribute("href","javascript:__utmLinker('" + link.getAttribute("href") + "')");
						}
					}
				}
			}//Done looping through the arguments
		} // done working with the arguments
		else
		{ // no arguments were passed in
			for(var loop=0;loop<links.length;loop++)
			{
				link=links[loop];
				if(link.getAttribute("href"))
				{
					link.setAttribute("href","javascript:__utmLinker('" + link.getAttribute("href") + "')");
				}
			}
		}
	}
}

function externalize_links()
{
	if(!document.getElementsByTagName)
	{
		return;
	}
	var anchors = document.getElementsByTagName("a");
	for(var i = 0; i < anchors.length; i++)
	{
		var anchor = anchors[i];
		if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
		{
			anchor.target = "_blank";
		}
	}
}

function init()
{
	externalize_links();
	utmLinkHrefs('https://secure.cvnt.net/');
}
window.onLoad = init;






/* 
Image preloader that works with jQuery.
Cite: http://www.innovatingtomorrow.net/2008/04/30/preloading-content-jquery
*/
jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	}
}