function calculeaza() {
var vrtaxa =1;
var vform = 1;
var i=0;
var Avar = 0;
var Bvar = 0;
var Cvar = 0 ;
var Dvar = 0 ;
var Evar = 0 ;
var co2 = 0;
var taxaluc = 0;
var taxaluc2 = 0;
var a1c2 = new Array(7);
var a1c3 = new Array(7);
var a2c2 = new Array(6);
var a2c3 = new Array(44);
var a3c2 = new Array(6);
var a4c2 = new Array(20);
var nr1 = 0;
var nr2 = 0;
var vcategorie =0
var vcapacitate = 0;
var vnorma = 0;
var vvarsta = 0;
var vemisie = null;
var varll =0;
//--->
a1c2[0] = 120;
a1c2[1] = 150;
a1c2[2] = 180;
a1c2[3] = 210;
a1c2[4] = 240;
a1c2[5] = 270;
a1c2[6] = 271999;
a1c3[0] = 0;
a1c3[1] = 0.5;
a1c3[2] = 1.0;
a1c3[3] = 2.0;
a1c3[4] = 4.0;
a1c3[5] = 6.0;
a1c3[6] = 8.0;
//-->
a2c2[0] = 1400;
a2c2[1] = 1600;
a2c2[2] = 2000;
a2c2[3] = 2500;
a2c2[4] = 3000;
a2c2[5] = 30009999;
a2c3[1] = 0.20;
a2c3[2] = 0.30;
a2c3[3] = 0.40;
a2c3[4] = 0.60;
a2c3[5] = 0.80;
a2c3[6] = 1.00;
a2c3[7] = 0.65;
a2c3[8] = 1.00;
a2c3[9] = 1.30;
a2c3[10] = 1.90;
a2c3[11] = 2.50;
a2c3[12] = 3.00;
a2c3[13] = 1.70;
a2c3[14] = 2.60;
a2c3[15] = 3.30;
a2c3[16] = 5.00;
a2c3[17] = 7.00;
a2c3[18] = 8.00;
a2c3[19] = 3.50;
a2c3[20] = 5.50;
a2c3[21] = 7.00;
a2c3[22] = 10.00;
a2c3[23] = 14.00;
a2c3[24] = 16.00;
a2c3[25] = 10.50;
a2c3[26] = 16.50;
a2c3[27] = 21.00;
a2c3[28] = 30.00;
a2c3[29] = 42.00;
a2c3[30] = 48.00;
//-->
a3c2[0] = 0.03 ;
a3c2[1] = 0.1 ;
a3c2[2] = 0.3 ;
a3c2[3] = 1 ;
a3c2[4] = 3 ;
a3c2[5] = 9 ;

//-->
a4c2[0] = 0;
a4c2[1] = 3;
a4c2[2] = 5;
a4c2[3] = 8;
a4c2[4] = 10;
a4c2[5] = 13;
a4c2[6] = 21;
a4c2[7] = 28;
a4c2[8] = 33;
a4c2[9] = 38;
a4c2[10] = 43;
a4c2[11] = 49;
a4c2[12] = 55;
a4c2[13] = 61;
a4c2[14] = 66;
a4c2[15] = 73;
a4c2[16] = 79;
a4c2[17] = 84;
a4c2[18] = 89;
a4c2[19] = 93;
a4c2[20] = 95;
//-->


vcategorie = 0;
vcapacitate = Number(document.getElementById('capacitate').value);
vnorma = Number(document.getElementById('norma').value);
vvarsta = Number(document.getElementById('varsta').value);
vemisie = Number(document.getElementById('emisie').value);

if (document.getElementById('filtru').value == 1 )
	vrtaxa= 0.75;
else
   vrtaxa=1;


//-->  CALCUL  Nivel taxa emisie in functie de Emisia de dioxid
//--> Se calculeaza numai pentru categoria M1
 Avar = vemisie ;
 Bvar =0 ;
if (vcategorie == 0 && ( vnorma == 4  ||  vnorma == 5) && vemisie > 0 )
 {
   for (i=0;i<=7;i++)
    {if (Avar <= a1c2[i]) {Bvar= a1c3[i],  i = 8}}
    vform  = 0.7;
//  vform  = 0.7  numai daca in Anexa 2 nu se schimba nivelul taxei pt. Euro 5 si 6
 }
//-->
//--> CALCUL coeficient de reducere (Anexa 4)
Evar = a4c2[vvarsta-1];
//---> CALCUL Nivel taxa euro / 1 cmc (Anexa 2, si 3)
// corelez norma cu pozitia din Anexa 2
   if (vnorma == 5 ) nr2 = 1 ;
   if (vnorma == 4 ) nr2 = 2 ;
   if (vnorma == 3 ) nr2 = 3 ;
   if (vnorma == 2 ) nr2 = 4 ;
   if (vnorma == 13 ) nr2 = 5 ;
Cvar = vcapacitate;
Dvar =0 ;
nr1 = 0;
// Euro 5,6 si  Hibride   este 0  indiferent de categorie
// calcul pt Categoriile  N1 si M1 Euro 1-4 si Non Euro
  if (vcategorie == 0 || vcategorie == 3)
 {
     if (vnorma >=2 && vnorma <= 5 || vnorma == 13)
      for (i=0;i<=6;i++)
          if (Cvar <= a2c2[i])
           {nr1 = i,  Dvar = a2c3[(nr2 -1)*6 +i+1]; i = 7; }
  }

// calcul pt Categoriile M2, M3, N2, N3
   if (vcategorie == 1 || vcategorie == 2 || vcategorie == 4 || vcategorie == 5 )
      {if (vnorma == 13 ) Dvar = 9;
      if ( vnorma >=8 && vnorma <=12) Dvar = a3c2[12-vnorma];
      }

//---> Calculez taxa
if(vcapacitate > 0 && vnorma > 0 && vvarsta > 0) {

	if (Avar > 0) {
	 taxaluc = ((Avar*Bvar*0.3) + (Cvar*Dvar*vform))* (100-Evar)/100;
    }
	else
	 taxaluc =  (Cvar*Dvar*vform) * (100-Evar)/100;

    taxaluc = taxaluc*vrtaxa;
    taxaluc = Math.round(taxaluc*100)/100;


	document.getElementById('rezultatta').innerHTML = (taxaluc).toFixed(2)+' &euro;';
	return true;
}

}
////////////////////////



////////////////////////

function IsNumeric(strString)
{
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	if (strString.length == 0)
		return false;
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
			blnResult = false;
	}
	return blnResult;
}

function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}



function indice_capac_cilindrica(norma,capac)
{
	if(capac<=1400)
	{
		if(norma == 1 || norma == 2 || norma == 3)
			return 0;
		else if(norma==4)
			return 0.2;
		else if(norma==5)
			return 0.65;
		else if(norma==6)
			return 1.7;
		else if(norma==7)
			return 3.5;
		else if(norma==8)
			return 10.5;
	}
	else if(capac>1400 && capac<=1600)
	{
		if(norma == 1 || norma == 2 || norma == 3)
			return 0;
		else if(norma==4)
			return 0.3;
		else if(norma==5)
			return 1;
		else if(norma==6)
			return 2.6;
		else if(norma==7)
			return 5.5;
		else if(norma==8)
			return 16.5;
	}
	else if(capac>1600 && capac<=2000)
	{
		if(norma == 1 || norma == 2 || norma == 3)
			return 0;
		else if(norma==4)
			return 0.4;
		else if(norma==5)
			return 1.3;
		else if(norma==6)
			return 3.3;
		else if(norma==7)
			return 7;
		else if(norma==8)
			return 21;
	}
	else if(capac>2000 && capac<=2500)
	{
		if(norma == 1 || norma == 2 || norma == 3)
			return 0;
		else if(norma==4)
			return 0.6;
		else if(norma==5)
			return 1.9;
		else if(norma==6)
			return 5;
		else if(norma==7)
			return 10;
		else if(norma==8)
			return 30;
	}
	else if(capac>2500 && capac<=3000)
	{
		if(norma == 1 || norma == 2 || norma == 3)
			return 0;
		else if(norma==4)
			return 0.8;
		else if(norma==5)
			return 2.5;
		else if(norma==6)
			return 7;
		else if(norma==7)
			return 14;
		else if(norma==8)
			return 42;
	}
	else if(capac>3000 )
	{
		if(norma == 1 || norma == 2 || norma == 3)
			return 0;
		else if(norma==4)
			return 1;
		else if(norma==5)
			return 3;
		else if(norma==6)
			return 8;
		else if(norma==7)
			return 16;
		else if(norma==8)
			return 48;
	}
	return 0;
}


function emisia_co2f(norma, val)
{



	if(norma==3 || norma==4)
	{
		if(val<= 120)
			return 0;
		else if(val>120 && val<=150)
			return 0.5;
		else if(val>150 && val<=180)
			return 1;
		else if(val>180 && val<=210)
			return 2;
		else if(val>210 && val<=240)
			return 4;
		else if(val>240 && val<=270)
			return 6;
		else if(val>270)
			return 8;
	}
	return 0;
}

function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}




/*
 * Copyright (C) 2006 Baron Schwartz <baron at sequent dot org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, version 2.1.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 * details.
 *
 * $Revision: 1.3 $
 */

// Abbreviations: LODP = Left Of Decimal Point, RODP = Right Of Decimal Point
Number.formatFunctions = {count:0};

// Constants useful for controlling the format of numbers in special cases.
Number.prototype.NaN         = 'NaN';
Number.prototype.posInfinity = 'Infinity';
Number.prototype.negInfinity = '-Infinity';

Number.prototype.numberFormat = function(format, context) {
    if (isNaN(this) ) {
        return Number.prototype.NaNstring;
    }
    else if (this == +Infinity ) {
        return Number.prototype.posInfinity;
    }
    else if ( this == -Infinity) {
        return Number.prototype.negInfinity;
    }
    else if (Number.formatFunctions[format] == null) {
        Number.createNewFormat(format);
    }
    return this[Number.formatFunctions[format]](context);
}

Number.createNewFormat = function(format) {
    var funcName = "format" + Number.formatFunctions.count++;
    Number.formatFunctions[format] = funcName;
    var code = "Number.prototype." + funcName + " = function(context){\n";

    // Decide whether the function is a terminal or a pos/neg/zero function
    var formats = format.split(";");
    switch (formats.length) {
        case 1:
            code += Number.createTerminalFormat(format);
            break;
        case 2:
            code += "return (this < 0) ? this.numberFormat(\""
                + String.escape(formats[1])
                + "\", 1) : this.numberFormat(\""
                + String.escape(formats[0])
                + "\", 2);";
            break;
        case 3:
            code += "return (this < 0) ? this.numberFormat(\""
                + String.escape(formats[1])
                + "\", 1) : ((this == 0) ? this.numberFormat(\""
                + String.escape(formats[2])
                + "\", 2) : this.numberFormat(\""
                + String.escape(formats[0])
                + "\", 3));";
            break;
        default:
            code += "throw 'Too many semicolons in format string';";
            break;
    }
    eval(code + "}");
}

Number.createTerminalFormat = function(format) {
    // If there is no work to do, just return the literal value
    if (format.length > 0 && format.search(/[0#?]/) == -1) {
        return "return '" + String.escape(format) + "';\n";
    }
    // Negative values are always displayed without a minus sign when section separators are used.
    var code = "var val = (context == null) ? new Number(this) : Math.abs(this);\n";
    var thousands = false;
    var lodp = format;
    var rodp = "";
    var ldigits = 0;
    var rdigits = 0;
    var scidigits = 0;
    var scishowsign = false;
    var sciletter = "";
    // Look for (and remove) scientific notation instructions, which can be anywhere
    m = format.match(/\..*(e)([+-]?)(0+)/i);
    if (m) {
        sciletter = m[1];
        scishowsign = (m[2] == "+");
        scidigits = m[3].length;
        format = format.replace(/(e)([+-]?)(0+)/i, "");
    }
    // Split around the decimal point
    var m = format.match(/^([^.]*)\.(.*)$/);
    if (m) {
        lodp = m[1].replace(/\./g, "");
        rodp = m[2].replace(/\./g, "");
    }
    // Look for %
    if (format.indexOf('%') >= 0) {
        code += "val *= 100;\n";
    }
    // Look for comma-scaling to the left of the decimal point
    m = lodp.match(/(,+)(?:$|[^0#?,])/);
    if (m) {
        code += "val /= " + Math.pow(1000, m[1].length) + "\n;";
    }
    // Look for comma-separators
    if (lodp.search(/[0#?],[0#?]/) >= 0) {
        thousands = true;
    }
    // Nuke any extraneous commas
    if ((m) || thousands) {
        lodp = lodp.replace(/,/g, "");
    }
    // Figure out how many digits to the l/r of the decimal place
    m = lodp.match(/0[0#?]*/);
    if (m) {
        ldigits = m[0].length;
    }
    m = rodp.match(/[0#?]*/);
    if (m) {
        rdigits = m[0].length;
    }
    // Scientific notation takes precedence over rounding etc
    if (scidigits > 0) {
        code += "var sci = Number.toScientific(val,"
            + ldigits + ", " + rdigits + ", " + scidigits + ", " + scishowsign + ");\n"
            + "var arr = [sci.l, sci.r];\n";
    }
    else {
        // If there is no decimal point, round to nearest integer, AWAY from zero
        if (format.indexOf('.') < 0) {
            code += "val = (val > 0) ? Math.ceil(val) : Math.floor(val);\n";
        }
        // Numbers are rounded to the correct number of digits to the right of the decimal
        code += "var arr = val.round(" + rdigits + ").toFixed(" + rdigits + ").split('.');\n";
        // There are at least "ldigits" digits to the left of the decimal, so add zeros if needed.
        code += "arr[0] = (val < 0 ? '-' : '') + String.leftPad((val < 0 ? arr[0].substring(1) : arr[0]), "
            + ldigits + ", '0');\n";
    }
    // Add thousands separators
    if (thousands) {
        code += "arr[0] = Number.addSeparators(arr[0]);\n";
    }
    // Insert the digits into the formatting string.  On the LHS, extra digits are copied
    // into the result.  On the RHS, rounding has chopped them off.
    code += "arr[0] = Number.injectIntoFormat(arr[0].reverse(), '"
        + String.escape(lodp.reverse()) + "', true).reverse();\n";
    if (rdigits > 0) {
        code += "arr[1] = Number.injectIntoFormat(arr[1], '" + String.escape(rodp) + "', false);\n";
    }
    if (scidigits > 0) {
        code += "arr[1] = arr[1].replace(/(\\d{" + rdigits + "})/, '$1" + sciletter + "' + sci.s);\n";
    }
    return code + "return arr.join('.');\n";
}

Number.toScientific = function(val, ldigits, rdigits, scidigits, showsign) {
    var result = {l:"", r:"", s:""};
    var ex = "";
    // Make ldigits + rdigits significant figures
    var before = Math.abs(val).toFixed(ldigits + rdigits + 1).trim('0');
    // Move the decimal point to the right of all digits we want to keep,
    // and round the resulting value off
    var after = Math.round(new Number(before.replace(".", "").replace(
        new RegExp("(\\d{" + (ldigits + rdigits) + "})(.*)"), "$1.$2"))).toFixed(0);
    // Place the decimal point in the new string
    if (after.length >= ldigits) {
        after = after.substring(0, ldigits) + "." + after.substring(ldigits);
    }
    else {
        after += '.';
    }
    // Find how much the decimal point moved.  This is #places to LODP in the original
    // number, minus the #places in the new number.  There are no left-padded zeroes in
    // the new number, so the calculation for it is simpler than for the old number.
    result.s = (before.indexOf(".") - before.search(/[1-9]/)) - after.indexOf(".");
    // The exponent is off by 1 when it gets moved to the left.
    if (result.s < 0) {
        result.s++;
    }
    // Split the value around the decimal point and pad the parts appropriately.
    result.l = (val < 0 ? '-' : '') + String.leftPad(after.substring(0, after.indexOf(".")), ldigits, "0");
    result.r = after.substring(after.indexOf(".") + 1);
    if (result.s < 0) {
        ex = "-";
    }
    else if (showsign) {
        ex = "+";
    }
    result.s = ex + String.leftPad(Math.abs(result.s).toFixed(0), scidigits, "0");
    return result;
}

Number.prototype.round = function(decimals) {
    if (decimals > 0) {
        var m = this.toFixed(decimals + 1).match(
            new RegExp("(-?\\d*)\.(\\d{" + decimals + "})(\\d)\\d*$"));
        if (m && m.length) {
            return new Number(m[1] + "." + String.leftPad(Math.round(m[2] + "." + m[3]), decimals, "0"));
        }
    }
    return this;
}

Number.injectIntoFormat = function(val, format, stuffExtras) {
    var i = 0;
    var j = 0;
    var result = "";
    var revneg = val.charAt(val.length - 1) == '-';
    if ( revneg ) {
       val = val.substring(0, val.length - 1);
    }
    while (i < format.length && j < val.length && format.substring(i).search(/[0#?]/) >= 0) {
        if (format.charAt(i).match(/[0#?]/)) {
            // It's a formatting character; copy the corresponding character
            // in the value to the result
            if (val.charAt(j) != '-') {
                result += val.charAt(j);
            }
            else {
                result += "0";
            }
            j++;
        }
        else {
            result += format.charAt(i);
        }
        ++i;
    }
    if ( revneg && j == val.length ) {
        result += '-';
    }
    if (j < val.length) {
        if (stuffExtras) {
            result += val.substring(j);
        }
        if ( revneg ) {
             result += '-';
        }
    }
    if (i < format.length) {
        result += format.substring(i);
    }
    return result.replace(/#/g, "").replace(/\?/g, " ");
}

Number.addSeparators = function(val) {
    return val.reverse().replace(/(\d{3})/g, "$1,").reverse().replace(/^(-)?,/, "$1");
}

String.prototype.reverse = function() {
    var res = "";
    for (var i = this.length; i > 0; --i) {
        res += this.charAt(i - 1);
    }
    return res;
}

String.prototype.trim = function(ch) {
    if (!ch) ch = ' ';
    return this.replace(new RegExp("^" + ch + "+|" + ch + "+$", "g"), "");
}

String.leftPad = function (val, size, ch) {
    var result = new String(val);
    if (ch == null) {
        ch = " ";
    }
    while (result.length < size) {
        result = ch + result;
    }
    return result;
}

String.escape = function(string) {
    return string.replace(/('|\\)/g, "\\$1");
}