﻿// *****************************************
// *** AJAX VORSCHLAGSSUCHE FÜR COMMERCE ***
// *****************************************

function autocompleterCallbackCommerce(parameter, query) {
	var suchartid = document.getElementById('suchartid_commerce').value
	var param = document.getElementById('produkte').value
	var bld = document.getElementById('suchbldid_commerce').value
	var meineurl = "/Compnet/Search?p=ajaxsuche&suchartid=PB&suchbldid="+ bld + "&suchwort="+param;
	return meineurl;
}
		
function initAutocompleterCommerce() {
	var meineurl = "/Compnet/Search";
	var suchartid = document.getElementById('suchartid_commerce').value
	new Ajax.Autocompleter('produkte', 'res_produkte', meineurl, { minChars: 4, frequency:0.1, afterUpdateElement: updateONRcommerce, method:'get', callback:function(parameter, query){return autocompleterCallbackCommerce(parameter, query)} } );
}
		
function updateONRcommerce(txt, li) {
	document.getElementById('onr_commerce').value = '';
	document.getElementById('vorreihung').value = '';
						
	document.getElementById('onr_commerce').value = li.childNodes[0].id
	document.getElementById('vorreihung').value = li.childNodes[0].childNodes[0].id
			
	if(document.getElementById('onr_commerce').value.length > 0) {
   			
		if(document.getElementById('vorreihung').value == 'j') {
			window.location = "http://www.compnet.at/Compnet/?p=suche&suchartid=FmP&suchwort=" + encodeURI(document.getElementById('produkte').value) + "&suchonr=" + document.getElementById('onr_commerce').value + "&suchbldid=" + document.getElementById('suchbldid_commerce').value + "&vorr=j";
  	}
  	else {
  		window.location = "http://www.compnet.at/Compnet/?p=suche&suchartid=FmP&suchwort=" + encodeURI(document.getElementById('produkte').value) + "&suchonr=" + document.getElementById('onr_commerce').value + "&suchbldid=" + document.getElementById('suchbldid_commerce').value + "&vorr=n";
  	}
   			
	} else {
	window.location = "http://www.compnet.at/Compnet/?p=suche&suchartid=PB&suchwort=" + encodeURI(document.getElementById('produkte').value) + "&suchbldid=" + document.getElementById('suchbldid_commerce').value;
	}
			
}
		
function resetInput() {
	document.getElementById('onr_commerce').value = '';
	document.getElementById('vorreihung').value = '';
}