		function pm_auto_complete(i){
	
		$("#pm_name"+i).autocomplete('getproduct.php', {
		width: 450,
		matchContains: true,
		selectFirst: false
		});
		
			$("#pm_name"+i).result(function(event, data, formatted) {
				$("#pm_autoid"+i).val(data[1]);
				$("#pm_price"+i).val(data[3]);
			});
		}
		
	function calc(){
		row = new Number($('#row').val());
		gtotal = 0;
			for(i = 1;i<row;i++){
					harga 	= new Number($('#pm_price'+i).val());
					qty 	= new Number($('#pm_qty'+i).val());
					subtotal = harga * qty;
					$('#pm_subtotal'+i).val(subtotal);
					gtotal = gtotal + new Number(subtotal);
				}
			$('#gtotal').text(formatDecimal(gtotal));
			$('#price').val(gtotal);
		}
		
	function addrow(){
			id = new Number($('#row').val());
			
			tbl_row = '<tr><td>'+id+'</td><td><input type="text" id="pm_name'+id+'" name="pm_name'+id+'" class="input" style="width:100%;" ';
			tbl_row = tbl_row +	' onfocus="pm_auto_complete('+id+')" autocomplete="off"> ';
			tbl_row = tbl_row +	' <input type="hidden" id="pm_autoid'+id+'" name="pm_autoid'+id+'"></td> ';
			tbl_row = tbl_row + '<td class="tr"><input type="text" id="pm_price'+id+'" name="pm_price'+id+'" class="input tr" style="width:100%;" onkeyup="calc()"/></td>';
			tbl_row = tbl_row + '<td class="tr"><input type="text" class="input tr" style="width:100%;" id="pm_qty'+id+'" name="pm_qty'+id+'"';
			tbl_row = tbl_row +	' placeholder="0" value="0" onkeyup="calc()" autocomplete="off"> ';
			tbl_row = tbl_row + '<td><input readonly="readonly" id="pm_subtotal'+id+'" name="pm_subtotal'+id+'" class="input tr" style="width:100%;" onblur="chk_row('+id+')"/></td>';			
			tbl_row = tbl_row + '</tr>';
			
			$("#tbl").last().append(tbl_row);
			$('#pm_name'+id).focus();
						
			new_id = id + 1;

			$('#row').val(new_id);
			calc();
		}
			

		function chk_row(id){
			next_row = new Number(id) + 1;
				if(!$('#pm_qty'+next_row).length){
					if($('#pm_qty'+id).val()!=0){
							addrow()
						}
					}
			}