function formatcurrency(st) {
	st += "";
	var theValue = st;
	var finalString = '';

	if(theValue.length < 4) {
		finalString = theValue;
	}
	else {
		if(theValue.indexOf(".")==-1) { //"."
			theValueEx = "";
		}
		else {
			temp = theValue.split("."); //"."
			theValue=temp[0];
			theValueEx= "." + temp[1]; //"."
		}

		var modulus = theValue.length % 3
		var count = 0
		finalString = theValue.substring(0, modulus)

		if(modulus != 0) finalString += '.' // ','
		for(i = modulus; i < theValue.length; i++) {
			if(count == 3){ 
				finalString += '.'; //'.';
				count = 0;
			}
			finalString += theValue.charAt(i);
			count++;
		}
		finalString = finalString + theValueEx;
	}
	
	return finalString;
}

var comqty=0;
var bookqty=0;
var comcount=1;comqty=1;
var checkall=0;
function hitung(nm_frm,item,count,jumlah_elemen){
	//eval("var harga=nm_frm.harga"+item+".value");
	var harga = eval("nm_frm.harga"+item+".value");
	//alert(harga);
	//eval("var qty=nm_frm.qty"+item);
	var qty = eval("nm_frm.qty"+item);
	if ((isNaN(qty.value))||(qty.value<=0)||(qty.value=='')) {
		qty.value=1;
		total=parseInt(harga);
	} else {
		qty.value=parseInt(qty.value);
		var total=parseInt(harga)*parseInt(qty.value);
	}
	
	eval("nm_frm.total_x"+item+".value=formatcurrency(total)")	;
	eval("nm_frm.qtycom"+count+".value=qty.value")	;
	eval("nm_frm.total"+count+".value=total");
	//alert(nm_frm.total);
	hitungtotal(nm_frm,jumlah_elemen);
	
}

function hitungtotal(nm_frm,jumlah_elemen){	
	var total = 0;
	total = parseInt(total);
	for(i=0;i<jumlah_elemen;i++)
		{
			ntotal = eval("nm_frm.total"+i+".value");
			nqty = eval("nm_frm.qtycom"+i+".value");
			ntotal = parseInt(ntotal);
			nqty = parseInt(nqty);
			total=total+ntotal;			
			nqty = 0;
			ntotal = 0;
		}
	//alert(total);
	nm_frm.xtotal.value = formatcurrency(total);
	nm_frm.total.value = total;
}
