import torrus 1.0.9
[freeside.git] / httemplate / edit / cust_main / bottomfixup.js
1 function bottomfixup(what) {
2
3 %# ../cust_main.cgi
4   var layervars = new Array(
5     'payauto',
6     'payinfo', 'payinfo1', 'payinfo2', 'paytype',
7     'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
8     'paystart_month', 'paystart_year', 'payissue',
9     'payip',
10     'paid'
11   );
12
13   var cf = document.CustomerForm;
14   var payby = cf.payby.options[cf.payby.selectedIndex].value;
15   for ( f=0; f < layervars.length; f++ ) {
16     var field = layervars[f];
17     copyelement( cf.elements[payby + '_' + field],
18                  cf.elements[field]
19                );
20   }
21
22   //this part does USPS address correction
23   standardize_locations();
24
25 }
26
27 <% include( '/elements/standardize_locations.js',
28             'callback', 'post_geocode();'
29           )
30 %>
31
32 function post_geocode() {
33
34 % if ( $conf->exists('cust_main-require_censustract') ) {
35
36   //alert('fetch census tract data');
37   var cf = document.CustomerForm;
38   var state_el = cf.elements['ship_state'];
39   var census_data = new Array(
40     'year',   <% $conf->config('census_year') || '2009' %>,
41     'address', cf.elements['ship_address1'].value,
42     'city',    cf.elements['ship_city'].value,
43     'state',   state_el.options[ state_el.selectedIndex ].value,
44     'zip',     cf.elements['ship_zip'].value
45   );
46
47   censustract( census_data, update_censustract );
48
49 % }else{
50
51   document.CustomerForm.submit();
52
53 % }
54
55 }
56
57 var set_censustract;
58
59 function update_censustract(arg) {
60
61   var argsHash = eval('(' + arg + ')');
62
63   var cf = document.CustomerForm;
64
65   var msacode    = argsHash['msacode'];
66   var statecode  = argsHash['statecode'];
67   var countycode = argsHash['countycode'];
68   var tractcode  = argsHash['tractcode'];
69   var error      = argsHash['error'];
70   
71   var newcensus = 
72     new String(statecode)  +
73     new String(countycode) +
74     new String(tractcode).replace(/\s$/, '');  // JSON 1 workaround
75
76   set_censustract = function () {
77
78     cf.elements['censustract'].value = newcensus
79     cf.submit();
80
81   }
82
83   if (error || cf.elements['censustract'].value != newcensus) {
84     // popup an entry dialog
85
86     if (error) { newcensus = error; }
87     newcensus.replace(/.*ndefined.*/, 'Not found');
88
89     var choose_censustract =
90       '<CENTER><BR><B>Confirm censustract</B><BR>' +
91       '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
92       'census_year=<% $conf->config('census_year') || '2008' %>' +
93       '&latitude=' + cf.elements['latitude'].value +
94       '&longitude=' + cf.elements['longitude'].value +
95       '" target="_blank">Map service module location</A><BR>' +
96       '<A href="http://maps.ffiec.gov/FFIECMapper/TGMapSrv.aspx?' +
97       'census_year=<% $conf->config('census_year') || '2008' %>' +
98       '&zip_code=' + cf.elements['ship_zip'].value +
99       '" target="_blank">Map zip code center</A><BR><BR>' +
100       '<TABLE>';
101     
102     choose_censustract = choose_censustract + 
103       '<TR><TH style="width:50%">Entered census tract</TH>' +
104         '<TH style="width:50%">Calculated census tract</TH></TR>' +
105       '<TR><TD>' + cf.elements['censustract'].value +
106         '</TD><TD>' + newcensus + '</TD></TR>' +
107         '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>';
108
109     choose_censustract = choose_censustract +
110       '<TR><TD ALIGN="center">' +
111         '<BUTTON TYPE="button" onClick="document.CustomerForm.submit();"><IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract </BUTTON>' + 
112       '</TD><TD ALIGN="center">' +
113         '<BUTTON TYPE="button" onClick="set_censustract();"><IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract </BUTTON>' + 
114       '</TD></TR>' +
115       '<TR><TD COLSPAN=2 ALIGN="center">' +
116         '<BUTTON TYPE="button" onClick="document.CustomerForm.submitButton.disabled=false; parent.cClick();"><IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission</BUTTON></TD></TR>' +
117         
118       '</TABLE></CENTER>';
119
120     overlib( choose_censustract, CAPTION, 'Confirm censustract', STICKY, AUTOSTATUSCAP, CLOSETEXT, '', MIDX, 0, MIDY, 0, DRAGGABLE, WIDTH, 576, HEIGHT, 268, BGCOLOR, '#333399', CGCOLOR, '#333399', TEXTSIZE, 3 );
121
122   } else {
123
124     cf.submit();
125
126   }
127
128 }
129
130 function copyelement(from, to) {
131   if ( from == undefined ) {
132     to.value = '';
133   } else if ( from.type == 'select-one' ) {
134     to.value = from.options[from.selectedIndex].value;
135     //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
136   } else if ( from.type == 'checkbox' ) {
137     if ( from.checked ) {
138       to.value = from.value;
139     } else {
140       to.value = '';
141     }
142   } else {
143     if ( from.value == undefined ) {
144       to.value = '';
145     } else {
146       to.value = from.value;
147     }
148   }
149   //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
150 }
151
152 <%init>
153
154 my $conf = new FS::Conf;
155
156 </%init>