﻿$(function() {
	$('input.submit-button.finish, input.submit-button.next, input.submit-button.back, input.submit-button.submit').mouseenter(function() { $(this).addClass('hover'); }).mouseleave(function() { $(this).removeClass('hover'); });
	if ($('div.question').is('*')) {
		$('div.question:not(.focused)').click(function() { $('div.question.focused').removeClass('focused'); $(this).addClass('focused'); });
		$('input, select, textarea').focus(function() { $('div.question.focused').removeClass('focused'); $(this).closest('div.question').addClass('focused'); });
		$(document).click(function(e) { var target = e.target; if (!$(target).is('div.question') && !$(target).parents().is('div.question')) { $('div.question.focused').removeClass('focused'); } });
	} else if ($('div.form-field').is('*')) {
		$('div.form-field:not(.focused)').click(function() { $('div.form-field.focused').removeClass('focused'); $(this).addClass('focused'); });
		$('input, select, textarea').focus(function() { $('div.form-field.focused').removeClass('focused'); $(this).addClass('focused'); });
		$(document).click(function(e) { var target = e.target; if (!$(target).is('div.form-field') && !$(target).parents().is('div.form-field')) { $('div.form-field.focused').removeClass('focused'); } });
	} else if ($('div.graph').is('*')) { $('input, select, textarea').focus(function() { $(this).addClass('focused'); }); }
	$('input.selectquestion.radiobuttonlist.other').keydown(function(e) { if (e.keyCode == 9) return; $(this).closest('div.survey-answer').find('.radiolist input').each(function() { $(this).attr("checked", ""); }); });
	$('div.selectquestion.radiolist input').click(function() { $(this).closest('div.survey-answer').find('input.other:first').val('') });
	$('input.selectquestion.dropdownlist.other').keydown(function(e) { if (e.keyCode == 9) return; $(this).closest('div.survey-answer').find('select:first').val(''); });
	$('select.selectquestion.dropdownlist').change(function() { $(this).closest('div.survey-answer').find('input.other:first').val(''); });
	$('table.rankinggroup.radiolist tr, table.selectgroup.radiolist tr, table.selectgroup.checkboxlist tr').mouseenter(function() { $(this).addClass('focused'); }).mouseleave(function() { $(this).removeClass('focused'); });
});
