﻿function DoPrinterFriendly()
{
	window.print();
}

function CreatePrinterFriendlyLinks()
{
	try
	{
		var elementToAddLinksTo = $('#LinksHere')[0];
		var allLinks = $('.body a, .Summary a');
		var previousTocElement = null;
		var links = new Array();
		for (var i = 0; i < allLinks.length; i++)
		{
			var myLink = allLinks[i];
			if (myLink.href != null && myLink.href != "")
			{
				if (myLink.href != myLink.innerHTML)
				{
					links.push(myLink);
				}
			}
		}

		if (links.length > 0)
		{
			for (var i = links.length - 1; i >= 0; i--)
			{
				var myLink = links[i];
				if (myLink.href != null && myLink.href != "")
				{
					if (myLink.href != myLink.innerHTML)
					{
						// Found a link with a description different from its href
						// First, insert a footnote reference number.
						var newElement = document.createElement("sup");
						var footNoteText = '';
						if ($(myLink).hasClass('fancyZoom'))
						{
							footNoteText = '<br />';
						}
						footNoteText += "&nbsp;(" + (i + 1) + ")";
						if ($(myLink).hasClass('fancyZoom'))
						{
							footNoteText += ' See Links in this Document at the end for the full URL of this image.';
						}
						newElement.innerHTML = footNoteText;
						newElement.className = "foot-note print-only-inline";
						myLink.parentNode.insertBefore(newElement, myLink.nextSibling);
						// Now add the link to the Links TOC at the end of the article
						var newTocLink = document.createElement("span");
						var newLinkText = '(' + (i + 1) + ') ';
						if ($(myLink).hasClass('fancyZoom'))
						{
							newLinkText += 'Image: ';
						}

						newLinkText += myLink.href;
						newTocLink.innerHTML = newLinkText;
						elementToAddLinksTo.insertBefore(newTocLink, previousTocElement);
						newTocLink.parentNode.insertBefore(
								document.createElement("br"), newTocLink.nextSibling);
						previousTocElement = newTocLink;
					}
				}
			}
		}
		else
		{
			$('#TocLinks').hide();
		}
	}
	catch (ex)
  { }
}

$(document).ready(function ()
{
	$("#QuickDocId").addClass("required");
	$("#QuickDocId").addClass("number");
	$("#details").validate({
		errorLabelContainer: "#QuickErrors",
		errorElement: "span",
		submitHandler: function (form)
		{
			document.location.href = '/' + $('#QuickDocId')[0].value;
		}
	})
});

