bug 2530 : create new date object in javascript function instead of modifying passed...
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / serials / subscription-add.tmpl
1 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2 <title>Koha &rsaquo; Serials &rsaquo; <!-- TMPL_IF name="mod" --> Modify subscription to <!-- TMPL_VAR name="bibliotitle" --><!-- TMPL_ELSE -->New subscription<!-- /TMPL_IF --></title>
3 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4 <!-- TMPL_INCLUDE NAME="calendar.inc" -->
5
6 <script type="text/javascript">
7 <!--
8
9 // the english words used in display purposes
10 var text = new Array(_("Number"),_("Volume"),_("Issue"),_("Month"),_("Week"),_("Starting with:"),_("Rollover at:"),_("Choose Hemisphere:"),_("Northern"),_("Southern"),
11 _("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
12 var weekno_label = _("Week # ");
13 var is_season = 0;
14 var is_hemisphere = 1;
15 var irregular_issues;   // will hold irregularity object.
16
17 function formatDate(myDate) {
18     var d = new Array( myDate.getFullYear(), myDate.getMonth() + 1 ,myDate.getDate());
19     if(d[1].toString().length == 1) { d[1] = '0'+d[1] };
20     if(d[2].toString().length == 1) { d[2] = '0'+d[2] };
21     <!-- TMPL_IF NAME="dateformat_us" -->
22         return(d[1] + '/' + d[2] + '/' + d[0]) ;
23     <!-- TMPL_ELSIF NAME="dateformat_metric" -->
24         return(d[2] + '/' + d[1] + '/' + d[0]) ;
25     <!-- TMPL_ELSE -->
26         return(''+d[0] + '-' + d[1] + '-' + d[2]) ;
27     <!-- /TMPL_IF -->    
28 }
29
30 Date.prototype.addDays = function(days) {
31     this.setDate(this.getDate()+days);
32 }
33
34 function getWeeksArray(startDate,periodicity) {
35 // returns an array of syspref-formatted dates starting at the first day of startDate's year.
36 // This prediction method will not accurately predict irregularites beyond the first year.
37 // FIXME : Should replace with ajax query to get the first Monday of the year so that week numbers have correct dates.
38     var incr=1;
39     if(periodicity==3) {  // 1/2 wks
40         incr=2;
41     } else if(periodicity == 4) { // 1/3 wks
42         incr=3;
43     }
44     var weeksArray = new Array;
45     var jan01 = new Date();
46     jan01.setDate(1);
47     jan01.setMonth(0);
48     jan01.setFullYear(startDate.getFullYear());
49     for(var i=0;i<52;i++) {
50         weeksArray[i] = formatDate(jan01) + ' ' + weekno_label + (i + 1);
51         jan01.addDays( 7 ); 
52     }
53     return weeksArray;
54 }
55
56 function YMDaToYWDa(S) {
57     with (new Date(Date.UTC(S[0], S[1] - 1, S[2]))) {
58         var DoW = getUTCDay();
59         setUTCDate(getUTCDate() - (DoW + 6) % 7 + 3);
60         var ms = valueOf();
61         setUTCMonth(0, 4);
62         var WN = Math.round((ms - valueOf()) / 604800000) + 1;
63         return [getUTCFullYear(), WN, DoW == 0 ? 7 : DoW];
64     }
65 }
66 function dayofyear(d) { // d is a Date object
67 var yn = d.getFullYear();
68 var mn = d.getMonth();
69 var dn = d.getDate();
70 var d1 = new Date(yn,0,1,12,0,0); // noon on Jan. 1
71 var d2 = new Date(yn,mn,dn,12,0,0); // noon on input date
72 var ddiff = Math.round((d2-d1)/864e5);
73 return ddiff+1;
74 }
75
76
77 // create irregularity object.
78 function IrregularPattern() {
79         this.months = new Array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
80         this.seasons = new Array(_("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"));
81     this.daynames = new Array(_("Monday"),_("Tuesday"),_("Wednesday"),_("Thursday"),_("Friday"),_("Saturday"),_("Sunday"));
82     // create weeks irregularity selection array:
83     this.firstissue = new Date();
84     this.firstissue.setDate(1);
85     this.firstissue.setMonth(0);
86     <!-- TMPL_IF NAME='firstacquiyear' --> // it's a mod, we already have a start date.
87         this.firstissue.setFullYear( <!-- TMPL_VAR NAME="firstacquiyear" --> );
88     <!-- /TMPL_IF -->
89         this.weeks = getWeeksArray(this.firstissue); 
90
91     this.numskipped = 0;
92     // init:
93         var irregular = '<!-- TMPL_VAR NAME="irregularity" -->';
94     this.skipped = irregular.split(',');
95 }
96
97 IrregularPattern.prototype.update = function() {
98                 this.skipped= new Array;
99                 var cnt = 0;
100                 // daily periodicity, we interpret irregular array as which days of week to skip.
101                 // else if weekly periodicity, week numbers (starting from 01 Jan) to skip.
102         // else  irregular array is list of issues to skip
103                 var summary_str = '';
104                 this.numskipped = 0;
105         if(document.f.irregularity_select) {
106             for( var i in document.f.irregularity_select.options ) {
107                 if( document.f.irregularity_select.options[i].selected ) {
108                     this.skipped[cnt] = document.f.irregularity_select.options[i].value ;
109                     summary_str += document.f.irregularity_select.options[i].text + "\n" ;
110                                     cnt++;
111                                     this.numskipped++;
112                             }
113                     }
114                     var summary = document.getElementById("irregularity_summary");
115                     if(summary) {
116                             summary.value = summary_str;
117                             summary.rows= ( cnt > 6 ) ? cnt : 6 ; // textarea will bre resized, but not more than 6 lines will show.
118                     }
119         }
120 }
121
122 IrregularPattern.prototype.irregular = function(index) { 
123         for( var i in this.skipped) {
124                         if( this.skipped[i] == index) {
125                                 return true;
126                         }
127         }
128         return false;
129 }
130
131 function init_pattern() {
132         irregular_issues = new IrregularPattern();
133 }
134 function reset_pattern() {
135         document.getElementById("numberpattern").value = '';
136     document.getElementById("irregularity").innerHTML = '';
137         init_pattern();
138         reset_num_pattern();
139
140 }
141 // common pre defined number patterns
142 function reset_num_pattern() {
143 var patternchoice = document.getElementById("numberpattern").value;
144     switch(patternchoice){
145     case "2":
146         document.f.add1.value=1;
147         document.f.add2.value=1;
148         document.f.add3.value=1;
149         document.f.every1.value=12;
150         document.f.every2.value=1;
151         document.f.every3.value=1;
152         document.f.whenmorethan1.value=9999999;
153         document.f.whenmorethan2.value=12;
154         document.f.whenmorethan3.value=4;
155         document.f.setto1.value=0;
156         document.f.setto2.value=1;
157         document.f.setto3.value=1;
158         document.f.lastvalue1.value=1;
159         document.f.lastvalue2.value=1;
160         document.f.lastvalue3.value=1;
161         document.f.numberingmethod.value=_("Vol {X}, No {Y}, Issue {Z}");
162         moreoptions(text[1],text[0],text[2]);
163         display_table(0); // toggle info box on (1) or off (0)
164         break;
165     case "3":
166         document.f.add1.value=1;
167         document.f.add2.value=1;
168         document.f.add3.value='';
169         document.f.every1.value=12;
170         document.f.every2.value=1;
171         document.f.every3.value='';
172         document.f.whenmorethan1.value=9999999;
173         document.f.whenmorethan2.value=12;
174         document.f.whenmorethan3.value='';
175         document.f.setto1.value=0;
176         document.f.setto2.value=1;
177         document.f.setto3.value='';
178         document.f.lastvalue1.value=1;
179         document.f.lastvalue2.value=1;
180         document.f.lastvalue3.value='';
181         document.f.numberingmethod.value=_("Vol {X}, No {Y}");
182         moreoptions(text[1],text[0]);
183         display_table(0);
184         break;
185     case "4":
186         document.f.add1.value=1;
187         document.f.add2.value=1;
188         document.f.add3.value='';
189         document.f.every1.value=12;
190         document.f.every2.value=1;
191         document.f.every3.value='';
192         document.f.whenmorethan1.value=9999999;
193         document.f.whenmorethan2.value=12;
194         document.f.whenmorethan3.value='';
195         document.f.setto1.value=0;
196         document.f.setto2.value=1;
197         document.f.setto3.value='';
198         document.f.lastvalue1.value=1;
199         document.f.lastvalue2.value=1;
200         document.f.lastvalue3.value='';
201         document.f.numberingmethod.value=_("Vol {X}, Issue {Y}");
202         moreoptions(text[1],text[2]);
203         display_table(0);
204         break;
205     case "5":
206 //        var d = new Date(document.f.firstacquidate.value);
207 //        var smonth = d.getMonth();
208         document.f.add1.value=1;
209         document.f.add2.value=1;
210         document.f.add3.value='';
211         document.f.every1.value=12;
212         document.f.every2.value=1;
213         document.f.every3.value='';
214         document.f.whenmorethan1.value=9999999;
215         document.f.whenmorethan2.value=12;
216         document.f.whenmorethan3.value='';
217         document.f.setto1.value=0;
218         document.f.setto2.value=1;
219         document.f.setto3.value='';
220         document.f.numberingmethod.value=_("No {X}, Issue {Y}");
221         moreoptions(text[0],text[2]);
222         display_table(0);
223         break;
224     case "6":
225         var d = new Date(document.f.firstacquidate.value);
226         var sYear = d.getFullYear();
227         moreoptions_seasons(text[15],sYear);
228         var d = new Date(document.f.firstacquidate.value);
229         var sYear = d.getFullYear();
230         document.f.add1.value=1;
231         document.f.add2.value='1';
232         document.f.add3.value='';
233         document.f.every1.value=4;
234         document.f.every2.value='1';
235         document.f.every3.value='';
236         document.f.whenmorethan1.value=9999999;
237         document.f.whenmorethan2.value='4';
238         document.f.whenmorethan3.value='';
239         document.f.setto1.value=0;
240         document.f.setto2.value='1';
241         document.f.setto3.value='';
242         document.f.periodicity.value='8';
243         document.f.numberingmethod.value=_("{Y} {X}");
244         moreoptions_seasons(text[15],sYear);
245         document.f.lastvalue1temp.value=document.f.lastvalue1.value=sYear;
246         display_table(0);
247         is_season = 1;
248         break;
249     case "7":
250         display_table(1);
251         document.getElementById("more_options").innerHTML = '';
252         document.f.irreg_check.value=1; 
253         break;
254     case "8":  // Year/Number
255         var d = (document.f.firstacquidate.value) ? new Date( document.f.firstacquidate.value) : new Date() ;
256         var sYear = d.getFullYear();
257         document.f.add1.value=1;
258         document.f.add2.value=1;
259         document.f.add3.value='';
260         document.f.every1.value=12;
261         document.f.every2.value=1;
262         document.f.every3.value='';
263         document.f.whenmorethan1.value=9999999;
264         document.f.whenmorethan2.value=12;
265         document.f.whenmorethan3.value='';
266         document.f.setto1.value=0;
267         document.f.setto2.value=1;
268         document.f.setto3.value='';
269         document.f.lastvalue1.value=sYear;
270           switch (document.f.periodicity.value){
271             case 1:              
272               var doy = dayofyear(d);
273               document.f.lastvalue2.value=doy; 
274               document.f.whenmorethan2.value=365; 
275               break;      
276             case 12:     
277               var doy = dayofyear(d);
278               document.f.lastvalue2.value=doy*2; 
279               document.f.whenmorethan2.value=730; 
280               break;      
281             case 2:
282             case 3:
283             case 4:
284               var YWDa = YMDaToYWDa(d);
285               document.f.lastvalue2.value=YWDA[1]/(document.f.periodicity.value-1); 
286               break;      
287             case 5:
288               var smonth = d.getMonth();
289               document.f.lastvalue2.value=smonth;
290               break;      
291             case 6:
292               var smonth = d.getMonth();
293               document.f.lastvalue2.value=smonth/2;
294               document.f.whenmorethan2.value=6;
295               break;      
296             case 7:
297             case 8:      
298               var smonth = d.getMonth();
299               document.f.lastvalue2.value=smonth/3;
300               document.f.whenmorethan2.value=4;
301               break;      
302             case 9:                        
303               var smonth = d.getMonth();
304               document.f.lastvalue2.value=smonth/6;
305               document.f.whenmorethan2.value=2;
306               break;      
307             default:
308           } 
309         document.f.lastvalue3.value='';
310         document.f.numberingmethod.value=_("{X} / {Y}");
311         moreoptions(text[16],text[0]);
312      //   document.f.lastvalue1temp.value=sYear;
313      //   document.f.lastvalue2temp.value=document.f.lastvalue2.value;
314         display_table(0);
315         break;
316     default:
317         document.f.add1.value=1;
318         document.f.add2.value='';
319         document.f.add3.value='';
320         document.f.every1.value=1;
321         document.f.every2.value='';
322         document.f.every3.value='';
323         document.f.whenmorethan1.value=9999999;
324         document.f.whenmorethan2.value='';
325         document.f.whenmorethan3.value='';
326         document.f.setto1.value=0;
327         document.f.setto2.value='';
328         document.f.setto3.value='';
329         document.f.lastvalue1.value=1;
330         document.f.lastvalue2.value='';
331         document.f.lastvalue3.value='';
332         document.f.numberingmethod.value='{X}';
333 //        moreoptions_daily_check(text[0]);
334         moreoptions(text[0]);
335         document.f.irreg_check.value=1;
336         display_table(0);
337         break;
338     }
339 }
340
341 function display_table(n) {
342     if(n==1){
343         document.getElementById("basetable").style.display = 'block';
344     } else if(n==0){
345         document.getElementById("basetable").style.display = 'none';
346     } else {
347                 var disp_val = ( document.getElementById("basetable").style.display == 'none' ) ? 'block' : 'none' ;
348                         document.getElementById("basetable").style.display = disp_val;
349         }
350 }
351
352 function set_num_pattern_from_template_vars() {
353         if(!document.getElementById("numberpattern")){ return false; }
354     document.getElementById("numberpattern").value = '<!-- TMPL_VAR NAME="numberpattern" -->';
355     reset_num_pattern();
356     
357     document.f.add1.value='<!-- TMPL_VAR NAME="add1" -->';
358     document.f.add2.value='<!-- TMPL_VAR NAME="add2" -->';
359     document.f.add3.value='<!-- TMPL_VAR NAME="add3" -->';
360     document.f.every1.value='<!-- TMPL_VAR NAME="every1" -->';
361     document.f.every2.value='<!-- TMPL_VAR NAME="every2" -->';
362     document.f.every3.value='<!-- TMPL_VAR NAME="every3" -->';
363     document.f.whenmorethan1.value='<!-- TMPL_VAR NAME="whenmorethan1" -->';
364     document.f.whenmorethan2.value='<!-- TMPL_VAR NAME="whenmorethan2" -->';
365     document.f.whenmorethan3.value='<!-- TMPL_VAR NAME="whenmorethan3" -->';
366     document.f.setto1.value='<!-- TMPL_VAR NAME="setto1" -->';
367     document.f.setto2.value='<!-- TMPL_VAR NAME="setto2" -->';
368     document.f.setto3.value='<!-- TMPL_VAR NAME="setto3" -->';
369     document.f.lastvalue1.value='<!-- TMPL_VAR NAME="lastvalue1" -->';
370     document.f.lastvalue2.value='<!-- TMPL_VAR NAME="lastvalue2" -->';
371     document.f.lastvalue3.value='<!-- TMPL_VAR NAME="lastvalue3" -->';
372     document.f.numberingmethod.value='<!-- TMPL_VAR NAME="numberingmethod" -->';
373
374     var more_strY;
375     var more_strZ;
376     <!-- TMPL_IF NAME="add2" -->
377     if(<!-- TMPL_VAR NAME="add2" --> > 0){
378         more_strY="Y";
379     }
380     <!-- /TMPL_IF -->
381     <!-- TMPL_IF NAME="add3" -->
382     if(<!-- TMPL_VAR NAME="add3" --> > 0){
383         more_strZ="Z";
384     }
385     <!-- /TMPL_IF -->
386     document.f.lastvalue1temp.value='<!-- TMPL_VAR NAME="lastvalue1" -->';
387     if(more_strY){
388         document.f.lastvalue2temp.value='<!-- TMPL_VAR NAME="lastvalue2" -->';
389     document.f.whenmorethan2temp.value='<!-- TMPL_VAR NAME="whenmorethan2" -->';
390     }
391     if(more_strZ){
392         document.f.lastvalue3temp.value='<!-- TMPL_VAR NAME="lastvalue3" -->';
393     document.f.whenmorethan3temp.value='<!-- TMPL_VAR NAME="whenmorethan3" -->';
394     }
395 }
396
397 // a pre check with more options to see if 'number' and '1/day' are chosen
398 <!-- 
399 function moreoptions_daily_check(x) {
400     var periodicity = document.f.periodicity.value;
401     var errortext='';
402     if(periodicity == 1){ // i.e. daily
403         document.getElementById("irregularity").innerHTML = '';
404         errortext =_("Please indicate which days of the week you <b>DO NOT<\/b> expect to receive issues.<br \/>");
405         for(var j=0;j<irregular_issues.daynames.length;j++){
406             errortext +="<input type='checkbox' name='irregular' id='irregular"+(j+1)+"' value='"+(j+1)+"' />"+irregular_issues.daynames[j]+" &nbsp; ";
407         }
408         var error = errortext;
409         moreoptions(x);
410         document.getElementById("irregularity").innerHTML = error;
411     } else {
412         document.getElementById("irregularity").innerHTML = '';
413         document.getElementById("more_options").innerHTML = '';
414         moreoptions(x);
415     }
416 }
417 -->
418
419
420 // to dispaly the more options section
421 function moreoptions(x,y,z){
422 document.getElementById("irregularity").innerHTML = '';
423 document.getElementById("more_options").innerHTML = '';
424 var textbox = '';
425     // alert("X: "+x+"Y: "+y+"Z: "+z);
426     if(x){
427         textbox +="<table id='irregularity_table'>\n<tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
428         if(y){
429             textbox +="<th>"+y+"<\/th>";
430             if(z){
431                 textbox +="<th>"+z+"<\/th>";
432             }
433         }
434         textbox +="<\/tr>\n";
435         textbox +="<tr><th scope=\"row\">"+text[5]+"<\/td><td><input type='text' name='lastvalue1temp' id='lastvalue1temp' size='4' onkeyup='moreoptionsupdate(this)' value=\"" + document.f.lastvalue1.value +  "\" /><\/td>\n";
436         if(y){
437             textbox +="<td><input type='text' name='lastvalue2temp' id='lastvalue2temp' size='4' onkeyup='moreoptionsupdate(this)' value=\"" + document.f.lastvalue2.value + "\" /><\/td>\n";
438             if(z){
439                 textbox +="<td><input type='text' name='lastvalue3temp' id='lastvalue3temp' size='4' onkeyup='moreoptionsupdate(this)' value=\"" + document.f.lastvalue3.value + "\" /><\/td>\n";
440             }
441         }
442         textbox +="<\/tr>\n";
443         if(y){
444             textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
445             textbox +="<td>&nbsp;<\/td>\n";
446             textbox +="<td><input type='text' name='whenmorethan2temp' id='whenmorethan2temp' size='4' onkeyup='moreoptionsupdate(this,1)'><\/td>\n";
447             if(z){
448                 textbox +="<td><input type='text' name='whenmorethan3temp' id='whenmorethan3temp' size='4' onkeyup='moreoptionsupdate(this,1)'><\/td>\n";
449             }
450             textbox +="<\/tr>";
451         } else {
452           textbox +="<tr> <td>"+_("issues expected")+"</td><td><input type='text' name='issuesexpected1temp' id='issuesexpected1temp' size='4' onkeyup='moreoptionsupdate(this,0)' value=\"" + document.f.issuesexpected1.value + "\" ></td></tr>";
453         }
454         textbox +="<\/table>\n";
455     }
456     document.getElementById("more_options").innerHTML = textbox;
457 }
458
459 function hemispheres(chosen){
460 var selbox = document.getElementById("season1");
461     if(selbox){
462     var selboxselected = selbox.options[selbox.selectedIndex].value;
463     selbox.options.length = 0;
464
465     if ( (chosen == "1") || ( ! (chosen) && is_hemisphere == 1 )) {
466         selbox.options[selbox.options.length] = new Option(text[11],'1');
467         selbox.options[selbox.options.length] = new Option(text[12],'2');
468         selbox.options[selbox.options.length] = new Option(text[13],'3');
469         selbox.options[selbox.options.length] = new Option(text[14],'4');
470         is_hemisphere = 1;
471         selbox.options[selboxselected-1].selected = true;
472     }
473
474     if ( (chosen == "2") || ( ! (chosen) && is_hemisphere == 2 )) {
475         selbox.options[selbox.options.length] = new Option(text[13],'1');
476         selbox.options[selbox.options.length] = new Option(text[10],'2');
477         selbox.options[selbox.options.length] = new Option(text[11],'3');
478         selbox.options[selbox.options.length] = new Option(text[12],'4');
479         is_hemisphere = 2;
480         selbox.options[selboxselected-1].selected = true;
481     }
482     }
483 }
484
485 // to display the more options section for seasons
486 function moreoptions_seasons(x,y){
487 // x = 'Season'.  y = 'Year'.
488 document.getElementById("irregularity").innerHTML = '';
489 document.getElementById("more_options").innerHTML = '';
490 var textbox = '';
491     //alert("X: "+x+"Year: "+y);
492     if(x){
493         var hemi_select = parseInt('<!-- TMPL_VAR NAME="hemisphere" -->');
494         textbox +="<li><label for=\"hemisphere\">"+ text[7]  +"<\/label><select name='hemisphere' id=\"hemisphere\" onchange='hemispheres(this.options[this.selectedIndex].value)'>";
495         for(var i = 1; i <= 2; i++){
496             textbox +="<option value='"+i+"'";
497             if(i == hemi_select){
498                 textbox += " selected "
499             }
500             textbox +=">"+text[i+7]+"<\/option>";
501         }
502         textbox +="<\/li>\n";
503         textbox +="<table id='seasonal_irregularity'><tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
504         textbox +="<th>"+text[16]+"<\/th>";
505         textbox +="<\/tr>\n";
506         textbox +="<tr><th scope=\"row\">"+text[5]+"<\/th><td><select name='lastvalue2temp' id='lastvalue2temp' id='season1' onchange='moreoptionsupdate(this)'>";
507         for(var j = 1; j <= 4; j++){
508             textbox +="<option value='"+j+"'>"+text[j+9]+"<\/option>";
509         }
510         textbox +="<\/select><\/td>";
511         var isyr = irregular_issues.firstissue;
512         textbox += "<td>" + irregular_issues.firstissue.getFullYear() + "<\/td><\/tr>\n";
513         textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
514         textbox +="<td><input type='text' name='whenmorethan2temp' id='whenmorethan2temp' size='4' onkeyup='moreoptionsupdate(this,1)'><\/td>\n";
515                 textbox +="<\/tr><\/table>\n";
516
517     }
518     document.getElementById("more_options").innerHTML = textbox;
519 }
520
521 function irregularity_check(){
522     document.f.irreg_check.value = 1; // Irregularity button now pushed
523     var periodicity = document.f.periodicity.value;
524         var rollover = document.f.issuesexpected1.value;
525     if( (document.f.whenmorethan2) && ( document.f.whenmorethan2.value > 0) ){
526       rollover = document.f.whenmorethan2.value;
527     }
528     if((document.f.whenmorethan3) && document.f.whenmorethan3.value > 0 ){
529         // FIXME: Irregularity check assumes that the full prediction pattern repeats each year.
530                 //  In cases where the outermost periodicity is > 1 year,  
531                 //  e.g. where a volume spans two years, the irregularity check will be incorrect, 
532         // but you can safely ignore the check, submit the form, and the prediction pattern should be correct.
533                 //  a way to distinguish between these two cases is needed.
534                 rollover = document.f.whenmorethan3.value * document.f.whenmorethan2.value;
535     }
536     var error='';
537     var toobig;
538     var expected; 
539     var errortext = _("<b>Warning irregularity detected<\/b><br \/>");
540     switch(periodicity){
541     case "12":
542         if(rollover < 730) expected =730;
543         if(rollover > 730) {
544             expectedover=730;
545             toobig=1;
546         }
547         break;
548     case "1":
549         if(rollover < 365) expected =365;
550         if(rollover > 365) {
551             expectedover=365;
552             toobig=1;
553         }
554         break;
555     case "2":
556         if(rollover < 52) expected =52;
557         if(rollover > 52){
558             expectedover=52;
559             toobig=1;
560         }
561         break;
562     case "3":
563         if(rollover < 26) expected =26;
564         if(rollover > 26){
565             expectedover=26;
566             toobig=1;
567         }
568         break;
569     case "4":
570         if(rollover < 17) expected =17;
571         if(rollover > 17){
572             expectedover=17;
573             toobig=1;
574         }
575         break;
576     case "5":
577         if(rollover < 12) expected =12;
578         if(rollover > 12){
579             expectedover=12;
580             toobig=1;
581         }
582         break;
583     case "6":
584         if(rollover < 6) expected =6;
585         if(rollover > 6){
586             expectedover=6;
587             toobig=1;
588         }
589         break;
590     case "7":
591         if(rollover < 4) expected =4;
592         if(rollover > 4){
593             expectedover=4;
594             toobig=1;
595         }
596         break;
597     case "8":
598         if(rollover < 4) expected =4;
599         if(rollover > 4){
600             expectedover=4;
601             toobig=1;
602         }
603         break;
604     case "9":
605         if(rollover < 2) expected =2;
606         if(rollover > 2){
607             expectedover=2;
608             toobig=1;
609         }
610         break;
611     case "10":
612         if(rollover < 1) expected =1;
613         if(rollover > 1){
614             expectedover=1;
615             toobig=1;
616         }
617         break;
618     default:
619         break;
620     }
621     if(expected){
622         if(expected == 365 || expected==730){  // what about leap years ?
623                         // FIXME:  We interpret irregularity as which days per week for periodicity==1.
624                         //  We need two cases: one in which we're published n days/week, in which case irregularity should be per week,
625                         //  and a regular daily pub, where irregularity should be per year.
626             errortext += _("Please indicate which days of the week you <b>DO NOT<\/b> expect to receive issues.<br \/>");
627         } else {
628             errortext +=expected+_(" issues expected, ")+rollover+_(" were entered. <br \/>Please indicate which date(s) an issue is not expected<br \/>");
629             irregular_issues.numskipped = expected - rollover;
630                 }
631         errortext +="<select multiple id='irregularity_select' name='irregularity_select' onchange='irregular_issues.update();'>\n"; 
632                 errortext +=irregular_options(periodicity);
633                 errortext += "</select>\n <textarea rows='6' width='18' id='irregularity_summary' name='irregularity_summary' value='foo' />";
634         error=errortext;
635     }
636     if(toobig){
637         errortext +=expectedover+_(" issues expected, ")+rollover+_(" were entered.<p class='warning'> You seem to have indicated more issues per year than expected.</p>");
638         error=errortext;
639     }
640     if(error.length ==0){
641         error=_("No irregularities noticed");
642     }
643         display_example(expected);
644     document.getElementById("irregularity").innerHTML = error;
645         irregular_issues.update();
646 }
647
648 function irregular_options(periodicity){
649     var titles;
650     var count;
651     var errortext='';
652     if(periodicity == 1) {
653         expected = 7;
654         titles = irregular_issues.daynames;
655         count = 1;
656     }
657     if(periodicity == 2 || periodicity == 3 || periodicity == 4) { 
658         titles = irregular_issues.weeks;
659                 count = 1;
660         if(periodicity==3) {  // 1/2 wks
661             expected = 26;
662         } else if(periodicity == 4) { // 1/3 wks
663             expected = 17;
664         } else {
665             expected = 52;
666         }
667     }
668     if(periodicity == 5 || periodicity == 6 || periodicity == 7 || periodicity == 8 || periodicity == 9) {
669         if(periodicity == 8 && numberpattern==8) {
670             is_season = 1; // setting up from edit page
671         } 
672         if(is_season){
673             titles = irregular_issues.seasons;
674             expected = 4;
675             if(is_hemisphere == 2){
676                 count = 2;
677             } else {
678                 count = 1;
679             }
680         } else {
681             titles = irregular_issues.months;
682             expected = 12;
683             count = 1;
684         }
685     }
686         if( !expected) {
687                 return '';   // don't know how to deal with irregularity.
688         }       
689     for(var j=0;j<expected;j++){   // rch - changed frrom (1..expected).
690         if(isArray(titles)){
691             if(count>expected){
692                 count = count-expected;
693             }
694             if(is_season && is_hemisphere == 1){
695                 errortext +="<option value='"+((count*3)-2)+"'>"+titles[j]+"<\/option>\n";
696 // alert("value: "+((count*3)-2)+" title: "+titles[j]);
697             } else if(is_season && is_hemisphere == 2){
698                 errortext +="<option value='"+((count*3)-2)+"'>"+titles[j-1]+"<\/option>\n";
699 // alert("value: "+((count*3)-2)+" title: "+titles[j-1]);
700             } else {  // all non-seasonal periodicities:
701                 var incr=1; // multiplier for ( 1/n weeks)  patterns; in this case the irreg calc relies on the week# , not the issue#.
702                 if(periodicity==3) {  // 1/2 wks
703                     incr=2;
704                 } else if(periodicity == 4) { // 1/3 wks
705                     incr=3;
706                 }
707                 errortext += "<option value='" + (1+j*incr) ;  
708                                 if(irregular_issues.irregular(1+incr*j)) {
709                                         errortext += "' selected='selected" ;
710                                 }
711                                 errortext += "'>"+titles[incr*j]+"<\/option>\n";
712             }
713             count++;
714         } else { 
715             errortext +="<option value='"+j+"'>"+titles+" "+j+"<\/option>\n";
716         }
717     }
718     return errortext;
719 }
720
721
722 function display_example(expected){
723     var startfrom1 = parseInt(document.f.lastvalue1.value);
724     var startfrom2 = parseInt(document.f.lastvalue2.value);
725     var startfrom3 = parseInt(document.f.lastvalue3.value);
726     var every1 = parseInt(document.f.every1.value);
727     var every2 = parseInt(document.f.every2.value);
728     var every3 = parseInt(document.f.every3.value);
729     var numberpattern = document.f.numberingmethod.value;
730     var whenmorethan2 = parseInt(document.f.whenmorethan2.value);
731     var whenmorethan3 = parseInt(document.f.whenmorethan3.value);
732     var setto2 = parseInt(document.f.setto2.value);
733     var setto3 = parseInt(document.f.setto3.value);
734     var displaytext = _("Based on the information entered, the Numbering Pattern will look like this: <br \/><ul class=\"numpattern_preview\">");
735     if(startfrom3>0){
736         var count=startfrom3-1;
737         var count2=startfrom2;
738         for(var i = 0 ; i < 12; i++){
739             if(count>=whenmorethan3){
740                 count=setto3;
741                 if(count2>=whenmorethan2){
742                     startfrom1++;
743                     count2=setto2;
744                 } else {
745                     count2++;
746                 }
747             } else {
748                 count++;
749             }
750             displaytext += '<li>' + numberpattern.replace(/{Z}/,count) + '</li>\n';
751             displaytext = displaytext.replace(/{Y}/,count2);
752             displaytext = displaytext.replace(/{X}/,startfrom1);
753
754         }
755     }
756     if(startfrom2>0 && !startfrom3){
757         var count=startfrom2-1;
758         for(var i=0;i<12;i++){
759             if(count>=whenmorethan2){
760                 startfrom1++;
761                 count=setto2;
762             } else {
763                 count++;
764             }
765
766             if(is_season){
767                 if(is_hemisphere == 2){
768                     if(count == 1) {
769                         displaytext += numberpattern.replace(/{Y}/,text[count+12])+'\n';
770                     } else {
771                         displaytext += numberpattern.replace(/{Y}/,text[count+8])+'\n';
772                     }
773                 } else {
774                 displaytext += numberpattern.replace(/{Y}/,text[count+10])+'\n';
775                 }
776             } else {
777                 displaytext += numberpattern.replace(/{Y}/,count)+'\n';
778             }
779             displaytext = displaytext.replace(/{X}/,startfrom1)+'<br \/>\n';
780         }
781     }
782     if(startfrom1>0 && !startfrom2 && !startfrom3){
783         var offset=eval(document.f.issuesexpected1.value);
784         if (!offset){
785             offset = 12 
786         }
787         for(var i=startfrom1;i<(startfrom1+offset);i+=every1){
788             displaytext += numberpattern.replace(/{X}/,i)+'<br \/>\n';
789         }
790     }
791    //  displaytext = "<div style='padding: 5px; background-color: #CCCCCC'>"+displaytext+"<\/div>";
792     document.getElementById("displayexample").innerHTML = displaytext;
793 }
794
795 function isArray(obj) {
796 if (obj.constructor.toString().indexOf("Array") == -1)
797     return false;
798 else
799     return true;
800 }
801
802 function moreoptionsupdate(inputfield,rollover){
803     fieldname = inputfield.name;
804     // find parent element in base table by stripping 'temp' from element name.
805     basefield = document.getElementById(fieldname.slice(0,-4));
806     var fieldnumber = fieldname.slice(-5,-4);
807
808 //    fieldnametemp = fieldname.slice(0,-1)+"temp"+fieldnametempnumber;
809 //    eval("document.f."+fieldname+".value = document.f."+fieldnametemp+".value");
810     basefield.value = inputfield.value;
811     var patternchoice = document.getElementById("numberpattern").value;
812     switch(patternchoice){
813     case "2":
814     case "4":
815     case "5":
816     case "8": // Year, Number.  -- Why not just use Vol, Number withvol==year??
817        if (document.f.lastvalue2temp.value>0){document.f.innerloop1.value = document.f.lastvalue2temp.value - 1;}
818       break;   
819     }  
820     if(rollover){
821 //        eval("document.f.every"+(fieldnametempnumber-1)+".value = document.f."+fieldnametemp+".value");
822        // calculate rollover  for higher level of periodicity.
823        // FIXME: This calculation only works if addN = 1 , that is, the X,Y,and Z each only increment by zero or one on each issue.
824
825        // if there are two levels of periodicity, (e.g. vol{X},num{Y},issue{Z}, then every1=every2*whenmorethan2 
826        // otherwise, every2 == 1.
827        var addN = (document.getElementById('add'+fieldnumber)) ? document.getElementById('add'+fieldnumber).value : 1 ;
828        var everyN = (document.getElementById('every'+fieldnumber)) ? document.getElementById('every'+fieldnumber).value : 1 ;
829        document.getElementById('every'+(fieldnumber-1)).value = basefield.value * everyN / addN ;
830      }
831 }
832
833
834 function check_input(e){
835     var unicode=e.charCode? e.charCode : e.keyCode
836     if (unicode!=8 && unicode !=46 && unicode!=9 && unicode !=13){ // if key isn't backspace or delete
837         if (unicode<48||unicode>57) { // if not a number
838             alert(_("Needs to be entered in digit form -eg 10"));
839             return false // disable key press
840         }
841     }
842 }
843
844 function addbiblioPopup(biblionumber) {
845         var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
846         if(biblionumber){ destination += "&biblionumber="+biblionumber; }
847  window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
848 }
849
850 function Plugin(f)
851 {
852          window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
853 }
854
855 function FindAcqui(f)
856 {
857          window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
858 }
859
860 function Find_ISSN(f)
861 {
862          window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
863 }
864
865
866 function Check(f) {
867     if (f.aqbooksellerid.value.length==0) {
868         input_box = confirm(_("If you wish to claim late or missing issues you must link this subscription to a vendor. Click OK to ignore or Cancel to return and enter a vendor"));
869                 if (input_box==true) {
870                 }
871                 else {
872                         return false;
873                 }
874     }
875         if (f.biblionumber.value.length==0) {
876         alert(_("You must choose or create a biblio"));
877     } else if(f.startdate.value.length != 0 && f.sublength.value > 0) {
878         if (f.irreg_check.value == 1) {
879             document.f.submit();
880         } else {
881             if(f.numbering_pattern.value == ''){
882                 alert(_("Please choose a numbering pattern"));
883             } else {
884                 alert(_("Please check for irregularity by clicking 'Test Prediction Pattern'"));
885             }
886         }
887     } else {
888         alert(_("You must choose a start date and a subscription length"));
889     }
890         if(irregular_issues.numskipped < irregular_issues.skipped.length ) {
891                 alert(_("You have not accounted for all missing issues."));
892         }
893     return false;
894 }
895
896 $(document).ready(function() {
897 init_pattern();
898 <!-- TMPL_IF name="mod" -->
899     set_num_pattern_from_template_vars();
900     <!-- TMPL_IF name="hemisphere" -->
901         is_hemisphere = <!-- TMPL_VAR NAME="hemisphere" --> ;
902     hemispheres();
903     <!-- /TMPL_IF -->
904 <!-- /TMPL_IF -->
905 <!-- TMPL_IF name="irregularity" -->
906     irregularity_check();
907 <!-- /TMPL_IF -->
908 $('#numberpattern').change( function() { 
909     reset_num_pattern(); 
910     });
911 });
912 -->
913 </script>
914 </head>
915 <body>
916 <!-- TMPL_INCLUDE NAME="header.inc" -->
917 <!-- TMPL_INCLUDE NAME="serials-search.inc" -->
918
919 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo; <!-- TMPL_IF name="mod" --> Modify subscription for <span class="title"><!-- TMPL_VAR name="bibliotitle" --></span><!-- TMPL_ELSE -->New subscription<!-- /TMPL_IF --></div>
920
921 <div id="doc3" class="yui-t7">
922    
923    <div id="bd">
924    <div class="yui-g">
925 <h1><!-- TMPL_IF name="mod" --> Modify subscription for <i><!-- TMPL_VAR name="bibliotitle" --></i><!-- TMPL_ELSE -->Add a new subscription<!-- /TMPL_IF --></h1>
926     <form method="post" name="f" action="/cgi-bin/koha/serials/subscription-add.pl">
927 <!-- TMPL_IF name="mod" -->
928         <input type="hidden" name="op" value="modsubscription" />
929         <input type="hidden" name="subscriptionid" value="<!-- TMPL_VAR name="subscriptionid" -->" />
930 <!-- TMPL_ELSE -->
931         <input type="hidden" name="op" value="addsubscription" />
932 <!-- /TMPL_IF -->
933 <input type="hidden" name="user" value="<!-- TMPL_VAR name="loggedinusername" -->" />
934 <input type="hidden" name="irreg_check" value="0" />
935 <input type="hidden" name="issuesexpected1" id="issuesexpected1" value="0" />
936
937         <div class="yui-u first">
938     <fieldset id="subscription_add_information" class="rows">
939         <legend>Subscription details</legend>
940         <ol>
941         <li><span class="label">Subscription #</span> <!--TMPL_VAR name="subscriptionid"--></li>
942         <li>
943             <span class="label">Librarian: </span>            <!-- TMPL_VAR name="loggedinusername" -->
944         </li>
945         <li>
946             <label for="aqbooksellerid">Vendor: </label>
947             <input type="text" name="aqbooksellerid" id="aqbooksellerid" value="<!-- TMPL_VAR name="aqbooksellerid" -->" size="8" /> (<input type="text" name="aqbooksellername" value="<!-- TMPL_VAR name="aqbooksellername" -->" disabled="disabled" readonly="readonly" />) <div class="inputnote"><a href="#" onclick="FindAcqui(f)">Search for a vendor</a></div>
948         </li>
949         <li>
950             <label for="biblionumber" class="required" title="Subscriptions must be associated with a bibliographic record">Biblio:</label>
951             
952                 <input type="text" name="biblionumber" id="biblionumber" value="<!-- TMPL_VAR name="bibnum" -->" size="8" /> 
953                 (<input type="text" name="title" value="<!-- TMPL_VAR name="bibliotitle" -->" disabled="disabled" readonly="readonly" />) <span class="required" title="Subscriptions must be associated with a bibliographic record">Required</span>
954                <div class="inputnote"> <a href="#" onclick="Plugin(f)">Search for Biblio</a> | <!--TMPL_IF Name="mod"--><a href="#" onclick="addbiblioPopup(<!-- TMPL_VAR NAME="bibnum" -->); return false;">Edit biblio</a><!-- TMPL_ELSE -->
955                 <a href="#" onclick="addbiblioPopup(); return false;">Create Biblio</a><!--/TMPL_IF--></div>
956             
957         </li>
958         <li class="radio">
959             <!-- TMPL_IF name="serialsadditems" -->
960                 <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1" checked="checked" /><label for="serialsadditems-yes">create an item record when receiving this serial</label></p>
961                 <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" /><label for="serialsadditems-no">do not create an item record when receiving this serial </label></p>
962             <!-- TMPL_ELSE -->
963                 <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1"/><label for="serialsadditems-yes">create an item record when receiving this serial</label></p>
964                 <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" checked="checked" /><label for="serialsadditems-no">do not create an item record when receiving this serial</label></p>
965             <!-- /TMPL_IF -->
966         </li>
967         <li>
968             <label for="callnumber">Call Number:</label>
969             <input type="text" name="callnumber" id="callnumber" value="<!-- TMPL_VAR name="callnumber" -->" size="20" />
970         </li>
971         <li>
972             <label for="branchcode">Library:</label>
973             
974                 <select name="branchcode" id="branchcode" style="width: 20em;">
975                     <!-- TMPL_UNLESS NAME="Independantbranches" --><option value="">None</option><!-- /TMPL_UNLESS -->
976                     <!-- TMPL_LOOP name="branchloop" --><!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="branchname" --></option>
977                                 <!-- TMPL_ELSE -->
978                                 <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option>
979                                 <!-- /TMPL_IF -->
980                     <!-- /TMPL_LOOP -->
981                 </select> (select a library)
982             
983         </li>
984         <li>
985             <label for="notes">Public note:</label>
986             <textarea name="notes" id="notes" cols="30" rows="2"><!-- TMPL_VAR name="notes" --></textarea>
987         </li>
988         <li>
989             <label for="internalnotes">Nonpublic note:</label>
990             <textarea name="internalnotes" id="internalnotes" cols="30" rows="2"><!-- TMPL_VAR name="internalnotes" --></textarea>
991         </li>
992         <li>
993             <label for="letter">Patron notification: </label>
994             
995                <!-- TMPL_IF NAME="letterloop" -->
996                            <select name="letter" id="letter">
997                     <option value="">None</option>
998                 <!-- TMPL_LOOP name="letterloop" -->
999                                 <!-- TMPL_IF name="selected" -->
1000                     <option value="<!-- TMPL_VAR name="value" -->" selected="selected"><!-- TMPL_VAR name="lettername" --></option>
1001 <!-- TMPL_ELSE -->
1002                     <option value="<!-- TMPL_VAR name="value" -->"><!-- TMPL_VAR name="lettername" --></option>
1003 <!-- /TMPL_IF -->
1004                 <!-- /TMPL_LOOP -->
1005                 </select> 
1006                                 <div class="hint">Select a notice and patrons on the routing list will be notified when new issues are received.</div>
1007                 <!-- TMPL_ELSE -->
1008                                 <div class="hint">To notify patrons of new serial issues, you must <a href="/cgi-bin/koha/tools/letter.pl">define a notice</a>.</div>
1009                                 <!-- /TMPL_IF -->
1010         </li>
1011         </ol>
1012
1013             <div style="float:left;clear:left;margin:1em;"><strong>Note:</strong>
1014             
1015                 <ul>
1016                     <li>The subscription <strong>must</strong> be associated with a bibliographic record.</li>
1017                     <li>You <strong>must</strong> select a vendor if you wish to generate claims.</li>
1018                 </ul></div>
1019             
1020             
1021         </fieldset>
1022         </div>
1023         
1024 <div class="yui-u">
1025 <div id="subscription_form_planning">
1026         <fieldset class="rows">
1027         <legend>Serials planning</legend>
1028     <ol>
1029         <li>
1030            <label for="firstacquidate"> First issue publication date:</label>
1031                 <!-- TMPL_UNLESS NAME="mod" --><img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="acqui_button" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" /><!-- /TMPL_UNLESS -->
1032                 <input type="text" name="firstacquidate" value="<!-- TMPL_VAR name="firstacquidate" -->"  size="13" maxlength="10" id="acqui_date" <!-- TMPL_IF NAME="mod" -->disabled="true"<!-- /TMPL_IF --> style="border-width: 0px;"  />
1033         </li>
1034            <!-- TMPL_IF NAME="mod" --><li><label for="nextacquidate"> Next issue publication date:</label>
1035                 <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="next_acqui_button" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
1036                 <input type="text" name="nextacquidate" value="<!-- TMPL_VAR name="nextacquidate" -->" size="13" maxlength="10" id="next_acqui_date" style="border-width: 0px;"  />
1037                 </li><!-- /TMPL_IF -->
1038                 <!-- both scripts for calendar must follow the input field --> 
1039                 <script type="text/javascript">
1040                     Calendar.setup({
1041                         inputField      :   "<!-- TMPL_IF NAME="mod" -->next_<!-- /TMPL_IF -->acqui_date",
1042                         ifFormat       :   "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
1043                         button         :   "<!-- TMPL_IF NAME="mod" -->next_<!-- /TMPL_IF -->acqui_button",
1044                         align          :   "Tl",
1045                         onUpdate        :    function(cal) { 
1046                                                              irregular_issues.weeks = getWeeksArray(cal.date);
1047                                                             irregular_issues.firstissue = cal.date;
1048                                                             if(document.irregularity_summary) {
1049                                                                 irregular_issues.update();
1050                                                             }
1051                                                             if(document.getElementById("seasonal_irregularity")) {
1052                                                                 moreoptions_seasons(text[15]);
1053                                                             }
1054                                                         } 
1055                         });
1056                     Calendar.setup({
1057                         inputField      :   "<!-- TMPL_IF NAME="mod" -->next_<!-- /TMPL_IF -->acqui_date",
1058                         ifFormat       :   "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
1059                         button         :   "<!-- TMPL_IF NAME="mod" -->next_<!-- /TMPL_IF -->acqui_date",
1060                         align          :   "Tl",
1061                         onUpdate        :    function(cal) { irregular_issues.weeks = getWeeksArray(cal.date);
1062                                                             irregular_issues.firstissue = cal.date;
1063                                                             if(document.irregularity_summary) {
1064                                                                 irregular_issues.update();
1065                                                             }
1066                                                             if(document.getElementById("seasonal_irregularity")) {
1067                                                                 moreoptions_seasons(text[15]);
1068                                                             }
1069                                                         } 
1070                         });
1071                 </script>
1072         <li>
1073             <label for="periodicity" class="required">Frequency:</label>
1074             
1075                 <select name="periodicity" size="1" id="periodicity" onchange="javascript:document.getElementsByName('manualhist')[0].checked=(this.value==1); reset_num_pattern();">
1076                 <option value="" selected="selected">-- please choose --</option>
1077                 <!-- TMPL_IF name="periodicity16" -->
1078                 <option value="16" selected="selected">Without periodicity</option>
1079                 <!-- TMPL_ELSE -->
1080                     <option value="16">Without periodicity</option>
1081                 <!-- /TMPL_IF -->
1082                 <!-- TMPL_IF name="periodicity48" -->
1083                 <option value="48" selected="selected">Unknown</option>
1084                 <!-- TMPL_ELSE -->
1085                 <option value="48">Unknown</option>
1086                 <!-- /TMPL_IF -->
1087                 <!-- TMPL_IF name="periodicity32" -->
1088                 <option value="32" selected="selected">Irregular</option>
1089                 <!-- TMPL_ELSE -->
1090                     <option value="32">Irregular</option>
1091                 <!-- /TMPL_IF -->
1092
1093                 <!-- TMPL_IF name="periodicity12" -->
1094                     <option value="12" selected="selected">2/day</option>
1095                 <!-- TMPL_ELSE -->
1096                     <option value="12">2/day</option>
1097                 <!-- /TMPL_IF -->
1098                 <!-- TMPL_IF name="periodicity1" -->
1099                     <option value="1" selected="selected">daily (n/week)</option>
1100                 <!-- TMPL_ELSE -->
1101                     <option value="1">daily (n/week)</option>
1102                 <!-- /TMPL_IF -->
1103                 <!-- TMPL_IF name="periodicity2" -->
1104                     <option value="2" selected="selected">1/week</option>
1105                 <!-- TMPL_ELSE -->
1106                     <option value="2">1/week</option>
1107                 <!-- /TMPL_IF -->
1108                 <!-- TMPL_IF name="periodicity3" -->
1109                     <option value="3" selected="selected">1/2 weeks </option>
1110                 <!-- TMPL_ELSE -->
1111                     <option value="3">1/2 weeks </option>
1112                 <!-- /TMPL_IF -->
1113                 <!-- TMPL_IF name="periodicity4" -->
1114                     <option value="4" selected="selected">1/3 weeks</option>
1115                 <!-- TMPL_ELSE -->
1116                     <option value="4">1/3 weeks</option>
1117                 <!-- /TMPL_IF -->
1118                 <!-- TMPL_IF name="periodicity5" -->
1119                     <option value="5" selected="selected">1/month</option>
1120                 <!-- TMPL_ELSE -->
1121                     <option value="5">1/month</option>
1122                 <!-- /TMPL_IF -->
1123                 <!-- TMPL_IF name="periodicity6" -->
1124                     <option value="6" selected="selected">1/2 months (6/year)</option>
1125                 <!-- TMPL_ELSE -->
1126                     <option value="6">1/2 months (6/year)</option>
1127                 <!-- /TMPL_IF -->
1128                 <!-- TMPL_IF name="periodicity7" -->
1129                     <option value="7" selected="selected">1/3 months (1/quarter)</option>
1130                 <!-- TMPL_ELSE -->
1131                     <option value="7">1/3 months (1/quarter)</option>
1132                 <!-- /TMPL_IF -->
1133                 <!-- periodicity8 is 1/quarter, exactly like periodicity7 but will use it for seasonal option -->
1134                 <!-- TMPL_IF name="periodicity8" -->
1135                     <option value="8" selected="selected">1/quarter (seasonal)</option>
1136                 <!-- TMPL_ELSE -->
1137                     <option value="8">1/quarter (seasonal)</option>
1138                 <!-- /TMPL_IF -->
1139
1140                 <!-- TMPL_IF name="periodicity9" -->
1141                     <option value="9" selected="selected">2/years</option>
1142                 <!-- TMPL_ELSE -->
1143                     <option value="9">2/year</option>
1144                 <!-- /TMPL_IF -->
1145                 <!-- TMPL_IF name="periodicity10" -->
1146                     <option value="10" selected="selected">1/year</option>
1147                 <!-- TMPL_ELSE -->
1148                     <option value="10">1/year</option>
1149                 <!-- /TMPL_IF -->
1150                 <!-- TMPL_IF name="periodicity11" -->
1151                     <option value="11" selected="selected">1/2 years</option>
1152                 <!-- TMPL_ELSE -->
1153                     <option value="11">1/2 years</option>
1154                 <!-- /TMPL_IF -->
1155                 </select> <span class="required">Required</span></li>
1156                                 <li><label for="manuallist"> Manual history:</label> <input type="checkbox" name="manualhist" id="manuallist" value="1" /></li>
1157         <li>
1158            <label for="numberpattern"> Numbering pattern:</label>
1159             
1160                 <select name="numbering_pattern" size="1" id="numberpattern" >
1161                     <option value="" selected="selected">-- please choose --</option>
1162                     <!-- TMPL_IF name="numberpattern1" -->
1163                         <option value="1" selected="selected">Number</option>
1164                     <!-- TMPL_ELSE -->
1165                         <option value="1">Number</option>
1166                     <!-- /TMPL_IF -->
1167                     <!-- TMPL_IF name="numberpattern2" -->
1168                         <option value="2" selected="selected">Volume, Number, Issue</option>
1169                     <!-- TMPL_ELSE -->
1170                         <option value="2">Volume, Number, Issue</option>
1171                     <!-- /TMPL_IF -->
1172                     <!-- TMPL_IF name="numberpattern3" -->
1173                         <option value="3" selected="selected">Volume, Number</option>
1174                     <!-- TMPL_ELSE -->
1175                         <option value="3">Volume, Number</option>
1176                     <!-- /TMPL_IF -->
1177                     <!-- TMPL_IF name="numberpattern4" -->
1178                         <option value="4" selected="selected">Volume, Issue</option>
1179                     <!-- TMPL_ELSE -->
1180                         <option value="4">Volume, Issue</option>
1181                     <!-- /TMPL_IF -->
1182                     <!-- TMPL_IF name="numberpattern5" -->
1183                         <option value="5" selected="selected">Number, Issue</option>
1184                     <!-- TMPL_ELSE -->
1185                         <option value="5">Number, Issue</option>
1186                     <!-- /TMPL_IF -->
1187                     <!-- TMPL_IF name="numberpattern6" -->
1188                         <option value="6" selected="selected">Seasonal only</option>
1189                     <!-- TMPL_ELSE -->
1190                         <option value="6">Seasonal only</option>
1191                     <!-- /TMPL_IF -->
1192                     <!-- TMPL_IF name="numberpattern8" -->
1193                         <option value="8" selected="selected">Year/Number</option>
1194                     <!-- TMPL_ELSE -->
1195                         <option value="8">Year/Number</option>
1196                     <!-- /TMPL_IF -->          
1197                     <!-- TMPL_IF name="numberpattern7" -->
1198                         <option value="7" selected="selected">None of the above</option>
1199                     <!-- TMPL_ELSE -->
1200                         <option value="7">None of the above</option>
1201                     <!-- /TMPL_IF -->
1202                 </select>
1203         </li>
1204                 <li id="more_options"></li>
1205                 <li id="irregularity"></li>
1206                    <li id="displayexample"></li>
1207         <li>
1208            <label for="startdate" class="required"> Subscription start date:</label>
1209             
1210                 <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="button1" style="cursor: pointer;" alt="Show Calendar" title="Show Calendar" />
1211                 <input type="text" name="startdate" value="<!-- TMPL_VAR name="startdate" -->" size="13" maxlength="10" id="beginning_date" style="border-width: 0px;" />
1212                 <!-- both scripts for calendar must follow the input field --> 
1213                 <script type="text/javascript">
1214                     Calendar.setup({
1215                         inputField   : "beginning_date",
1216                         ifFormat     : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
1217                         button       : "button1",
1218                         align        : "Tl"
1219                     });
1220                 </script>
1221                 <script type="text/javascript">
1222                     Calendar.setup({
1223                         inputField   : "beginning_date",
1224                         ifFormat     : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
1225                         button       : "beginning_date",
1226                         align        : "Tl"
1227                     });
1228                 </script>
1229             <span class="required">Required</span>
1230         </li>
1231         <li>
1232             <label for="subtype" class="required">Subscription length:</label>
1233             
1234                 <select name="subtype" id="subtype">
1235                     <!-- TMPL_LOOP NAME="subtype" -->
1236                         <!-- TMPL_IF NAME="selected" -->
1237                         <option value="<!-- TMPL_VAR NAME="name" -->" selected="selected">
1238                         <!-- TMPL_ELSE -->
1239                         <option value="<!-- TMPL_VAR NAME="name" -->">
1240                         <!-- /TMPL_IF -->
1241                         <!-- TMPL_VAR NAME="name" -->
1242                         </option>
1243                     <!-- /TMPL_LOOP -->
1244                 </select>
1245                 <input type="text" name="sublength" value="<!-- TMPL_VAR name="sublength" -->" size="3" onkeypress="return check_input(event)" /> (enter amount in numerals)
1246             <span class="required">Required</span>
1247         </li>
1248     <li><label for="numberingmethod">Numbering formula:</label> <input type="text" name="numberingmethod" id="numberingmethod" value="<!-- TMPL_VAR name="numberingmethod" -->" />
1249     </li>
1250     </ol>
1251         </fieldset>
1252 </div>
1253         <fieldset class="action">
1254         <input type="button" class="action_test" value="Test Prediction Pattern" onclick="javascript:irregularity_check()" />
1255         <input type="button" class="action_reset" value="Reset Pattern" onclick="javascript:reset_pattern()" />
1256     <input type="button" class="action_save"  value="Save subscription" onclick="Check(this.form)" accesskey="w" />
1257         </fieldset>
1258     <fieldset class="action">
1259     <input type="button" class="action_advanced" value="Show/Hide Advanced Pattern" onclick="javascript:display_table()" />
1260     </fieldset>
1261            <div id="basetable"  style="display: none;">
1262             <table class="small">
1263                 <tr><th colspan="4">Advanced Prediction Pattern</th></tr>
1264                                 <tr>
1265                     <th>&nbsp;</th>
1266                     <th>X</th>
1267                     <th>Y</th>
1268                     <th>Z</th>
1269                 </tr>
1270                 <tr>
1271                     <td>Add</td>
1272                     <td>
1273                         <input type="text" name="add1" id="add1" value="<!-- TMPL_VAR name="add1" -->" />
1274                     </td>
1275                     <td>
1276                         <input type="text" name="add2" id="add2" value="<!-- TMPL_VAR name="add2" -->" />
1277                     </td>
1278                     <td>
1279                         <input type="text" name="add3" id="add3" value="<!-- TMPL_VAR name="add3" -->" />
1280                     </td>
1281                 </tr>
1282                 <tr>
1283                     <td>once every</td>
1284                     <td><input type="text" name="every1" id="every1" value="<!-- TMPL_VAR name="every1" -->" /></td>
1285                     <td><input type="text" name="every2" id="every2" value="<!-- TMPL_VAR name="every2" -->" /></td>
1286                     <td><input type="text" name="every3" id="every3" value="<!-- TMPL_VAR name="every3" -->" /></td>
1287                 </tr>
1288                 <tr>
1289                     <td>When more than</td>
1290                     <td><input type="text" name="whenmorethan1" id="whenmorethan1" value="<!-- TMPL_VAR name="whenmorethan1" -->" /></td>
1291                     <td><input type="text" name="whenmorethan2" id="whenmorethan2" value="<!-- TMPL_VAR name="whenmorethan2" -->" /></td>
1292                     <td><input type="text" name="whenmorethan3" id="whenmorethan3" value="<!-- TMPL_VAR name="whenmorethan3" -->" /></td>
1293                 </tr>
1294                 <tr>
1295                     <td>inner counter</td>
1296                     <td><input type="text" name="innerloop1" id="innerloop1" value="<!-- TMPL_VAR name="innerloop1" -->" /></td>
1297                     <td><input type="text" name="innerloop2" id="innerloop2" value="<!-- TMPL_VAR name="innerloop2" -->" /></td>
1298                     <td><input type="text" name="innerloop3" id="innerloop3" value="<!-- TMPL_VAR name="innerloop3" -->" /></td>
1299                 </tr>
1300                 <tr>
1301                     <td>Set back to</td>
1302                     <td><input type="text" name="setto1" id="setto1" value="<!-- TMPL_VAR name="setto1" -->" /></td>
1303                     <td><input type="text" name="setto2" id="setto2" value="<!-- TMPL_VAR name="setto2" -->" /></td>
1304                     <td><input type="text" name="setto3" id="setto3" value="<!-- TMPL_VAR name="setto3" -->" /></td>
1305                 </tr>
1306                 <tr>
1307                     <td>
1308                         <!-- TMPL_IF name="mod" -->
1309                             Last value
1310                         <!-- TMPL_ELSE -->
1311                             Begins with
1312                         <!-- /TMPL_IF -->
1313                     </td>
1314                     <td><input type="text" name="lastvalue1" id="lastvalue1" value="<!-- TMPL_VAR name="lastvalue1" -->" /></td>
1315                     <td><input type="text" name="lastvalue2" id="lastvalue2" value="<!-- TMPL_VAR name="lastvalue2" -->" /></td>
1316                     <td><input type="text" name="lastvalue3" id="lastvalue3" value="<!-- TMPL_VAR name="lastvalue3" -->" /></td>
1317                 </tr>
1318             </table>
1319         </div>
1320
1321 </div>
1322
1323 </form>
1324 </div>
1325
1326 <!--TMPL_IF Name="history"-->
1327 <div id="subscription_form_history">
1328     <h2>Subscription history</h2>
1329     <form method="post" action="/cgi-bin/koha/serials/subscription-add.pl">
1330         <input type="hidden" name="op" value="modsubscription" />
1331         <input type="hidden" name="subscriptionid" value="<!-- TMPL_VAR name="subscriptionid" -->" />
1332         <input type="hidden" name="history_only" value="1" />
1333         <p>Hint : you can update the serial history manually. This can be useful for an old subscription or to clean the existing history. Modify these fields with care, as future serial receive will continue to update them automatically.</p>
1334         <table>
1335             <tr>
1336             <td>Subscription start date</td>
1337             <td><input type="text" name="histstartdate" value="<!-- TMPL_VAR name="histstartdate" -->" /> (start date of the 1st subscription)</td>
1338             </tr>
1339             <tr>
1340             <td>Subscription end date</td>
1341             <td><input type="text" name="histenddate" value="<!-- TMPL_VAR name="histenddate" -->" />(if empty, subscription is still active)</td>
1342             </tr>
1343             <tr>
1344                 <td>Received issues</td>
1345                 <td><textarea name="recievedlist" cols="60" rows="5"><!-- TMPL_VAR name="recievedlist" --></textarea></td>
1346             </tr>
1347             <tr>
1348                 <td>Missing issues</td>
1349                 <td><textarea name="missinglist" cols="60" rows="5"><!-- TMPL_VAR name="missinglist" --></textarea></td>
1350             </tr>
1351             <tr>
1352                 <td>Note for OPAC</td>
1353                 <td><textarea name="opacnote" cols="60" rows="5"><!-- TMPL_VAR name="opacnote" --></textarea></td>
1354             </tr>
1355             <tr>
1356                 <td>Note for staff</td>
1357                 <td><textarea name="librariannote" cols="60" rows="5"><!-- TMPL_VAR name="librariannote" --></textarea></td>
1358             </tr>
1359         </table>
1360     <input type="submit" value="Save subscription history"  />
1361     </form>
1362 </div>
1363 <!--/TMPL_IF-->
1364
1365 </div>
1366
1367 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->