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'];
64 standardize_address = function () {
66 var cf = document.CustomerForm;
67 var state_el = cf.elements['state'];
68 var ship_state_el = cf.elements['ship_state'];
71 cf.elements['company'].value = argsHash['new_company'];
72 cf.elements['address1'].value = argsHash['new_address1'];
73 cf.elements['address2'].value = argsHash['new_address2'];
74 cf.elements['city'].value = argsHash['new_city'];
75 setselect(cf.elements['state'], argsHash['new_state']);
76 cf.elements['zip'].value = argsHash['new_zip'];
80 cf.elements['ship_company'].value = argsHash['new_ship_company'];
81 cf.elements['ship_address1'].value = argsHash['new_ship_address1'];
82 cf.elements['ship_address2'].value = argsHash['new_ship_address2'];
83 cf.elements['ship_city'].value = argsHash['new_ship_city'];
84 setselect(cf.elements['ship_state'], argsHash['new_ship_state']);
85 cf.elements['ship_zip'].value = argsHash['new_ship_zip'];
90 var cf = document.CustomerForm;
92 % if ( $conf->exists('enable_taxproducts') ) {
94 if ( <% $taxpre %>error ) {
96 var country_el = cf.elements['<% $taxpre %>country'];
97 var country = country_el.options[ country_el.selectedIndex ].value;
99 if ( country == 'CA' || country == 'US' ) {
101 var state_el = cf.elements['<% $taxpre %>state'];
102 var state = state_el.options[ state_el.selectedIndex ].value;
104 var url = "cust_main/choose_tax_location.html" +
105 "?data_vendor=cch-zip" +
106 ";city=" + cf.elements['<% $taxpre %>city'].value +
108 ";zip=" + cf.elements['<% $taxpre %>zip'].value +
109 ";country=" + country +
113 OLgetAJAX( url, update_geocode, 300 );
117 cf.elements['geocode'].value = 'DEFAULT';
126 if ( changed || ship_changed ) {
128 % if ( $conf->exists('cust_main-auto_standardize_address') ) {
130 standardize_address();
135 // popup a confirmation popup
138 '<CENTER><BR><B>Confirm address standardization</B><BR><BR>' +
143 confirm_change = confirm_change +
144 '<TR><TH>Entered billing address</TH>' +
145 '<TH>Standardized billing address</TH></TR>';
146 // + '<TR><TD> </TD><TD> </TD></TR>';
148 if ( argsHash['company'] || argsHash['new_company'] ) {
149 confirm_change = confirm_change +
150 '<TR><TD>' + argsHash['company'] +
151 '</TD><TD>' + argsHash['new_company'] + '</TD></TR>';
154 confirm_change = confirm_change +
155 '<TR><TD>' + argsHash['address1'] +
156 '</TD><TD>' + argsHash['new_address1'] + '</TD></TR>' +
157 '<TR><TD>' + argsHash['address2'] +
158 '</TD><TD>' + argsHash['new_address2'] + '</TD></TR>' +
159 '<TR><TD>' + argsHash['city'] + ', ' + argsHash['state'] + ' ' + argsHash['zip'] +
160 '</TD><TD>' + argsHash['new_city'] + ', ' + argsHash['new_state'] + ' ' + argsHash['new_zip'] + '</TD></TR>' +
161 '<TR><TD> </TD><TD> </TD></TR>';
165 if ( ship_changed ) {
167 confirm_change = confirm_change +
168 '<TR><TH>Entered service address</TH>' +
169 '<TH>Standardized service address</TH></TR>';
170 // + '<TR><TD> </TD><TD> </TD></TR>';
172 if ( argsHash['ship_company'] || argsHash['new_ship_company'] ) {
173 confirm_change = confirm_change +
174 '<TR><TD>' + argsHash['ship_company'] +
175 '</TD><TD>' + argsHash['new_ship_company'] + '</TD></TR>';
178 confirm_change = confirm_change +
179 '<TR><TD>' + argsHash['ship_address1'] +
180 '</TD><TD>' + argsHash['new_ship_address1'] + '</TD></TR>' +
181 '<TR><TD>' + argsHash['ship_address2'] +
182 '</TD><TD>' + argsHash['new_ship_address2'] + '</TD></TR>' +
183 '<TR><TD>' + argsHash['ship_city'] + ', ' + argsHash['ship_state'] + ' ' + argsHash['ship_zip'] +
184 '</TD><TD>' + argsHash['new_ship_city'] + ', ' + argsHash['new_ship_state'] + ' ' + argsHash['new_ship_zip'] + '</TD></TR>' +
185 '<TR><TD> </TD><TD> </TD></TR>';
189 var addresses = 'address';
191 if ( changed && ship_changed ) {
192 addresses = 'addresses';
193 height = 396; // #what
196 confirm_change = confirm_change +
198 '<BUTTON TYPE="button" onClick="document.CustomerForm.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered ' + addresses + '</BUTTON>' +
200 '<BUTTON TYPE="button" onClick="standardize_address(); document.CustomerForm.submit();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized ' + addresses + '</BUTTON>' +
202 '<TR><TD COLSPAN=2 ALIGN="center">' +
203 '<BUTTON TYPE="button" onClick="document.CustomerForm.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
207 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 );
219 function update_geocode() {
222 set_geocode = function (what) {
224 var cf = document.CustomerForm;
226 //alert(what.options[what.selectedIndex].value);
227 var argsHash = eval('(' + what.options[what.selectedIndex].value + ')');
228 cf.elements['<% $taxpre %>city'].value = argsHash['city'];
229 setselect(cf.elements['<% $taxpre %>state'], argsHash['state']);
230 cf.elements['<% $taxpre %>zip'].value = argsHash['zip'];
231 cf.elements['geocode'].value = argsHash['geocode'];
237 overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
241 function copyelement(from, to) {
242 if ( from == undefined ) {
244 } else if ( from.type == 'select-one' ) {
245 to.value = from.options[from.selectedIndex].value;
246 //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
247 } else if ( from.type == 'checkbox' ) {
248 if ( from.checked ) {
249 to.value = from.value;
254 if ( from.value == undefined ) {
257 to.value = from.value;
260 //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
263 function setselect(el, value) {
265 for ( var s = 0; s < el.options.length; s++ ) {
266 if ( el.options[s].value == value ) {
267 el.selectedIndex = s;
274 my $conf = new FS::Conf;
276 my $taxpre = $conf->exists('tax-ship_address') ? 'ship_' : '';