// ----------------------------------------------------
var itemSelectHandler = function (sType, aArgs) {
YAHOO.log(sType); //this is a string representing the event;
//e.g., "itemSelectEvent"
var oMyAcInstance = aArgs[0]; // your AutoComplete instance
var elListItem = aArgs[1]; //the
element selected in the suggestion
//container
var aData = aArgs[2]; //array of the data for the item as returned by the DataSource
var my_input_id = aArgs[0]._elTextbox.id;
var my_product_code_reg_exp = /product-code/g;
var my_product_code_search = my_input_id.search(my_product_code_reg_exp);
var my_product = my_input_id.substring(0, my_product_code_search - 1);
send_data(my_product, 'product-code');
}; // var itemSelectHandler = function (sType, aArgs) {
// ----------------------------------------------------
function set_values (return_data) {
//alert(return_data);
my_product = return_data.product.replace(/_/g, '-');
my_form_id = my_product + '-form';
my_form = document.getElementById(my_form_id);
my_product_code_element_id = my_product + '-product-code';//alert(my_product_code_element_id);
my_product_code_element = document.getElementById(my_product_code_element_id);
selections = return_data.selections;
potential_values = return_data.potential_values;
product_code = selections.product_code;
my_product_code_element.value = product_code;
my_add_button_id = my_product + '-add-button';
my_add_button = document.getElementById(my_add_button_id);
my_pdf_button_id = my_product + '-pdf';
my_pdf_button = document.getElementById(my_pdf_button_id);
if (product_code != '') {
my_add_button.style.display = 'block';
my_pdf_button.style.display = 'block';
} else {
my_add_button.style.display = 'none';
my_pdf_button.style.display = 'none';
}
for (var potential_values_key in potential_values) {
// example: ultrasteel-stud-web-text-select-depend
select_id = my_product + '-' + potential_values_key.replace(/_/g, '-') + '-select-depend';
my_select = document.getElementById(select_id);
select_values = potential_values[potential_values_key];
my_select.options.length = 0;
my_select.options[0] = new Option ('Choose...', '');
for (i = 0; i < select_values.length; i++) {
new_value = select_values[i];
my_select.options[i + 1] = new Option (select_values[i], select_values[i]);
if (new_value == selections[potential_values_key]) {
my_select.selectedIndex = i + 1;
} // if
} // for
} // for
disable_form_elements(my_product, false);
if ((return_data.change_key == 'product_code') && (product_code == '')) {
alert ('Product code not found.');
}
} // function set_values ()
// ----------------------------------------------------
var returning_data = {
// Successful XHR response handler
success : function (o) {
var return_data = [];
// Use the JSON Utility to parse the data returned from the server
try {
return_data = YAHOO.lang.JSON.parse(o.responseText);
} catch (x) {
alert('Error processing product data. Please inform support.');
return;
}
set_values(return_data);
}, // success : function (o) {
failure : function (o) {
if (!YAHOO.util.Connect.isCallInProgress(o)) {
// Causes error if you try to navigate to another page before the responses are returned from ajax.php.
// alert('Error retrieving product data. Please inform support.');
}
}, // failure : function (o) {
timeout : 20000
}; // var returning_data = {
// ----------------------------------------------------
function send_data (my_product, my_change_key) {
my_form_id = my_product + '-form';
disable_form_elements(my_product, true);
my_form = document.getElementById(my_form_id);
my_product_code_element_id = my_product + '-product-code';
my_product_code_element = document.getElementById(my_product_code_element_id);
if (my_change_key == 'initialize') {
my_send_product_code = '';
} else {
my_send_product_code = my_product_code_element.value
}
send_array = {
'product' : my_product.replace(/-/g, '_'),
'change_key' : my_change_key.replace(/-/g, '_'),
'selections' : {
'product_code' : my_send_product_code
}
};
for (i = 0; i < my_form.length; i ++) {
e = my_form.elements[i];
my_id = new String(e.id);
select_depend_reg_exp = /select-depend/g;
select_name_begin = my_product.length;
select_depend_search = my_id.search(select_depend_reg_exp);
if (select_depend_search >= 0) {
my_selector_name = my_id.substring(select_name_begin + 1, select_depend_search - 1);
if (my_change_key == 'initialize') {
send_array.selections[my_selector_name.replace(/-/g, '_')] = '';
} else {
send_array.selections[my_selector_name.replace(/-/g, '_')] = e.value;
} // if
} // if
} // for
var jsonStr = YAHOO.lang.JSON.stringify(send_array);//alert(jsonStr);
YAHOO.util.Connect.asyncRequest('POST',"ajax.php", returning_data, 'send_array=' + escape(jsonStr));
} // function send_data () {
// ----------------------------------------------------