<?php

use app\base\Common;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use kartik\widgets\DepDrop;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model app\models\substanceuse */
/* @var $form yii\widgets\ActiveForm */

$Surveys = Common::getSurvey();
$PIDs = Common::getEnrollPIDs("sufup");
$Visits = Common::getCohortVisits();

if(Yii::$app->params['SURVEY'] != '') {
	$Locations = Common::getSurlocations(Yii::$app->params['SURVEY']);
}
if(Yii::$app->params['SURVEY'] != '' && Yii::$app->params['LOCATION'] != '') {
	$Locations = Common::getSurlocations(Yii::$app->params['SURVEY']);
	$PIDs = Common::getEnrollPIDs("sufup",Yii::$app->params['SURVEY'], Yii::$app->params['LOCATION']);
}
if(!$model->isNewRecord) {
	$Visits = Common::getPIDsVisit($model->substance_use_survey, $model->substance_use_loc, $model->substance_use_part_id);
}

$JS="

$('#substanceusefup-substance_use_part_id').on('select2:select', function (evt) {
		var pid = $(this)[0].value;		
		if(pid != '') {
			var link = $('#pid-info').data('link') + pid;			
			$.ajax({
				type: 'post',
				url: 'visit',
				data: 'pid='+$(this)[0].value,
				success: function(response) {	
                    			
					if(response.visit != null) {
						
						$('#substanceusefup-visit_code').val(response.visit);
						$('#substanceusefup-visit').val(response.visit);
						
					} else {
						$('#substanceusefup-visit_code').val('');
						$('#substanceusefup-visit').val('');
						
					}
					
				}
			});
		}
	});
		
	
	$('#substanceusefup-substance_use_part_id').on('select2:unselect', function (evt) {
		$('#substanceusefup-visit_code').val('');
		$('#substanceusefup-visit').val('');
	});
	
   
    $('#substanceusefup-substance_use_part_id').on('select2:select', function (evt) {
		$('div.form-group.field-substanceusefup-substance_use_q1,div.form-group.field-substanceusefup-substance_use_q2,div.form-group.field-substanceusefup-substance_use_q3,div.form-group.field-substanceusefup-substance_use_q4,div.form-group.field-substanceusefup-substance_use_q6c,div.form-group.field-substanceusefup-substance_use_q6d,div.form-group.field-substanceusefup-substance_use_q7c,div.form-group.field-substanceusefup-substance_use_q7d,div.form-group.field-substanceusefup-substance_use_q8c,div.form-group.field-substanceusefup-substance_use_q8d,div.form-group.field-substanceusefup-substance_use_q9c,div.form-group.field-substanceusefup-substance_use_q9d,div.form-group.field-substanceusefup-substance_use_q10c,div.form-group.field-substanceusefup-substance_use_q10d,div.form-group.field-substanceusefup-substance_use_q11c,div.form-group.field-substanceusefup-substance_use_q11d,div.form-group.field-substanceusefup-substance_use_q12c,div.form-group.field-substanceusefup-substance_use_q12d,div.form-group.field-substanceusefup-substance_use_q13c,div.form-group.field-substanceusefup-substance_use_q13d,div.form-group.field-substanceusefup-substance_use_q14,div.form-group.field-substanceusefup-substance_use_q15,div.form-group.field-substanceusefup-substance_use_q16,div.form-group.field-substanceusefup-substance_use_q17a,div.form-group.field-substanceusefup-substance_use_q17b,div.form-group.field-substanceusefup-substance_use_q18a,div.form-group.field-substanceusefup-substance_use_q18b,div.form-group.field-substanceusefup-substance_use_q19a,div.form-group.field-substanceusefup-substance_use_q19b,div.form-group.field-substanceusefup-substance_use_q20a,div.form-group.field-substanceusefup-substance_use_q20b,div.form-group.field-substanceusefup-substance_use_q21a,div.form-group.field-substanceusefup-substance_use_q21b,div.form-group.field-substanceusefup-substance_use_q22a,div.form-group.field-substanceusefup-substance_use_q22b,div.form-group.field-substanceusefup-substance_use_q23a,div.form-group.field-substanceusefup-substance_use_q23b,div.form-group.field-substanceusefup-substance_use_q24a,div.form-group.field-substanceusefup-substance_use_q24b,div.form-group.field-substanceusefup-substance_use_q25a,div.form-group.field-substanceusefup-substance_use_q25b,div.form-group.field-substanceusefup-substance_use_q26a,div.form-group.field-substanceusefup-substance_use_q26b,div.form-group.field-substanceusefup-substance_use_q27a,div.form-group.field-substanceusefup-substance_use_q27b,div.form-group.field-substanceusefup-substance_use_q28a,div.form-group.field-substanceusefup-substance_use_q28b').addClass('required').show();
				
	});
			
	
	$('#substanceusefup-substance_use_q13c').change(function(){
	 if($(this).val() !='' && $(this).val() =='0' && $('#substanceusefup-substance_use_q6c').val() == '0' && $('#substanceusefup-substance_use_q7c').val() == '0' && $('#substanceusefup-substance_use_q8c').val() == '0' && $('#substanceusefup-substance_use_q9c').val() == '0' && $('#substanceusefup-substance_use_q10c').val() == '0' && $('#substanceusefup-substance_use_q11c').val() == '0' && $('#substanceusefup-substance_use_q12c').val() == '0' && $('#substanceusefup-substance_use_q4').val() == '1')
		$('#modal').modal('show').find('.modal-body').html('All of Q5a-Q12a cannot be 0 (No). At least one of Q5a-12a must be 1 (Yes).');
	});
		
	
	$('#substanceusefup-substance_use_q14').change(function(){
		if($(this).val() > 180 && $(this).val() != 997)
			$('#modal').modal('show').find('.modal-body').html('Acceptable range: 0-180, 997. Please double check your answer.');
	});
	
	$('#substanceusefup-substance_use_q14').change(function(){
	 if(($(this).val() !='' && $(this).val() ==0) && ($('#substanceusefup-substance_use_q6c').val() == '1' || $('#substanceusefup-substance_use_q7c').val() == '1' || $('#substanceusefup-substance_use_q8c').val() == '1' || $('#substanceusefup-substance_use_q9c').val() == '1' || $('#substanceusefup-substance_use_q10c').val() == '1' || $('#substanceusefup-substance_use_q11c').val() == '1' || $('#substanceusefup-substance_use_q12c').val() == '1' || $('#substanceusefup-substance_use_q13c').val() == '1' ))
		$('#modal').modal('show').find('.modal-body').html('The value of Q13 should not be 0 if any value for Q5c-12c is coded as 1.');
	});
	
	$('#substanceusefup-substance_use_q15').change(function(){
		if(($(this).val() ==0 || $(this).val() > 10) && $(this).val() != 997)
		$('#modal').modal('show').find('.modal-body').html('Acceptable range: 1-10, 997. Please double check your answer.');
	});
	
	 $('#substanceusefup-substance_use_q1').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q2,div.form-group.field-substanceusefup-substance_use_q3').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q2,#substanceusefup-substance_use_q3').val('');	
		} else {
		   $('div.form-group.field-substanceusefup-substance_use_q2,div.form-group.field-substanceusefup-substance_use_q3').addClass('required').show();	
			
		}
	});	
	
	 $('#substanceusefup-substance_use_q4').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 1) {
			$('div.form-group.field-substanceusefup-substance_use_q6c,div.form-group.field-substanceusefup-substance_use_q6d,div.form-group.field-substanceusefup-substance_use_q7c,div.form-group.field-substanceusefup-substance_use_q7d,div.form-group.field-substanceusefup-substance_use_q8c,div.form-group.field-substanceusefup-substance_use_q8d,div.form-group.field-substanceusefup-substance_use_q9c,div.form-group.field-substanceusefup-substance_use_q9d,div.form-group.field-substanceusefup-substance_use_q10c,div.form-group.field-substanceusefup-substance_use_q10d,div.form-group.field-substanceusefup-substance_use_q11c,div.form-group.field-substanceusefup-substance_use_q11d,div.form-group.field-substanceusefup-substance_use_q12c,div.form-group.field-substanceusefup-substance_use_q12d,div.form-group.field-substanceusefup-substance_use_q13c,div.form-group.field-substanceusefup-substance_use_q13d,div.form-group.field-substanceusefup-substance_use_q14,div.form-group.field-substanceusefup-substance_use_q15').addClass('required').show();	
			
		} else {
			$('div.form-group.field-substanceusefup-substance_use_q6c,div.form-group.field-substanceusefup-substance_use_q6d,div.form-group.field-substanceusefup-substance_use_q7c,div.form-group.field-substanceusefup-substance_use_q7d,div.form-group.field-substanceusefup-substance_use_q8c,div.form-group.field-substanceusefup-substance_use_q8d,div.form-group.field-substanceusefup-substance_use_q9c,div.form-group.field-substanceusefup-substance_use_q9d,div.form-group.field-substanceusefup-substance_use_q10c,div.form-group.field-substanceusefup-substance_use_q10d,div.form-group.field-substanceusefup-substance_use_q11c,div.form-group.field-substanceusefup-substance_use_q11d,div.form-group.field-substanceusefup-substance_use_q12c,div.form-group.field-substanceusefup-substance_use_q12d,div.form-group.field-substanceusefup-substance_use_q13c,div.form-group.field-substanceusefup-substance_use_q13d,div.form-group.field-substanceusefup-substance_use_q14,div.form-group.field-substanceusefup-substance_use_q15').removeClass('required').hide();
		$('#substanceusefup-substance_use_q6c,#substanceusefup-substance_use_q6d,#substanceusefup-substance_use_q7c,#substanceusefup-substance_use_q7d,#substanceusefup-substance_use_q8c,#substanceusefup-substance_use_q8d,#substanceusefup-substance_use_q9c,#substanceusefup-substance_use_q9d,#substanceusefup-substance_use_q10c,#substanceusefup-substance_use_q10d,#substanceusefup-substance_use_q11c,#substanceusefup-substance_use_q11d,#substanceusefup-substance_use_q12c,#substanceusefup-substance_use_q12d,#substanceusefup-substance_use_q13c,#substanceusefup-substance_use_q13d,#substanceusefup-substance_use_q14,#substanceusefup-substance_use_q15').val('');	
		   
			
		}
	});	
	
	$('#substanceusefup-substance_use_q1,#substanceusefup-substance_use_q4').trigger('change');
	
	
	$('#substanceusefup-substance_use_q6c').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q6d').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q6d').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q6d').addClass('required').show();	
			
		}
	});	
	
	
	
	$('#substanceusefup-substance_use_q7c').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q7d').removeClass('required').hide();
		  $('#substanceusefup-substance_use_q7d').val('');	
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q7d').addClass('required').show();	
			
		}
	});	
	
	
	
	$('#substanceusefup-substance_use_q8c').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q8d').removeClass('required').hide();
		$('#substanceusefup-substance_use_q8d').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q8d').addClass('required').show();	
			
		}
	});	
	
	
	
	$('#substanceusefup-substance_use_q9c').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q9d').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q9d').val('');	
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q9d').addClass('required').show();	
			
		}
	});	
	

	$('#substanceusefup-substance_use_q10c').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q10d').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q10d').val('');	
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q10d').addClass('required').show();	
			
		}
	});	
	
	
	
	$('#substanceusefup-substance_use_q11c').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q11d').removeClass('required').hide();
		$('#substanceusefup-substance_use_q11d').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q11d').addClass('required').show();	
			
		}
	});	
	
	
	
	$('#substanceusefup-substance_use_q12c').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q12d').removeClass('required').hide();
		$('#substanceusefup-substance_use_q12d').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q12d').addClass('required').show();	
			
		}
	});	
	
		
	$('#substanceusefup-substance_use_q13c').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q13d').removeClass('required').hide();
		$('#substanceusefup-substance_use_q13d').val('');	
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q13d').addClass('required').show();	
			
		}
	});	
   	
	 $('#substanceusefup-substance_use_q14').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q15').removeClass('required').hide();
		$('#substanceusefup-substance_use_q15').val('');	
		} else {
		   $('div.form-group.field-substanceusefup-substance_use_q15').addClass('required').show();	
			
		}
	});	
	
		
	$('#substanceusefup-substance_use_q16').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('#17_interview_inst1,#17_interview_inst2,#17_interview_inst_line').hide();
			$('div.form-group.field-substanceusefup-substance_use_q17a,div.form-group.field-substanceusefup-substance_use_q17b,div.form-group.field-substanceusefup-substance_use_q18a,div.form-group.field-substanceusefup-substance_use_q18b,div.form-group.field-substanceusefup-substance_use_q19a,div.form-group.field-substanceusefup-substance_use_q19b,div.form-group.field-substanceusefup-substance_use_q20a,div.form-group.field-substanceusefup-substance_use_q20b,div.form-group.field-substanceusefup-substance_use_q21a,div.form-group.field-substanceusefup-substance_use_q21b,div.form-group.field-substanceusefup-substance_use_q22a,div.form-group.field-substanceusefup-substance_use_q22b,div.form-group.field-substanceusefup-substance_use_q23a,div.form-group.field-substanceusefup-substance_use_q23b,div.form-group.field-substanceusefup-substance_use_q24a,div.form-group.field-substanceusefup-substance_use_q24b,div.form-group.field-substanceusefup-substance_use_q25a,div.form-group.field-substanceusefup-substance_use_q25b,div.form-group.field-substanceusefup-substance_use_q26a,div.form-group.field-substanceusefup-substance_use_q26b,div.form-group.field-substanceusefup-substance_use_q27a,div.form-group.field-substanceusefup-substance_use_q27b,div.form-group.field-substanceusefup-substance_use_q28a,div.form-group.field-substanceusefup-substance_use_q28b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q17a,#substanceusefup-substance_use_q17b,#substanceusefup-substance_use_q18a,#substanceusefup-substance_use_q18b,#substanceusefup-substance_use_q19a,#substanceusefup-substance_use_q19b,#substanceusefup-substance_use_q20a,#substanceusefup-substance_use_q20b,#substanceusefup-substance_use_q21a,#substanceusefup-substance_use_q21b,#substanceusefup-substance_use_q22a,#substanceusefup-substance_use_q22b,#substanceusefup-substance_use_q23a,#substanceusefup-substance_use_q23b,#substanceusefup-substance_use_q24a,#substanceusefup-substance_use_q24b,#substanceusefup-substance_use_q25a,#substanceusefup-substance_use_q25b,#substanceusefup-substance_use_q26a,#substanceusefup-substance_use_q26b,#substanceusefup-substance_use_q27a,#substanceusefup-substance_use_q27b,#substanceusefup-substance_use_q28a,#substanceusefup-substance_use_q28b').val('');
		} else {
			$('#17_interview_inst1,#17_interview_inst2,#17_interview_inst_line').show();
		   $('div.form-group.field-substanceusefup-substance_use_q17a,div.form-group.field-substanceusefup-substance_use_q17b,div.form-group.field-substanceusefup-substance_use_q18a,div.form-group.field-substanceusefup-substance_use_q18b,div.form-group.field-substanceusefup-substance_use_q19a,div.form-group.field-substanceusefup-substance_use_q19b,div.form-group.field-substanceusefup-substance_use_q20a,div.form-group.field-substanceusefup-substance_use_q20b,div.form-group.field-substanceusefup-substance_use_q21a,div.form-group.field-substanceusefup-substance_use_q21b,div.form-group.field-substanceusefup-substance_use_q22a,div.form-group.field-substanceusefup-substance_use_q22b,div.form-group.field-substanceusefup-substance_use_q23a,div.form-group.field-substanceusefup-substance_use_q23b,div.form-group.field-substanceusefup-substance_use_q24a,div.form-group.field-substanceusefup-substance_use_q24b,div.form-group.field-substanceusefup-substance_use_q25a,div.form-group.field-substanceusefup-substance_use_q25b,div.form-group.field-substanceusefup-substance_use_q26a,div.form-group.field-substanceusefup-substance_use_q26b,div.form-group.field-substanceusefup-substance_use_q27a,div.form-group.field-substanceusefup-substance_use_q27b,div.form-group.field-substanceusefup-substance_use_q28a,div.form-group.field-substanceusefup-substance_use_q28b').addClass('required').show();	
			
		}
	});	
	
	$('#substanceusefup-substance_use_q14,#substanceusefup-substance_use_q16').trigger('change');
	
$('#substanceusefup-substance_use_q17a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q17b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q17b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q17b').addClass('required').show();	
			
		}
});		
$('#substanceusefup-substance_use_q18a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q18b').removeClass('required').hide();
		$('#substanceusefup-substance_use_q18b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q18b').addClass('required').show();	
			
		}
});	
$('#substanceusefup-substance_use_q19a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q19b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q19b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q19b').addClass('required').show();	
			
		}
});	
$('#substanceusefup-substance_use_q20a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q20b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q20b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q20b').addClass('required').show();	
			
		}
});	
$('#substanceusefup-substance_use_q21a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q21b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q21b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q21b').addClass('required').show();	
			
		}
});	
$('#substanceusefup-substance_use_q22a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q22b').removeClass('required').hide();
		  $('#substanceusefup-substance_use_q22b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q22b').addClass('required').show();	
			
		}
});	

$('#substanceusefup-substance_use_q23a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q23b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q23b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q23b').addClass('required').show();	
			
		}
});	

$('#substanceusefup-substance_use_q24a').change(function(){	
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q24b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q24b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q24b').addClass('required').show();	
			
		}
});	
$('#substanceusefup-substance_use_q25a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q25b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q25b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q25b').addClass('required').show();	
			
		}
});	

$('#substanceusefup-substance_use_q26a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q26b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q26b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q26b').addClass('required').show();	
			
		}
});	
$('#substanceusefup-substance_use_q27a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q27b').removeClass('required').hide();
		 $('#substanceusefup-substance_use_q27b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q27b').addClass('required').show();	
			
		}		
});	
$('#substanceusefup-substance_use_q28a').change(function(){
		// $('div.form-group').show();
		$('div.help-block').html('');
		$('div.error-summary').hide();
		$('div.form-group').removeClass('has-success').removeClass('has-error');
		if($(this).val() == 0) {
			$('div.form-group.field-substanceusefup-substance_use_q28b').removeClass('required').hide();
		  $('#substanceusefup-substance_use_q28b').val('');
		} else {
		    $('div.form-group.field-substanceusefup-substance_use_q28b').addClass('required').show();	
			
		}
});	

$('#substanceusefup-substance_use_q6c,#substanceusefup-substance_use_q7c,#substanceusefup-substance_use_q8c,#substnceuse-substance_use_q9c,#substanceusefup-substance_use_q10c,#substanceusefup-substance_se_q11c,#substanceusefup-substance_use_q12c,#substanceusefup-substance_use_q13c,#substanceusefup-substance_use_q17a,#substanceusefup-substance_use_q18a,#substanceusefup-substance_use_q19a,#substanceusefup-substance_use_q20a,#substanceusefup-substance_use_q21a,#substanceusefup-substance_use_q22a,#substanceusefup-substance_use_q23a,#substanceusefup-substance_use_q24a,#substanceusefup-substance_use_q25a,#substanceusefup-substance_use_q26a,#substanceusefup-substance_use_q27a,#substanceusefup-substance_use_q28a').trigger('change');


";
$this->registerJs($JS);


?>

<div class="substance_use-form">
	<div class="panel panel-default">
		<div class="panel-heading">
			
		</div>
		<div class="panel-body">
			<div class="row">
				<div class="col-lg-12">
					<?php
						$form = ActiveForm::begin(['options' => ['class' => 'form-horizontal']]);
						$template = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-4">{input}{error}</div>',
						];
						$chklist_template = [
							'labelOptions' => ['class' => 'form-label'],
							'template' => '<div class="col-sm-5">{label}{hint}</div><div class="col-sm-7 checkbox-list">{input}{error}</div>',
						];
						$htemplate = [
							'options' => ['tag' => false],
							'template' => '{input}'
						];
					?>
					
                    <?= Common::generateControl($form, $model, $template, 'substance_use_survey', $Surveys, 'survey', 'getEnrollPIDs','su') ?>
					<?= Common::generateControl($form, $model, $template, 'substance_use_loc', $Locations, 'location', '', [Html::getInputId($model, 'substance_use_survey')]) ?>
					<?= Common::generateControl($form, $model, $template, 'substance_use_part_id', $PIDs, 'pid', '', [Html::getInputId($model, 'substance_use_survey'), Html::getInputId($model, 'substance_use_loc')]) ?>
					
					 <?php  if($model->isNewRecord) : ?>					 
                     <?= $form->field($model, 'visit', $template)->dropDownList($Visits,['prompt' => 'Select','disabled' => true]) ?>	
                     <?php  else: ?>	
                      <?= $form->field($model, 'visit_code', $template)->widget(DepDrop::classname(), ['data'=>$Visits, 'options'=>['prompt'=>$model->getAttributeLabel('visit_code')],'disabled' => true, 'pluginOptions'=>['depends'=>[Html::getInputId($model, 'substance_use_survey'), Html::getInputId($model, 'substance_use_loc'), Html::getInputId($model, 'substance_use_part_id')], 'placeholder'=>$model->getAttributeLabel('visit_code'), 'url'=>Url::to(['/dashboard/getids']), 'params'=>['common-method1', Html::getInputId($model, 'substance_use_part_id')]]]) ?>						 
					 <?php  endif; ?>  					 
					
                     <?= $form->field($model, 'visit_code', $htemplate)->hiddenInput()->label() ?>
					 
					<div class="form-group">
					 <div class="col-sm-5">
					 <?= Html::label('INTERVIEWER READ: The next few questions are about your use of drugs and alcohol.') ?>
					 </div>
					</div>
					
					<?= $form->field($model, 'substance_use_q1', $template)->dropDownList($model->q1, ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU1.</strong><br />");?>
					<?= $form->field($model, 'substance_use_q2', $template)->dropDownList($model->q2, ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU2</strong> to translate number of drinks.<br />");?>			
					<?= $form->field($model, 'substance_use_q3', $template)->dropDownList($model->q3, ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU3.</strong><br />");?>
					
					<?= $form->field($model, 'substance_use_q4', $template)->dropDownList($model->yes_no_dk, ['prompt'=>'Select']); ?>
												
					<?= $form->field($model, 'substance_use_q6c', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION For Q6a - Q13a : </strong> There are more drugs on the card than on the screen so use/review the card and for each category to make sure that you are getting all of the information. Code ‘Other’ only if the drug is not listed on the Card and does not fit into any of the categories<br /><br /> <strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU6.</strong><br />");?>
					
					<?= $form->field($model, 'substance_use_q6d', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>					
					
					<?= $form->field($model, 'substance_use_q7c', $template)->dropDownList($model->yes_no , ['prompt'=>'Select']); ?>						
					<?= $form->field($model, 'substance_use_q7d', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
					
					<?= $form->field($model, 'substance_use_q8c', $template)->dropDownList($model->yes_no , ['prompt'=>'Select']); ?>						
					<?= $form->field($model, 'substance_use_q8d', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
					
					<?= $form->field($model, 'substance_use_q9c', $template)->dropDownList($model->yes_no , ['prompt'=>'Select']); ?>						
					<?= $form->field($model, 'substance_use_q9d', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
					
					<?= $form->field($model, 'substance_use_q10c', $template)->dropDownList($model->yes_no , ['prompt'=>'Select']); ?>						
					<?= $form->field($model, 'substance_use_q10d', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
					
					<?= $form->field($model, 'substance_use_q11c', $template)->dropDownList($model->yes_no , ['prompt'=>'Select']); ?>						
					<?= $form->field($model, 'substance_use_q11d', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
					
					<?= $form->field($model, 'substance_use_q12c', $template)->dropDownList($model->yes_no , ['prompt'=>'Select']); ?>						
					<?= $form->field($model, 'substance_use_q12d', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
					
					<?= $form->field($model, 'substance_use_q13c', $template)->dropDownList($model->yes_no , ['prompt'=>'Select']); ?>						
					<?= $form->field($model, 'substance_use_q13d', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
					
					<?= $form->field($model, 'substance_use_q14', $template)->textInput(['maxlength' => true])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Code 997 for Don’t Know.</strong><br />") ?>	
					<?= $form->field($model, 'substance_use_q15', $template)->textInput(['maxlength' => true,'data-min' => 1,'data-msg' => 'This value cannot be “0”. Please double-check that this answer is correct'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Code 997 for Don’t Know.</strong><br />") ?>	
					<?= $form->field($model, 'substance_use_q16', $template)->dropDownList($model->yes_no , ['prompt'=>'Select']); ?>
					
										
					<div id="17_interview_inst_line" class="hline-bottom">
					 <div class="col-sm-5">
					 
					 </div>
					</div>
					
					<div id="17_interview_inst1" class="form-group">
					 <div class="col-sm-5">
					 <?= Html::label('<br><h6>Non-Injection Drug Use :</h6> ') ?>
					 </div>
					</div>
					
					<div id="17_interview_inst2" class="form-group">
					 <div class="col-sm-5">
					 <?= Html::label('INTERVIEWER READ: Please tell me all of the drugs that you used by a non-injection route in the past 6 months. We are interested in drugs that you have sniffed, snorted, smoked or ingested for non-medical purposes.') ?>
					 </div>
					</div>
					
					<?= $form->field($model, 'substance_use_q17a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION For Q17a - Q28a: <strong> There are more drugs on the card than on the screen so use/review the card and for each category to make sure that you are getting all of the information. Code ‘Other’ only if the drug is not listed on the Card and does not fit into any of the categories.<br /><br />INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU17.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q17b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q18a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU18.</strong><br />");?>					
				    <?= $form->field($model, 'substance_use_q18b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q19a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU19.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q19b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q20a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU20.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q20b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q21a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU21.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q21b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q22a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU22.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q22b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q23a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU23.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q23b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q24a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU24.</strong><br />");?>					
				    <?= $form->field($model, 'substance_use_q24b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q25a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU25.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q25b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q26a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU26.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q26b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q27a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU27.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q27b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
				    <?= $form->field($model, 'substance_use_q28a', $template)->dropDownList($model->yes_no , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use <strong>Card SU28.</strong><br />");?>						
				    <?= $form->field($model, 'substance_use_q28b', $template)->dropDownList($model->often , ['prompt'=>'Select'])->hint("<strong>INTERVIEWER INSTRUCTION : </strong> Use Card SU6d.<br />");?>
					
					<?= $form->field($model, 'status', $htemplate)->hiddenInput(['value' => 1])->label() ?>
					<?= $form->field($model, $model->isNewRecord ? 'create_user' : 'update_user', $htemplate)->hiddenInput(['value' => yii::$app->user->identity->id])->label("") ?>
					<div class="form-group">
						<div class="col-sm-offset-5 col-sm-7">
									
					<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
					<?= Html::a('Cancel', ['/'.Yii::$app->controller->id], ['class' => 'btn btn-default']) ?>
						</div>
					</div>
					<?php ActiveForm::end(); ?>
				</div>
				<!-- /.col-lg-6 (nested) -->
			</div>
			<!-- /.row (nested) -->
		</div>
		<!-- /.panel-body -->
	</div>
	<!-- /.panel -->
</div>