var debug = false;

function updateImage(stockCode)
{
	var oRadio = document.forms[0].elements['stockcode'];

    for(var i = 0; i < oRadio.length; i++) 
    { 
        if(oRadio[i].checked)
        {
            if(oRadio[i].value == stockCode)
            {
               document.getElementById(oRadio[i].value).style.display = 'block';
            }
       }
       else
       {
            document.getElementById(oRadio[i].value).style.display = 'none';
       }
    }
}

function bindPrice()
{
	var quantity = getQuantity();
	var stockCode = getRadioControlValue('stockcode');
	var unitPrice = 0;
	var total = 0;

	// Initialise the users, companies, employees fields.
	getSelectControlValue('users', -1);
	getSelectControlValue('companies', -1);
	getSelectControlValue('employees', -1);
		
	if (stockCode.length > 0 && quantity > 0)
	{
		var evalString = 'break' + stockCode;
		
		if (debug)
			alert(evalString);
			
		var itemArray = eval(evalString);
		
		for (i = 0; i < itemArray.length; i++)
		{												
			var quantityBreakArray = itemArray[i];						
			
			var quantityBreak = quantityBreakArray[0];
			var breakPrice = quantityBreakArray[1];						
								
			//Always set the price.
			//But break when we find a match.
			unitPrice = breakPrice;
			
			if (quantity <= quantityBreak)
			{
				break;
			}
		}
	}
	
	total = quantity * unitPrice;
	total = total.toFixed(2);

	if (debug)
		alert('Total = ' + total);

	var selectedUnitNetControl = getControlByID('selectedunitnet');
	selectedUnitNetControl.value = unitPrice;

	bindTotalPrice(total);
	
	updateImage(stockCode);
}
