Bug 2365 : Inner counter not properly set for serials subscriptions not starting...
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / additem.js
1 function countItemBlocks() {
2     var outeritemblock = document.getElementById('outeritemblock');
3     var quantityrec = document.getElementById('quantityrec');
4     var origquantityrec = document.getElementById('origquantityrec');
5     var itemblockcount = outeritemblock.getElementsByTagName('div');
6     var num = parseFloat(origquantityrec.value) + itemblockcount.length;
7     quantityrec.setAttribute('value',num);
8 }
9 function deleteItemBlock(index) {
10     var aDiv = document.getElementById(index);
11     aDiv.parentNode.removeChild(aDiv);
12     countItemBlocks();
13 }
14 function cloneItemBlock(index) {    
15     var original = document.getElementById(index); //original <div>
16     var clone = original.cloneNode(true);
17     // set the attribute for the new 'div' subfields
18     clone.setAttribute('id',index + index);//set another id.
19     var NumTabIndex;
20     NumTabIndex = parseInt(original.getAttribute('tabindex'));
21     if(isNaN(NumTabIndex)) NumTabIndex = 0;
22     clone.setAttribute('tabindex',NumTabIndex+1);
23     var CloneButtonPlus;
24     var CloneButtonMinus;
25   //  try{
26         CloneButtonPlus = clone.getElementsByTagName('a')[0];
27         CloneButtonPlus.setAttribute('onclick',"cloneItemBlock('" + index + index + "')");
28     CloneButtonMinus = clone.getElementsByTagName('a')[1];
29     CloneButtonMinus.setAttribute('onclick',"deleteItemBlock('" + index + index + "')");
30     CloneButtonMinus.setAttribute('style',"display:inline");
31    // }
32     //catch(e){        // do nothig if ButtonPlus & CloneButtonPlus don't exist.
33     //}
34     // insert this line on the page    
35     original.parentNode.insertBefore(clone,original.nextSibling);
36     countItemBlocks();
37 }
38 function check_additem() {
39         var     barcodes = document.getElementsByName('barcode');
40         var success = true;
41         for(i=0;i<barcodes.length;i++){
42                 for(j=0;j<barcodes.length;j++){
43                         if( (i > j) && (barcodes[i].value == barcodes[j].value) && barcodes[i].value !='') {
44                                 barcodes[i].className='error';
45                                 barcodes[j].className='error';
46                                 success = false;
47                         }
48                 }
49         }
50         // TODO : Add AJAX function to test against barcodes already in the database, not just 
51         // duplicates within the form.  
52         return success;
53 }