﻿	var anonymousHost = 'http://www.mpegla.com';
	var secureHost = 'secure.mpegla.com';
	
	function FixAnonymousLinks() {
		$(function() {
			// select all 'a' tags that do not have target="_blank" attribute
			$('a:not([target="_blank"])').each(function(i) {
				if ($(this).attr('href'))
				{
					var originalHref = $(this).attr('href');
					$(this).attr('href', EnsureProperHost(originalHref));
				}
			});
		});
	}
	
	function EnsureProperHost(href) {
		if (0 == href.indexOf('/')) {
			if (document.location.host.indexOf(secureHost) > -1)
			{
			href = anonymousHost + href;
			}
		} else if (-1 == href.lastIndexOf('/')) {
			if (href.indexOf('mailto') == -1){
				if (href.indexOf('doPostBack') == -1){
			    	if (href.indexOf('#') == -1){
			    		if (document.location.host.indexOf(secureHost) > -1)
						{
			    		href = document.location.href.replace(CurrentPageName(), '') + href;
			    		href = href.replace('http://' + document.location.host, anonymousHost);
			    		}
			    	}
			   	}
			}
		}
		return href;
	}
	
	
	function CurrentPageName() {
		return document.location.href.substring(
			document.location.href.length
			, document.location.href.lastIndexOf('/') + 1
		);
	}


/// overrides the default ProcessDefaultOnLoad function.  The contents are the same as the original function,
/// which a SharePoint out of the box function, with the exception of the line ProcessImn(); which has been commented out
/// this will keep the gold bar from showing up if the site is in the "Internet zone" in internet explorer
	function ProcessDefaultOnLoad(onLoadFunctionNames)
	{
		//** Uncomment this to see when this runs
		//alert('Fixing the Issue');
		
		ProcessPNGImages();
		UpdateAccessibilityUI();
		
		//** We comment out the offending ootb function
		//** and leave the rest of the functions as they were
		//ProcessImn();
		for (var i=0; i < onLoadFunctionNames.length; i++)
		{
			var expr="if(typeof("+onLoadFunctionNames[i]+")=='function'){"+onLoadFunctionNames[i]+"();}";
			eval(expr);
		}
		if (typeof(_spUseDefaultFocus)!="undefined")
			DefaultFocus();
	}
