var totalCostBefore = '';
var totalCostAfter = '';
var deliveryCost = '';
var radioTrue = false;

function updateAmount(url, id, element_id, method)
{
	options = {method:'post',postBody:'product_id='+id+'&method='+method}
	
	new Ajax.Updater(document.getElementById(element_id), url, options);
}

function updateSubtotal(url, id, eid, con)
{
	options = {method:'post',postBody:'product_id='+id}
	
	new Ajax.Updater(document.getElementById('subtotal['+eid+']['+con+']'), url, options);
}

function updateTotal(url, payment_id, delivery_id)
{
	options = {method:'post', postBody:'delivery_id='+delivery_id+'&payment_id='+payment_id };
				
	new Ajax.Updater(document.getElementById('total_price'), url, options);
	
	document.getElementById('checkout_button').disabled = "";
}

function checkUsername(url, name)
{
	options = {method:'post',postBody:'client_identification='+name, onSuccess: function(t) { colorUsername(t.responseText) }}
	
	new Ajax.Request(url, options);
}

function checkAV() {
	if ( $F('av') == 'true' ) {
		document.order_complete.submit();
	} else {
		new Effect.Highlight('av_box', { startcolor : '#ffaeae' } );
	}
}

function confiUpdatePrice(url, product_id)
{
	var option_id = new Object();
	var option_id;
	var sendVar = '';
	var x = 0;
	
	for (i = 0; i < document.getElementsByTagName('input').length; i++)
	{
		if (document.getElementsByTagName('input')[i].type == 'radio')
		{
			if (document.getElementsByTagName('input')[i].checked == true)
			{
				option_id[x] = document.getElementsByTagName('input')[i].value;
				x++;
			}
		}
	}
	
	for (keyVar in option_id)
	{
		sendVar += option_id[keyVar] + ', ';
	}
	
	sendVar = sendVar.substr(0, sendVar.length - 2);
	
	options = {method:'post',postBody:'product_id='+product_id+'&option_ids='+sendVar, onSuccess: function(t) { updateFields(t.responseText) }}
	
	new Ajax.Request(url, options);
}

function updateFields(value)
{
	value = value.split('-');
	
	if (value.length == 2)
	{
		document.getElementById('price_excl').innerHTML = '(&euro; '+value[0]+  ' excl. btw)';
		document.getElementById('price_incl').innerHTML = '&euro; '+value[1];
	}
	else if (value.length)
	{
		document.getElementById('price_old').innerHTML = '&euro; '+value[0];
		document.getElementById('price_new_incl').innerHTML = '&euro; '+value[2];
		document.getElementById('price_new_excl').innerHTML = '(&euro; '+value[1]+  ' excl. btw)';
	}
}
