﻿// used in DivisionsPageTemplateBase
function ValidateLinks()
{
	// If any img src or link href ends with either of these strings, it is considered invalid.
	//var SUBSTRING1 = "/Superior/undefined";
	var SUBSTRING1 = "/Superior/";
	
	var msg = "";
	var url;
	var i;

	var StringEndsWith = function(str, substr)
	{
		return str.lastIndexOf(substr) == str.length - substr.length;
	}

	// checks img src
	for(i = 0; i < document.images.length; i++)
	{
		url = document.images[i].src;
	
		if(StringEndsWith(url, SUBSTRING1))
			msg += "Image" + i + ":" + url + "+ImageAlt" + i + ":" + document.images[i].alt + "+";
	}

	// checks link href
	for(i = 0; i < document.links.length; i++)
	{
		url = document.links[i].href;
	
		if(StringEndsWith(url, SUBSTRING1))
			msg += "Link" + i + ":" + url + "+LinkInnerHtml" + i + ":" + document.links[i].innerHTML + "+";
	}

	if(msg == "")
		window.setTimeout(ValidateLinks, 500);
	else
	{
		msg = msg.substr(0, msg.length - 1);	// removes the extra "+"
		(new Image()).src = "LINKPROBLEM.aspx?links=" + msg;	// sends link errors using PageNotFound reporting mechanism (LINKPROBLEM.aspx is not an actual page)
	}
}

ValidateLinks();
