default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / elements / order_pkg.js
1 function pkg_changed () {
2   var form = document.OrderPkgForm;
3   var discountnum = form.discountnum;
4   var opt = form.pkgpart.options[form.pkgpart.selectedIndex];
5
6   usageprice_pkg_changed( opt.value );
7
8   var date_button = document.getElementById('start_date_button');
9   var date_button_disabled = document.getElementById('start_date_disabled');
10   var date_text = document.getElementById('start_date_text');
11
12   var radio_now = document.getElementById('start_now');
13   var radio_on_hold = document.getElementById('start_on_hold');
14   var radio_on_date = document.getElementById('start_on_date');
15
16   if ( form.pkgpart.selectedIndex > 0 ) {
17
18     form.submitButton.disabled = false;
19     if ( discountnum ) {
20       if ( opt.getAttribute('data-can_discount') == 1 ) {
21         form.discountnum.disabled = false;
22         discountnum_changed(form.discountnum);
23       } else {
24         form.discountnum.disabled = true;
25         discountnum_changed(form.discountnum);
26       }
27     }
28
29     // if this form element exists, then the start date is a future
30     // package change date; don't replace it
31     if ( form.delay ) {
32       return;
33     }
34     form.start_date_text.value = opt.getAttribute('data-start_date');
35     if ( opt.getAttribute('data-can_start_date') == 1 ) {
36       date_text.style.backgroundColor = '#ffffff';
37       date_text.disabled = false;
38       date_button.style.display = '';
39       date_button_disabled.style.display = 'none';
40       if ( radio_on_date ) {
41         // un-disable all the buttons that might get disabled
42         radio_now.disabled = false;
43         radio_on_hold.disabled = false;
44         radio_on_date.disabled = false;
45         // if a start date has been entered, assume the user wants it
46         if ( form.start_date_text.value.length > 0 ) {
47           radio_now.checked = false;
48           radio_on_date.checked = true;
49         } else {
50           // if not, default to now
51           radio_now.checked = true;
52         }
53       }
54     } else { // the package is either fixed start date or start-on-hold
55       date_text.style.backgroundColor = '#dddddd';
56       date_text.disabled = true;
57       date_button.style.display = 'none';
58       date_button_disabled.style.display = '';
59       if ( radio_on_date ) {
60         if ( opt.getAttribute('data-start_on_hold') == 1 ) {
61           // disallow all options but "On hold"
62           radio_on_hold.checked = true;
63           radio_now.checked = false;
64           radio_now.disabled = true;
65         } else {
66           // disallow all options but "On date"
67           radio_on_hold.checked = false;
68           radio_now.checked = true;
69           radio_now.disabled = false;
70         }
71       }
72     }
73
74   } else {
75     form.submitButton.disabled = true;
76
77     date_text.style.backgroundColor = '#dddddd';
78     date_text.disabled = true;
79     date_button.style.display = 'none';
80     date_button_disabled.style.display = '';
81     radio_now.disabled = true;
82     radio_on_date.disabled = true;
83     radio_on_hold.disabled = true;
84
85     if ( discountnum ) { form.discountnum.disabled = true; }
86     discountnum_changed(form.discountnum);
87   }
88
89 }
90
91 function standardize_new_location() {
92   var form = document.OrderPkgForm;
93   var loc = form.locationnum;
94   if (loc.type == 'select-one' && loc.options[loc.selectedIndex].value == -1){
95     standardize_locations();
96   } else {
97     form.submit();
98   }
99 }
100
101 function submit_abort() {
102   document.OrderPkgForm.submitButton.disabled = false;
103   nd(1);
104 }