// JScript File

$(document).ready(function () {
	$('#showMoreOptions').click(function () {
		$(this).hide();
		$('#hideMoreOptions').show();
		$('#moreOptions').slideDown("fast");
		return false;
	});
	$('#hideMoreOptions').click(function () {
		$(this).hide();
		$('#showMoreOptions').show();
		$('#moreOptions').slideUp("fast");
		return false;
	});
	$('.hideShowKeywords').toggle(function () {
		$('#keywordList').slideDown("fast");
		$(this).text('Keywords (hide)');
		return false;
	}, function () {
		$('#keywordList').slideUp("fast");
		$(this).text('Keywords (show)');
		return false;
	});
	$('#showFutureEvents').click(function () {
		$('.pastEvent').addClass('hide');
		$('.futureEvent').removeClass('hide');
		$(this).addClass('ifCurrent');
		$('#showPastEvents').removeClass('ifCurrent');
		return false;
	});
	$('#showPastEvents').click(function () {
		$('.futureEvent').addClass('hide');
		$('.pastEvent').removeClass('hide');
		$(this).addClass('ifCurrent');
		$('#showFutureEvents').removeClass('ifCurrent');
		return false;
	});
	$('#documentFilter li').click(function () {
		var type = ($(this).attr('id') != undefined ? $(this).attr('id').substring(4) : '');
		if (type.length == 0) {
			$('.caseDocuments li.hide').removeClass('hide');
		} else {
			$('.caseDocuments li:not(.doc' + type + ')').addClass('hide');
			$('.caseDocuments li.doc' + type).removeClass('hide');
		}
		$('#documentFilter .ifCurrent').removeClass('ifCurrent');
		$(this).addClass('ifCurrent');
		return false;
	});
	$('.lAnswer').hide();
	$('.lQuestion').click(function () {
		$(this).parent().siblings().find('.lAnswer').slideUp("fast");
		$(this).siblings('.lAnswer').slideDown("fast");
		$('#expandCollapse a').text('Expand all answers').parent().removeClass('collapse').addClass('expand');
		if ($(this).attr('href') == '#')
			return false;
		else
			return true;
	});
	$('#expandCollapse a').click(function () {
		if ($('.lAnswer:hidden').length > 0) {
			$('.lAnswer').slideDown("fast");
			$(this).text('Collapse all answers').parent().removeClass('expand').addClass('collapse');
		}
		else {
			$('.lAnswer').slideUp("fast");
			$(this).text('Expand all answers').parent().removeClass('collapse').addClass('expand');
		}
		return false;
	});
	$('a[href$=pdf],a[href$=PDF]').click(function () {
		window.open(this.href);
		return false;
	});
	//judgment keywords
	setSelectedKeywords();
	$('.filterByKeyword,.adjustFilters').click(function () {
		var cat = $('.tabLinks a.selected').attr('class').split(' ')[1];
		$('#keywordList li.' + cat + '').show();
		$('#keywordList li:not(.' + cat + ')').hide();
		$('.popupBox').show();
		return false;
	});
	$('.closeBox,#applyKeywords').click(function () {
		setSelectedKeywords();
		$('.popupBox').hide();
		return false;
	});
	$('.tabLinks a').click(function () {
		var cat = $(this).attr('class').split(' ')[1];
		$('#keywordList li.' + cat + '').show();
		$('#keywordList li:not(.' + cat + ')').hide();
		$('.tabLinks a.selected').removeClass('selected');
		$(this).addClass('selected');
		return false;
	});
	if ($('#keywordList input:checked,#moreOptions select[value^=]').length > 0) {
		$('#showMoreOptions').click();
	}
	if ($('.futureEvent').length == 0) $('#showFutureEvents').hide();
	if ($('.pastEvent').length == 0) $('#showPastEvents').hide();
});
function setSelectedKeywords() {
	$('#selectedKeywords ul li:not(.adjustFilters)').remove();
	$('#selectedKeywords>a').text('Currently selected keywords');
	var lastItem = $('#keywordList input:checked').length - 1;
	var hasSelected = false
	$('#keywordList input:checked').each(function (i) {
		$('#selectedKeywords ul li.adjustFilters').before('<li><span>' + $(this).val() + '</span>' + (i == lastItem ? '' : ', ') + '</li>');
		hasSelected = true;
	});
	if (hasSelected) {
		$('.filterByKeyword a').text('Currently selected keywords:');
		$('.adjustFilters').show();
	}
	else {
		$('.filterByKeyword a').text('Filter by keyword');
		$('.adjustFilters').hide();
	}
}
