<script type="text/javascript">
    function showHeadCode(event)
    {
	  	obj = $('#form_add_head select[name=nature]').val();

	  	if(obj != "Selected")
	  	{
	  		showLoader();

	  		var route = "<?php echo e(route('head.code')); ?>";

			$.post(route,{'nature':obj,'_token': token},function(data,status){
			
			$('.show_code').val(data);
				
            removeLoader();

        	}).fail(function(data) {

		          messageToaster('error','Head code not found.','Failed');
		      
		          removeLoader();
		    
		     });   
	  	}
	  	else
	  	{
		   $('.show_code').val('');
	  	}
    }

     //AJAX REQUEST TO STORE USER(CUSTOMER) WHILE BOOKING
	function storeHead(event,obj)
	{
		event.preventDefault();

		var obj = $('#form_add_head');

		var form = document.querySelector('#form_add_head') // Find the <form> element

		var formData = new FormData(form); // Wrap form contents

		var route = obj.attr('action');	


		// alert(ajax_validate(obj,'add customer'));

		showLoader();

		$.ajax({
		url: route,
		type: obj.attr('method'),
		data:  formData,
		dataType: "json",
		contentType: false,
		cache: false,
		processData:false,
		success: function(result){
			if(result.id)
		    {
			   refreshHeadList(result.nature,result.head_tag);

			   $('#md_add_head').modal('hide');
		    }
	    	removeLoader();
		},
		error: function(data)
			   {
			       ajax_show_error(data);
			   } 	        
		});


	}

	//AJAX REQUEST TO STORE USER(CUSTOMER) WHILE BOOKING
	function updateHead(event,obj)
	{
		event.preventDefault();

		var obj = $('#form_update_head');

		var form = document.querySelector('#form_update_head') // Find the <form> element
		var formData = new FormData(form); // Wrap form contents

		var route = obj.attr('action');	

		// alert(ajax_validate(obj,'add customer'));

		showLoader();

		$.ajax({
		url: route,
		type: obj.attr('method'),
		data:  formData,
		dataType: "json",
		contentType: false,
		cache: false,
		processData:false,
		success: function(result){

			if(result.id)
		    {
			   refreshHeadList(result.nature,result.head_tag);

			   $('#md_update_head').modal('hide');

		    }

	    	removeLoader();
		},
		error: function(data)
			   {
			       ajax_show_error(data);
			   } 	        
		});


	}

	function removeHead(event,obj)
	{
		event.preventDefault();

		swal({
		  title: "Are you sure",
		  text: "you want to "+$(obj).attr('content')+'?',
		  icon: "warning",
		  buttons: true,
		  dangerMode: true,
		})
		.then((willDelete) => {

			if (willDelete) 
			{

				var remove_head_route = $(obj).attr('href');

					showLoader()

					$.get(remove_head_route,function(result,status){
					
						refreshHeadList(result.nature,result.head_tag);
						
				        removeLoader();


				        swal("Your request has been submitted!", {
			      			icon: "success",
			   	 		});

				});
			
			} 
			else 
			{
			    swal("Your request has been cancelled!");
			}
		});

		
	}


    function showHeadModel(event,reffer_class,nature)
    {
        $('#md_add_head').modal('show');

        // $('#form_add_head select[name=nature]').val(nature);

        $('#form_add_head select[name=nature]').find('option').remove();

        $('#form_add_head select[name=nature]').append('<option value="'+nature+'">'+nature+'</option>');

        showHeadCode(event);
    }

     

    function refreshHeadList(nature,head_tag)
    {
    	
  		showLoader();

  		var route = "<?php echo e(route('head.shownaturewise')); ?>";

		$.post(route,{'nature':nature,'_token': token},function(data,status){
		
			$('#'+head_tag).html(data);
			
        	removeLoader();

    	}).fail(function(data) {

	          messageToaster('error','Head code not found.','Failed');
	      
	          removeLoader();
	    
	    });   
	  	
    }

    

</script><?php /**PATH /home/ubuntu/rebmgisplus/skylite/resources/views/scripts/head.blade.php ENDPATH**/ ?>