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