/******************
    User custom JS
    ---------------

   Put JS-functions for your template here.
   If possible use a closure, or add them to the general Template Object "Template"
*/


$(document).on('ready pjax:scriptcomplete',function(){
    /**
     * Code included inside this will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute
     * @see https://learn.jquery.com/using-jquery-core/document-ready/
     */
});

/**
 * from Tony Partner -- LimeSurvey Forum
 * **/
$(document).on('ready',function(){
	$('.list-with-comment').each(function(i) {
 
		var naCode = 'NA';
 
		var thisQuestion = $(this);
		var qID = thisQuestion.attr('id').replace(/question/, '');
// 		console.log( 'qID: ' + qID );
		var $naInput = $('input:radio[id$="X'+qID+naCode+'"]', thisQuestion);
 
		if($naInput.length > 0) {
			// Hide the textarea
			if(!$naInput.is(':checked')) {
				$('.answer-item.text-item', thisQuestion).hide();
			}
 
			// Listener on the radios
			$('input:radio', thisQuestion).on('click', function(e) {
				if($(this).is($naInput)) {
					// Show the textarea
					$('.answer-item.text-item', thisQuestion).fadeIn(500);
				}
				else {
					// Hide the textarea
					$('.answer-item.text-item', thisQuestion).fadeOut(500, function(e) {
						$('.answer-item.text-item textarea', thisQuestion).val('').trigger('keyup');
					});
				}
			});
		}
	});
});