function checkQuant(elem, maxQuant) {
    if(isNaN(elem.value) || elem.value < 0) {
        alert('Positive numeric value expected here.');
        elem.value = 0;
        elem.focus();
        return false;
    }
    
    if(maxQuant > 0 && elem.value > maxQuant) {
        alert('Sorry. Only ' + maxQuant + ' product(s) is available.');
        elem.value = maxQuant;
        elem.focus();
        return false;
    }
    
    return true;
}  

function AddItem (field)
{
  field.value++;
}

function SubItem (field)
{
  if (field.value>0) field.value--;
}

function getInt(val) {
	if(!val || val == isNaN(val))
		ret = 0;
	else
		ret = eval(val);

	return ret;
}

function addToBasket (field)
{

  changeBasket (field, field.value);
}

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 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);
   
   setTimeout ('document.location.reload()', 500);
}

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);
}

/*
* Navigator test functions
*/
function isIE() {

    return navigatorName().toLowerCase().indexOf("microsoft internet explorer") != -1;
}

function isNN() {
    return navigatorName().toLowerCase().indexOf("netscape") != -1;
}

function navigatorName() {
    return navigator.appName;
}

function navigatorVersion() {
    return parseFloat(navigator.appVersion);
}

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));
  }
  val1 = roundVal(price,2);
  
  document.getElementById('price_' + id).value = val1;
}

function roundVal(val, scale) {
	scale = Math.pow(10, scale);
	val = Math.round(val * scale) / scale;
	return val;
}