<script type="text/javascript">
function transaction_details_modal(tid){
	if(tid!=''){ 
		var txnId = $('#td_txn_id_'+tid).html();
		$.ajax({url: "<?php echo $this->config->item('ajax_base_url').$this->config->item('admin_directory_name').'/';?>transactions/details_popup?tid="+tid, 
			beforeSend: function(){ 
				$('#td_txn_id_'+tid).html('Please Wait &nbsp;<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>');
			},
			success: function(result){ //alert(result);
				if(result!=''){
					$('#popup_trans_details_body').html(result);	
					jQuery("#trans_details_modal").modal('show');
					$('#td_txn_id_'+tid).html(txnId);
				}
			}
		});
	}
}
$(function () {
  $('[data-toggle="tooltip"]').tooltip();
});
function change_status_model(tid,action_sts){
	if(tid!=''){ 
		var txnId = $('#td_txn_id_'+tid).html();
		$.ajax({url: "<?php echo $this->config->item('ajax_base_url').$this->config->item('admin_directory_name').'/';?>transactions/update_status?tid="+tid+"&action_sts="+action_sts, 
			beforeSend: function(){ 
				$('#ch_sts_'+tid).html('<i class="fa fa-spinner fa-spin"></i>');
				$('#csPopTxnId').html(txnId);
				$('#h_tid').val(tid);
			},
			success: function(result){ //alert(result);
				if(result!=''){
					$('#popup_update_sts_body').html(result);	
					jQuery("#update_status_modal").modal('show');
					$('#ch_sts_'+tid).html('<i class="fa fa-pencil-square-o"></i>');
				}
			}
		});
	}
}
$(document).ready(function(){
	$('#updateStsFrm').validate({
		ignore: [], 
		highlight: function(element) {
			$(element).closest('.form-group').removeClass('has-success').addClass('has-error'); 
		},
		success: function(element) {
			element.closest('.form-group').removeClass('has-error').addClass('has-success');
			element.remove();
		},
		submitHandler: function(form){
			var site_base_url = $('#h_base_url').val();
			var form = $('#updateStsFrm');
			var url = site_base_url+form.attr('action');
			$.ajax({
				type: "POST",
				url: url,
				data: form.serialize(), // serializes the form's elements.
				beforeSend: function(){
					$('#updateBtn').html('Please Wait <i class="fa fa-spinner fa-spin"></i>');
				},
				success: function(result, status, xhr){//alert(result);
					if(result=='success'){
						window.location=site_base_url+'transactions';
					}else{
						$('#result_display').html('<div class="alert alert-danger">'+result+'</div>');
						$('#updateBtn').html('Update Now!');
					}
				},
				error: function(xhr, status, error_desc){
					$('#result_display').html('<div class="alert alert-danger">'+error_desc+'</div>');
					$('#updateBtn').html('Update Now!');
				}
			});		
			return false;
		}
	});
});
</script>
<style>
address label{margin-right:10px;}
</style>
<div class="modal fade" id="trans_details_modal" tabindex="-1" role="dialog">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title" style="display: inline-block;">Transaction Details</h4>
				<button type="button" class="close" data-dismiss="modal">&times;</button>
			  </div>
			<div class="modal-body" id="popup_trans_details_body"></div>
		</div>
	</div>
</div>

<div class="modal fade" id="update_status_modal" tabindex="-1" role="dialog">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<form method="post" id="updateStsFrm" action="transactions/update_sts_entry">
				<input type="hidden" id="h_base_url" name="h_base_url" value="<?php echo base_url().$this->config->item('admin_directory_name').'/';?>" />
				<input type="hidden" id="h_tid" name="h_tid" value="0" />
				<div class="modal-header">
					<h4 class="modal-title" style="display: inline-block;">Change Status for <span id="csPopTxnId"></span></h4>
					<button type="button" class="close" data-dismiss="modal">&times;</button>
				  </div>
				<div class="modal-body" id="popup_update_sts_body"></div>
				<div class="modal-footer">
					<button type="submit" id="updateBtn" class="btn btn-primary">Update Now!</button>
				</div>
			</form>
		</div>
	</div>
</div>