var spacerImageUrl = "/images/spacer.gif";
jQuery.support.cors = true;
var $pageTools;
var $slidingPageTools;
var $layoutWrapper;
var resizeTimeout;
var scrollTimeout;

// insertTextAtCursor
function insertTextAtCursor(textBox, textValue) {
	if (document.selection) {  // older IE
		textBox.focus();
		sel = document.selection.createRange();
		sel.text = textValue;
	}
	else if (textBox.selectionStart || textBox.selectionStart == '0') {  // not older IE
		var startPos = textBox.selectionStart;
		var endPos = textBox.selectionEnd;
		textBox.value = textBox.value.substring(0, startPos)
			+ textValue
			+ textBox.value.substring(endPos, textBox.value.length);
	}
	else {
		textBox.value += textValue;
	}
}

// convertJsonToSelectOptions
function convertJsonToSelectOptions(json, $selectBox, idPropertyName, titlePropertyName, initialItemText) {
	// createOptionText utility functino
	function createOptionText(value, text) {
		return '<option value="' + value + '">' + text + '</option>'
	}

	// requires array with 'id' and 'title'
	if (json.length == 0) {
		return;
	}
	var optionString = '';
	//if (initialItemText && (json.length > 1)) {
	if (initialItemText) {
		optionString += createOptionText('-1', '< ' + initialItemText + ' >');
	}
	for (var i = 0; i < json.length; i++) {
		optionString += createOptionText(json[i][idPropertyName], json[i][titlePropertyName]);
	}
	$selectBox.append($(optionString));
}

// supportsLocalStorage
function supportsLocalStorage() {
	return ('localStorage' in window) && window['localStorage'] !== null;
}

// createDelayManager
function createDelayManager() {
	var timer = 0;
	return function (callback, ms) {
		clearTimeout(timer);
		timer = setTimeout(callback, ms);
	};
}

// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
	var timeout;
	return function () {
		var context = this, args = arguments;
		var later = function () {
			timeout = null;
			if (!immediate) func.apply(context, args);
		};
		var callNow = immediate && !timeout;
		clearTimeout(timeout);
		timeout = setTimeout(later, wait);
		if (callNow) func.apply(context, args);
	};
}

// browserIsIE
function browserIsIE() {
	return (navigator.userAgent.indexOf("MSIE") != -1) || (navigator.userAgent.indexOf("Trident") != -1);
}
var galleriaLoaded = false;

// loadGalleria
function loadGalleria(themeName) {
	if (galleriaLoaded) {
		return true;
	}

	var themeFile;
	if (themeName == 'clubexpress') {
		themeFile = '/script/galleria/themes/clubexpress/galleria.clubexpress.js?v=20220926';
	}
	else {
		themeFile = '/script/galleria/themes/twelve/galleria.twelve.min.js?v=20130808';
	}
	$.ajax({
		url: "/script/galleria/galleria-min.js",
		dataType: "script",
		cache: true,
		async: false,
		success: function () {
			galleriaLoaded = true;
			window.setTimeout(function () {
				Galleria.loadTheme(themeFile);
			}, 200);
		}
	});
}

var firstTimeout = true;
var $timeoutDialog;

// displayTimeoutWarning
function displayTimeoutWarning(timeoutPeriod) {
	if (window != window.top) {
		window.top.displayTimeoutWarning(timeoutPeriod);
		return;
	}
	if (firstTimeout) {
		refreshSession(timeoutPeriod);
		firstTimeout = false;
		return;
	}
	if (!$timeoutDialog) {
		var timeoutWarningHtml =
			'<div><div class="message">Your web session will expire in a few minutes. Click the "Refresh" button to keep it active.</div> \
			<div class="button-panel" style="text-align:center;margin:auto;padding-top:5px;"><a href="#" onclick="refreshSession(' + timeoutPeriod + '); return false;" class="ce-button">Refresh</a></div></div>'
		$timeoutDialog = $(timeoutWarningHtml);
	}
	$timeoutDialog.dialog({ "title": "Session Timeout", "autoOpen": true, "resizable": false });
}

// refreshSession
function refreshSession(timeoutPeriod) {
	if ($timeoutDialog) {
		$timeoutDialog.dialog('close');
	}
	$.get("refresh.ashx", function (data) {
		if (data == "1") {
			window.setTimeout(function () { displayTimeoutWarning(timeoutPeriod) }, timeoutPeriod);
		}
		else {
			alert("Sorry, your session expired and could not be refreshed");
		}
	});
}

// validateAndPostBack
function validateAndPostBack(controlName, postBackArgument) {
	if (validatePage()) {
		__doPostBack(controlName, postBackArgument);
	}
}

// validatePage
function validatePage() {
	if (typeof (DES_ValidateGroup) == 'function') {
		return DES_ValidateGroup("*");
	}
	// should never get to the else - left here just in case we missed something
	else {
		if (typeof (Page_ClientValidate) == 'function') {
			Page_ClientValidate();
			return Page_IsValid;
		}
		else {

			if (typeof (VAM_ValOnClick) == 'function') {
				VAM_ValOnClick('', '');
				return VAM_ValOnSubWGrp('*');
			}
		}
	}
	return true;
}

// alignWithInstructionText
function alignWithInstructionText(selector) {
	$(selector).css("margin-left", $(".instruction-text").css("margin-left"));
}

var modalPopupArray;
var popupNumber = 0;
if (window == window.top) {
	modalPopupArray = new Array();
}

// popupinfo properties (elements of modalPopupArray):
// * $dialog - reference to div for jquery dialog
// * $widget - dialog("widget") result
// * number - popup number - should be the position in the array
// * iframeName - the name attribute of the iframe - for use in window.frames[]
// * dialogId - the id of the dialog wrapper before calling 'dialog'
// * setupComplete - has the popup been set up - has the title been set and the help link adjusted
// * opener - the window which opened the popup - could be top, or another popup
// * pageId - the page id from the url - set by the popup call back
// * popupWidth/popupHeight - the original width and height

// closeModalPopup
// closes the last popup on the list
function closeModalPopup() {
	if (window.top.modalPopupArray.length == 0) {
		return;
	}
	// do this because the close button is not part of the current window
	var currentWindow = window.top.frames[window.top.modalPopupArray[window.top.modalPopupArray.length - 1].iframeName].window;
	if (currentWindow.enableChangeWarning && currentWindow.localChangesPending) {
		showChangeWarning(function () { currentWindow.localChangesPending = false; closeModalPopup(); });
		return;
	}
	currentWindow.localChangesPending = false;
	if (window.top.modalPopupArray.length == 1) {
		window.top.otherChangesPending = false;
	}

	var popupInfo = getModalPopupInfo();

	if (popupInfo.onClose) {
		popupInfo.onClose();
	}
	window.top.modalPopupArray.pop();
	popupInfo.$dialog.dialog("option", "beforeClose", null);

	$("#" + popupInfo.iframeName).remove();
	popupInfo.$dialog.dialog("close");
	popupInfo.$dialog.dialog("destroy");
	popupInfo.$dialog.remove();
}

// getOpener
// get 'opener' for most recent modal popup - top of stack
function getOpener() {
	if (window != window.top) {
		return window.top.getOpener();
	}

	var lastPopup = getModalPopupInfo();
	return lastPopup.opener;
}

// getModalPopupInfo
// get popupInfo for most recent modal popup - top of stack
function getModalPopupInfo() {
	return window.top.modalPopupArray[window.top.modalPopupArray.length - 1];
}

// setupModalPopup
// set title and help link, return opener
function setupModalPopup(title, pageId) {
	if (window != window.top) {
		return window.top.setupModalPopup(title, pageId);
	}
	var popupInfo = getModalPopupInfo();
	if (!popupInfo) {
		return;
	}
	popupInfo.pageId = pageId;
	if (!popupInfo.setupComplete) {

		$("#title_box", popupInfo.$widget).html(title);
		if (modalPopupArray.length == 1) {
			popupInfo.opener = window.top;
		}
		else {
			popupInfo.opener = window.frames[modalPopupArray[modalPopupArray.length - 2].iframeName].window;
		}

		popupInfo.setupComplete = true;
	}
	popupInfo.$dialog.dialog("open");
	return popupInfo;
}

// hidePopupHelpLink
function hidePopupHelpLink() {
	$("#help_box", getModalPopupInfo().$widget).hide();
}

// openPopup
// obsolete - use openModalPopup or openNonModalPopup
// doing only modal for now
// popupName and useScrollBar parameters are no longer used
function openPopup(popupUrl, popupName, popupWidth, popupHeight, modal, useScrollBar) {
	openModalPopup(popupUrl, popupWidth, popupHeight, "");
}

// openModalPopup
function openModalPopup(popupUrl, popupWidth, popupHeight, title, resizable, dialogClass, allowFullScreen, hidePrintLink) {
	if (window != window.top) {
		window.top.openModalPopup(popupUrl, popupWidth, popupHeight, title, resizable, dialogClass);
		return;
	}

	if (!title) {
		title = "";
	}
	if (resizable !== false) {
		resizable = true;
	}
	popupNumber += 1;
	var popupIframeName = 'popup_iframe' + popupNumber;
	var popupDialogId = "popup_dialog" + popupNumber;
	var popupHtml = "<div id='" + popupDialogId + "' class='popup-dialog-content' ><iframe frameborder='0' " + (allowFullScreen ? "allowfullscreen='true' " : '') + "name='" + popupIframeName + "' id='" + popupIframeName + "' class='popup-iframe' src='" + popupUrl + "'></iframe></div>";
	var $popup = $(popupHtml);
	var newPopupInfo = { $dialog: $popup, number: popupNumber, iframeName: popupIframeName, dialogId: popupDialogId, setupComplete: false, "popupWidth": popupWidth + 35, "popupHeight": popupHeight + 40 };
	modalPopupArray.push(newPopupInfo);

	var printBoxHtml = "";//hidePrintLink ? "" : "<div id='print_box' title='Print' iframe_name='" + popupIframeName + "'></div>";
	var maximizeBoxHtml = "";
	if (allowFullScreen !== false) {
		allowFullScreen = true;
	}
	if (allowFullScreen && (popupWidth > 350)) {
		maximizeBoxHtml = "<div id='max_box' title='Maximize'></div>";
	}

	var titleHtml = "<div><div id='title_box'>" + title + "</div>" + maximizeBoxHtml + "</div>" + printBoxHtml + "<div class='clear'></div>	</div>"
	showPopup(newPopupInfo.$dialog, popupWidth, popupHeight, true, titleHtml, dialogBeforeClose, resizable, dialogClass, popupIframeName);
	newPopupInfo.$widget = newPopupInfo.$dialog.dialog("widget");
}

// showPopup
// this should never be called directly
function showPopup($popup, popupWidth, popupHeight, modal, title, beforeCloseFunction, resizable, dialogClass, popupIframeName) {
	var initialOptions = {
		'dialogClass': 'popup-dialog-wrapper' + (dialogClass ? ' ' + dialogClass : ''),
		'width': popupWidth,
		'height': popupHeight,
		'title': '',
		'modal': modal,
		'beforeClose': beforeCloseFunction,
		'resizable': resizable,
		'autoOpen': false,
		'draggable': true,
		'closeText': "Close",
		"position": { my: "center center", at: "center center-10%", of: window },
		"maximized": false,
		'open': function () {
			attachPopupClickHandlers($popup.dialog("widget"), popupIframeName);
			//$("body").css("overflow", "hidden");
		}
	};

	var dialog = $popup.dialog(initialOptions);
	//dialog.on("dialogbeforeclose", beforeCloseFunction);
	setHtmlDialogTitle(title, dialog);
}
// setHtmlDialogTitle
function setHtmlDialogTitle(htmlTitle, $dialog) {
	if (!$dialog) {
		$dialog = getModalPopupInfo().$dialog;
	}
	$dialog.data("uiDialog")._title = function (title) {
		title.html(this.options.title);
	};
	$dialog.dialog('option', 'title', htmlTitle);
}

// attachPopupClickHandlers
function attachPopupClickHandlers(dialogWidget, popupIframeName) {
	$("#max_box", dialogWidget).unbind().click(function () {
		maximizeDialog();
	});
	$("#help_box", dialogWidget).click(function () {
		showHelpForPopup();
	});
	//$("#print_box", dialogWidget).unbind().click(function () {
	//	printIframeDialog(popupIframeName);
	//});
}

// showHelpForPopup
// should be called *only* by the standard popup help link
function showHelpForPopup() {
	showHelp(getModalPopupInfo().pageId);
}

// showHelp
// called by showHelpForPopup and pages which need to show help without using a HelpLink
function showHelp(helpId) {
	if (!helpId) {
		helpId = pageId;
	}
	var win = window.open(helpUrlBase + helpId, "ce_help", "", true);
	win.focus();
}

// showHelpPopup
// used only for vcard, vcal, cvv, and other little help popups
function showHelpPopup(url, width, height) {
	if (!width) {
		width = 400;
	}
	if (!height) {
		height = 600;
	}
	var popupHtml = "<div class='help-dialog'><iframe class='popup-iframe' name='help_iframe' id='help_iframe' src='" + url + "' height='98%' width='98%'></iframe></div>";
	var $helpPopup = $(popupHtml);
	var titleHtml = "<div><div id='title_box'>Help</div><div class='clear'></div></div>"

	showPopup($helpPopup, width, height, false, titleHtml, null, true, 'help', 'help_iframe');
	$helpPopup.dialog("open");
	$helpPopup.dialog("moveToTop");
}

// resizeDialog
function resizeDialog(newWidth, newHeight) {
	var popupInfo = getModalPopupInfo();
	var $popup = popupInfo.$dialog;

	$popup.dialog("option", "width", newWidth);
	$popup.dialog("option", "height", newHeight + 20);
	$popup.dialog("option", "position", { my: "center center", at: "center center-10%" });
	storeResizedPopupSize();
}

// resizeDialogBy
function resizeDialogBy(widthChange, heightChange) {
	var popupInfo = getModalPopupInfo();
	var $popup = popupInfo.$dialog;
	var newWidth = $popup.dialog("option", "width") + widthChange;
	var newHeight = $popup.dialog("option", "height") + heightChange;
	$popup.dialog("option", "width", newWidth);
	$popup.dialog("option", "height", newHeight);
	$popup.dialog("option", "position", { my: "center center", at: "center center-10%" });
	storeResizedPopupSize();
}

// fitDialog
function fitDialog(options) {
	if (!options) {
		options = {};
	}
	if (!options.$widthElement) {
		options.$widthElement = $("form");
	}
	if ((options.widthAdjustment !== 0) && (!options.widthAdjustment)) {
		options.widthAdjustment = 10;
	}
	if (!options.$heightElement) {
		options.$heightElement = options.$widthElement;
	}
	if ((options.heightAdjustment !== 0) && (!options.heightAdjustment)) {
		options.heightAdjustment = 40;
	}
	resizeDialog(options.$widthElement.width() + options.widthAdjustment, options.$heightElement.height() + options.heightAdjustment);
}

// storeResizedPopupSize
function storeResizedPopupSize() {
	var popupInfo = getModalPopupInfo();
	var $popup = popupInfo.$dialog;
	popupInfo.popupHeight = $popup.dialog("option", "height");
	popupInfo.popupWidth = $popup.dialog("option", "width");
}

// maximizeDialog
function maximizeDialog() {
	var popupInfo = getModalPopupInfo();
	var $popup = popupInfo.$dialog;
	var currentOptions = $popup.dialog("option");
	var $maxBox;

	if (currentOptions.maximized) {
		$popup.dialog("option", "maximized", false);
		$popup.dialog("option", "width", popupInfo.popupWidth);
		$popup.dialog("option", "height", popupInfo.popupHeight);
		$popup.dialog("option", "resizable", true);
		$popup.dialog("option", "position", { my: "center center", at: "center center" });
		$maxBox = $("#max_box", $popup.$widget);
		$maxBox.attr('title', 'Maximize');
		$maxBox.removeClass("restore");
	}
	else {
		var newPosition = { my: "left top", at: "left top", of: window };
		$popup.dialog("option", "position", newPosition);
		$popup.dialog("option", "width", $(window).width() - 15);
		$popup.dialog("option", "height", $(window).height() - 10);
		$popup.dialog("option", "resizable", false);
		$popup.dialog("option", "maximized", true);
		$maxBox = $("#max_box", $popup.$widget);
		$maxBox.attr('title', 'Restore');
		$maxBox.addClass("restore");
	}

	$popup.$widget = $popup.dialog("widget");
}

// dialogBeforeClose
// this should never be called directly
function dialogBeforeClose(event, ui) {
	closeModalPopup();
	return false;
}

// showPhotoAlbum
function showPhotoAlbum(moduleId, clubId, itemId = 0) {
	if (itemId == 0) {
		itemId = moduleId;
	}
	openModalPopup('/popup.aspx?page_id=215&amp;club_id=' + clubId + '&amp;module_id=' + moduleId + '&amp;item_id=' + itemId, 640, 580, '', true, 'photo-album', true, true);
}

// showPhotoAlbumTrackable
function showPhotoAlbumTrackable(moduleId, clubId, trackingUrl) {
	//Ajax call
	$.ajax({
		type: "GET",
		url: trackingUrl + "&trackOnly=true", //track only flag indicates the handler not to redirect
		async: false,
		crossDomain: true,
		cache: false,
		success: function (responseText) {
			//call it on success
			showPhotoAlbum(moduleId, clubId);
		}, error: function (xhr, status, error) {
			alert(xhr.responseText);
		}
	});

}


var multiSelectLoaded = false;
// loadMultiSelect
function loadMultiSelect() {
	if (multiSelectLoaded) {
		return;
	}
	if (document.createStyleSheet) {
		document.createStyleSheet('script/jquery.multiselect.css');
	}
	else {
		$("head").append($("<link rel='stylesheet' href='script/jquery.multiselect.css' type='text/css' media='screen' />"));
	}
	$.ajax({
		url: "script/jquery.multiselect.js?v=1.3",
		dataType: "script",
		cache: true,
		async: false,
		success: function () {
			multiSelectLoaded = true;
		}
	});
}

// showPhoto
function showPhoto(url) {
	showImage(url);
}

// showImage
function showImage(url, title, description) {
	if (window != window.top) {
		window.top.showImage(url, title, description);
		return;
	}

	var $dialog = $("<div></div>");
	var image = document.createElement("img")

	image.onload = function () {
		var imageWidth = this.width;
		var maxWidth = $(window).width() - 60;
		if (imageWidth > maxWidth) {
			imageWidth = maxWidth;
		}

		this.width = imageWidth;
		this.title = title;
		$dialog.append(this);
		$dialog.dialog({ "resizable": false, "width": imageWidth + 10, "autoOpen": true, "modal": true, "dialogClass": "image-dialog", "minHeight": "40px", "minWidth": "40px" });
		setHtmlDialogTitle(title, $dialog);
	};
	image.onerror = function () {
		showErrorMessage("Sorry - the requested image could not be loaded");
	};
	image.src = url;
}

// popupCalendarForTextbox
function popupCalendarForTextbox(textBoxControl) {
	$(textBoxControl).datepicker({ selectOtherMonths: true, showOtherMonths: true, yearRange: "-10:+10", changeYear: true, changeMonth: true });
	$(textBoxControl).datepicker("show");
}

// image management stuff

var fileInputControl = null;
var imagePreviewControl = null;
var testImage = null;
var resizeRequired = false;
var maxImageWidth;
var maxImageHeight;
var imageSuccessFunction;
var imageErrorFunction;
var showResizeMessage;

// browserCanShowPreview
function browserCanShowPreview() {
	return false;  // this is going away
}

// getPreviewFileName
function getPreviewFileName(fullFileName) {
	if (!fullFileName) {
		return "";
	}
	var startPosition = fullFileName.lastIndexOf("\\");
	return fullFileName.substring(startPosition + 1);
}

// getUrlFileName
function getUrlFileName(fullFileName) {
	if (!fullFileName) {
		return "";
	}
	var startPosition = fullFileName.lastIndexOf("/");
	return fullFileName.substring(startPosition + 1).replace(")", "");
}

// previewImageWithFileName
function previewImageWithFileName(fileName, imagePreviewControlName, maxWidth, maxHeight, successFunction, errorFunction, resizeMessageRequired) {
	imagePreviewControl = document.getElementById(imagePreviewControlName);
	maxImageWidth = maxWidth;
	maxImageHeight = maxHeight;

	if (successFunction) {
		imageSuccessFunction = successFunction;
	}
	if (errorFunction) {
		imageErrorFunction = errorFunction;
	}
	if (resizeMessageRequired == true) {
		showResizeMessage = true;
	}
	else {
		showResizeMessage = false;
	}

	imagePreviewControl.style.visibility = "hidden";
	testImage = new Image();
	testImage.onload = resizePreview;
	if (imageErrorFunction) {
		testImage.onerror = imageErrorFunction;
	}

	testImage.src = fileName;
}

// resizePreview
function resizePreview() {
	testImage.onload = null;
	testImage.onerror = null;
	var originalWidth = testImage.width;
	var widthRatio = 1;
	if (originalWidth > maxImageWidth) {
		testImage.width = maxImageWidth;
		widthRatio = originalWidth / maxImageWidth;
		testImage.height = testImage.height / widthRatio;
		resizeRequired = true;
	}

	if (testImage.height > maxImageHeight) {
		var heightRatio = testImage.height / maxImageHeight;
		testImage.height = testImage.height / heightRatio;
		testImage.width = testImage.width / heightRatio;
		resizeRequired = true;
	}

	imagePreviewControl.onload = showPreviewImage;
	if (imageErrorFunction) {
		imagePreviewControl.onerror = imageErrorFunction;
	}

	imagePreviewControl.width = testImage.width;
	imagePreviewControl.height = testImage.height;
	imagePreviewControl.src = testImage.src;
	if ((resizeRequired == true) && (showResizeMessage)) {
		alert("The image will be resized as shown to fit the available space");
	}
	resizeRequired = false;
}

// showPreviewImage
function showPreviewImage() {
	imagePreviewControl.onload = null;
	imagePreviewControl.onerror = null;
	if (testImage == null) {
		return;
	}
	imagePreviewControl.width = testImage.width;
	imagePreviewControl.height = testImage.height;
	imagePreviewControl.style.visibility = "visible";
	testImage = null;
	if (imageSuccessFunction) {
		imageSuccessFunction();
	}
}

// resizeImage
function resizeImage(image, maxImageWidth, maxImageHeight) {
	var originalWidth = image.width;
	var widthRatio = 1;
	if (originalWidth > maxImageWidth) {
		image.width = maxImageWidth;
		widthRatio = originalWidth / maxImageWidth;
		image.height = image.height / widthRatio;
	}

	if (image.height > maxImageHeight) {
		var heightRatio = image.height / maxImageHeight;
		image.height = image.height / heightRatio;
		image.width = image.width / heightRatio;
	}
}

// refreshPage
function refreshPage() {
	var submitButton = document.getElementById(submitButtonName);
	if (submitButton == null) {
		if (enableChangeWarning) {
			if (otherChangesPending) {
				sessionStorage.setItem('otherChangesPending', '1');
			}
			localChangesPending = false;
			window.top.otherChangesPending = false;
		}
		var currentUrl = window.location.href;
		if (currentUrl.indexOf("action=") == -1) {
			window.location.reload();
		}
		else {
			var regex = new RegExp("action=[^&]*&?");
			newUrl = currentUrl.replace(regex, "");
			window.location.href = newUrl;
		}
	}
	else {
		submitButton.onclick();
	}
}

// formatNumber
function formatNumber(number, decimalPlaces, useSeparator) {
	if (isNaN(parseFloat(number))) {
		return "NaN";
	}
	if (isNaN(parseInt(decimalPlaces, 10))) {
		decimalPlaces = 2;
	}

	if (decimalPlaces == 0) {
		number = Math.round(number);
	}

	var options = { minimumFractionDigits: decimalPlaces, maximumFractionDigits: decimalPlaces, useGrouping: useSeparator };
	return number.toLocaleString(window.navigator.language, options);
}

//// formatNumber
//function formatNumber(number, decimalPlaces, dollarSign, scaleFactor) {
//	//return formatNumber2(number, decimalPlaces, dollarSign, scaleFactor, true);
//	return formatNumber3(number, decimalPlaces, true);
//}

//// formatNumber2
//function formatNumber2(number, decimalPlaces, dollarSign, scaleFactor, useSeparator) {
//	return formatNumber3(number, decimalPlaces, useSeparator);
//if (isNaN(parseFloat(number))) {
//	return "NaN";
//}
//if (isNaN(parseInt(decimalPlaces, 10))) {
//	decimalPlaces = 2;
//}

//if (decimalPlaces == 0) {
//	if (commas == true) {
//		return addCommas(Math.round(number).toString());
//	}
//	else {
//		return Math.round(number).toString();
//	}
//}

//if (isNaN(parseInt(scaleFactor))) {
//	scaleFactor = 0;
//}
//var numberString = "" + Math.round(number * Math.pow(10, (decimalPlaces - scaleFactor)));
//while (numberString.length <= decimalPlaces) {
//	numberString = "0" + numberString;
//}
//var decimalPosition = numberString.length - decimalPlaces;

//if (dollarSign == true) {
//	dollarSign = "$ ";
//}
//else {
//	dollarSign = "";
//}
//if (commas) {
//	return dollarSign + addCommas(numberString.substring(0, decimalPosition) + "." + numberString.substring(decimalPosition, numberString.length));
//}
//else {
//	return numberString.substring(0, decimalPosition) + "." + numberString.substring(decimalPosition, numberString.length);
//}
//}

//// addCommas
//function addCommas(nStr) {
//	nStr += '';
//	x = nStr.split('.');
//	x1 = x[0];
//	x2 = x.length > 1 ? '.' + x[1] : '';
//	var rgx = /(\d+)(\d{3})/;
//	while (rgx.test(x1)) {
//		x1 = x1.replace(rgx, '$1' + ',' + '$2');
//	}
//	return x1 + x2;
//}

// roundFloat
function roundFloat(number, decimalPlaces) {
	if (isNaN(parseFloat(number))) {
		return "NaN";
	}
	if (isNaN(parseInt(decimalPlaces, 10))) {
		decimalPlaces = 2;
	}

	return parseFloat(number.toFixed(decimalPlaces));
}

// getAjaxObject
function getAjaxObject() {
	if (window.ActiveXObject) { // IE 
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		if (window.XMLHttpRequest) { // Non-IE browsers
			return new XMLHttpRequest();
		}
		else {
			return null;
		}
	}
}

// trimString
function trimString(input) {
	var regex = new RegExp("^\\s+");
	var output = input.replace(regex, "");

	regex = new RegExp("\\s+$");
	output = output.replace(regex, "");

	return output;
}

// keyDownHandler
function keyDownHandler(e) {
	var keyNumber = 0;
	var source;
	if (e) {
		// netscape/mozilla code
		keyNumber = e.which;
		source = e.target;
	}
	else {
		// ie code
		keyNumber = window.event.keyCode;
		source = window.event.srcElement;
	}

	// let alpha, numeric, and standard punctuation keys go
	if ((keyNumber >= 32) && (keyNumber <= 97)) {
		return true;
	}

	// escape
	if (keyNumber == 27) {
		var cancelButton = document.getElementById(cancelButtonName);
		if (cancelButton == null) {
			doCancel();
		}
		else {
			window.setTimeout(cancelButton.onclick, 20);
		}
		return false;
	}

	// F1
	if (keyNumber == 112) {
		showHelp(pageId);
		return false;
	}

	// enter (return)
	if (keyNumber == 13) {
		if ((source.type == "textarea") || (source.tagName == "A")) {
			return true;
		}
		else if ((source.type == "text") && (source.id) && (source.id.indexOf('tag_box') != -1)) {
			// enter key in a tag box should not trigger a post back
			return false;
		}
		else if (source.className == "ql-editor") {
			// enter key in a Quill Editor should not trigger a post back
			return false;
		}
		else {
			var submitButton = document.getElementById(submitButtonName);
			if (submitButton != null) {
				submitButton.onclick();
			}
			return false;  // return false for enter keys so that there are no accidental form submits
		}
	}

	// default
	return true;
}   // keyDownHandler

// escapeQuotes
function escapeQuotes(text) {
	return text.replace(/"/g, '\\"').replace(/'/g, "\\'");
}

// encodeQuotes
function encodeQuotes(text) {
	return text.replace(/"/g, '&quot;').replace(/'/g, "&#39;");
}

// showInfoMessage
function showInfoMessage(message, sticky) {
	var options = { "dialogClass": "info-dialog", "resizable": "false", "modal": false, title: "Message", addOKButton: true };

	if (typeof message == "string") {
		options.sticky = !!sticky;
		options.message = message;
	}
	else {
		if (message.jquery) {
			options.$message = message;

			if (message.attr("sticky") || (!!sticky)) {
				options.sticky = true;
			}
			var messageTitle = message.attr("title");
			if (messageTitle) {
				options.title = messageTitle;
			}
		}
		else {
			return;
		}
	}
	showMessage(options);
	return options;
}

// showErrorMessage
function showErrorMessage(message) {
	var options = { "dialogClass": "error-dialog", "title": "Error", "sticky": true, "addOKButton": true, "resizable": "false", "modal": true, "position": { my: "center center", at: "center center", within: window } };
	if (typeof message == "string") {
		options.message = message;
	}
	else {
		if (message.jquery) {
			options.$message = message;
		}
		else {
			return;
		}
	}
	options.titleOnly = false;
	if (isPopup) {
		options.position.within = $("div.popup-wrapper");
		options.position.of = null;
	}
	showMessage(options);
}

// showMessage
function showMessage(options) {
	if ((!options.message) && (!options.$message)) {
		return;
	}

	if (!options.$message) {
		options.$message = $("<div>" + options.message + "</div>");
	}

	if (options.addOKButton) {
		options.buttons = [{
			text: "Ok",
			click: function () { $(this).dialog("close"); }
		}];
		options.open = function () {
			$(this).focus();
			$(this).keydown(function (e) {
				if (e.keyCode == $.ui.keyCode.ENTER) {
					$(this).dialog("close");
					return false;
				}
			});
		};
	}
	if (!options.sticky) {
		options.open = function () {
			var $this = $(this);
			setTimeout(function () { try { $this.dialog("option", "hide", { effect: "fade", duration: 2000 }); $this.dialog("close"); } catch (e) { } }, 5000);
		};
	}

	var $dialog = options.$message.dialog(options).dialog("widget");
	options.$message.dialog("open");
}

// askYesNoQuestion
function askYesNoQuestion(questionText, questionTitle, yesText, yesFunction, noText, noFunction) {
	var options = {
		'questionText': questionText,
		title: questionTitle,
		buttons: [
			{
				text: yesText,
				click: function () {
					$(this).dialog("close");
					if (yesFunction) {
						yesFunction.call();
					}
				}
			},
			{
				text: noText,
				click: function () {
					$(this).dialog("close");
					if (noFunction) {
						noFunction.call();
					}
				}
			}
		]
	}
	askQuestion(options);
}

// askQuestion
function askQuestion(customOptions) {
	var options = {
		modal: true,
		zIndex: 10000,
		autoOpen: true,
		width: 'auto',
		resizable: false,
		close: function (event, ui) {
			$(this).remove();
		}
	};
	$.extend(options, customOptions);

	$('<div></div>').appendTo('body').html('<div id="ask_question_text">' + options.questionText + '</div>').dialog(options);
}

function enableMenus() {
	var $subParents = $("ul.site-menu li.sub-parent").not('.mobile-layout-wrapper ul.site-menu li.sub-parent, ul.site-menu.mobile-site-menu li.sub-parent');
	if ($subParents.length != 0) {

		$subParents.hoverIntent(
			function () {
				$("ul.sub-menu", $(this)).show().attr("aria-expanded", "true");
				$("ul.sub-menu.mega-sub ul.sub-menu", $(this)).css('display', 'inline-block');
				$(this).find("ul.sub-menu.mega-sub").position({
					"my": "right top",
					"at": "right bottom",
					"of": $(this),
					"collision": "fit"
				});
			},
			function () {
				$("ul.sub-menu", $(this)).hide().removeAttr("aria-expanded");
			}
		);
		$subParents.click(function (event) {
			showSubMenu(event, this);
		});
		$subParents.keydown(function (event) {
			if (event.which == 9) {
				return;
			}
			showSubMenu(event, this);
		});
	}
}
// ready
// process message boxes and widgets, page tools
$(document).ready(function () {
	enableMenus();

	// connect keyHandler function to key down event
	document.onkeydown = keyDownHandler;

	var $error = $("#error_message");
	if ($error.length != 0) {
		showErrorMessage($error.html());
		$error.hide();
	}

	var $info = $("#info_message");
	if ($info.length != 0) {
		var sticky = $info.attr("sticky");
		showInfoMessage($info.html(), sticky);
		$info.hide();
	}

	setupChangeWarning();

	// nothing else applies to popups
	if (isPopup) {
		return;
	}
	if (isMobileDevice) {
		mobilePageToolsHide();
	}
	else {
		$pageTools = $("#page_tools");
		$slidingPageTools = $("#sliding_page_tools");
		getLayoutWrapper();
		setupPageTools();
	}

	if (userLoggedIn) {
		wrapHighResolution();
		displayFavorites();
	}
	removeLegacyEditable();
});		// end of doc.ready

// showSubMenu
function showSubMenu(event, target) {
	var $submenu = $("ul.sub-menu", $(target));
	if ($submenu.attr("aria-expanded")) {
		$submenu.removeAttr("aria-expanded").hide();
	}
	else {
		$submenu.attr("aria-expanded", "true").show();
	}
}

// displayFavorites
function displayFavorites() {
	$('#favorites_hover').hoverIntent(
		function () {
			$("#favorites_dropdown").show();
		},
		function () {
			$("#favorites_dropdown").hide();
		});
}

// getLayoutWrapper
function getLayoutWrapper() {
	$layoutWrapper = $("#layout_wrapper, div.layout-wrapper");
	if ($layoutWrapper.length != 0) {
		return;
	}
	$layoutWrapper = $("div.template-wrapper");
	if ($layoutWrapper.length != 0) {
		return;
	}
	$layoutWrapper = $("div.content-container");
	if ($layoutWrapper.length != 0) {
		return;
	}
	$layoutWrapper = $("div.page-container");
	if ($layoutWrapper.length != 0) {
		return;
	}
	$layoutWrapper = $("td.content-container");
	if ($layoutWrapper.length != 0) {
		return;
	}
	$layoutWrapper = $("table.outer-box");
	if ($layoutWrapper.length != 0) {
		return;
	}
	$layoutWrapper = $("table.template-table");
	if ($layoutWrapper.length != 0) {
		return;
	}
	$layoutWrapper = $("table.main-table");
	if ($layoutWrapper.length != 0) {
		return;
	}
	$layoutWrapper = $("#page_content");
}

// page tools stuff
var $pageToolsReferenceElement;
var pageWidth, layoutWidth, windowWidth;
var horizontalPosition, verticalPosition;
var tooWide;
var myPosition = "left top";
var atPosition;
var forcedPosition = false;
var PageToolsEvent = {};
PageToolsEvent.Load = 1;
PageToolsEvent.Resize = 2;
PageToolsEvent.Scroll = 3;
PageToolsEvent.PageWidth = 4;
var xCookie = "ptx";
var yCookie = "pty";

// setupPageTools
function setupPageTools() {
	if (previewMode || (($pageTools.length == 0) && $slidingPageTools.length == 0)) {
		$pageTools.hide();
		$slidingPageTools.hide();
		return;
	}
	if (isIE7) {
		window.setTimeout(function () {
			positionPageTools(PageToolsEvent.Load);
		}, 1000);
	}
	else {
		positionPageTools(PageToolsEvent.Load);
	}
	$(window).resize(function () {
		clearTimeout(resizeTimeout);
		resizeTimeout = setTimeout(function () { positionPageTools(PageToolsEvent.Resize); }, 100);
	});
	$(window).scroll(function () {
		clearTimeout(scrollTimeout);
		scrollTimeout = setTimeout(function () { positionPageTools(PageToolsEvent.Scroll); }, 100);
	});
	$("#drag_box", $pageTools).hover(function () { $pageTools.draggable({ "stop": function (event, ui) { forcePageToolsPosition(ui.position.left, ui.position.top); } }) });
}

// positionPageTools
function positionPageTools(event) {
	if (event == PageToolsEvent.Load) {
		var ptx = getCookie(xCookie);
		if (ptx) {
			var pty = getCookie(yCookie);
			forcedPosition = true;
			getForcedPosition(ptx, pty);
		}
		else {
			verticalPosition = "top+200";
			if (pageToolsReferenceSelector) {
				$pageToolsReferenceElement = $(pageToolsReferenceSelector);
			}
			else {
				$pageToolsReferenceElement = $layoutWrapper;
			}
			windowWidth = $(window).outerWidth();
			forcedPosition = false;
		}
	}

	if (!forcedPosition) {
		if ((event == PageToolsEvent.Load) || (event == PageToolsEvent.PageWidth)) {
			layoutWidth = $layoutWrapper.outerWidth();
			if (isIE7) {
				pageWidth = $pageToolsReferenceElement.get(0).offsetWidth;
			}
			else {
				pageWidth = $pageToolsReferenceElement.outerWidth();
			}

			// adjust page width for centering
			if (pageWidth > layoutWidth) {
				pageWidth += (pageWidth - layoutWidth);
			}
			else {
				pageWidth = layoutWidth;
			}
		}

		if (event == PageToolsEvent.Resize) {
			var newWindowWidth = $(window).width();
			// skip ie7 repeated resize events
			if (newWindowWidth == windowWidth) {
				return;
			}
			else {
				windowWidth = newWindowWidth;
			}
		}

		if (event != PageToolsEvent.Scroll) {
			if (pageWidth > (windowWidth - 60)) {
				tooWide = true;
				myPosition = "right top";
				horizontalPosition = "right";
			}
			else {
				tooWide = false;
				myPosition = "left top";
				var toolsX = windowWidth - ((windowWidth - pageWidth) / 2);
				horizontalPosition = "left+" + Math.round(toolsX);
			}
			atPosition = horizontalPosition + " " + verticalPosition;
		}
	}
	$pageTools.position({ my: myPosition, at: atPosition, of: window });
	if (tooWide) {
		$pageTools.css("z-index", 200);
	}
}

// getForcedPosition
function getForcedPosition(x, y) {
	verticalPosition = "top+" + y;

	horizontalPosition = "left+" + x;
	atPosition = horizontalPosition + " " + verticalPosition;
}

// forcePageToolsPosition
function forcePageToolsPosition(x, y) {
	var scrollTopPosition;

	if (window.pageYOffset != null) {
		scrollTopPosition = window.pageYOffset;
	}
	else {
		scrollTopPosition = window.document.documentElement.scrollTop;
	}

	var offset = Math.max(0, scrollTopPosition);
	y -= offset;

	setCookie(xCookie, x, 7);
	setCookie(yCookie, y, 7);

	getForcedPosition(x, y);

	forcedPosition = true;
}

///cookie stuff
// setCookie
function setCookie(name, value, days) {
	var expires;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		expires = "; expires=" + date.toGMTString();
	}
	else {
		expires = "";
	}
	document.cookie = name + "=" + value + expires + "; SameSite=Lax; secure; path=/";
}

// getCookie
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substr(1, c.length);
		if (c.indexOf(nameEQ) == 0) {
			return c.substr(nameEQ.length, c.length);
		}
	}
	return null;
}

// deleteCookie
function deleteCookie(name) {
	setCookie(name, "", -1);
}

// hoverIntent v1.10.1 // 2019.10.05 // jQuery v1.7.0+
// http://briancherne.github.io/jquery-hoverIntent/
//
// You may use hoverIntent under the terms of the MIT license.Basically that
// means you are free to use hoverIntent as long as this header is left intact.
// Copyright 2007 - 2019 Brian Cherne
!function (factory) { "function" == typeof define && define.amd ? define(["jquery"], factory) : "object" == typeof module && module.exports ? module.exports = factory(require("jquery")) : jQuery && !jQuery.fn.hoverIntent && factory(jQuery) }(function ($) { "use strict"; function track(ev) { cX = ev.pageX, cY = ev.pageY } var cX, cY, _cfg = { interval: 100, sensitivity: 6, timeout: 0 }, INSTANCE_COUNT = 0, compare = function (ev, $el, s, cfg) { if (Math.sqrt((s.pX - cX) * (s.pX - cX) + (s.pY - cY) * (s.pY - cY)) < cfg.sensitivity) return $el.off(s.event, track), delete s.timeoutId, s.isActive = !0, ev.pageX = cX, ev.pageY = cY, delete s.pX, delete s.pY, cfg.over.apply($el[0], [ev]); s.pX = cX, s.pY = cY, s.timeoutId = setTimeout(function () { compare(ev, $el, s, cfg) }, cfg.interval) }; $.fn.hoverIntent = function (handlerIn, handlerOut, selector) { var instanceId = INSTANCE_COUNT++, cfg = $.extend({}, _cfg); $.isPlainObject(handlerIn) ? (cfg = $.extend(cfg, handlerIn), $.isFunction(cfg.out) || (cfg.out = cfg.over)) : cfg = $.isFunction(handlerOut) ? $.extend(cfg, { over: handlerIn, out: handlerOut, selector: selector }) : $.extend(cfg, { over: handlerIn, out: handlerIn, selector: handlerOut }); function handleHover(e) { var ev = $.extend({}, e), $el = $(this), hoverIntentData = $el.data("hoverIntent"); hoverIntentData || $el.data("hoverIntent", hoverIntentData = {}); var state = hoverIntentData[instanceId]; state || (hoverIntentData[instanceId] = state = { id: instanceId }), state.timeoutId && (state.timeoutId = clearTimeout(state.timeoutId)); var mousemove = state.event = "mousemove.hoverIntent.hoverIntent" + instanceId; if ("mouseenter" === e.type) { if (state.isActive) return; state.pX = ev.pageX, state.pY = ev.pageY, $el.off(mousemove, track).on(mousemove, track), state.timeoutId = setTimeout(function () { compare(ev, $el, state, cfg) }, cfg.interval) } else { if (!state.isActive) return; $el.off(mousemove, track), state.timeoutId = setTimeout(function () { !function (ev, $el, s, out) { var data = $el.data("hoverIntent"); data && delete data[s.id], out.apply($el[0], [ev]) }(ev, $el, state, cfg.out) }, cfg.timeout) } } return this.on({ "mouseenter.hoverIntent": handleHover, "mouseleave.hoverIntent": handleHover }, cfg.selector) } });

// used only by photo albums and color picker
// closable 11/27/2012 from rick strahl
(function (e) { e.fn.closable = function (t) { var n = { handle: null, closeHandler: null, cssClass: "closebox", imageUrl: null, fadeOut: null }; e.extend(n, t); return this.each(function (t) { var r = e(this); var i = r.css("position"); if (!i || i == "static") r.css("position", "absolute"); var s = n.handle ? e(n.handle).css({ position: "relative" }) : r; var o = n.imageUrl ? e("<img>").attr("src", n.imageUrl).css("cursor", "pointer") : e("<div>"); o.addClass(n.cssClass).click(function (t) { if (n.closeHandler) if (!n.closeHandler.call(this, t)) return; if (n.fadeOut) e(r).fadeOut(n.fadeOut); else e(r).hide() }); if (n.imageUrl) o.css("background-image", "none"); s.append(o) }) } })(jQuery)

// text size control
var textSizeState = 1;
var $textSizeElements = null;
function toggleTextSize() {
	if (!$textSizeElements) {
		$textSizeElements = $("*").not("body").not("#footer *").not(".footer-container *").not(".main-menu *").not(".site-menu *").not(".ui-tabs-nav *").not("#user_panel *").not("#tool_wrapper *");
	}

	switch (textSizeState) {
		case 1:
			$textSizeElements.css("font-size", "inherit");
			$("body").css("font-size", "115%");
			textSizeState = 2;
			break;
		case 2:
			$("body").css("font-size", "130%");
			textSizeState = 3;
			break;
		case 3:
			$textSizeElements.css("font-size", "");
			$("body").css("font-size", "");
			textSizeState = 1;
			break;
	}
}

// styleDialog
function styleDialog($printDoc) {
	$("h1", $printDoc).show();
	var $scripts = $("script", $printDoc);
	$scripts.remove();
}

// printIframeDialog
function printIframeDialog(iframeName) {
	var dialogIframe = window.top.frames[iframeName];
	var $printElement = $("div#popup_wrapper > form", dialogIframe.document);
	printPage($printElement);
}

var printAreaLoaded = false;

// printPage
function printPage(contentContainer, pageHeader, clubName, clubUrl, additionalCss) {
	var $content;
	if (contentContainer) {
		if (contentContainer.jquery) {
			$content = contentContainer;
		}
		else {
			$content = $("#" + contentContainer);
		}
	}
	else {
		$content = $("#page_content");
		if ($content.length == 0) {
			$content = $("#ctl00_page_content");
		}
	}
	if ($content.length == 0) {
		return;
	}
	$content.find('script').remove();
	var options = {
		popClose: false,
		mode: 'iframe',
		extraCss: additionalCss,
		popTitle: pageHeader,
		header: pageHeader,
		callback: styleDialog
	};

	if (printAreaLoaded) {
		$content.printArea(options);
	}
	else {
		$.ajax({
			url: "/script/printArea_min.js?v=20221027",
			dataType: "script",
			cache: true,
			async: true,
			success: function () {
				$content.printArea(options);
				printAreaLoaded = true;
			}
		});
	}
}

// manager page legends
var legendLoaded = false;

// setupLegend
function setupLegend() {
	var $managerTables = $("table.manager-table").filter(":not(.no-legend)");
	$managerTables.each(function () {
		var $table = $(this);
		if ($("tbody tr td a", $table).length == 0) {
			return;
		}
		var $maintainHeader = $("tr:first th:last", $table);
		//		var $maintainHeader = $("tr th", $table).filter(':last');
		if ($maintainHeader.length != 1) {
			return;
		}
		var $legendWrapper = $('<div class="legend-wrapper" aria-hidden="true"><div class="legend-drop-down"></div><div class="legend-drop-info"></div></div>');
		$maintainHeader.append($legendWrapper);
		$legendWrapper.hoverIntent(
			function () { loadLegend($table, $legendWrapper); $(".legend-drop-info", $legendWrapper).show().position({ 'my': 'right bottom ', 'at': 'left bottom ', 'of': $(".legend-drop-down", $legendWrapper), 'collision': 'fit' }); },
			function () { $(".legend-drop-info", $legendWrapper).hide(); }
		);
	});
}

// loadLegend
function loadLegend($table, $legendWrapper) {
	if ($table.data("legendLoaded")) {
		return;
	}

	var $iconCell = $("tbody tr td", $table).filter(':last-child');
	var $icons = $("a:not(.no-legend)", $iconCell);
	if ($icons.length == 0) {
		return;
	}
	var legendList = {};
	var legendHtml = '';

	$icons.each(function () {
		legendList[this.className] = this.title;
	});

	for (var className in legendList) {
		legendHtml += '<div class="legend-item"><div class="legend-icon ' + className + '"></div>' + legendList[className] + '</div>'
	}
	$("div.legend-drop-info", $legendWrapper).html(legendHtml);
	$table.data("legendLoaded", true);
}

// addTextareaResize
function addTextareaResize($textareas) {
	if (navigator.userAgent.match(/(MSIE)|(Trident)|(Edge)/)) {
		$textareas.resizable({
			handles: "se",
			stop: function (event, ui) { if (!isIE7) { ui.element.css("height", "-=10px"); } }
		});
		$("div.ui-resizable-se", $textareas.parent()).css("bottom", "13px").css('right', '7px');  // this is a trick to push the resize icon into the textarea
		if (!isIE7) {
			$textareas.parent().css("height", "-=10px");  // shrinks unneeed space under text area
		}
	}
	else {
		$textareas.wrap('<div class="textarea-wrapper"></div>');
	}
}

// addTextareaCounters
function addTextareaCounters($textareas, options) {
	if (!options) {
		options = {
			skipWhenDisabled: true
		};
	}
	$textareas.each(function () {
		var $textarea = $(this);
		if (options.skipWhenDisabled) {
			if ($textarea.prop("disabled")) {
				return;
			}
		}
		var maxLength = $textarea.attr('max_length');
		if (maxLength) {
			options.maxCharacterSize = maxLength;
		}
		if (!options.maxCharacterSize) {
			return;  // no default
		}

		$textarea.textareaCount(options);
	});
}

// setupTextareas
// add counter and resize handles
function setupTextareas(selector, options) {
	var $textareas;
	if (!selector) {
		$textareas = $('textarea').filter(":not(.no-counter)");  // select all except elements that explicitly do not want counters - default
	}
	else {
		if (typeof selector == "string") {
			$textareas = $(selector);
		}
		else {
			if (selector.jquery) {
				$textareas = selector;
			}
		}
	}
	if ($textareas.length == 0) {
		return;
	}

	$.ajax({
		url: "/script/jquery.textareaCounter.plugin.js?v=20150417",
		dataType: "script",
		cache: true,
		async: true,
		success: function () {
			addTextareaResize($textareas);
			addTextareaCounters($textareas, options);
		}
	});
}

// animateSocial
// new layout script for social icons located in layoutwidget.js instead of here.
function animateSocial() {
	$('div#share_button_container').click(function () {
		$('div#vistoggle').fadeTo(300, 1).show();
	});
	$('div#social_close').click(function () {
		$('div#vistoggle').fadeTo(300, 0).hide();
	});
	$('a.social-panel-icon').hover(function () {
		$(this).stop().fadeTo(300, 1).siblings().stop().fadeTo(300, 0.2);
		if ($('div#share_pop_out').is(':visible')) {
			$(this).stop().fadeTo(300, 1).siblings().stop().fadeTo(300, 1);
		}
	},
		function () {
			$(this).stop().fadeTo(300, 1).siblings().stop().fadeTo(300, 1);
		});
	$('div#share_hover_button').hover(function () {
		$(this).stop().fadeTo(300, 1).siblings().stop().fadeTo(300, 0.2);
	},
		function () {
			$(this).stop().fadeTo(300, 1).siblings().stop().fadeTo(300, 1);
		});
}

// mobilePageToolsHide
function mobilePageToolsHide() {
	$('#mobile_tools_handle').click(function () {
		var down = $('#mobile_tools').css('height') == '60px';
		if (down) {
			$('#mobile_tools').animate({ height: 5 }, 500);
			$('#tools_position').hide();
		}
		else {
			$('#mobile_tools').animate({ height: 60 }, 500);
			$('#tools_position').show();
		}
		// $('#mobile_tools').animate({ height: 5 });
	});
}

// valAlert
function valAlert(group, isValid) {
	if (!isValid) {
		showErrorMessage("Please correct the errors shown");
	}
}

// wrapHighResolution
function wrapHighResolution() {
	$('img.hi-res').wrap("<span class='hi-res-wrapper'> <a href='#' class='hi-res-icon' onclick='downloadHiRes(this);return false;' title='Click to download hi res version'></a></span>")
}

// downloadHiRes
function downloadHiRes(el) {
	$this = $(el);
	var url = $this.siblings('img.hi-res').attr("src");
	var orUrl = url.replace("/screen/", "/original/");
	window.open(orUrl, "_blank");
}

var $buttonMenu;
var $buttonMenuField;
// showButtonMenu
// new code should call this instead
function showButtonMenu(triggerElement, array, fieldId) {
	if ($buttonMenu) {
		hideButtonMenu();
	}
	var $trigger = $(triggerElement);
	if (fieldId) {
		$buttonMenuField = $('#' + fieldId);
	}

	var menuHtml = "<div aria-expanded='true' class='button-menu'>" + array.join('') + "</div>";
	$buttonMenu = $(menuHtml);
	$buttonMenu.appendTo('body');
	$buttonMenu.position({
		my: "left top",
		at: "left bottom",
		of: $trigger,
		collision: 'flipfit'
	});

	$("a", $buttonMenu).attr("role", 'menuitem');
	$("a", $buttonMenu).first().focus();
	window.setTimeout(function () {
		document.addEventListener('click', hideButtonMenu);
	}, 200);
}

// hideButtonMenu
function hideButtonMenu() {
	$buttonMenu.remove();
	$buttonMenu = null;
	document.removeEventListener('click', hideButtonMenu);
	if ($buttonMenuField) {
		$buttonMenuField.focus();
		$buttonMenuField = null;
	}
}

// dropdownmenu
// keep this non-standard function name spelling so that existing code will still work
// do not call this in new work
function dropdownmenu(trigger, event, array) {
	showButtonMenu(trigger, array);
}

// delayhidemenu
// not used - only here to avoid error on old code
function delayhidemenu() {
	// do nothing
}

var searchVisible = getCookie("hidesp-" + pageId) != "1";

// toggleSearch - used only on new manager pages
function toggleSearch() {
	searchVisible = !searchVisible;
	hideAndShowSearch();
}

// hideAndShowSearch
function hideAndShowSearch() {
	if (searchVisible) {
		//$('fieldset.search-panel').css('visibility', 'visible').css('height', 'auto').css('padding-top', '').css('padding-bottom', '');
		$('fieldset.search-panel').css('display', 'block');
		$('#toggle_image').attr('src', '/images/manager_buttons/arrow_drop_up.svg');
		$('#toggle_text').html('Hide<br>Search');
		setCookie("hidesp-" + pageId, "0", 1);
	}
	else {
		$('fieldset.search-panel').css('display', 'none');
		//$('fieldset.search-panel').css('visibility', 'hidden').css('height', '0px').css('padding-top', '0px').css('padding-bottom', '0px');
		$('#toggle_image').attr('src', '/images/manager_buttons/arrow_drop_down.svg');
		$('#toggle_text').html('Show<br>Search');
		setCookie("hidesp-" + pageId, "1", 1);
	}
}

// clientLogger
function clientLogger(message, notify, email) {
	console.log(message);
	var queryString = '';
	if (notify) {
		queryString += "notify=1&";
	}
	if (email) {
		queryString += "email=" + encodeURI(email);
	}
	$.ajax({
		url: "handlers/client_logger.ashx?" + queryString,
		contentType: "text/plain",
		async: true,
		data: message,
		dataTyoe: "text",
		method: "POST",
		processData: false
	});
}

var $waitMessage;
// showWaitMessage
function showWaitMessage(waitContent, waitTitle) {
	var messageHtml = "	<div id='wait_message'>" + waitContent + "<img src='/images/wait.gif' /></div>";
	if (!waitTitle) {
		waitTitle = 'Please Wait...';
	}
	document.body.style.cursor = "wait";
	$waitMessage = $(messageHtml)
	$waitMessage.dialog({ title: waitTitle, modal: true, autoOpen: true, closeOnEscape: false, resizable: false, dialogClass: "wait" });
}

/*
 * 	<div id="wait_message" style="width: 300px; display: none; padding-top: 20px; padding-bottom: 20px; font-size: 16px; text-align: center; color: blue; background-color: #eeeeee;">
		Please wait while your payment is processed...
		<br />
		<img src='/images/progressbar_green.gif' />
	</div>

*/
// hideWaitMessage
function hideWaitMessage() {
	document.body.style.cursor = "";
	if ($waitMessage) {
		$waitMessage.dialog("close");
		$waitMessage = null;
	}
}
// removeLegacyEditable
function removeLegacyEditable() {
	$('div.column,div.inner-column').removeAttr('contenteditable');
}

// launchSignup
function launchSignup() {
	openModalPopup('/popup.aspx?page_id=6', 500, 760, 'Signup', true, 'signup', false, true);
}


// change detection 
var previousChangesPending = false;
var previousotherChangesPending = false;

// setupChangeWarning
// called by main ready function
function setupChangeWarning() {
	if (enableChangeWarning) {
		applyChangeHandler();
		if (sessionStorage.getItem('otherChangesPending')) {
			window.top.otherChangesPending = true;
			sessionStorage.removeItem('otherChangesPending');
		}
		var originalDoPostback = __doPostBack;

		// new __doPostBack
		__doPostBack = function (target, argument) {
			if ((argument == 'cancel') && (localChangesPending || window.top.otherChangesPending)) {
				// this is used only by cancel buttons which post back
				showChangeWarning(function () {
					var currentWindow = isPopup ? (window.top.frames[window.top.modalPopupArray[window.top.modalPopupArray.length - 1].iframeName].window) : window;
					currentWindow.localChangesPending = false;
					window.top.otherChangesPending = false;
					__doPostBack(target, '');
				});
				return;
			}

			if (localChangesPending) {
				$("#changes_pending").val("1");
			}

			// hide the changes flags so that beforeunload doesn't prevent the post back
			previousChangesPending = localChangesPending;
			localChangesPending = false;
			previousotherChangesPending = window.top.otherChangesPending;
			window.top.otherChangesPending = false;

			originalDoPostback(target, argument); // call the original
		}  // end of new __doPostBack
	}
	// this handles content edit pages
	// this is done for all content pages in case they have a popup that needs protection
	if (!isPopup) {
		window.addEventListener('beforeunload', function (event) {
			if (enableChangeWarning && (localChangesPending || window.top.otherChangesPending)) {
				event.returnValue = 'asd';
				event.preventDefault();
			}
		})
	}
}

// handleCancelButton
function handleCancelButton(url) {
	//askYesNoQuestion("Changes you made have not been saved.", "Leave page?", "Leave", function () { window.location.href = url; }, "Cancel", null);
	if (enableChangeWarning && (localChangesPending || window.top.otherChangesPending)) {
		showChangeWarning(function () {
			localChangesPending = false;
			if (isPopup) {
				window.top.otherChangesPending = false;
			}
			window.location.href = url;
		});
	}
	else {
		window.location.href = url;
	}
}

// showChangeWarning
function showChangeWarning(leaveFunction) {
	askYesNoQuestion("Changes you made have not been saved.", "Leave page?", "Leave", leaveFunction, "Cancel", null);
}

// applyChangeHandler
function applyChangeHandler() {
	$("input,select,textarea").not('input[type=hidden]').on('input', function () {
		localChangesPending = true;
		if (isPopup) {
			window.top.otherChangesPending = true;
		}
	});
}

// removeSelectChangeHandler
function removeSelectChangeHandler() {
	$("select").off('input');
}

// setChangesPendingFlag
function setChangesPendingFlag() {
	localChangesPending = true;
	window.top.otherChangesPending = isPopup;
}

// resetChangesPendingFlag
function resetChangesPendingFlag() {
	localChangesPending = false;
	window.top.otherChangesPending = false;
}

// ajaxRequestFinished
function ajaxRequestFinished() {
	localChangesPending = previousChangesPending;
	window.top.otherChangesPending = previousotherChangesPending;
	applyChangeHandler();  // refresh event handlers in case fields were replaced or added
}

// addParameterToLink
function addParameterToLink(control, parameterName, parameterValue) {
	var oldHref = control.href;
	if (!oldHref.includes(parameterName)) {
		var newHref = oldHref + "&" + parameterName + "=" + parameterValue;
		control.setAttribute('href', newHref);
	}
}

// removeParameterFromLink
function removeParameterFromLink(control, parameterName) {
	var oldHref = control.href;
	if (oldHref.includes(parameterName)) {
		var newHref = removeURLParameter(oldHref, parameterName);
		control.setAttribute('href', newHref);
	}
}

// removeURLParameter - https://stackoverflow.com/a/1634841
function removeURLParameter(url, parameter) {
	//prefer to use l.search if you have a location/link object
	var urlparts = url.split('?');
	if (urlparts.length >= 2) {

		var prefix = encodeURIComponent(parameter) + '=';
		var pars = urlparts[1].split(/[&;]/g);

		//reverse iteration as may be destructive
		for (var i = pars.length; i-- > 0;) {
			//idiom for string.startsWith
			if (pars[i].lastIndexOf(prefix, 0) !== -1) {
				pars.splice(i, 1);
			}
		}

		return urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : '');
	}
	return url;
}

// addParameterToPopUpLink
function addParameterToPopUpLink(control, parameterName, parameterValue) {
	//<a role="button" href="#" onclick="openModalPopup('/popup.aspx?page_id=128&club_id=870027&report_group_id=23&report_member_id=138832&', 400, 375, ''); return false;">LinkText</a>
	var oldOnClick = control.getAttribute('onclick');
	if (!oldOnClick.includes(parameterName)) {
		var lastParameterIndex = oldOnClick.lastIndexOf("&");
		if (lastParameterIndex == -1) {
			lastParameterIndex = oldOnClick.length;
		}
		var newParameterString = "&" + parameterName + "=" + parameterValue;
		var newOnClick = oldOnClick.slice(0, lastParameterIndex) + newParameterString + oldOnClick.slice(lastParameterIndex);
		control.setAttribute('onclick', newOnClick);
	}
}

// removeParameterFromLink
function removeParameterFromPopUpLink(control, parameterName) {
	var oldOnClick = control.getAttribute('onclick');
	if (oldOnClick.includes(parameterName)) {
		var urlStartIndex = oldOnClick.indexOf("'/") + 2;
		var urlEndIndex = oldOnClick.indexOf("',");
		var oldUrlPortion = oldOnClick.slice(urlStartIndex, urlEndIndex);
		var newUrlPortion = removeURLParameter(oldUrlPortion, parameterName);

		var newOnClick = oldOnClick.slice(0, urlStartIndex) + newUrlPortion + oldOnClick.slice(urlEndIndex);
		control.setAttribute('onclick', newOnClick);
	}
}


function renewNow() {
	window.location.href = renewLink;
}

function payNow() {
	window.location.href = paymentLink;
}

function closeThis() {
	$('.ui-dialog').dialog().dialog("close");
}

// showUserPopup
function showUserPopup(renewal, isTrial) {
	var message;
	var title;
	if (isTrial) {
		title = "Upgrade Your Trial Membership";
		message = "<div style='text-align:center;line-height:2;'>It looks like your trial membership is expiring.<br/><br> <button style='padding:.4em 1em;margin:3px;' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' onclick='renewNow();'>Yes, I want to Upgrade Now</button><button style='padding:.4em 1em;margin:3px;' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' onclick='closeThis();'> No, I won&apos;t Upgrade Now</button></div>";
	}
	else if (renewal && !isTrial) {
		title = "Your membership is expiring";
		message = "<div style='text-align:center;line-height:2;'>It looks like your membership is expiring soon.<br/><br> <button style='padding:.4em 1em;margin:3px;' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' onclick='renewNow();'>Yes, I want to Renew Now</button><button style='padding:.4em 1em;margin:3px;' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' onclick='closeThis();'> No, I won&apos;t Renew Now</button></div>";
	}
	else {
		title = "You have a pending payment";
		message = "<div style='text-align:center;line-height:2;'>It looks like you have at least one pending payment.<br><br> <button style='padding:.4em 1em;margin:3px;' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' onclick='payNow();'>Yes, I want to make a Payment</button><button style='padding:.4em 1em;margin:3px;' class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' onclick='closeThis();'> No, I won&apos;t Pay Now</button></div>";
	}
	var options = {
		"dialogClass": "info-dialog",
		"resizable": true,
		"modal": false,
		'title': title,
		'addOKButton': false,
		'sticky': true,
		'message': message,
		'width': 'auto'
	};
	showMessage(options);
}

var stripeLoaded;

$(window).on("load", function () {
	setTimeout(function () {
		var $widgets = $("div.ce-widget, div.widget-container").not(".no-handler");
		if ($widgets.length != 0) {
			processWidgets($widgets);
		}
		var $layoutWidgets = $("div.layout-widget, div.layout-widget-container");
		if ($layoutWidgets.length != 0) {
			processLayoutWidgets($layoutWidgets);
		}
	}, 1000);
});

$(window).on("focus", function () {
	console.log("focus");
	var $widgets = $("div.ce-widget, div.widget-container").not(".no-handler");
	if ($widgets.length != 0) {
		processWidgets($widgets);
	}
});

// checkAllowDoubleClick - For popup links that need to reactivate within a couple seconds
function checkAllowDoubleClick(el, milliseconds) {
	// Default to 2000 ms
	if (typeof milliseconds == 'undefined') {
		milliseconds = 2000;
	}

	var $this = $(el);
	// If the link is already disabled, exit the function
	if ($this.hasClass('disabled')) {
		return false;
	}

	// Prevent the default action of the link (navigation)
	//e.preventDefault();

	// Disable the link to prevent further clicks
	$this.addClass('disabled');
	setTimeout(function () {
		$this.removeClass('disabled');
	}, milliseconds);
	return true;
}