function did(obj){
    return document.getElementById(obj);
}

function produk(k){
    did('ProdukKategoriDetailId').value = k;
    document.produk.submit();
}

function number_format(number){
    var str = '', nh, c, x;
    nh = number.toString();
    c = 1;
    for (x = nh.length - 1; x >= 0; x--, c++) {
        str += nh.charAt(x);
        if (c % 3 == 0 && c != nh.length) 
            str += '.';
    }
    str = str.split("");
    str.reverse();
    str = str.join("");
    return str;
}

function pilkota(tb, ttl, c, stat){
    var frm = document.formtrans;
    var tberat = tb;
    var i = did('kirimlist_'+c).value.lastIndexOf("-");
    var piltarif = parseInt(did('kirimlist_'+c).value.substring(0, i));
    var hasil;
    var tarif;
	if (stat == 1) {
		tarif = (Math.ceil(tberat) * piltarif);
//		if (tberat >= 150) 
//			tarif += tarif * 0.5;
//		if (tarif < 20000) 
//			tarif = 20000;
//		if (tberat < 1) 
//			tarif = 20000;
		if (piltarif == 0) 
			tarif = 0;
	}else{
		tarif = piltarif;
	}
    hasil = (tarif + ttl);
    did('txttarif').innerHTML = number_format(did('kirimlist_'+c).value.substring(0, i));
    did('txttarif2').innerHTML = number_format(tarif);
    did('txttbayar').innerHTML = number_format(hasil);
}

function batal(id){
    did(id).value = 0
    document.formtrans.submit()
}

function chcl(obj, stat){
    obj.style.borderColor = stat ? '#BBF' : '';
    obj.style.backgroundColor = stat ? '#BBF' : '';
    obj.style.cursor = stat ? 'pointer' : '';
}

function chimg(obj, img){
    obj.src = img;
}

function swapimg(obj1, obj2){
    did(obj2).src = obj1.src;
}
function loadimg(img, obj){
	did(obj).src = img;
}

function numbersonly(e){
    var unicode = e.charCode ? e.charCode : e.keyCode
	//if the key isn't the backspace, left, right, del, tab (which we should allow)
    if (unicode != 8 && unicode != 37 && unicode != 39 && unicode != 46 && unicode != 9) { 
        if (unicode < 48 || unicode > 57) //if not a number
            return false //disable key press
    }
}

function cart_radio_kirim(i, l){
    for (x = 0; x < l; x++) {
        did('kirimlist_' + x).disabled = (i == x)?false:true;
    }
}

