bug 4464: properly check if a subfield is populated if it is in a textarea
[wip/koha-chris_n.git] / koha-tmpl / intranet-tmpl / prog / en / modules / cataloguing / addbiblio.tmpl
1 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2 <title>Koha &rsaquo; Cataloging &rsaquo; <!-- TMPL_IF NAME="biblionumber" -->Editing <!-- TMPL_VAR NAME="title" escape="html" --> (Record Number <!-- TMPL_VAR name="biblionumber" -->)<!-- TMPL_ELSE -->Add MARC Record<!-- /TMPL_IF --></title>
3 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4 <script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/yui/plugins/bubbling-min.js"></script>
5 <script type="text/javascript">
6 //<![CDATA[
7
8      var fields_in_use = {};
9          $(document).ready(function() {
10                 $('#addbibliotabs > ul').tabs().bind('show.ui-tabs', function(e, ui) {
11                         $("#"+ui.panel.id+" input:eq(0)").focus();
12                 });
13         $('.tag').each(function() {
14             var field_id = this.getAttribute('id').substring(0, 7);
15             if (field_id in fields_in_use) {
16                 fields_in_use[field_id]++;
17             } else {
18                 fields_in_use[field_id] = 1;
19             }
20         });
21         $('.subfield_line').each(function() {
22             var field_id = this.getAttribute('id').substring(0, 12);
23             if (field_id in fields_in_use) {
24                 fields_in_use[field_id]++;
25             } else {
26                 fields_in_use[field_id] = 1;
27             }
28         });
29          });
30          
31          $('#header_search > ul').tabs().bind('show.ui-tabs', function(e, ui) { $('#header_search > div:not(.ui-tabs-hide)').find('input').eq(0).focus(); });
32
33 function confirmnotdup(){
34         $("#confirm_not_duplicate").attr("value","1");
35         // alert(_("Not a duplicate confirmed. Please click on Add biblio to save the record"));
36         var checkform = $("#f");
37         Check(checkform);
38 }
39
40 /**
41  * 
42  * 
43  */
44 function Check(dest){
45     var StrAlert = AreMandatoriesNotOk();
46     if( ! StrAlert ){
47         document.f.submit();
48         return true;
49     } else {
50         alert(StrAlert);
51         return false;
52     }
53 }
54
55 function Dopop(link,i) {
56     defaultvalue = document.getElementById(i).value;
57     window.open(link+"&result="+defaultvalue,"valuebuilder",'width=700,height=550,toolbar=false,scrollbars=yes');
58 }
59
60 /**
61  * this function open a popup to search on z3950 server.
62  */
63 function PopupZ3950() {
64     var strQuery = GetZ3950Terms();
65         if(strQuery){
66         window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
67     } 
68 }
69
70 /**
71  * check if mandatory subfields are written
72  */
73 function AreMandatoriesNotOk(){
74     var mandatories = new Array();
75     var mandatoriesfields = new Array();
76     var tab = new Array();
77     var label = new Array();
78     var flag=0;
79     var tabflag= new Array();  
80     <!-- TMPL_LOOP NAME='BIG_LOOP' -->
81         <!-- TMPL_LOOP NAME='innerloop' -->
82                 <!-- TMPL_IF NAME="mandatory" -->
83                 mandatoriesfields.push(new Array("<!-- TMPL_VAR NAME="tag" -->","<!-- TMPL_VAR NAME="index" --><!-- TMPL_VAR NAME="random" -->","<!-- TMPL_VAR NAME="index" -->"));
84                 <!-- /TMPL_IF -->
85                 <!-- TMPL_LOOP NAME='subfield_loop'-->
86                         <!-- TMPL_IF NAME='mandatory'-->mandatories.push("<!-- TMPL_VAR NAME='id' -->");
87                         tab.push("<!-- TMPL_VAR NAME='number' -->");
88                         label.push("<!-- TMPL_VAR NAME='marc_lib' -->");
89                 <!-- /TMPL_IF -->
90             <!-- /TMPL_LOOP -->
91         <!-- /TMPL_LOOP -->
92     <!-- /TMPL_LOOP -->
93     var StrAlert = _("Can't save this record because the following field aren't filled:");
94     StrAlert += "\n\n";
95     for(var i=0,len=mandatories.length; i<len ; i++){
96         var tag=mandatories[i].substr(4,3);
97         var subfield=mandatories[i].substr(17,1);
98         var tagnumber=mandatories[i].substr(19,mandatories[i].lastIndexOf("_")-19);
99         tabflag[tag+subfield+tagnumber]=new Array();
100         tabflag[tag+subfield+tagnumber][0]=0;
101         if( ! document.getElementById(mandatories[i]).value){
102             tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ;
103             document.getElementById(mandatories[i]).setAttribute('class','subfield_not_filled');
104             document.getElementById(mandatories[i]).focus();
105             tabflag[tag+subfield+tagnumber][1]=label[i];
106             tabflag[tag+subfield+tagnumber][2]=tab[i];
107         } else {
108             tabflag[tag+subfield+tagnumber][0] = 1;
109         }    
110     }
111     for (var tagsubfieldid in tabflag){
112       if (tabflag[tagsubfieldid][0]==0){
113         var tag=tagsubfieldid.substr(0,3);
114         var subfield=tagsubfieldid.substr(3,1);    
115         StrAlert += "\t* "+_("tag ")+tag+_(" subfield ")+subfield+" "+tabflag[tagsubfieldid][1]+_(" in tab ")+tabflag[tagsubfieldid][2]+"\n";
116         //StrAlert += "\t* "+label[i]+_(" in tab ")+tab[i]+"\n"; 
117         flag=1;    
118       }   
119     }   
120     
121     /* Check for mandatories field(not subfields) */
122     for(var i=0,len=mandatoriesfields.length; i<len; i++){
123             isempty  = true;
124                 arr      = mandatoriesfields[i];
125         divid    = "tag_" + arr[0] + "_" + arr[1];
126         varegexp = new RegExp("^tag_" + arr[0] + "_code_");
127         
128                 if(parseInt(arr[0]) >= 10){
129                 elem = document.getElementById(divid);
130                 eleminputs = elem.getElementsByTagName('input');
131                 
132                 for(var j=0,len2=eleminputs.length; j<len2; j++){
133         
134                         if(eleminputs[j].name.match(varegexp) && eleminputs[j].value){
135                                         inputregexp = new RegExp("^tag_" + arr[0] + "_subfield_" + eleminputs[j].value + "_" + arr[2]);
136                                         
137                                         for( var k=0; k<len2; k++){
138                                                 if(eleminputs[k].id.match(inputregexp) && eleminputs[k].value){
139                                                         isempty = false
140                                                 }
141                                         }
142                                         
143                                         elemselect = elem.getElementsByTagName('select');
144                                         for( var k=0; k<elemselect.length; k++){
145                                                 if(elemselect[k].id.match(inputregexp) && elemselect[k].value){
146                                                         isempty = false
147                                                 }
148                                         }
149                         }
150                 }
151
152                 elemtextareas = elem.getElementsByTagName('textarea');
153                 for(var j=0,len2=elemtextareas.length; j<len2; j++){
154                 // this bit assumes that the only textareas in this context would be for subfields
155                 if (elemtextareas[j].value) {
156                     isempty = false;
157                 }
158             }
159         }else{
160                 isempty = false;
161         }
162         
163         if(isempty){
164                 flag = 1;
165                 StrAlert += _("\t* Field ") + arr[0] + _(" is mandatory, at least one of its subfields must be filled.") + "\n";
166         }
167         
168     }
169     
170     if(flag){
171             return StrAlert;
172         } else {
173                 return flag;
174         }
175 }
176
177 /** 
178  * check if z3950 mandatories are set or not
179  */
180 function GetZ3950Terms(){
181  var strQuery="&frameworkcode="+document.forms['f'].frameworkcode.value;
182     var mandatories = new Array();
183     var mandatories_label = new Array();
184     <!-- TMPL_LOOP NAME='BIG_LOOP' --><!-- TMPL_LOOP NAME='innerloop' --><!-- TMPL_LOOP NAME='subfield_loop'--><!-- TMPL_IF NAME='z3950_mandatory'-->mandatories.push("<!-- TMPL_VAR NAME='id' -->");
185         mandatories_label.push("<!-- TMPL_VAR NAME='z3950_mandatory' -->");<!-- /TMPL_IF --><!-- /TMPL_LOOP --><!-- /TMPL_LOOP --><!-- /TMPL_LOOP -->
186     
187     for(var i=0,len=mandatories.length; i<len ; i++){
188         var field_value = document.getElementById(mandatories[i]).value;
189         if( field_value ){
190             strQuery += "&"+mandatories_label[i]+"="+field_value;
191         }
192     }
193     return strQuery;
194 }
195
196 function Changefwk(FwkList) {
197         var fwk = FwkList.options[FwkList.selectedIndex].value;
198         window.location = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=<!--TMPL_VAR Name="biblionumber"-->&breedingid=<!-- TMPL_VAR name="breedingid" -->&frameworkcode="+fwk;
199
200 }
201
202 // returns the subfieldcode based upon subfieldid writing
203 function getSubfieldcode(tagsubfieldid){
204     // 3 : tag +3 : tagnumber +4 : number of _ +8 subfield -1 begins at 0  
205     return tagsubfieldid.substr(3+3+4+8-1,1);
206 }
207
208 // Take the base of tagsubfield information (removing the subfieldcodes and subfieldindexes)
209 // returns the filter
210 function getTagInputnameFilter(tagsubfieldid){
211     var tagsubfield=tagsubfieldid.substr(0,tagsubfieldid.lastIndexOf("_"));  
212     var tagcode=tagsubfield.substr(tagsubfield.lastIndexOf("_"));
213     tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_"));
214     tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_"));
215     tagsubfield=tagsubfield+"_."+tagcode;
216     return tagsubfield;  
217 }
218
219 function openAuth(tagsubfieldid,authtype) {
220     // let's take the base of tagsubfield information (removing the indexes and the codes
221     var element=document.getElementById(tagsubfieldid);
222     var tagsubfield=getTagInputnameFilter(tagsubfieldid);
223     var elementsubfcode=getSubfieldcode(element.name);
224     var mainmainstring=element.value;
225     var mainstring="";  
226     var inputs = element.parentNode.parentNode.getElementsByTagName("input");
227
228     for (var myindex =0; myindex<inputs.length;myindex++){
229         if (inputs[myindex].name && inputs[myindex].name.match(tagsubfield)){
230             var subfieldcode=getSubfieldcode(inputs[myindex].name);
231             if (isNaN(parseInt(subfieldcode)) && inputs[myindex].value != "" && subfieldcode!=elementsubfcode){
232                 mainstring=inputs[myindex].value+" "+mainstring;
233             }      
234         }
235     }           
236         newin=window.open("../authorities/auth_finder.pl?authtypecode="+  authtype+ "&index="+tagsubfieldid+"&value_mainstr="+encodeURI(mainmainstring)+"&value_main="+encodeURI(mainstring), "_blank",'width=700,height=550,toolbar=false,scrollbars=yes');
237 }
238
239
240 function ExpandField(index) {
241     var original = document.getElementById(index); //original <div>
242     var divs = original.getElementsByTagName('div');
243     for(var i=0,divslen = divs.length ; i<divslen ; i++){      // foreach div
244         if(divs[i].getAttribute('id').match(/^subfield/)){  // if it s a subfield
245             if (divs[i].style.display == 'block') {
246                 divs[i].style.display = 'none';
247             } else {
248                 divs[i].style.display = 'block';
249             }
250         }
251     }
252 }
253
254 /**
255  * To clone a field or a subfield by clicking on '+' button
256  */ 
257 function CloneField(index) {
258     var original = document.getElementById(index); //original <div>
259     fields_in_use[index.substr(0, 7)]++;
260     var clone = original.cloneNode(true);
261     var new_key = CreateKey();
262     var new_id  = original.getAttribute('id')+new_key;
263     
264     clone.setAttribute('id',new_id); // setting a new id for the parent div
265     
266     var divs = clone.getElementsByTagName('div');
267     
268     <!-- TMPL_UNLESS NAME='hide_marc'--> // No indicator if hide_marc
269         // setting a new name for the new indicator
270         for(var i=0; i < 2; i++) {
271             var indicator = clone.getElementsByTagName('input')[i];
272             indicator.setAttribute('name',indicator.getAttribute('name')+new_key);
273         }
274     <!-- /TMPL_UNLESS -->
275         
276     // settings all subfields
277     for(var i=0,divslen = divs.length ; i<divslen ; i++){      // foreach div
278         if(divs[i].getAttribute("id").match(/^subfield/)){  // if it s a subfield
279             
280             // set the attribute for the new 'div' subfields
281             divs[i].setAttribute('id',divs[i].getAttribute('id')+new_key);
282             
283             var inputs   = divs[i].getElementsByTagName('input');
284             var id_input = "";
285             
286             for( j = 0 ; j < inputs.length ; j++ ) {
287                 if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
288                         inputs[j].value = "";
289                 }
290             }
291             
292             inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
293             inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
294             var id_input;
295             try {
296                 id_input = inputs[1].getAttribute('id')+new_key;
297                 inputs[1].setAttribute('id',id_input);
298                 inputs[1].setAttribute('name',inputs[1].getAttribute('name')+new_key);
299             } catch(e) {
300                 try{ // it s a select if it is not an input
301                     var selects = divs[i].getElementsByTagName('select');
302                     id_input = selects[0].getAttribute('id')+new_key;
303                     selects[0].setAttribute('id',id_input);
304                     selects[0].setAttribute('name',selects[0].getAttribute('name')+new_key);
305                 }catch(e2){ // it is a textarea if it s not a select or an input
306                         var textaeras = divs[i].getElementsByTagName('textarea');
307                         id_input = textaeras[0].getAttribute('id')+new_key;
308                         textaeras[0].setAttribute('id',id_input);
309                     textaeras[0].setAttribute('name',textaeras[0].getAttribute('name')+new_key);
310                 }
311             }
312             
313             <!-- TMPL_UNLESS NAME='advancedMARCEditor'-->
314             // when cloning a subfield, re set its label too.
315             var labels = divs[i].getElementsByTagName('label');
316             labels[0].setAttribute('for',id_input);
317             <!-- /TMPL_UNLESS -->
318             
319             <!-- TMPL_UNLESS NAME='hide_marc'-->
320                 // updating javascript parameters on button up
321                 var imgs = divs[i].getElementsByTagName('img');
322                 imgs[0].setAttribute('onclick',"upSubfield(\'"+divs[i].getAttribute('id')+"\');");
323             <!-- /TMPL_UNLESS -->
324             
325             // setting its '+' and '-' buttons
326             try {
327                 var spans = divs[i].getElementsByTagName('span');
328                 for (var j = 0; j < spans.length; j++) {
329                     if(spans[j].getAttribute('class') == 'buttonPlus'){
330                         spans[j].setAttribute('onclick',"CloneSubfield('" + divs[i].getAttribute('id') + "')");
331                     } else if (spans[j].getAttribute('class') == 'buttonMinus') {
332                         spans[j].setAttribute('onclick',"UnCloneField('" + divs[i].getAttribute('id') + "')");
333                     }
334                 }
335             }
336             catch(e){
337                 // do nothig if ButtonPlus & CloneButtonPlus don t exist.
338             }
339             
340             // button ...
341             var spans=0;
342             try {
343                 spans = divs[i].getElementsByTagName('a');
344             } catch(e) {
345                 // no spans
346             }
347             if(spans){
348                 var buttonDot;
349                 if(!CloneButtonPlus){ // it s impossible to have  + ... (buttonDot AND buttonPlus)
350                     buttonDot = spans[0];
351                     if(buttonDot){
352                         // 2 possibilities :
353                         try{
354                             var buttonDotOnClick = buttonDot.getAttribute('onclick');
355                             if(buttonDotOnClick.match('Clictag')){   // -1- It s a plugin
356                                 var re = /\('.*'\)/i;
357                                 buttonDotOnClick = buttonDotOnClick.replace(re,"('"+inputs[1].getAttribute('id')+"')");
358                                 if(buttonDotOnClick){
359                                     buttonDot.setAttribute('onclick',buttonDotOnClick);
360                                 }
361                             } else {
362                                 if(buttonDotOnClick.match('Dopop')) {  // -2- It's a auth value
363                                     var re1 = /&index=.*',/;
364                                     var re2 = /,.*\)/;
365
366                                     buttonDotOnClick = buttonDotOnClick.replace(re1,"&index="+inputs[1].getAttribute('id')+"',");
367                                     buttonDotOnClick = buttonDotOnClick.replace(re2,",'"+inputs[1].getAttribute('id')+"')");
368                                     
369                                     if(buttonDotOnClick){
370                                             buttonDot.setAttribute('onclick',buttonDotOnClick);
371                                     }
372                                 }
373                             }
374                             try {
375                                 // do not copy the script section.
376                                 var script = spans[0].getElementsByTagName('script')[0];
377                                 spans[0].removeChild(script);
378                             } catch(e) {
379                                 // do nothing if there is no script
380                             }
381                         }catch(e){}
382                         }
383                 }
384             }
385             <!-- TMPL_UNLESS NAME='hide_marc'-->
386                 var buttonUp = divs[i].getElementsByTagName('img')[0];
387                 buttonUp.setAttribute('onclick',"upSubfield('" + divs[i].getAttribute('id') + "')");
388             <!-- /TMPL_UNLESS -->
389             
390         } else { // it's a indicator div
391             if(divs[i].getAttribute('id').match(/^div_indicator/)){
392                 var inputs = divs[i].getElementsByTagName('input');
393                 inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
394                 inputs[1].setAttribute('id',inputs[1].getAttribute('id')+new_key);
395                 
396                 var CloneButtonPlus;
397                 try {
398                     var anchors = divs[i].getElementsByTagName('a');
399                     for (var j = 0; j < anchors.length; j++) {
400                         if (anchors[j].getAttribute('class') == 'buttonPlus') {
401                             anchors[j].setAttribute('onclick',"CloneField('" + new_id + "')");
402                         } else if (anchors[j].getAttribute('class') == 'buttonMinus') {
403                             anchors[j].setAttribute('onclick',"UnCloneField('" + new_id + "')");
404                         }
405                     }
406                 }
407                 catch(e){
408                     // do nothig CloneButtonPlus doesn't exist.
409                 }
410                 // setting its 'Expand' property
411                 var ExpandFieldA=0;
412                 try {
413                     ExpandFieldA = divs[i].getElementsByTagName('a')[0];
414                     ExpandFieldA.setAttribute('onclick',"ExpandField('" + divs[i].parentNode.getAttribute('id') + "')");
415                 }
416                 catch(e){
417                     // do nothig if ButtonPlus & CloneButtonPlus don t exist.
418                 }
419
420             }
421         }
422     }
423     
424     // insert this line on the page
425     original.parentNode.insertBefore(clone,original.nextSibling);
426 }
427
428 function CloneSubfield(index){
429     var original = document.getElementById(index); //original <div>
430     fields_in_use[index.substr(0, 12)]++;
431     var clone = original.cloneNode(true);
432     var new_key = CreateKey();
433     var new_id  = original.getAttribute('id')+new_key;
434     // set the attribute for the new 'div' subfields
435     var inputs     = clone.getElementsByTagName('input');
436     var selects    = clone.getElementsByTagName('select');
437     var textareas  = clone.getElementsByTagName('textarea');
438     var linkid;
439
440     // input
441     var id_input = "";
442     for(var i=0,len=inputs.length; i<len ; i++ ){
443         id_input = inputs[i].getAttribute('id')+new_key;
444         inputs[i].setAttribute('id',id_input);
445         inputs[i].setAttribute('name',inputs[i].getAttribute('name')+new_key);
446         linkid = id_input;
447     }
448     
449     // select 
450     for(var i=0,len=selects.length; i<len ; i++ ){
451         id_input = selects[i].getAttribute('id')+new_key;
452         selects[i].setAttribute('id',selects[i].getAttribute('id')+new_key);
453         selects[i].setAttribute('name',selects[i].getAttribute('name')+new_key);
454     }
455     
456     // textarea
457     for(var i=0,len=textareas.length; i<len ; i++ ){
458         id_input = textareas[i].getAttribute('id')+new_key;
459         textareas[i].setAttribute('id',textareas[i].getAttribute('id')+new_key);
460         textareas[i].setAttribute('name',textareas[i].getAttribute('name')+new_key);
461     }
462
463     // Changing the "..." link's onclick attribute for plugin callback
464     var links  = clone.getElementsByTagName('a');
465     var link = links[0];
466     var buttonDotOnClick = link.getAttribute('onclick');
467     if(buttonDotOnClick.match('Clictag')){   // -1- It s a plugin
468         var re = /\('.*'\)/i;
469         buttonDotOnClick = buttonDotOnClick.replace(re,"('"+linkid+"')");
470         if(buttonDotOnClick){
471             link.setAttribute('onclick',buttonDotOnClick);
472         }
473     }
474
475
476     <!-- TMPL_UNLESS NAME='advancedMARCEditor' -->
477     // when cloning a subfield, reset its label too.
478     var label = clone.getElementsByTagName('label')[0];
479     label.setAttribute('for',id_input);
480     <!-- /TMPL_UNLESS -->
481     
482     // setting a new if for the parent div
483     clone.setAttribute('id',new_id);
484     
485     try {
486         var buttonUp = clone.getElementsByTagName('img')[0];
487         buttonUp.setAttribute('onclick',"upSubfield('" + new_id + "')");
488         var spans = clone.getElementsByTagName('span');
489         if(spans.length){
490                 for(var i = 0 ,lenspans = spans.length ; i < lenspans ; i++){
491                         if(spans[i].getAttribute('class') == 'buttonPlus'){
492                     spans[i].setAttribute('onclick',"CloneSubfield('" + new_id + "')");
493                 } else if (spans[i].getAttribute('class') == 'buttonMinus') {
494                     spans[i].setAttribute('onclick',"UnCloneField('" + new_id + "')");
495                 }
496             }
497         }
498     }
499     catch(e){
500         // do nothig if ButtonPlus & CloneButtonPlus don't exist.
501     }
502     // insert this line on the page
503     original.parentNode.insertBefore(clone,original.nextSibling);
504 }
505
506  /**
507  * This function removes or clears unwanted subfields
508  */
509 function UnCloneField(index) {
510     var original = document.getElementById(index);
511     var field_id;
512     if (index.match("tag")) {
513         field_id = index.substr(0, 7);
514     } else {
515         field_id = index.substr(0, 12);
516     }
517     if (1 == fields_in_use[field_id]) {
518         // clear inputs, but don't delete
519         $(":input.input_marceditor", original).each(function(){
520             // thanks to http://www.learningjquery.com/2007/08/clearing-form-data for
521             // hint about clearing selects correctly
522             var type = this.type;
523             var tag = this.tagName.toLowerCase();
524             if (type == 'text' || type == 'password' || tag == 'textarea') {
525                 this.value = "";
526             } else if (type == 'checkbox' || type == 'radio') {
527                 this.checked = false;
528             } else if (tag == 'select') {
529                 this.selectedIndex = -1;
530             }
531         });
532         $(":input.indicator", original).val("");
533     } else {
534         original.parentNode.removeChild(original);
535         fields_in_use[field_id]--;
536     }
537 }
538
539 /**
540  * This function create a random number
541  */
542 function CreateKey(){
543     return parseInt(Math.random() * 100000);
544 }
545
546 /**
547  * This function allows to move a subfield up by clickink on the 'up' button .
548  */
549 function upSubfield(index) {
550     try{
551         var line = document.getElementById(index); // get the line where the user has clicked.
552     } catch(e) {
553         return; // this line doesn't exist...
554     }
555     var tag = line.parentNode; // get the dad of this line. (should be "<div id='tag_...'>")
556     
557     // getting all subfields for this tag
558     var subfields = tag.getElementsByTagName('div');
559     var subfieldsLength = subfields.length;
560     
561     if(subfieldsLength<=1) return; // nothing to do if there is just one subfield.
562     
563     // among all subfields 
564     for(var i=0;i<subfieldsLength;i++){ 
565         if(subfields[i].getAttribute('id') == index){ //looking for the subfield which is clicked :
566             if(i==1){ // if the clicked subfield is on the top
567                 tag.appendChild(subfields[1]);
568                 return;
569             } else {
570                 var lineAbove = subfields[i-1];
571                 tag.insertBefore(line,lineAbove);
572                 return;
573             }
574         }
575     }
576 }
577
578 function unHideSubfield(index,labelindex) { // FIXME :: is it used ?
579     subfield = document.getElementById(index);
580     subfield.style.display = 'block';
581     label = document.getElementById(labelindex);
582     label.style.display='none'; 
583 }
584 //]]>
585 </script>
586 <link type="text/css" rel="stylesheet" href="<!-- TMPL_VAR NAME="themelang" -->/css/addbiblio.css" />
587 </head>
588 <body>
589 <div id="yui-cms-loading">
590       <div id="yui-cms-float">
591           Loading, please wait...
592       </div>
593   </div>
594 <script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/yui/plugins/loading-min.js"></script>
595 <script type="text/javascript">
596 //<![CDATA[
597 (function() {
598         // configuring the loading mask
599         YAHOO.widget.Loading.config({
600                 opacity: 0.8
601         });
602 })();
603 //]]>
604 </script>
605 <!-- TMPL_INCLUDE NAME="header.inc" -->
606 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/cataloguing/addbooks.pl">Cataloging</a>  &rsaquo; <!-- TMPL_IF NAME="biblionumber" -->Editing <em><!-- TMPL_VAR NAME="title" escape="html" --></em> (Record Number <!-- TMPL_VAR name="biblionumber" -->)<!-- TMPL_ELSE -->Add MARC Record<!-- /TMPL_IF --></div>
607
608 <div id="doc" class="yui-t7">
609
610 <div id="bd">
611         <div id="yui-main">
612         <div class="yui-g">
613
614
615
616 <h1><!-- TMPL_IF NAME="biblionumber" -->Editing <em><!-- TMPL_VAR NAME="title" escape="html" --></em> (Record Number <!-- TMPL_VAR name="biblionumber" -->)</h1><!-- TMPL_ELSE -->Add MARC Record</h1><!-- /TMPL_IF -->
617
618 <!-- TMPL_UNLESS name="number" -->
619     <!-- show duplicate warning on tab 0 only -->
620         <!-- TMPL_IF name="duplicatebiblionumber" -->
621                     <div class="dialog alert">
622                         <h4>Duplicate Record suspected</h4>
623                         <p>Is this a duplicate of <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!-- TMPL_VAR name="duplicatebiblionumber" -->" onclick="openWindow('../MARCdetail.pl?biblionumber=<!-- TMPL_VAR name="duplicatebiblionumber" -->&amp;popup=1', 'Duplicate biblio'; return false;)"><!-- TMPL_VAR name="duplicatetitle" --></a>?</p>
624                         <form action="/cgi-bin/koha/cataloguing/additem.pl" method="get">
625                             <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR name="duplicatebiblionumber" -->" />
626                             <input type="submit" class="edit" value="Yes: Edit existing items" />
627                         </form>
628                         <form action="/cgi-bin/koha/cataloguing/addbiblio.pl" method="get">
629                             <input type="submit" class="save" onclick="confirmnotdup(); return false;" value="No: Save as New Record" />
630                         </form>
631                     </div>
632         <!-- /TMPL_IF -->
633     <!-- /TMPL_UNLESS -->
634
635 <!--TMPL_IF Name="done"-->
636     <script type="text/javascript">
637         opener.document.forms['f'].biblionumber.value=<!--TMPL_VAR Name="biblionumber"-->;
638         opener.document.forms['f'].title.value='<!--TMPL_VAR Name="title" ESCAPE="HTML"-->';
639         window.close();
640     </script>
641 <!--TMPL_ELSE-->
642     <form method="post" name="f" id="f" action="/cgi-bin/koha/cataloguing/addbiblio.pl" onsubmit="return Check();">
643     <input type="hidden" value="" id="redirect" name="redirect" />
644         <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
645 <!-- /TMPL_IF -->
646         
647 <div id="toolbar">
648
649 <script type="text/javascript">
650         //<![CDATA[
651
652         // prepare DOM for YUI Toolbar
653
654          $(document).ready(function() {
655                 $("#z3950searchc").empty();
656         $("#savebutton").empty();
657             yuiToolbar();
658          });
659
660     var onOption = function () {
661         return Check();
662     }
663
664     function redirect(dest){
665         $("#redirect").attr("value",dest);
666         return Check();
667     }
668
669     var savemenu = [
670         { text: _("Save and view record"), value: 1, onclick: {fn:function(){redirect("view");}} },
671         { text: _("Save and edit items"), value: 2, onclick: {fn:function(){redirect("items");}} }
672     ];
673
674
675         // YUI Toolbar Functions
676
677         function yuiToolbar() {
678             // new YAHOO.widget.Button("addbiblio");
679
680         var savesplitmenu = new YAHOO.widget.Button({
681             type: "split",
682             label: _("Save"),
683             id: "addbiblio",
684             name: "savemenubutton",
685             menu: savemenu,
686             container: "savebutton"
687          });
688
689         savesplitmenu.on("click", onOption); 
690
691                 new YAHOO.widget.Button({
692             id: "z3950search",
693             type: "button",
694             label: _("Z39.50 Search"),
695             container: "z3950searchc",
696                         onclick: {fn:function(){PopupZ3950()}}
697         });
698         }
699
700         //]]>
701         </script>
702
703                 <ul class="toolbar">
704                         <li id="savebutton"><input id="addbiblio" type="submit" value="Save" /></li>
705                         <li id="z3950searchc"><input type="button" id="z3950search" value="Z39.50 Search" onclick="PopupZ3950(); return false;" /></li>
706                         <li id="changeframework"><label for="Frameworks">Change framework: </label>
707                         <select name="Frameworks" id="Frameworks" onchange="Changefwk(this);">
708                                         <option value="">Default</option>                
709                                                         <!-- TMPL_LOOP NAME="frameworkcodeloop" -->                                             
710                                 <option value="<!-- TMPL_VAR NAME="value"-->" <!-- TMPL_VAR NAME="selected" -->>
711                                                      <!-- TMPL_VAR NAME="frameworktext" -->                                      
712                                  </option>                          
713                                                 <!-- /TMPL_LOOP -->
714                         </select> 
715 <input type="hidden" name="op" value="addbiblio" /></li>
716                 </ul>
717 </div>
718
719 <!--TMPL_IF Name="popup"-->
720         <input type="hidden" name="mode" value="popup" />
721 <!--/TMPL_IF-->
722         <input type="hidden" name="frameworkcode" value="<!-- TMPL_VAR NAME="frameworkcode" -->" />
723         <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR NAME="biblionumber" -->" />
724         <input type="hidden" name="breedingid" value="<!-- TMPL_VAR NAME="breedingid" -->" />
725
726 <div id="addbibliotabs" class="toptabs numbered">
727         <ul><!-- TMPL_LOOP name="BIG_LOOP" -->
728           <li>  <!-- TMPL_IF name="number" -->
729                 <a href="/cgi-bin/koha/cataloguing/addbiblio.pl#tab<!-- TMPL_VAR name="number" -->XX"><!-- TMPL_VAR name="number"--></a>
730             <!-- TMPL_ELSE -->
731                 <a href="/cgi-bin/koha/cataloguing/addbiblio.pl#tab<!-- TMPL_VAR name="number" -->XX"><!-- TMPL_VAR name="number"--></a>
732             <!-- /TMPL_IF --></li>
733         <!--  /TMPL_LOOP --></ul>
734
735 <!-- TMPL_LOOP name="BIG_LOOP" -->
736 <!-- hide every tab except the 1st -->
737 <!-- TMPL_IF name="number" -->
738     <div id="tab<!-- TMPL_VAR name="number" -->XX">
739 <!-- TMPL_ELSE -->
740     <div id="tab<!-- TMPL_VAR name="number" -->XX">
741 <!-- /TMPL_IF -->
742
743     
744     <!-- TMPL_LOOP NAME="innerloop" -->
745         <!-- TMPL_IF NAME="tag" -->
746         <div class="tag" id="tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->">
747         <div class="tag_title" id="div_indicator_tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->">
748             <!-- TMPL_UNLESS name="hide_marc" -->
749                 <!-- TMPL_IF NAME="advancedMARCEditor" -->
750                 <a href="#" tabindex="1" class="tagnum" title="<!-- TMPL_VAR NAME="tag_lib"--> - Click to Expand this Tag" onclick="ExpandField('tag_<!-- TMPL_VAR NAME="tag"-->_<!-- TMPL_VAR NAME='index' --><!-- TMPL_VAR NAME="random" -->'); return false;"><!-- TMPL_VAR NAME="tag" --></a>
751                 <!-- TMPL_ELSE -->
752                         <span class="tagnum" title="<!-- TMPL_VAR NAME="tag_lib" -->"><!-- TMPL_VAR NAME="tag" --></span>
753                 <!-- /TMPL_IF -->
754                 <!-- TMPL_IF NAME="fixedfield" -->
755                         <input tabindex="1" class="indicator flat" type="text" style="display:none;" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator1" -->" />
756                         <input tabindex="1" class="indicator flat" type="text" style="display:none;" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator2" -->" />
757                 <!-- TMPL_ELSE -->
758                         <input tabindex="1" class="indicator flat" type="text" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator1" -->" />
759                         <input tabindex="1" class="indicator flat" type="text" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator2" -->" />
760                 <!-- /TMPL_IF --> -
761             <!-- TMPL_ELSE -->
762                 <!-- TMPL_IF NAME="fixedfield" -->
763                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator1" -->" />
764                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator2" -->" />
765                 <!-- TMPL_ELSE -->
766                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator1" -->" />
767                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator2" -->" />
768                 <!-- /TMPL_IF -->
769             <!-- /TMPL_UNLESS -->
770
771             <!-- TMPL_UNLESS NAME="advancedMARCEditor" -->
772                     <a href="#" tabindex="1" class="expandfield" onclick="ExpandField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Click to Expand this Tag"><!-- TMPL_VAR NAME="tag_lib" --></a>
773             <!-- /TMPL_UNLESS -->
774             <!-- TMPL_IF name="repeatable" -->
775                 <a href="#" tabindex="1" class="buttonPlus" onclick="CloneField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Repeat this Tag">+</a>
776                 <a href="#" tabindex="1" class="buttonMinus" onclick="UnCloneField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Delete this Tag">&#8722;</a>
777             <!-- /TMPL_IF -->
778             
779         </div>
780         
781         <!-- TMPL_LOOP NAME="subfield_loop" -->
782             <!--  One line on the marc editor -->
783             <div class="subfield_line" style="<!-- TMPL_VAR NAME='visibility' -->; float: left; clear: left; width: 100%;" id="subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->">
784             
785                 <!--TMPL_UNLESS NAME="advancedMARCEditor" -->
786                     <label for="tag_<!-- TMPL_VAR NAME='tag'-->_subfield_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->" <!-- TMPL_IF NAME="fixedfield" --> style="display:none;" <!-- /TMPL_IF --> class="labelsubfield">
787                 <!-- /TMPL_UNLESS --> 
788                 
789                 <!-- TMPL_UNLESS name="hide_marc" -->
790                 <span class="subfieldcode"><!-- TMPL_IF NAME="fixedfield" --> 
791                         <img class="buttonUp" style="display:none;" src="<!-- TMPL_VAR NAME="themelang" -->/../img/up.png" onclick="upSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->')" alt="Move Up" title="Move Up" />
792                     <!-- TMPL_ELSE -->
793                         <img class="buttonUp" src="<!-- TMPL_VAR NAME="themelang" -->/../img/up.png" onclick="upSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->')" alt="Move Up" title="Move Up" />
794                     <!-- /TMPL_IF -->
795                         <input title="<!-- TMPL_VAR NAME='marc_lib_plain' -->" style=" <!-- TMPL_IF NAME="fixedfield" -->display:none; <!-- /TMPL_IF -->border:0;" type="text" tabindex="0" name="tag_<!-- TMPL_VAR NAME='tag'-->_code_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->" value="<!-- TMPL_VAR NAME="subfield" -->" size="1" maxlength="1" class="flat" />
796  </span>
797                 <!-- TMPL_ELSE -->
798                     <input type="hidden" name="tag_<!-- TMPL_VAR NAME='tag'-->_code_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->" value="<!-- TMPL_VAR NAME="subfield" -->" />
799  </span>
800                 <!-- /TMPL_UNLESS -->
801             
802                 <!-- TMPL_UNLESS NAME="advancedMARCEditor" -->
803                     <!-- TMPL_IF name="mandatory" --><span class="subfield subfield_mandatory"><!-- TMPL_ELSE --><span class="subfield"><!-- /TMPL_IF -->
804                         <!-- TMPL_VAR NAME="marc_lib_plain" -->
805                         <!-- TMPL_IF NAME="mandatory" --><span class="mandatory_marker" title="This field is mandatory">*</span><!-- /TMPL_IF -->
806                     </span>
807                     </label>
808                 <!-- /TMPL_UNLESS -->
809                 
810                 <!-- TMPL_VAR NAME="marc_value" -->
811                 
812                 <!-- TMPL_IF NAME="repeatable" -->
813                     <span class="buttonPlus" onclick="CloneSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->')">+</span>
814                     <span class="buttonMinus" onclick="UnCloneField('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->')">&#8722;</span>
815                 <!-- /TMPL_IF -->
816
817                 
818             </div>
819             <!-- End of the line -->
820             
821         <!-- /TMPL_LOOP -->
822         </div>
823         <!-- /TMPL_IF --><!-- tag -->
824     <!-- /TMPL_LOOP -->
825     </div>
826 <!-- /TMPL_LOOP -->
827 </div>
828 </form>
829
830 </div>
831 </div>
832 </div>
833
834 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->