1 <INPUT TYPE="hidden" NAME="<% $opt{'field_name'} %>" VALUE="<% $value %>">
3 <!-- some false laziness w/ misc/batch-cust_pay.html, though not as bad as i'd thought at first... -->
6 NAME = "<% $opt{'field_name'} %>_search"
7 ID = "<% $opt{'field_name'} %>_search"
9 VALUE="<% $cust_main ? $cust_main->name : '(cust #, name or company)' %>"
10 onFocus="clearhint_<% $opt{'field_name'} %>_search(this);"
11 onClick="clearhint_<% $opt{'field_name'} %>_search(this);"
12 onChange="smart_<% $opt{'field_name'} %>_search(this);"
15 % if ( $opt{'find_button'} ) {
16 <INPUT TYPE = "button"
18 NAME = "<% $opt{'field_name'} %>_findbutton"
19 onClick = "smart_<% $opt{'field_name'} %>_search(this.form.<% $opt{'field_name'} %>_search);"
23 <SELECT NAME="<% $opt{'field_name'} %>_select" ID="<% $opt{'field_name'} %>_select" STYLE="color:#ff0000; display:none" onChange="select_<% $opt{'field_name'} %>(this);">
26 <% include('/elements/xmlhttp.html',
27 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi',
28 'subs' => [ 'smart_search' ],
32 <SCRIPT TYPE="text/javascript">
34 function clearhint_<% $opt{'field_name'} %>_search (what) {
36 what.style.color = '#000000';
38 if ( what.value == '(cust #, name or company)' )
41 if ( what.value.indexOf('Customer not found: ') == 0 )
42 what.value = what.value.substr(20);
46 function smart_<% $opt{'field_name'} %>_search(what) {
48 var customer = what.value;
50 if ( customer == 'searching...' || customer == ''
51 || customer.indexOf('Customer not found: ') == 0 )
54 if ( what.getAttribute('magic') == 'nosearch' ) {
55 what.setAttribute('magic', '');
59 //what.value = 'searching...'
61 what.style.color= '#000000';
62 what.style.backgroundColor = '#dddddd';
64 var customer_select = document.getElementById('<% $opt{'field_name'} %>_select');
66 //alert("search for customer " + customer);
68 function <% $opt{'field_name'} %>_search_update(customers) {
70 //alert('customers returned: ' + customers);
72 var customerArray = eval('(' + customers + ')');
74 what.disabled = false;
75 what.style.backgroundColor = '#ffffff';
77 if ( customerArray.length == 0 ) {
79 what.form.<% $opt{'field_name'} %>.value = '';
81 what.value = 'Customer not found: ' + what.value;
82 what.style.color = '#ff0000';
84 what.style.display = '';
85 customer_select.style.display = 'none';
87 } else if ( customerArray.length == 1 ) {
89 //alert('one customer found: ' + customerArray[0]);
91 what.form.<% $opt{'field_name'} %>.value = customerArray[0][0];
92 what.value = customerArray[0][1];
94 what.style.display = '';
95 customer_select.style.display = 'none';
99 //alert('multiple customers found, have to create select dropdown');
101 //blank the current list
102 for ( var i = customer_select.length; i >= 0; i-- )
103 customer_select.options[i] = null;
105 opt(customer_select, '', 'Multiple customers match "' + customer + '" - select one', '#ff0000');
107 //add the multiple customers
108 for ( var s = 0; s < customerArray.length; s++ )
109 opt(customer_select, customerArray[s][0], customerArray[s][1], '#000000');
111 opt(customer_select, 'cancel', '(Edit search string)', '#000000');
113 what.style.display = 'none';
114 customer_select.style.display = '';
120 smart_search( customer, <% $opt{'field_name'} %>_search_update );
125 function select_<% $opt{'field_name'} %> (what) {
127 var custnum = what.options[what.selectedIndex].value;
128 var customer = what.options[what.selectedIndex].text;
130 var customer_obj = document.getElementById('<% $opt{'field_name'} %>_search');
132 if ( custnum == '' ) {
133 //what.style.color = '#ff0000';
135 } else if ( custnum == 'cancel' ) {
137 customer_obj.style.color = '#000000';
139 what.style.display = 'none';
140 customer_obj.style.display = '';
141 customer_obj.focus();
145 what.form.<% $opt{'field_name'} %>.value = custnum;
147 customer_obj.value = customer;
148 customer_obj.style.color = '#000000';
150 what.style.display = 'none';
151 customer_obj.style.display = '';
157 function opt(what,value,text,color) {
158 var optionName = new Option(text, value, false, false);
159 optionName.style.color = color;
160 var length = what.length;
161 what.options[length] = optionName;
168 $opt{'field_name'} ||= 'custnum';
170 my $value = $opt{'curr_value'} || $opt{'value'};
174 $cust_main = qsearchs({
175 'table' => 'cust_main',
176 'hashref' => { 'custnum' => $value },
177 'extra_sql' => " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql,