<script type="text/javascript">

	function setBank(event,obj,unique_element)
	{
		event.preventDefault();

		obj = $(obj);

		var subhead_name = $('.'+unique_element+'_subhead_name');

		var bank_list    = $('.'+unique_element+'_bank_list option:selected');

		if(bank_list.text() != "Select Bank")
		{
			subhead_name.attr('readonly',true);
			subhead_name.val(bank_list.text());
		}
		else
		{
			subhead_name.removeAttr('readonly',true);
			subhead_name.val('');
		}
	}

	function verifyBank(event,obj,unique_element)
	{
		event.preventDefault();

		obj = $(obj);



		var bank_section = $('.'+unique_element+'_subhead_bank_section');
		var bank_list    = $('.'+unique_element+'_bank_list option');
		var subhead_name = $('.'+unique_element+'_subhead_name');

		bank_list.eq('0').prop('selected',true);


		if(obj.val() == "Bank")
		{
			bank_section.show();
			subhead_name.attr('readonly',true);
		}
		else
		{
			bank_section.hide();
			subhead_name.removeAttr('readonly');
			subhead_name.val('');
		}
	}

	function showSubHeadModel(event,head)
    {
    	event.preventDefault();

    	var route = "{{url('showsubheadmodal')}}/"+head;

		showLoader();

		$.get(route,function(data)
		{


        	$('#add_subhead_modal').html(data);

    		$('#md_add_subhead').modal('show');


    		removeLoader();
  		}); 
    }

    function showUpdateSubHeadModel(event,subhead)
    {
    	event.preventDefault();

        $('#update_subhead_modal').html('');


    	var route = "{{url('showupdatesubheadmodal')}}/"+subhead;

		showLoader();

		$.get(route,function(data)
		{
        	$('#update_subhead_modal').html(data);

    		$('#md_update_subhead').modal('show');


    		removeLoader();
  		}); 
    }

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

		var obj = $('#form_add_subhead');

		var form = document.querySelector('#form_add_subhead') // 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){
			
			$('#'+result.head_tag).html(result.subhead_view);

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


	}

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

		var obj = $('#form_update_subhead');

		var form = document.querySelector('#form_update_subhead') // 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){
			
			$('#'+result.head_tag).html(result.subhead_view);

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


	}

	function removeSubhead(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){
					
						
						$('#'+result.head_tag).html(result.subhead_view);

						
				        removeLoader();


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

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

		
	}


	
	function checkOpeningBalanceAccount(obj,unique_element)
	{
		var account = $('.account_'+unique_element);


		account.hide();

		if(obj.value > 0)
		{
			account.show();
		}
	}

	
</script>