function bundle_article_change(article_id,product_id) {
	try {
		bundle_products_ids = document.getElementById('bundle_products_ids').value;

		if(article_id && product_id) {
			document.getElementById('bundle_selected_article['+product_id+']').value = parseInt(article_id);
			document.getElementById('bundle_selected_article_price['+product_id+']').value = parseFloat(document.getElementById('bundle_article_price['+article_id+']').value);
			document.getElementById('bundle_selected_article_ordernumber['+product_id+']').value = document.getElementById('bundle_article_ordernumber['+article_id+']').value;
			document.getElementById('bundle_selected_article_stock_amount['+product_id+']').value = document.getElementById('bundle_article_stock_amount['+article_id+']').value;
			document.getElementById('bundle_product['+product_id+']').value = article_id;
		}
		
		current_article_price = parseFloat(document.getElementById('article_price_plain').value);
		current_article_ordernumber = document.getElementById('article_ordernumber_plain').value;

		bundle_products_ids = bundle_products_ids.split(',');

		var lowset_article_stock = 99999;
		var lowest_stock_article_id = 0;
		
		for( var i =0; i < bundle_products_ids.length; i++) {

			current_article_price = current_article_price + parseFloat(document.getElementById('bundle_selected_article_price['+bundle_products_ids[i]+']').value);
			if(document.getElementById('bundle_selected_article_ordernumber['+bundle_products_ids[i]+']').value != '') {
				current_article_ordernumber = current_article_ordernumber + '-' + document.getElementById('bundle_selected_article_ordernumber['+bundle_products_ids[i]+']').value;
			}

			article_stock_amount = parseInt(document.getElementById('bundle_selected_article_stock_amount['+bundle_products_ids[i]+']').value);
			if(isNaN(article_stock_amount)) article_stock_amount = 0;

			if(article_stock_amount <= lowset_article_stock) {
				lowset_article_stock = document.getElementById('bundle_selected_article_stock_amount['+bundle_products_ids[i]+']').value;
				lowest_stock_article_id = document.getElementById('bundle_selected_article['+bundle_products_ids[i]+']').value;
			}
		}

		if(lowest_stock_article_id != 0 && document.getElementById('article-stock')) {
			document.getElementById('article-stock').innerHTML = document.getElementById('bundle_article_stock['+lowest_stock_article_id+']').value;
		}

		if (document.getElementById('main_product_price_us'))
			document.getElementById('main_product_price_us').innerHTML = formatPrice(current_article_price, '$');
		else
			document.getElementById('main_product_price').innerHTML = formatPrice(current_article_price, '&euro;');
		document.getElementById('main_product_ordernumber').innerHTML = current_article_ordernumber;
		
		
	} catch (err) {
		//alert('FEHLER!\nEs ist ein Fehler aufgetreten [CODE: com_product_bundle#bundle_article_change '+err+']');
	}
}

function formatPrice(price, currency) {

	if (currency == '$')
		price = currency+" " + price.toFixed(2).replace('.',',');
	else
		price = price.toFixed(2).replace('.',',')+" "+currency;

	return price;
}


$(function() {
    // dieser Code wird ausgef�hrt, wenn das
    // HTML-Dokument geladen ist
    bundle_article_change();
});
