var accCount = [];
var previous_r = "";
var previous_w = null;
var chosen = "";
var chosenClassName = "";
var models = [];
var maxAccTypes = 4;
  if( normalColor==undefined )
    var normalColor="#000000";
  if( awayColor==undefined )
    var awayColor="#ccccd1";
function res()
{ 
	document.vero.reset(); 
} 
if(window.addEventListener )
{
	addEventListener("unload", res, false );
}
function handleRow( num, useDiscount, weight, unid )
{
	if(previous_w) document.getElementById(previous_w).className = chosenClassName;
	
	chosenClassName = document.getElementById( 'row_'+num ).className;
	chosenClassName=chosenClassName.replace("_hover","")
	//asetetaan rivi
	if( previous_r.length > 0 )
	{
		//window.status=previous_r+" "+previous_w+" "+ chosenClassName;
		document.getElementById(previous_r).checked = false;
	}
	document.getElementById( 'r_'+num ).checked = true;
	previous_r = "r_"+num;
	previous_w = "row_"+num;
	document.getElementById( 'row_'+num ).className = chosenClassName+"_hover";
	chosen = num;
  // haetaan CO2 ja lasketaan veroprosentti
  var thisCO2 = document.getElementById( 'CO2_'+num ).value;
  var taxPros = 0;
  if( thisCO2 != null )
    taxPros = Math.round( (4.88 + 0.122 * thisCO2)*10 ) / 10;
  if( useDiscount )
  {
	countweight = 50 * ( Math.floor( weight/50 - 0.0001 ) + 1 );
	minus = Math.round( (Math.pow( (countweight-2500)/100, 0.34 ) * 8.54 ) * 10 ) / 10;
	taxPros = taxPros - minus;
  }
  var originalPrice = 0;
  var tax = 0;
  var ylva = 0;
  var taxValue = 0;
  var sumPrice = 0;
  var id = '';
  // lasketaan ja kirjoitetaan jokaiseen varusteeseen
  for( vt=1; vt<=maxAccTypes; vt++ )
  {
    for( i=1; i<=accCount[vt]; i++ )
    {
       id = vt.toString()+"_"+i.toString();
       if( models[id] == undefined || models[id].indexOf( unid )>-1 )
       {
         originalPrice = document.getElementById( 'accPrice_'+vt+'_'+i ).value;
         if( originalPrice != null )
         {
           ylva = originalPrice * 0.945;
           taxValue = Math.round( (ylva / (1- taxPros/100) )*100 ) / 100;
           tax = Math.floor( (taxValue * taxPros / 100)*100 ) / 100;
           sumPrice = Math.round( (originalPrice*1 + tax*1)*100 ) / 100;
           if( models[id] != undefined )
           {
             document.getElementById( 'p_'+vt+'_'+i ).style.color = normalColor;
             document.getElementById( 't_'+vt+'_'+i ).style.color = normalColor;
           }
           document.getElementById( 'accTax_'+vt+'_'+i ).innerHTML = tax.toFixed(2).replace('.', ',');
           document.getElementById( 'accSum_'+vt+'_'+i ).innerHTML = "<b>"+sumPrice.toFixed(2).replace('.', ',')+"</b>";
         }
       }
       else
       {
           document.getElementById( 'p_'+vt+'_'+i ).style.color = awayColor;
           document.getElementById( 't_'+vt+'_'+i ).style.color = awayColor;
           document.getElementById( 'accTax_'+vt+'_'+i ).innerHTML = "&nbsp;";
           document.getElementById( 'accSum_'+vt+'_'+i ).innerHTML = "&nbsp;";
       }
    }
  }  
  // selite
  document.getElementById( 'taxexpl' ).innerHTML = "Autoveron perusteena valitsemasi auton \""+document.getElementById("n_"+num).innerHTML+"\" CO<sub>2</sub>-päästö "+thisCO2+" g/km.";
}

