function changePrice(id,value) {    
  var rez=0;
  var allValid = /^[0-9\.]*$/; 
  if(value.length > 0) {
    if(!allValid.test(value)) {
      var old = document.getElementById('amount_' + id).value;
      old=old.substr(0, (old.length)-1);
      document.getElementById('amount_' + id).value = old;
      changePrice(id, old);
    } else {            
      value=parseFloat(value);
      if(value < 1000000 && value >= 0) {
        
        discount_name   = 'div_discount_' + id;
        item_price_name = 'item_price_' + id;
        min_amount_name = 'div_min_amount_' + id;
        
        t = parseFloat(document.getElementById(item_price_name).innerHTML);
        if(value >= parseFloat(document.getElementById(min_amount_name).innerHTML)) {
          if(document.getElementById(discount_name) != null) {
            d = parseFloat(document.getElementById(discount_name).innerHTML);  
            if(d > 0) {
              rez = t * (value - (value * d / 100));
            } else {
              rez = t * v;
            }
          } else {
            rez = t * value;  
          }
        } else {
          rez = 0;
        }
      }   
      //alert(sprintf("%01.2f",parseFloat(rez)));
      rez2=rez;
      rez=Math.round(rez*100)/100
      rez=rez.toString();
      var stf=rez.split(".");
      if(!stf[1]) stf[1]="0";
        if(stf[1].length < 3) {
          for(i=stf[1].length; i < 2; i++) stf[1]=stf[1]+'0';
        }

      document.getElementById('p'+id).innerHTML = stf[0]+'.'+stf[1];   
    }
  } else {
    document.getElementById('p'+id).innerHTML = '0.00';
  }
  countTotal();
}

function countTotal() {
	var total_c=0;
	for(i=0; i < 100; i++) {
		if(document.getElementById('p'+i))
		total_c = total_c + parseFloat(document.getElementById('p'+i).innerHTML);
	}
	total_c = Math.round(total_c*100)/100;
	total_cs=total_c.toString();
	var stf=total_cs.split(".");
	if(total_c!=0) {
    if(stf.length > 1) {
		  if(stf[1].length < 3) {
			  for(i=stf[1].length; i < 2; i++) {
          stf[1]=stf[1]+'0';
        }
		  }
    } else {
      stf[1] = '00';
    }
	} else { 
		stf[0]='0';
		stf[1]='00';
	}
	document.getElementById('viso_be_pvm').innerHTML = stf[0]+'.'+stf[1];
	proc=total_c * 0.18;	
	proc = Math.round(proc*100)/100;
	proc_s=proc.toString();
	var stf=proc_s.split(".");
	if(proc!=0) {
    if(stf.length > 1) { 
		  if(stf[1].length < 3) {
			  for(i=stf[1].length; i < 2; i++) stf[1]=stf[1]+'0';
		  }
    } else { 
      stf[1]='00';
    }
	} else { 
		stf[0]='0';
		stf[1]='00';
	}
	document.getElementById('viso_pvm').innerHTML = stf[0]+'.'+stf[1];
	total_cp=total_c + proc;
	total_cp = Math.round(total_cp*100)/100;
	total_cps=total_cp.toString();
	
	var stf=total_cps.split(".");
	if(total_cp!=0) {
    if(stf.length > 1) {
		  if(stf[1].length < 3) {
			  for(i=stf[1].length; i < 2; i++) stf[1]=stf[1]+'0';
		  }
    } else {
      stf[1]='00';
    }
	} else { 
		stf[0]='0';
		stf[1]='00';
	}
	document.getElementById('viso_su_pvm').innerHTML = stf[0]+'.'+stf[1];
	//viso_be_pvm
	//viso_pvm
	//viso_su_pvm
}
