summaryrefslogtreecommitdiff
path: root/httemplate/edit/cust_main/bottomfixup.js
blob: 4d9ef070dcc10c8ff901f1d6c7e3d0ea8c5bd251 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function bottomfixup(what) {

%# ../cust_main.cgi
  var layervars = new Array(
    'payauto',
    'payinfo', 'payinfo1', 'payinfo2', 'paytype',
    'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
    'paystart_month', 'paystart_year', 'payissue',
    'payip',
    'paid'
  );

  var cf = document.CustomerForm;
  var payby = cf.payby.options[cf.payby.selectedIndex].value;
  for ( f=0; f < layervars.length; f++ ) {
    var field = layervars[f];
    copyelement( cf.elements[payby + '_' + field],
                 cf.elements[field]
               );
  }

  //this part does USPS address correction
  standardize_locations();

}

<% include( '/elements/standardize_locations.js',
            'callback', 'post_geocode();'
          )
%>

function post_geocode() {

% if ( $conf->exists('cust_main-require_censustract') ) {

  //alert('fetch census tract data');
  var cf = document.CustomerForm;
  var state_el = cf.elements['ship_state'];
  var census_data = new Array(
    'year',   <% $conf->config('census_year') || '2009' %>,
    'address', cf.elements['ship_address1'].value,
    'city',    cf.elements['ship_city'].value,
    'state',   state_el.options[ state_el.selectedIndex ].value,
    'zip',     cf.elements['ship_zip'].value
  );

  censustract( census_data, update_censustract );

% }else{

  document.CustomerForm.submit();

% }

}

function copyelement(from, to) {
  if ( from == undefined ) {
    to.value = '';
  } else if ( from.type == 'select-one' ) {
    to.value = from.options[from.selectedIndex].value;
    //alert(from + " (" + from.type + "): " + to.name + " => (" + from.selectedIndex + ") " + to.value);
  } else if ( from.type == 'checkbox' ) {
    if ( from.checked ) {
      to.value = from.value;
    } else {
      to.value = '';
    }
  } else {
    if ( from.value == undefined ) {
      to.value = '';
    } else {
      to.value = from.value;
    }
  }
  //alert(from + " (" + from.type + "): " + to.name + " => " + to.value);
}

<%init>

my $conf = new FS::Conf;

</%init>