1 function bottomfixup(what) {
3 var layervars = new Array(
5 'payinfo', 'payinfo1', 'payinfo2', 'paytype',
6 'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
7 'paystart_month', 'paystart_year', 'payissue',
12 var cf = document.CustomerForm;
13 var payby = cf.payby.options[cf.payby.selectedIndex].value;
14 for ( f=0; f < layervars.length; f++ ) {
15 var field = layervars[f];
16 copyelement( cf.elements[payby + '_' + field],
21 //this part does USPS address correction
23 // XXX should this be first and should we update the form fields that are
26 var cf = document.CustomerForm;
28 var state_el = cf.elements['state'];
29 var ship_state_el = cf.elements['ship_state'];
31 //address_standardize(
32 var cust_main = new Array(
33 'company', cf.elements['company'].value,
34 'address1', cf.elements['address1'].value,
35 'address2', cf.elements['address2'].value,
36 'city', cf.elements['city'].value,
37 'state', state_el.options[ state_el.selectedIndex ].value,
38 'zip', cf.elements['zip'].value,
40 'ship_company', cf.elements['ship_company'].value,
41 'ship_address1', cf.elements['ship_address1'].value,
42 'ship_address2', cf.elements['ship_address2'].value,
43 'ship_city', cf.elements['ship_city'].value,
44 'ship_state', ship_state_el.options[ ship_state_el.selectedIndex ].value,
45 'ship_zip', cf.elements['ship_zip'].value
48 address_standardize( cust_main, update_address );
52 var standardize_address;
54 function update_address(arg) {
56 var argsHash = eval('(' + arg + ')');
58 var changed = argsHash['address_standardized'];
59 var ship_changed = argsHash['ship_address_standardized'];
60 var error = argsHash['error'];
61 var ship_error = argsHash['ship_error'];
65 standardize_address = function () {
67 var cf = document.CustomerForm;
68 var state_el = cf.elements['state'];
69 var ship_state_el = cf.elements['ship_state'];
72 cf.elements['company'].value = argsHash['new_company'];
73 cf.elements['address1'].value = argsHash['new_address1'];
74 cf.elements['address2'].value = argsHash['new_address2'];
75 cf.elements['city'].value = argsHash['new_city'];
76 setselect(cf.elements['state'], argsHash['new_state']);
77 cf.elements['zip'].value = argsHash['new_zip'];
81 cf.elements['ship_company'].value = argsHash['new_ship_company'];
82 cf.elements['ship_address1'].value = argsHash['new_ship_address1'];
83 cf.elements['ship_address2'].value = argsHash['new_ship_address2'];
84 cf.elements['ship_city'].value = argsHash['new_ship_city'];
85 setselect(cf.elements['ship_state'], argsHash['new_ship_state']);
86 cf.elements['ship_zip'].value = argsHash['new_ship_zip'];
91 var cf = document.CustomerForm;
93 % if ( $conf->exists('enable_taxproducts') ) {
95 if ( <% $taxpre %>error ||
96 new String(argsHash['new_<% $taxpre %>zip']).length < 10 )
99 var country_el = cf.elements['<% $taxpre %>country'];
100 var country = country_el.options[ country_el.selectedIndex ].value;
102 if ( country == 'CA' || country == 'US' ) {
104 var state_el = cf.elements['<% $taxpre %>state'];
105 var state = state_el.options[ state_el.selectedIndex ].value;
107 var url = "cust_main/choose_tax_location.html" +
108 "?data_vendor=cch-zip" +
109 ";city=" + cf.elements['<% $taxpre %>city'].value +
111 ";zip=" + cf.elements['<% $taxpre %>zip'].value +
112 ";country=" + country +
116 OLgetAJAX( url, update_geocode, 300 );
120 cf.elements['geocode'].value = 'DEFAULT';
129 if ( changed || ship_changed ) {
131 % if ( $conf->exists('cust_main-auto_standardize_address') ) {
133 standardize_address();
138 // popup a confirmation popup
141 '<CENTER><BR><B>Confirm address standardization</B><BR><BR>' +
146 confirm_change = confirm_change +
147 '<TR><TH>Entered billing address</TH>' +
148 '<TH>Standardized billing address</TH></TR>';
149 // + '<TR><TD> </TD><TD> </TD></TR>';
151 if ( argsHash['company'] || argsHash['new_company'] ) {
152 confirm_change = confirm_change +
153 '<TR><TD>' + argsHash['company'] +
154 '</TD><TD>' + argsHash['new_company'] + '</TD></TR>';
157 confirm_change = confirm_change +
158 '<TR><TD>' + argsHash['address1'] +
159 '</TD><TD>' + argsHash['new_address1'] + '</TD></TR>' +
160 '<TR><TD>' + argsHash['address2'] +
161 '</TD><TD>' + argsHash['new_address2'] + '</TD></TR>' +
162 '<TR><TD>' + argsHash['city'] + ', ' + argsHash['state'] + ' ' + argsHash['zip'] +
163 '</TD><TD>' + argsHash['new_city'] + ', ' + argsHash['new_state'] + ' ' + argsHash['new_zip'] + '</TD></TR>' +
164 '<TR><TD> </TD><TD> </TD></TR>';
168 if ( ship_changed ) {
170 confirm_change = confirm_change +
171 '<TR><TH>Entered service address</TH>' +
172 '<TH>Standardized service address</TH></TR>';
173 // + '<TR><TD> </TD><TD> </TD></TR>';
175 if ( argsHash['ship_company'] || argsHash['new_ship_company'] ) {
176 confirm_change = confirm_change +
177 '<TR><TD>' + argsHash['ship_company'] +
178 '</TD><TD>' + argsHash['new_ship_company'] + '</TD></TR>';
181 confirm_change = confirm_change +
182 '<TR><TD>' + argsHash['ship_address1'] +
183 '</TD><TD>' + argsHash['new_ship_address1'] + '</TD></TR>' +
184 '<TR><TD>' + argsHash['ship_address2'] +
185 '</TD><TD>' + argsHash['new_ship_address2'] + '</TD></TR>' +
186 '<TR><TD>' + argsHash['ship_city'] + ', ' + argsHash['ship_state'] + ' ' + argsHash['ship_zip'] +
187 '</TD><TD>' + argsHash['new_ship_city'] + ', ' + argsHash['new_ship_state'] + ' ' + argsHash['new_ship_zip'] + '</TD></TR>' +
188 '<TR><TD> </TD><TD> </TD></TR>';
192 var addresses = 'address';
194 if ( changed && ship_changed ) {
195 addresses = 'addresses';
196 height = 396; // #what
199 confirm_change = confirm_change +
201 '<BUTTON TYPE="button" onClick="document.CustomerForm.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered ' + addresses + '</BUTTON>' +
203 '<BUTTON TYPE="button" onClick="standardize_address(); document.CustomerForm.submit();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized ' + addresses + '</BUTTON>' +
205 '<TR><TD COLSPAN=2 ALIGN="center">' +
206 '<BUTTON TYPE="button" onClick="document.CustomerForm.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
210 overlib( confirm_change, CAPTION, 'Confirm address standardization', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, height, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
222 function update_geocode() {
225 set_geocode = function (what) {
227 var cf = document.CustomerForm;
229 //alert(what.options[what.selectedIndex].value);
230 var argsHash = eval('(' + what.options[what.selectedIndex].value + ')');
231 cf.elements['<% $taxpre %>city'].value = argsHash['city'];
232 setselect(cf.elements['<% $taxpre %>state'], argsHash['state']);
233 cf.elements['<% $taxpre %>zip'].value = argsHash['zip'];
234 cf.elements['geocode'].value = argsHash['geocode'];
240 overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
244 function copyelement(from, to) {
245 if ( from == undefined ) {
247 } else if ( from.type == 'select-one' ) {
248 to.value = from.options[from.selectedIndex].value;
249 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
250 } else if ( from.type == 'checkbox' ) {
251 if ( from.checked ) {
252 to.value = from.value;
257 if ( from.value == undefined ) {
260 to.value = from.value;
263 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
266 function setselect(el, value) {
268 for ( var s = 0; s < el.options.length; s++ ) {
269 if ( el.options[s].value == value ) {
270 el.selectedIndex = s;
277 my $conf = new FS::Conf;
279 my $taxpre = $conf->exists('tax-ship_address') ? 'ship_' : '';