function initTooltip(context) {
	$('*[title]', context)
		.not('.notooltip')
		.tooltip({
		track: true,
		delay: 250,
		showURL: false
	});
}

function startInit() {
	var context;
	if (
		arguments.length && (
			(typeof arguments[0] != 'function') &&
			(typeof arguments[0] == 'object') &&
			!arguments[0].target &&
			!arguments[0].srcElement
		)
	) {
		context = arguments[0];
	}
	else 
		context = $(document);
	//var context = (arguments.length && (typeof arguments[0] != 'function')) ? arguments[0] : $(document);
	if (!(context instanceof jQuery)) context = $(context);

	// run any theme initialization
	if (typeof startInitByTheme == 'function') {
		startInitByTheme(context);
	}

	// collapsible elements
	// requires jquery.collapsible.js
	if (typeof $.fn.eCollapse == 'function') {
		$(".collapsible", context).eCollapse();
	}

	// style-able and HTML tooltips
	// requires jquery.tooltip.js
	if (typeof $.fn.tooltip == 'function') {
		initTooltip(context);
	}

	// set initial focus
	$('.readyFocus', context).focus();
}

$(document).ready(function() {
  tb_pathToImage = APP_BASE_PATH + "image/loading.gif";

	$('#slt_agency_current').change(function() {
		var slt = this;
		if (confirm('Please confirm that you wish to change your current agency.  If you press OK, any unsaved changes on THIS page will be lost.')) {
			$.ajax({
				type: 'GET',
				url: APP_BASE_PATH + 'ws.php?output=text&module=core&ppf=core.ws&type=currentagency',
				data: {
					value: slt.options[slt.selectedIndex].value
				},
				success: function(data) {
					var success = data.length ? true : false;
					if (success) {
						location.replace(location.href);
					}
					else {
						alert('An error occurred while trying to change the Current Agency.  Please try again later.');
						slt.form.reset();
					}
				},
				error: function() {
					alert('An error occurred while trying to change the Current Agency.  Please try again later.');
					slt.form.reset();
				}
			});
		}
		else {
			slt.form.reset();
		}
	});

	$('#chbx_agency_current').click(function() {
		$.Util.setCookie('collapse_agency_current', (this.checked ? 1 : 0), 60, '.' + location.hostname);

		if (this.checked) {
			$(this).parents('div.collapsible:first').children('h2.trigger:first').click();
		}
	});

	$('#slt_survYear').change(function() {
		var slt = this;
		if (confirm('Please confirm that you wish to change the surveillance year.  If you press OK, any unsaved changes on THIS page will be lost.')) {
			$.ajax({
				type: 'GET',
				url: APP_BASE_PATH + 'ws.php?output=text&module=core&ppf=core.ws&type=survyear',
				data: {
					value: slt.options[slt.selectedIndex].value
				},
				success: function(data) {
					var success = data.length ? true : false;
					if (success) {
						location.replace(location.href);
					}
					else {
						alert('An error occurred while trying to change the surveillance year.  Please try again later.');
						slt.form.reset();
					}
				},
				error: function() {
					alert('An error occurred while trying to change the surveillance year.  Please try again later.');
					slt.form.reset();
				}
			});
		}
		else {
			slt.form.reset();
		}
	});
});
