3 $opt{'field_name'} ||= 'custnum';
8 'table' => 'cust_main',
9 'hashref' => { 'custnum' => $opt{'value'} },
10 'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql,
15 <INPUT TYPE="hidden" NAME="<%= $opt{'field_name'} %>" VALUE="<%= $opt{'value'} %>">
17 <!-- some false laziness w/ misc/batch-cust_pay.html, though not as bad as i'd thought at first... -->
19 <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);">
21 <SELECT NAME="<%= $opt{'field_name'} %>_select" ID="<%= $opt{'field_name'} %>_select" STYLE="color:#ff0000; display:none" onChange="select_<%= $opt{'field_name'} %>(this);">
24 <%= include('/elements/xmlhttp.html',
25 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi',
26 'subs' => [ 'smart_search' ],
30 <SCRIPT TYPE="text/javascript">
32 function clearhint_<%= $opt{'field_name'} %>_search (what) {
34 what.style.color = '#000000';
36 if ( what.value == '(cust #, name or company)' )
39 if ( what.value.indexOf('Customer not found: ') == 0 )
40 what.value = what.value.substr(20);
44 function smart_<%= $opt{'field_name'} %>_search(what) {
46 var customer = what.value;
48 if ( customer == 'searching...' || customer == ''
49 || customer.indexOf('Customer not found: ') == 0 )
52 if ( what.getAttribute('magic') == 'nosearch' ) {
53 what.setAttribute('magic', '');
57 //what.value = 'searching...'
59 what.style.color= '#000000';
60 what.style.backgroundColor = '#dddddd';
62 var customer_select = document.getElementById('<%= $opt{'field_name'} %>_select');
64 //alert("search for customer " + customer);
66 function <%= $opt{'field_name'} %>_search_update(customers) {
68 //alert('customers returned: ' + customers);
70 var customerArray = eval('(' + customers + ')');
72 what.disabled = false;
73 what.style.backgroundColor = '#ffffff';
75 if ( customerArray.length == 0 ) {
77 what.form.<%= $opt{'field_name'} %>.value = '';
79 what.value = 'Customer not found: ' + what.value;
80 what.style.color = '#ff0000';
82 what.style.display = '';
83 customer_select.style.display = 'none';
85 } else if ( customerArray.length == 1 ) {
87 //alert('one customer found: ' + customerArray[0]);
89 what.form.<%= $opt{'field_name'} %>.value = customerArray[0][0];
90 what.value = customerArray[0][1];
92 what.style.display = '';
93 customer_select.style.display = 'none';
97 //alert('multiple customers found, have to create select dropdown');
99 //blank the current list
100 for ( var i = customer_select.length; i >= 0; i-- )
101 customer_select.options[i] = null;
103 opt(customer_select, '', 'Multiple customers match "' + customer + '" - select one', '#ff0000');
105 //add the multiple customers
106 for ( var s = 0; s < customerArray.length; s++ )
107 opt(customer_select, customerArray[s][0], customerArray[s][1], '#000000');
109 opt(customer_select, 'cancel', '(Edit search string)', '#000000');
111 what.style.display = 'none';
112 customer_select.style.display = '';
118 smart_search( customer, <%= $opt{'field_name'} %>_search_update );
123 function select_<%= $opt{'field_name'} %> (what) {
125 var custnum = what.options[what.selectedIndex].value;
126 var customer = what.options[what.selectedIndex].text;
128 var customer_obj = document.getElementById('<%= $opt{'field_name'} %>_search');
130 if ( custnum == '' ) {
131 //what.style.color = '#ff0000';
133 } else if ( custnum == 'cancel' ) {
135 customer_obj.style.color = '#000000';
137 what.style.display = 'none';
138 customer_obj.style.display = '';
139 customer_obj.focus();
143 what.form.<%= $opt{'field_name'} %>.value = custnum;
145 customer_obj.value = customer;
146 customer_obj.style.color = '#000000';
148 what.style.display = 'none';
149 customer_obj.style.display = '';
155 function opt(what,value,text,color) {
156 var optionName = new Option(text, value, false, false);
157 optionName.style.color = color;
158 var length = what.length;
159 what.options[length] = optionName;