function AddItem (field)
{
  field.value++;
} 

function SubItem (field)
{
  if (field.value>0) field.value--; 
} 
   
function addToBasket (field)
{
  changeBasket (field, field.value);
}    

function changeBasket (field, quant)
{
   id = field.name.substring (field.name.indexOf ('_')+1);
   img = new Image ();
   productId = -1;
   if (id.indexOf('$') != -1) 
            productId = id.substring (id.indexOf('$')+1);
   else
            productId = id;

   img.src='./shop/update_basket.jsp?&quantity=' + quant + '&' + 'mbUpdate=run&cuid=' + Math.random() + '&id=' + productId + getAttributes (id);
   //alert (img.src);
   setTimeout ('document.location.reload()', 500);
}

function incrBasket (field)
{
   changeBasket (field, 1);
}

function descBasket (field)
{
   if (field.value>0) changeBasket (field, -1);
}

function getInt(val) {
	if(!val || val == isNaN(val))
		ret = 0;
	else
		ret = eval(val);
	
	return ret;
}

function roundVal(val, scale) {
	scale = Math.pow(10, scale);
	val = Math.round(val * scale) / scale;
	return val;
}

function recalcProduct (id)
{

  price = parseFloat (eval('price_' + id));
  arr = eval ('attrs_' + id);

  for(i = 0; i < arr.length; i++) {
      price += parseFloat (eval (arr[i].id + '_' + arr[i].value));
  }

  document.getElementById ('price_' + id).value = roundVal(price,2);
}

function getAttributes (id)
{
  arr = eval ('attrs_' + id);
  result = '';

  for(i = 0; i < arr.length; i++) {
     if (arr[i].value != 0) result +=  (',' +  arr[i].value);
  }

  return result;
}

function outputCents(amount) {
    amount = Math.round( ( (amount) - Math.floor(amount) ) *100);
    return (amount < 10 ? '.0' + amount : '.' + amount);
}

function format(val) {
    return Math.floor(val)+outputCents(val);
}



