<?php
	$rdata = array_map('to_utf8', array_map('nl2br', array_map('html_attr_tags_ok', $rdata)));
	$jdata = array_map('to_utf8', array_map('nl2br', array_map('html_attr_tags_ok', $jdata)));
?>
<script>
	$j(function() {
		var tn = 'gestion_banques';

		/* data for selected record, or defaults if none is selected */
		var data = {
			compte_emetteur: <?php echo json_encode(array('id' => $rdata['compte_emetteur'], 'value' => $rdata['compte_emetteur'], 'text' => $jdata['compte_emetteur'])); ?>,
			numero: <?php echo json_encode($jdata['numero']); ?>,
			banque: <?php echo json_encode($jdata['banque']); ?>,
			compte_beneficiaire: <?php echo json_encode(array('id' => $rdata['compte_beneficiaire'], 'value' => $rdata['compte_beneficiaire'], 'text' => $jdata['compte_beneficiaire'])); ?>,
			numero_cb: <?php echo json_encode($jdata['numero_cb']); ?>,
			banque_cb: <?php echo json_encode($jdata['banque_cb']); ?>,
			cheque_mv: <?php echo json_encode(array('id' => $rdata['cheque_mv'], 'value' => $rdata['cheque_mv'], 'text' => $jdata['cheque_mv'])); ?>
		};

		/* initialize or continue using AppGini.cache for the current table */
		AppGini.cache = AppGini.cache || {};
		AppGini.cache[tn] = AppGini.cache[tn] || AppGini.ajaxCache();
		var cache = AppGini.cache[tn];

		/* saved value for compte_emetteur */
		cache.addCheck(function(u, d) {
			if(u != 'ajax_combo.php') return false;
			if(d.t == tn && d.f == 'compte_emetteur' && d.id == data.compte_emetteur.id)
				return { results: [ data.compte_emetteur ], more: false, elapsed: 0.01 };
			return false;
		});

		/* saved value for compte_emetteur autofills */
		cache.addCheck(function(u, d) {
			if(u != tn + '_autofill.php') return false;

			for(var rnd in d) if(rnd.match(/^rnd/)) break;

			if(d.mfk == 'compte_emetteur' && d.id == data.compte_emetteur.id) {
				$j('#numero' + d[rnd]).html(data.numero);
				$j('#banque' + d[rnd]).html(data.banque);
				return true;
			}

			return false;
		});

		/* saved value for compte_beneficiaire */
		cache.addCheck(function(u, d) {
			if(u != 'ajax_combo.php') return false;
			if(d.t == tn && d.f == 'compte_beneficiaire' && d.id == data.compte_beneficiaire.id)
				return { results: [ data.compte_beneficiaire ], more: false, elapsed: 0.01 };
			return false;
		});

		/* saved value for compte_beneficiaire autofills */
		cache.addCheck(function(u, d) {
			if(u != tn + '_autofill.php') return false;

			for(var rnd in d) if(rnd.match(/^rnd/)) break;

			if(d.mfk == 'compte_beneficiaire' && d.id == data.compte_beneficiaire.id) {
				$j('#numero_cb' + d[rnd]).html(data.numero_cb);
				$j('#banque_cb' + d[rnd]).html(data.banque_cb);
				return true;
			}

			return false;
		});

		/* saved value for cheque_mv */
		cache.addCheck(function(u, d) {
			if(u != 'ajax_combo.php') return false;
			if(d.t == tn && d.f == 'cheque_mv' && d.id == data.cheque_mv.id)
				return { results: [ data.cheque_mv ], more: false, elapsed: 0.01 };
			return false;
		});

		cache.start();
	});
</script>

