3 % $opt{'field_name'} ||= 'custnum';
6 % if ( $opt{'value'} ) {
7 % $cust_main = qsearchs(
8 % 'table' => 'cust_main',
9 % 'hashref' => { 'custnum' => $opt{'value'} },
10 % 'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql,
16 <INPUT TYPE="hidden" NAME="<% $opt{'field_name'} %>" VALUE="<% $opt{'value'} %>">
18 <!-- some false laziness w/ misc/batch-cust_pay.html, though not as bad as i'd thought at first... -->
20 <INPUT TYPE="text" NAME="<% $opt{'field_name'} %>_search" ID="<% $opt{'field_name'} %>_search" SIZE="32" VALUE="<% $cust_main ? $cust_main->name : '(cust #, name or company)' %>" onFocus="clearhint_<% $opt{'field_name'} %>_search(this);" onClick="clearhint_<% $opt{'field_name'} %>_search(this);" onChange="smart_<% $opt{'field_name'} %>_search(this);">
22 <SELECT NAME="<% $opt{'field_name'} %>_select" ID="<% $opt{'field_name'} %>_select" STYLE="color:#ff0000; display:none" onChange="select_<% $opt{'field_name'} %>(this);">
25 <% include('/elements/xmlhttp.html',
26 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi',
27 'subs' => [ 'smart_search' ],
31 <SCRIPT TYPE="text/javascript">
33 function clearhint_<% $opt{'field_name'} %>_search (what) {
35 what.style.color = '#000000';
37 if ( what.value == '(cust #, name or company)' )
40 if ( what.value.indexOf('Customer not found: ') == 0 )
41 what.value = what.value.substr(20);
45 function smart_<% $opt{'field_name'} %>_search(what) {
47 var customer = what.value;
49 if ( customer == 'searching...' || customer == ''
50 || customer.indexOf('Customer not found: ') == 0 )
53 if ( what.getAttribute('magic') == 'nosearch' ) {
54 what.setAttribute('magic', '');
58 //what.value = 'searching...'
60 what.style.color= '#000000';
61 what.style.backgroundColor = '#dddddd';
63 var customer_select = document.getElementById('<% $opt{'field_name'} %>_select');
65 //alert("search for customer " + customer);
67 function <% $opt{'field_name'} %>_search_update(customers) {
69 //alert('customers returned: ' + customers);
71 var customerArray = eval('(' + customers + ')');
73 what.disabled = false;
74 what.style.backgroundColor = '#ffffff';
76 if ( customerArray.length == 0 ) {
78 what.form.<% $opt{'field_name'} %>.value = '';
80 what.value = 'Customer not found: ' + what.value;
81 what.style.color = '#ff0000';
83 what.style.display = '';
84 customer_select.style.display = 'none';
86 } else if ( customerArray.length == 1 ) {
88 //alert('one customer found: ' + customerArray[0]);
90 what.form.<% $opt{'field_name'} %>.value = customerArray[0][0];
91 what.value = customerArray[0][1];
93 what.style.display = '';
94 customer_select.style.display = 'none';
98 //alert('multiple customers found, have to create select dropdown');
100 //blank the current list
101 for ( var i = customer_select.length; i >= 0; i-- )
102 customer_select.options[i] = null;
104 opt(customer_select, '', 'Multiple customers match "' + customer + '" - select one', '#ff0000');
106 //add the multiple customers
107 for ( var s = 0; s < customerArray.length; s++ )
108 opt(customer_select, customerArray[s][0], customerArray[s][1], '#000000');
110 opt(customer_select, 'cancel', '(Edit search string)', '#000000');
112 what.style.display = 'none';
113 customer_select.style.display = '';
119 smart_search( customer, <% $opt{'field_name'} %>_search_update );
124 function select_<% $opt{'field_name'} %> (what) {
126 var custnum = what.options[what.selectedIndex].value;
127 var customer = what.options[what.selectedIndex].text;
129 var customer_obj = document.getElementById('<% $opt{'field_name'} %>_search');
131 if ( custnum == '' ) {
132 //what.style.color = '#ff0000';
134 } else if ( custnum == 'cancel' ) {
136 customer_obj.style.color = '#000000';
138 what.style.display = 'none';
139 customer_obj.style.display = '';
140 customer_obj.focus();
144 what.form.<% $opt{'field_name'} %>.value = custnum;
146 customer_obj.value = customer;
147 customer_obj.style.color = '#000000';
149 what.style.display = 'none';
150 customer_obj.style.display = '';
156 function opt(what,value,text,color) {
157 var optionName = new Option(text, value, false, false);
158 optionName.style.color = color;
159 var length = what.length;
160 what.options[length] = optionName;