function confirmAct(theForm, count_ids){
         var ids = "";
         var is_confirmed  = false;
         var is_invert = (theForm.act.value=='inv');
         var ids_count = 0;

         var e = theForm.elements['ids[]'];
         if (typeof(e)!='undefined') {
             var e_count  = (typeof(e.length) != 'undefined') ? e.length : 0;

             if (e_count) {
                 for (var i = 0; i < e_count; i++) {
                     if (is_invert) e[i].checked = !e[i].checked;
                     else if (e[i].checked) {
                          ids = ids + "\n" + e[i].value;
                          ids_count++;
                     }
                 }
             }
             else {
                   if (is_invert) e.checked = !e.checked;
                   else {
                         ids  += (typeof(e) != 'undefined' && e.checked) ? "\n"+e.value : "";
                         ids_count++;
                   }
             }

             if (!is_invert) {

                 if (ids!="") {
                     var Msg;
                     if (theForm.act.value=='beli') Msg = "membeli/memesan";
                     else if (theForm.act.value=='del') Msg = "menghapus/membatalkan pesanan";
                     else if (theForm.act.value=='save') Msg = "menyimpan perubahan pesanan";
                     else Msg = "";
                     if (count_ids) {
                         ids = "";
                     }

                     if (Msg!="") is_confirmed = confirm("Anda yakin akan " + Msg + " " + ids_count +" buku:\n" + ids);
                 }
                 else alert("Tidak ada buku yang dipilih. Anda harus memilih satu atau lebih buku");

                 if (is_confirmed) theForm.submit();

             }

             theForm.act[0].selected = true;
             return is_confirmed;
         }
         else theForm.act[0].selected = true;
}

function CheckUncheck(theElemen){
         var theForm = theElemen.form;
         var e = theForm.elements['ids[]'];
         if (typeof(e)!='undefined') {
             var e_count  = (typeof(e.length) != 'undefined') ? e.length : 0;

             if (e_count) {
                 for (var i = 0; i < e_count; i++) {
                     e[i].checked = theElemen.checked;
                 }
             }
             else e.checked = theElemen.checked;
         }
         else theElemen.checked = false;
}

function UnCheck(theForm){
         var e = theForm.elements['check_uncheck'];
         if (typeof(e)!='undefined') {
             if (!theForm.elements['ids[]'].checked) e.checked = false;
         }
}

function kuantumChange(theForm){
         var e = theForm.elements['ids[]'];
         var n = theForm.elements['newKuantum[]'];
         var o = theForm.elements['oldKuantum[]'];
         if (typeof(e)!='undefined') {
             var e_count  = (typeof(e.length) != 'undefined') ? e.length : 0;

             if (e_count) {
                 for (var i = 0; i < e_count; i++) {
                     if (n[i].value!=o[i].value) e[i].checked = true;
                 }
             }
             else {
                   if (n.value!=o.value) e.checked = true;
             }
         }
}

function simpanBelanjaan(theForm){
         if(confirm("Anda yakin akan menyimpan perubahan pesanan buku:\n")) {
            theForm.act.value = "save";
            theForm.submit();
         }
}

function doCheckOut(theForm) {
         if (confirm("Anda yakin akan Checkout?\nDengan checkout pesanan anda akan kami proses dan tidak bisa anda edit kembali.")) {
             theForm.checkout.value=1;
             theForm.submit();
         }
}
