function addCommas(nStr){nStr+='';x=nStr.split('.');x1=x[0];x2=x.length>1?'.'+x[1]:'';var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1=x1.replace(rgx,'$1'+','+'$2');}return x1+x2;}
function roundNumber(num,dec){var result=Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);return result;}

function flush(){
		$("#calculator-motor .results .r1amount").html(addCommas(0));
		$("#calculator-motor .results .r1percent").html(0+"%");
		$("#calculator-motor .results .r1payment").html(addCommas(0));
		
		$("#calculator-motor .results .r2amount").html(addCommas(0));
		$("#calculator-motor .results .r2percent").html(0+"%");
		$("#calculator-motor .results .r2payment").html(addCommas(0));
		
		$("#calculator-motor .results .r3amount").html(addCommas(0));
		$("#calculator-motor .results .r3percent").html(0+"%");
		$("#calculator-motor .results .r3payment").html(addCommas(0));
		$("#calculator-motor #sum").html(addCommas(0));
	}

marks={
	8:["A8","Q7","R8","RS4","S4","S5","S6","S8","TT"],
	10:["3-series-Cabrio E-30","3-series-Compakt","3-series-Coupe","3-series-Coupe E-46","3-series-Touring E-46","5-series-Touring E-34","5-series-Touring E-39","5-series-Touring E-60","645 Ci","645 Ci Convertible","7 series","8-series","M 5","M 6","Z 1","Z 3","Z 3 Coupe","Z 4","Z 8"],
	30:["Aspire","Cougat","Escort","Expedition","Explorer","Focus","Maverick","Mondeo","Mustang","Scorpio","Sierra","Transit","Windstar"],
	38:["Accent","Galloper","Getz","Poni","Santa Fe","Sonata"],
	43:["Grand Bird","Optima","Shuma","Sportage"],
	55:["230 GE (463.224,463.225)","300 GD (463.327,463.328)","350 G Turbo D (463.320,463.321)","350 G Turbo-D (463.300)","B class","C 30 CDI AMG","C 32 AMG","C 36 AMG","C 43 AMG","CL 500","CL 55 AMG","CL 55 AMG (W215)","CL 600","CL 600 (W 215)","CL 65 AMG","CLK Cabriolet 200---55AMG","CLK Compressor 200---55AMG","CLK55AMG","CLK55AMG V8V24","CLS 350","CLS 500","E 240 4 Matic","E 320 4 Matic","E 50 AMG (210.072)","E 55 AMG","E 55 T AMG","G 270 CDI","G 290 TD (461.335,461.336)","G 300 TD (463.330,463.331)","G 320","G 500 (W463)","G 55 AMG","G400 CDI","GL 320 GDI","GL 420 GDI","GL 450","GL 500","Mercedes-Benz A class","ML 55 AMG","R class","S 55 AMG","S 55 Lang AMG","S class","SEC/CL 420 (140.063)","SEC/CL 500 (140.070)","SEC/CL 600 (140.076)","SLK 32 AMG","SLK 55 AMG","SLR 5.4 i V8 24V Turbo","Viano"],
	//55:["230 GE (463.224,463.225)","300 GD (463.327,463.328)","350 G Turbo D (463.320,463.321)","350 G Turbo-D (463.300)","B class","C 30 CDI AMG","C 30 CDI AMG","C 32 AMG","C 32 AMG","C 36 AMG","C 43 AMG","C 43 AMG","CL 500","CL 55 AMG","CL 55 AMG","CL 55 AMG (W215)","CL 600","CL 600","CL 600","CL 600 (W 215)","CL 65 AMG","CLK Cabriolet 200---55AMG","CLK Compressor 200---55AMG","CLK55AMG","CLK55AMG V8V24","CLS 350","CLS 500","E 240 4  Matic","E 320 4  Matic","E 50 AMG (210.072)","E 55 AMG","E 55 T AMG","G 270 CDI","G 290 TD (461.335,461.336)","G 300 TD (463.330,463.331)","G 320","G 500 (W463)","G 500 (W463)","G 55 AMG","G400 CDI","GL 320 GDI","GL 420 GDI","GL 450","GL 500","Mercedes-Benz A class","ML 55 AMG","R class","S 55 AMG","S 55 Lang AMG","S class","SEC/CL 420 (140.063)","SEC/CL 500 (140.070)","SEC/CL 600 (140.076)","SLK 32 AMG","SLK 55 AMG","SLR 5.4 i V8 24V Turbo","Viano"],
	61:["Altima","Armada","Maxima","Pathfinder","Patrol","Sunny","Terrano","Terrano 2","Tiida","X terra"],
	65:["206","207","306","307","406","407","605"],
	82:["Camry","Celica","Corolla","Harrier","Land Cruiser 100","Land Cruiser 200","Land Cruiser Prado","Rav4","Sienna","Yaris"],
	84:["Bora 1J2 4 - motions","Bora Variant 1J6 4-motions","Caravelle","Corrado","Lupo(6X)","New Beetle","New Beetle Convertible","Phaeton","Polo (6N2)","Polo Classic (6KV2)","Touran","W 12"]
};

p={
	'K1':1.45,
	'K2':0.90,
	'K3':1.60,
	
	'I7':0, //CLASS
	'I8':0, //MODEL
	'I100':0,
	'I105':0,
	'I128':0,
	'I134':0,
	'I140':0,
	'I146':0,
	'I154':0,
	'I162':0,
	'I167':0,
	'I173':0,
	'I184':0,
	'I200':0,
	'I213':0,
	'I228':0,
	
	'K7':0,
	'K8':0,
	'K9':0,
	'K10':0,
	'K11':0,
	'K100':0,
	'K105':0,
	'K106':0,
	'K107':0,
	'K108':0,
	'K109':0,
	'K128':0,
	'K140':0,
	'K146':0,
	'K154':0,
	'K162':0,
	'K167':0,
	'K173':0,
	'K180':0,
	'K181':0,
	'K182':0,
	'K184':0,
	'K185':0,
	'K186':0,
	'K189':0,
	'K190':0,
	'K191':0,
	'K200':0,
	'K213':0,
	'K215':0,
	'K228':0,
	'K230':0,
	
	'O189':0,
	'Q189':0,
	
	'L213':0,
	'L215':0,
	'L216':0,
	
	'L228':0,
	'L230':0,
	'L231':0,
	
	'D14':1000000,
	
	'D182':100,
	'D183':95,
	'D184':90,
	'D185':85,
	'D186':80,
	'D187':75,
	'D188':70,
	'D189':60,
	'D190':50,
	'D191':35,
	'D192':25,
	'D193':18,
	'D194':15,
	'D195':13,
	
	'C215':1000000,
	'C216':2000000,
	'C217':3000000,
	'C218':4000000,
	
	'D215':0.15,
	'D216':0.10,
	'D217':0.10,
	'D218':0.10,
	
	'C230':1000000,
	'C231':2000000,
	'C232':3000000,
	'C233':4000000,
	'C234':5000000,
	
	'D230':1.50,
	'D231':1.00,
	'D232':0.90,
	'D233':0.70,
	'D234':0.70
};

$(document).ready(function(){
	
	
	
	/*


	if($("#left_fiz a[href$=\\=226]").length>0){
		
		$("#left_fiz a[href$=\\=226]").click(function(){
			$.get("calculators/motor.hy.htm", function(data){
				$('body').append(data);
				
				$.getScript('calculators/motor.js', function() {
					$("#calculator-motor").show("normal");
				});
				
			});

			return false;
		});
	}
	
	
	else if($("#left_fiz a[href$=\\=227]").length>0){
		
		if($("#logo img").attr("src")=="img/logo_am.jpg"){language="hy";}
		else if($("#logo img").attr("src")=="img/logo_ru.jpg"){language="hy";}
		else{language="en";}
		
		$("#left_fiz a[href$=\\=227]").click(function(){
			$.get("calculators/tourism."+language+".htm", function(data){
				$('body').append(data);
				
				$.getScript('calculators/tourism.js', function() {
					$("#calculator-tourism").show("normal");
				});
				
			});

			return false;
		});
	}
	*/
});