	var globalWizardStepIndex=1; //alyas
	var WizardNavAction=null;
	/*  Wizard */
	function loadTheSteps(){
		"use strict";
		// Chose here which method to send the email, available:
		// Simple phpmail text/plain > quotation.php (default)
		// Phpmaimer text/html > phpmailer/quotation_phpmailer.php
		// Phpmaimer text/html SMPT > phpmailer/quotation_phpmailer_smtp.php
		// PHPmailer with html template > phpmailer/quotation_phpmailer_template.php
		// PHPmailer with html template SMTP> phpmailer/quotation_phpmailer_template_smtp.php
		var d = new Date();
var ms = d.getMilliseconds();
		
		$('form#wrapped').attr('action', 'submission-confirmation/'+ms);
		$("#wizard_container").wizard({
			stepsWrapper: "#wrapped",
			submit: ".submit",
			//alyas			
			afterForward: function (event, state) {
				globalWizardStepIndex=(state.stepIndex)+1; // +1 to increment zero indexed
				WizardNavAction='forward';
				 swal.close();
				if(globalWizardStepIndex==3){
					$("#accordian_16>.card>.collapse").removeClass("show");
					$("#accordian_16>.card>.collapse:last").addClass("show");
					$('#btncollapzion').removeClass('d-none');
				}else{
					
				$('#btncollapzion').addClass('d-none');	
				}
				//console.log("Forward Wizard step index: "+globalWizardStepIndex);
				
				if(parseInt(globalWizardStepIndex) === 9){
				getAllInputs();	
					
					
				}
				
			},
			afterBackward: function (event, state){
				if(globalWizardStepIndex>1) globalWizardStepIndex--;
				WizardNavAction='backward';
				 swal.close();
				 
				 console.log("...After Backword..",globalWizardStepIndex);
				 
				if(globalWizardStepIndex==3){
					$("#accordian_16>.card>.collapse").removeClass("show");
					$("#accordian_16>.card>.collapse:last").addClass("show");
					$('#btncollapzion').removeClass('d-none');
				}else if(globalWizardStepIndex==6){
					$("div[id^=specialist_].d-none-holder").removeClass('d-none-holder').addClass('d-none');
				}else{
					
				$('#btncollapzion').addClass('d-none');	
				}
				//console.log("Backward Wizard step index: "+globalWizardStepIndex);
				
				
			},
			// @@ alyas
			beforeSelect: function (event, state) {
				
				/** alyas - FIX FOR MULTIPLE DRUGS **/
				if(state.stepIndex==3){
					$("#accordian_16>.card>.collapse").addClass("show");
				}
				/** @@ alyas - FIX FOR MULTIPLE DRUGS **/
				
				/** alyas - FIX FOR SPECIALIST **/
				console.log("fix for spec: ",state.stepIndex);
				$('#currentstepactive').html(state.stepIndex);
				if(state.stepIndex==6){
					$("div[id^=specialist_].d-none").removeClass('d-none').addClass('d-none-holder');
				}
				/** @@ alyas - FIX FOR SPECIALIST **/
				
				if ($('input#website').val().length != 0) {
					return false;
				}
				if (!state.isMovingForward)
					return true;
				var inputs = $(this).wizard('state').step.find(':input');
				var nm = $(inputs).attr('name');
				console.log(nm);
				console.log(inputs);
				
				return !inputs.length || !!inputs.valid();
			}
		}).validate({
			errorPlacement: function (error, element) {
				if (element.is(':radio') || element.is(':checkbox')) {
					error.insertBefore(element.next());
				} else {
					error.insertAfter(element);
				}
			}
		});
		//  progress bar
		$("#progressbar").progressbar();
		$("#wizard_container").wizard({
			afterSelect: function (event, state) {
				$("#progressbar").progressbar("value", state.percentComplete);
				$("#location").text("(" + state.stepsComplete + "/" + state.stepsPossible + ")");
			}
		});
		// Validate select
		$('#wrapped').validate({
			ignore: [],
			rules: {
				select: {
					required: true
				}
			},
			errorPlacement: function (error, element) {
				if (element.is('select:hidden')) {
					error.insertAfter(element.next('.nice-select'));
				} else {
					error.insertAfter(element);
				}
			}
		});
	}

/* File upload validate size and file type - For details: https://github.com/snyderp/jquery.validate.file*/
		$("form#wrapped")
			.validate({
				rules: {
					fileupload: {
						fileType: {
							types: ["jpg", "jpeg", "gif", "png", "pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"]
						},
						maxFileSize: {
							"unit": "KB",
							"size": 150
						},
						minFileSize: {
							"unit": "KB",
							"size": "2"
						}
					}
				}
			});
// Summary 
function getVals(formControl, controlType) {
	switch (controlType) {

		case 'question_1':
			// Get name for set of checkboxes
			var checkboxName = $(formControl).attr('name');

			// Get all checked checkboxes
			var value = [];
			$("input[name*='" + checkboxName + "']").each(function () {
				// Get all checked checboxes in an array
				if (jQuery(this).is(":checked")) {
					value.push($(this).val());
				}
			});
			$("#question_1").text(value.join(", "));
			break;

		case 'additional_message':
			// Get the value for a textarea
			var value = $(formControl).val();
			$("#additional_message").text(value);
			break;
            
         case 'fileupload':
			// Get the value for a textarea
			var value = $(formControl).val();
			$("#fileupload").text(value);
			break;
        
        case 'budget':
			// Get the value for a textarea
			var value = $(formControl).val();
			$("#budget").text(value);
			break;
	}
}

function getAllInputs(){
"use strict";
	
	var $postData  = $("#wrapped").find('input[name!=primary_dr_name]').serialize();
	$postData += ("&primary_dr_name="+getPrimaryDrName());
	

		$.ajax({
			type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
			     url: "/includes/question-review.php",
			success: function (data) {
		console.log(data);		
var html = data.html;
				var specialistgroup = data.specialistgroup;
		var phamcies = data.phamcies;
		var prescriptions = data.prescriptions;
		var primary = data.request.primary;		
			var specialist = data.request.specialist;		
				//primary_dr_name_
				var prime = '';
			if($.trim(primary) !== ''){
				   prime +=  '<h5 style="margin-top:20px;">Primary Care Physician</h5>';
		
				prime += $('#primary_dr_name_'+primary).val()+'<br>';
				
				
		
			
			}
				
				
			if($.trim(specialist) !== ''){
				   prime +=  '<h5 style="margin-top:20px;">Specialist</h5>';
		
				//prime += $('#specialist_dr_name_'+specialist).val()+'<br>';
				prime += specialistgroup;
				
				
		
			
			}	
				
				
				
				
				var phar = '';
			if(parseInt(phamcies.length) > 0){
			 
			   phar =  '<h5 style="margin-top:20px;">Pharmacies</h5>';
			   	$.each(phamcies, function (i, obj) {
				phar += $('#pharmacy_holder_'+obj).html()+'<br><br>';
				
				
			});
			 //phar += '<br>';  
			   
			}
			   
			html = prime+''+phar+''+html;	
				
				
		$('#question_review_9').html(html);		
	

				
				
	
			},
			error: function (data) {
		console.log('error');		

				
	

	
			},
			data: $postData, //$('#wrapped').serialize(),  // our data object
			
			//data: $('#wrapped').serialize(),  // our data object
			dataType: 'json', // what type of data do we expect back from the server
			encode: true
		})
			// using the done promise callback
			.done(function (data) {
			});

		// stop the form from submitting the normal way and refreshing the page

		return false;
	
	
	
	/*
var test = new Array();



	
	
	var inputTypes = [];
$('input[name!=""][value!=""][id!=""]').each(function() {
	var d = [];	
	var type = $(this).prop('type');
	var id = $(this).prop('id');
	var name = $(this).prop('name');
	var val = $(this).val();
	
	
		var d = [];
	if(type === 'checkbox' || type === 'radio'){
		
		if(type === 'checkbox'){
			
		
	if($(this).is(':checked')){
	
	d['id'] = name;
	d['value'] = val;	
		if($.trim(val) !== ''){
	inputTypes.push(d);	
			
				test.push(d);	
		}

		
	}	
			
		}
		
		if(type === 'radio'){
			
		

		
	val = $('input[name="'+name+'"]:checked').val();
		
			if($(this).is(':checked')){	
			
	d['id'] = name;
	d['value'] = val;	
	inputTypes.push(d);	
		test.push(d);			
			}
		
		
			
		}
		
		
		
	}else{
	
	
	d['id'] = name;
	d['value'] = val;
		if($.trim(val) !== ''){
	inputTypes.push(d);	
	test.push(d);		
		}
	}
	
	
   // inputTypes.push($(this).prop('type'));
});
	
	var myObjects = Object.assign({}, test);
	console.log(myObjects);
	var json = JSON.stringify(myObjects);
console.log(json);
	
	console.log(inputTypes);
	
	var myObject = Object.assign({}, inputTypes);
	
	var jsonString = JSON.stringify(myObject);
	console.log(jsonString);
   $.ajax({
        type: "POST",
       url: "/includes/question-review.php",
        data: {data:jsonString},
        cache: false,

        success: function(data){
           console.log(data);
			
		$('#question_review_9').html('Done');	
			
        },
	   error: function(data){
           console.log('ERROR');
        }
    });
	
	*/
	
}

function getPrimaryDrName(){

var $primary = '';

var $dataArray = $("#wrapped").serializeArray();
$.each($dataArray, function(i, field){
    if(field.name=='primary'){
$primary = field.value;
}
  });
  
  return $('#primary_dr_name_'+$primary).val();

}

$(document).ready(function(){
	
	$("#wrapped").on("submit",function(ev){
//ev.preventDefault();

console.log("form interrupted");

$('<input>', {
    type: 'hidden',
    id: 'primary_dr_name',
    name: 'primary_dr_name',
    value: getPrimaryDrName()
}).appendTo('#wrapped');

return true;
});
	
});