1 function standardize_locations() {
3 var cf = document.<% $formname %>;
5 var state_el = cf.elements['<% $main_prefix %>state'];
6 var ship_state_el = cf.elements['<% $ship_prefix %>state'];
8 var address_info = new Array(
13 'company', cf.elements['company'].value,
15 'address1', cf.elements['<% $main_prefix %>address1'].value,
16 'address2', cf.elements['<% $main_prefix %>address2'].value,
17 'city', cf.elements['<% $main_prefix %>city'].value,
18 'state', state_el.options[ state_el.selectedIndex ].value,
19 'zip', cf.elements['<% $main_prefix %>zip'].value,
21 'ship_address1', cf.elements['<% $ship_prefix %>address1'].value,
22 'ship_address2', cf.elements['<% $ship_prefix %>address2'].value,
23 'ship_city', cf.elements['<% $ship_prefix %>city'].value,
24 'ship_state', ship_state_el.options[ ship_state_el.selectedIndex ].value,
25 'ship_zip', cf.elements['<% $ship_prefix %>zip'].value
28 address_standardize( address_info, update_address );
32 var standardize_address;
34 function update_address(arg) {
36 var argsHash = eval('(' + arg + ')');
38 var changed = argsHash['address_standardized'];
39 var ship_changed = argsHash['ship_address_standardized'];
40 var error = argsHash['error'];
41 var ship_error = argsHash['ship_error'];
45 standardize_address = function () {
47 var cf = document.<% $formname %>;
48 var state_el = cf.elements['<% $main_prefix %>state'];
49 var ship_state_el = cf.elements['<% $ship_prefix %>state'];
54 cf.elements['<% $main_prefix %>company'].value = argsHash['new_company'];
56 cf.elements['<% $main_prefix %>address1'].value = argsHash['new_address1'];
57 cf.elements['<% $main_prefix %>address2'].value = argsHash['new_address2'];
58 cf.elements['<% $main_prefix %>city'].value = argsHash['new_city'];
59 setselect(cf.elements['<% $main_prefix %>state'], argsHash['new_state']);
60 cf.elements['<% $main_prefix %>zip'].value = argsHash['new_zip'];
66 cf.elements['<% $ship_prefix %>company'].value = argsHash['new_ship_company'];
68 cf.elements['<% $ship_prefix %>address1'].value = argsHash['new_ship_address1'];
69 cf.elements['<% $ship_prefix %>address2'].value = argsHash['new_ship_address2'];
70 cf.elements['<% $ship_prefix %>city'].value = argsHash['new_ship_city'];
71 setselect(cf.elements['<% $ship_prefix %>state'], argsHash['new_ship_state']);
72 cf.elements['<% $ship_prefix %>zip'].value = argsHash['new_ship_zip'];
75 post_standardization();
81 if ( changed || ship_changed ) {
83 % if ( $conf->exists('cust_main-auto_standardize_address') ) {
85 standardize_address();
89 // popup a confirmation popup
92 '<CENTER><BR><B>Confirm address standardization</B><BR><BR>' +
97 confirm_change = confirm_change +
98 '<TR><TH>Entered billing address</TH>' +
99 '<TH>Standardized billing address</TH></TR>';
100 // + '<TR><TD> </TD><TD> </TD></TR>';
102 if ( argsHash['company'] || argsHash['new_company'] ) {
103 confirm_change = confirm_change +
104 '<TR><TD>' + argsHash['company'] +
105 '</TD><TD>' + argsHash['new_company'] + '</TD></TR>';
108 confirm_change = confirm_change +
109 '<TR><TD>' + argsHash['address1'] +
110 '</TD><TD>' + argsHash['new_address1'] + '</TD></TR>' +
111 '<TR><TD>' + argsHash['address2'] +
112 '</TD><TD>' + argsHash['new_address2'] + '</TD></TR>' +
113 '<TR><TD>' + argsHash['city'] + ', ' + argsHash['state'] + ' ' + argsHash['zip'] +
114 '</TD><TD>' + argsHash['new_city'] + ', ' + argsHash['new_state'] + ' ' + argsHash['new_zip'] + '</TD></TR>' +
115 '<TR><TD> </TD><TD> </TD></TR>';
119 if ( ship_changed ) {
121 confirm_change = confirm_change +
122 '<TR><TH>Entered service address</TH>' +
123 '<TH>Standardized service address</TH></TR>';
124 // + '<TR><TD> </TD><TD> </TD></TR>';
126 if ( argsHash['ship_company'] || argsHash['new_ship_company'] ) {
127 confirm_change = confirm_change +
128 '<TR><TD>' + argsHash['ship_company'] +
129 '</TD><TD>' + argsHash['new_ship_company'] + '</TD></TR>';
132 confirm_change = confirm_change +
133 '<TR><TD>' + argsHash['ship_address1'] +
134 '</TD><TD>' + argsHash['new_ship_address1'] + '</TD></TR>' +
135 '<TR><TD>' + argsHash['ship_address2'] +
136 '</TD><TD>' + argsHash['new_ship_address2'] + '</TD></TR>' +
137 '<TR><TD>' + argsHash['ship_city'] + ', ' + argsHash['ship_state'] + ' ' + argsHash['ship_zip'] +
138 '</TD><TD>' + argsHash['new_ship_city'] + ', ' + argsHash['new_ship_state'] + ' ' + argsHash['new_ship_zip'] + '</TD></TR>' +
139 '<TR><TD> </TD><TD> </TD></TR>';
143 var addresses = 'address';
145 if ( changed && ship_changed ) {
146 addresses = 'addresses';
147 height = 396; // #what
150 confirm_change = confirm_change +
152 '<BUTTON TYPE="button" onClick="post_standardization();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered ' + addresses + '</BUTTON>' +
154 '<BUTTON TYPE="button" onClick="standardize_address();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized ' + addresses + '</BUTTON>' +
156 '<TR><TD COLSPAN=2 ALIGN="center">' +
157 '<BUTTON TYPE="button" onClick="document.<% $formname %>.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
161 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 );
167 post_standardization();
174 function post_standardization() {
176 var cf = document.<% $formname %>;
178 % if ( $conf->exists('enable_taxproducts') ) {
180 if ( new String(cf.elements['<% $taxpre %>zip'].value).length < 10 )
183 var country_el = cf.elements['<% $taxpre %>country'];
184 var country = country_el.options[ country_el.selectedIndex ].value;
185 var geocode = cf.elements['geocode'].value;
187 if ( country == 'CA' || country == 'US' ) {
189 var state_el = cf.elements['<% $taxpre %>state'];
190 var state = state_el.options[ state_el.selectedIndex ].value;
192 var url = "<% $p %>/misc/choose_tax_location.html" +
193 "?data_vendor=cch-zip" +
194 ";city=" + cf.elements['<% $taxpre %>city'].value +
196 ";zip=" + cf.elements['<% $taxpre %>zip'].value +
197 ";country=" + country +
198 ";geocode=" + geocode +
199 ";formname=" + '<% $formname %>' +
203 OLgetAJAX( url, update_geocode, 300 );
207 cf.elements['geocode'].value = 'DEFAULT';
214 cf.elements['geocode'].value = '';
227 function update_geocode() {
230 set_geocode = function (what) {
232 var cf = document.<% $formname %>;
234 //alert(what.options[what.selectedIndex].value);
235 var argsHash = eval('(' + what.options[what.selectedIndex].value + ')');
236 cf.elements['<% $taxpre %>city'].value = argsHash['city'];
237 setselect(cf.elements['<% $taxpre %>state'], argsHash['state']);
238 cf.elements['<% $taxpre %>zip'].value = argsHash['zip'];
239 cf.elements['geocode'].value = argsHash['geocode'];
246 overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
250 function setselect(el, value) {
252 for ( var s = 0; s < el.options.length; s++ ) {
253 if ( el.options[s].value == value ) {
254 el.selectedIndex = s;
262 my $conf = new FS::Conf;
266 my $formname = $opt{form} || 'CustomerForm';
267 my $onlyship = $opt{onlyship} || '';
268 my $main_prefix = $opt{main_prefix} || '';
269 my $ship_prefix = $opt{ship_prefix} || ($onlyship ? '' : 'ship_');
270 my $taxpre = $main_prefix;
271 $taxpre = $ship_prefix if ( $conf->exists('tax-ship_address') || $onlyship );
272 my $post_geocode = $opt{callback} || 'post_geocode();';
273 $withfirm = 0 if $opt{no_company};