function updatePriceList(id,mode,url)
{
	if (mode=='price')
	{
		parsedValue = updatePrice(id);
	} 
	else if (mode=='time')
	{
		parsedValue = updateTime(id);
	}
	else if (mode=='unit')
	{
		parsedValue = updateUnit(id);
	}
	
	//showTick(id);
	
	url = url.slice(0,url.length-1)
	
	url = url+parsedValue.toString().replace('.',',');
	
	new Ajax.Request(url, { asynchronous:true, evalScripts:true }); 
	
	return false;
}

// called when price updated
function updatePrice(id)
{
	priceElement = $('price_'+id);
	if(priceElement == null)
	{
		priceElement = $(id);	
	}
	
	value = parseFloat(priceElement.value.replace(',','.')) + '';
	var pos = value.indexOf('.');
	value = value.substring(0,pos >= 0 ? pos + 3 : value.length);
	
	if (value <= 0)
	{
		// value has been sent to 0
		priceElement.value = '';
		
		return value;
	}
	
	if (isNaN(value))
	{		
		// value has been incorrectly set
		value = 0;
		
		priceElement.value = '';
		
		return value;
	}
	priceElement.value = value.replace('.',',');
	
	return value;	
}

//called when realisation time is updated
function updateTime(id)
{
	timeElement = $('time_'+id);
	if(timeElement == null)
	{
		timeElement = $(id);	
	}
	
	value = parseInt(timeElement.value);
	
	if (value<=0)
	{
		// value has been sent to 0
		timeElement.value = '';
				
		return value;
	}
	
	if (isNaN(value))
	{		
		// value has been incorrectly set
		value = 0;
		
		timeElement.value = '';		
		
		return value;
	}
	
	timeElement.value = value;
	
	return value;		
}

//called when realisation time is updated
function updateUnit(id)
{
	element = $('time_unit_'+id); 
	
	value = element.value;
	
	return value;	
}

// shows tick when inserted price item is ok
// it means that price is not zero and time is not 0
function showTick(id)
{
	price = parseFloat(document.getElementById('price_'+id).value);
	
	time = parseFloat(document.getElementById('time_'+id).value);
	
	if (!isNaN(price) /*&& !isNaN(time)*/ && price != 0 /*&& time != 0*/)
	{
		$('price_item_'+id).className = 'ok';
	}
	else
	{				
		$('price_item_'+id).className = '';
	}
	
	return;
}

// shows ticks for all elements specified in the array
function showTicks(arr)
{
	arr = eval('(' + arr + ')');
	
	for (var i = 0; i < arr.length; i++)
	{
		showTick(arr[i]);
	}
}
