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['<% $main_prefix %>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,
22 'ship_company', cf.elements['<% $ship_prefix %>company'].value,
24 'ship_address1', cf.elements['<% $ship_prefix %>address1'].value,
25 'ship_address2', cf.elements['<% $ship_prefix %>address2'].value,
26 'ship_city', cf.elements['<% $ship_prefix %>city'].value,
27 'ship_state', ship_state_el.options[ ship_state_el.selectedIndex ].value,
28 'ship_zip', cf.elements['<% $ship_prefix %>zip'].value
31 address_standardize( address_info, update_address );
35 var standardize_address;
37 function update_address(arg) {
39 var argsHash = eval('(' + arg + ')');
41 var changed = argsHash['address_standardized'];
42 var ship_changed = argsHash['ship_address_standardized'];
43 var error = argsHash['error'];
44 var ship_error = argsHash['ship_error'];
48 standardize_address = function () {
50 var cf = document.<% $formname %>;
51 var state_el = cf.elements['<% $main_prefix %>state'];
52 var ship_state_el = cf.elements['<% $ship_prefix %>state'];
57 cf.elements['<% $main_prefix %>company'].value = argsHash['new_company'];
59 cf.elements['<% $main_prefix %>address1'].value = argsHash['new_address1'];
60 cf.elements['<% $main_prefix %>address2'].value = argsHash['new_address2'];
61 cf.elements['<% $main_prefix %>city'].value = argsHash['new_city'];
62 setselect(cf.elements['<% $main_prefix %>state'], argsHash['new_state']);
63 cf.elements['<% $main_prefix %>zip'].value = argsHash['new_zip'];
69 cf.elements['<% $ship_prefix %>company'].value = argsHash['new_ship_company'];
71 cf.elements['<% $ship_prefix %>address1'].value = argsHash['new_ship_address1'];
72 cf.elements['<% $ship_prefix %>address2'].value = argsHash['new_ship_address2'];
73 cf.elements['<% $ship_prefix %>city'].value = argsHash['new_ship_city'];
74 setselect(cf.elements['<% $ship_prefix %>state'], argsHash['new_ship_state']);
75 cf.elements['<% $ship_prefix %>zip'].value = argsHash['new_ship_zip'];
78 post_standardization();
84 if ( changed || ship_changed ) {
86 % if ( $conf->exists('cust_main-auto_standardize_address') ) {
88 standardize_address();
92 // popup a confirmation popup
95 '<CENTER><BR><B>Confirm address standardization</B><BR><BR>' +
100 confirm_change = confirm_change +
101 '<TR><TH>Entered billing address</TH>' +
102 '<TH>Standardized billing address</TH></TR>';
103 // + '<TR><TD> </TD><TD> </TD></TR>';
105 if ( argsHash['company'] || argsHash['new_company'] ) {
106 confirm_change = confirm_change +
107 '<TR><TD>' + argsHash['company'] +
108 '</TD><TD>' + argsHash['new_company'] + '</TD></TR>';
111 confirm_change = confirm_change +
112 '<TR><TD>' + argsHash['address1'] +
113 '</TD><TD>' + argsHash['new_address1'] + '</TD></TR>' +
114 '<TR><TD>' + argsHash['address2'] +
115 '</TD><TD>' + argsHash['new_address2'] + '</TD></TR>' +
116 '<TR><TD>' + argsHash['city'] + ', ' + argsHash['state'] + ' ' + argsHash['zip'] +
117 '</TD><TD>' + argsHash['new_city'] + ', ' + argsHash['new_state'] + ' ' + argsHash['new_zip'] + '</TD></TR>' +
118 '<TR><TD> </TD><TD> </TD></TR>';
122 if ( ship_changed ) {
124 confirm_change = confirm_change +
125 '<TR><TH>Entered service address</TH>' +
126 '<TH>Standardized service address</TH></TR>';
127 // + '<TR><TD> </TD><TD> </TD></TR>';
129 if ( argsHash['ship_company'] || argsHash['new_ship_company'] ) {
130 confirm_change = confirm_change +
131 '<TR><TD>' + argsHash['ship_company'] +
132 '</TD><TD>' + argsHash['new_ship_company'] + '</TD></TR>';
135 confirm_change = confirm_change +
136 '<TR><TD>' + argsHash['ship_address1'] +
137 '</TD><TD>' + argsHash['new_ship_address1'] + '</TD></TR>' +
138 '<TR><TD>' + argsHash['ship_address2'] +
139 '</TD><TD>' + argsHash['new_ship_address2'] + '</TD></TR>' +
140 '<TR><TD>' + argsHash['ship_city'] + ', ' + argsHash['ship_state'] + ' ' + argsHash['ship_zip'] +
141 '</TD><TD>' + argsHash['new_ship_city'] + ', ' + argsHash['new_ship_state'] + ' ' + argsHash['new_ship_zip'] + '</TD></TR>' +
142 '<TR><TD> </TD><TD> </TD></TR>';
146 var addresses = 'address';
148 if ( changed && ship_changed ) {
149 addresses = 'addresses';
150 height = 396; // #what
153 confirm_change = confirm_change +
155 '<BUTTON TYPE="button" onClick="post_standardization();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered ' + addresses + '</BUTTON>' +
157 '<BUTTON TYPE="button" onClick="standardize_address();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized ' + addresses + '</BUTTON>' +
159 '<TR><TD COLSPAN=2 ALIGN="center">' +
160 '<BUTTON TYPE="button" onClick="document.<% $formname %>.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
164 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 );
170 post_standardization();
177 function post_standardization() {
179 var cf = document.<% $formname %>;
181 % if ( $conf->exists('enable_taxproducts') ) {
183 if ( new String(cf.elements['<% $taxpre %>zip'].value).length < 10 )
186 var country_el = cf.elements['<% $taxpre %>country'];
187 var country = country_el.options[ country_el.selectedIndex ].value;
188 var geocode = cf.elements['geocode'].value;
190 if ( country == 'CA' || country == 'US' ) {
192 var state_el = cf.elements['<% $taxpre %>state'];
193 var state = state_el.options[ state_el.selectedIndex ].value;
195 var url = "<% $p %>/misc/choose_tax_location.html" +
196 "?data_vendor=cch-zip" +
197 ";city=" + cf.elements['<% $taxpre %>city'].value +
199 ";zip=" + cf.elements['<% $taxpre %>zip'].value +
200 ";country=" + country +
201 ";geocode=" + geocode +
202 ";formname=" + '<% $formname %>' +
206 OLgetAJAX( url, update_geocode, 300 );
210 cf.elements['geocode'].value = 'DEFAULT';
217 cf.elements['geocode'].value = '';
230 function update_geocode() {
233 set_geocode = function (what) {
235 var cf = document.<% $formname %>;
237 //alert(what.options[what.selectedIndex].value);
238 var argsHash = eval('(' + what.options[what.selectedIndex].value + ')');
239 cf.elements['<% $taxpre %>city'].value = argsHash['city'];
240 setselect(cf.elements['<% $taxpre %>state'], argsHash['state']);
241 cf.elements['<% $taxpre %>zip'].value = argsHash['zip'];
242 cf.elements['geocode'].value = argsHash['geocode'];
249 overlib( OLresponseAJAX, CAPTION, 'Select tax location', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
253 function setselect(el, value) {
255 for ( var s = 0; s < el.options.length; s++ ) {
256 if ( el.options[s].value == value ) {
257 el.selectedIndex = s;
265 my $conf = new FS::Conf;
269 my $formname = $opt{form} || 'CustomerForm';
270 my $onlyship = $opt{onlyship} || '';
271 my $main_prefix = $opt{main_prefix} || '';
272 my $ship_prefix = $opt{ship_prefix} || ($onlyship ? '' : 'ship_');
273 my $taxpre = $main_prefix;
274 $taxpre = $ship_prefix if ( $conf->exists('tax-ship_address') || $onlyship );
275 my $post_geocode = $opt{callback} || 'post_geocode();';
276 $withfirm = 0 if $opt{no_company};