<script type="text/javascript">
$(function(){

$('#notes').textbox('setValue','<?=$r->notes?>');

/*--- ---*/

$('#tl2Sim').click(function(){		
	//alert(1);
	KdBarang2 = $('#KdBarang2').combobox('getValue');
	weight= $('#weight').numberbox('getValue');
	price= $('#price').numberbox('getValue');
	amount= $('#amount').numberbox('getValue');
	ket_order= $('#ket_order').val();
		
	$('#dlg').dialog('close');
	$('#dg').datagrid('appendRow',{		
		KdBarang2: KdBarang2,
		NmBarang2: $('#NmBarang2').val(),
		color: $('#color').combobox('getValue'),
		Sat2: $('#Sat2').combobox('getValue'),
		weight: weight,
		price: price,
		amount: amount,
		ket_order: ket_order
	});	
	editDet('t');
});

$('#tl2Ubh2').click(function(){
	$('#dlg').dialog('close');
	var row = $('#dg').datagrid('getSelected');
	if (row){				
		editDet('u');
		var index = $('#dg').datagrid('getRowIndex', row);
		$('#dg').datagrid('updateRow',{
			index: index, 
			row: { 
				KdBarang2: $('#KdBarang2').combogrid('getValue'),
				NmBarang2: $('#NmBarang2').val(),
				color: $('#color').combobox('getValue'),
				Sat2: $('#Sat2').combobox('getValue'),
				qty: nformat2($('#qty').val(),0),
				weight: nformat2($('#weight').val(),3),
				price: nformat2($('#price').val(),4),
				amount: nformat2($('#amount').val(),2),
				ket_order: $('#ket_order').val()
				}
		});
	}
});

$('#tl2Hps').click(function(){
	var row = $('#dg').datagrid('getSelected');
	if (row){		
		$.messager.confirm('Confirm','Apakah anda yakin akan menghapus data ini?',function(r){
			if (r){
				$.post('<?=site_url(); ?>po_rm/delDet',{id:row.id,child_no:row.child_no},function(result){
					var result = eval('('+result+')');
					if (result.success){
						//$('#dg').datagrid('reload');	// reload the rm_in data
						var index = $('#dg').datagrid('getRowIndex', row);
						$('#dg').datagrid('deleteRow', index);
						$.messager.show({
							title: 'Info',
							msg: result.msg
						});
					} else {
						$.messager.show({	// show error message
							title: 'Error',
							msg: result.msg
						});
					}
				});
			}
		});		
	}
});


});//Akhir Document Ready
</script>