<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">$(document).ready(function() {	
	if ($("#globalSponsorships").length &gt; 0) {
		initFullSponsorshipPage ();
	}

	if ($("#leagueSponsorshipContainer").length &gt; 0) {
		initLeagueSponsorships ();
	}

	if ($("#sponsorDetails").length &gt; 0) {
		initAllSponsors ();
	}

	if ($("#sponsorEditForm").length &gt; 0) {
		initSponsorEdit ();
	}
});

function initFullSponsorshipPage () {
	$("select.addSponsorship").change(
		function ()
		{
			var sponsorID = $(this).val ();
			if (!sponsorID)
			{
				return false;
			}
			var aPieces = $(this).attr("id").split ('_');
			switch (aPieces[1])
			{
				case 'Global':
					//	valid, nothing specific to set
					break;
				case 'Sport':
					$("#sponsorshipFormSportID").val (aPieces[2]);
					break;
				case 'League':
					$("#sponsorshipFormLeagueID").val (aPieces[2]);
					break;
				default:
					return false;
					break;
			}
			$("#sponsorshipFormSponsorID").val (sponsorID);
			$("#sponsorshipFormAction").val ("addSponsorship");
			$("#sponsorshipForm").submit ();
		}
	);
	
	$("a.removeSponsorship").click (
		function ()
		{
			var sponsorScopeID = extractID ($(this).attr("id"));
			$("#sponsorshipFormSportID").val($(this).parents('.sponsorshipContainer').attr('data-sportID'));
			$("#sponsorshipFormLeagueID").val($(this).parents('.sponsorshipContainer').attr('data-leagueID'));
			$("#sponsorshipFormSponsorScopeID").val (sponsorScopeID);
			$("#sponsorshipFormAction").val ("removeSponsorship");
			$("#sponsorshipForm").submit ();
			return false;
		}
	);
	
	$("a.editSponsorshipDetails").click (
		function ()
		{
			var sponsorScopeID = extractID ($(this).attr("id"));
			var jEditBox = $("#sponsorshipDetailEdit_" + sponsorScopeID);
			var jDisplayBox = $("#sponsorshipDetailDisplay_" + sponsorScopeID);
			if (jEditBox.is(':visible'))
			{
				$(this).html('Customize Message');
				hide (jEditBox);
				show (jDisplayBox);
			}
			else
			{
				$(this).html('Close');
				show (jEditBox);
				hide (jDisplayBox);
			}
			return false;
		}
	);
	
	//	save changes to a sponsorship description
	$("input.sponsorshipDetailButton").click (
		function ()
		{
			var sponsorScopeID = extractID ($(this).attr("id"));
			$("#sponsorshipFormSponsorScopeID").val (sponsorScopeID);
			$("#sponsorshipFormSportID").val($(this).parents('.sponsorshipContainer').attr('data-sportID'));
			$("#sponsorshipFormLeagueID").val($(this).parents('.sponsorshipContainer').attr('data-leagueID'));
			$("#sponsorshipFormDescription").val ($("#sponsorshipDetailEdit_" + sponsorScopeID + " textarea").val());
			$("#sponsorshipFormAction").val ("updateSponsorshipDescription");
			$("#sponsorshipForm").submit ();
		}
	);
	
	//	inherited sponsorship customization
	$("a.customizeInheritedLink").click (
		function ()
		{
			var id = extractID($(this).attr("id"));
			var jEditBox = $("#customizeInheritedContainer_" + id);
			if (jEditBox.is (':visible'))
			{
				$(this).html('Customize');
				hide (jEditBox);
			}
			else
			{
				$(this).html('Close');
				show (jEditBox);
			}
			return false;
		}
	);

	initDeleteLinks ();
}

function initAllSponsors () {
	initDeleteLinks ();
}

function initSponsorEdit () {
	initDeleteLinks ();
}

function initLeagueSponsorships () {
	var $outer = $("#leagueSponsorshipContainer");
	$outer.on ('click', '.editMessage', function (e) {
		e.preventDefault ();
		var $li = $(this).parents ('li');
		$li.find ('.sponsorMessage,.links').hide ().end ()
		   .find ('.editControls').show ().end ();
	}).on ('click', '.cancel', function (e) {
		e.preventDefault ();
		var $li = $(this).parents ('li');
		$li.find ('.editControls').hide ().end ()
		   .find ('.sponsorMessage,.links').show ().end ();
	}).on ('click', '.removeSponsor', function (e) {
		if (confirm ('Remove this sponsor from the league or event?')) {
			var $li = $(this).parents ('li');
			var $form = $("#removeSponsorForm");
			$form.find ('input[Name=SponsorScopeID]').val ($li.attr ('data-scopeid'));
			$form.submit ();
		}
	}).on ('click', '.updateMessage', function (e) {
		var $li = $(this).parents ('li');
		var message = $li.find ("textarea").val ();
		if (!message) {
			alert ('Please provide a message to display with this sponsorship');
		}

		var $form = $('#updateMessageForm');
		$form.find ('input[Name=SponsorScopeID]').val ($li.attr ('data-scopeid')).end ()
			 .find ('input[Name=SponsorID]').val ($li.attr ('data-sponsorid')).end ()
			 .find ('input[Name=Type]').val ($li.attr ('data-type')).end ()
			 .find ('input[Name=Message]').val (message).end ()
			 .submit ();
	});

	$("#addSponsorChooser").on ('change', function () {
		if ($(this).val ()) {
			$("#addSponsorForm").submit ();
		}
	});
}

function initDeleteLinks () {
	$("a.deleteSponsor").click (function () {
		if (confirm ('Are you sure you want to delete this sponsor?'))
		{
			var id = extractID ($(this).attr ("id"));
			$("#deleteSponsorID").val (id);
			$("#deleteSponsorForm").submit ();
		}
		return false;
	});
}
</pre></body></html>