function calcvel(rpm,perimeter,primary,secondary,first,second,third,fourth,fifth,six) 
			{
			rpm = document.vel.txtRPM.value;
			perimeter =	document.vel.txtPerimeter.value;
			primary = document.vel.txtPrimary.value;
			secondary = document.vel.txtSecondary.value;
			first = document.vel.txtGear1.value;
			second = document.vel.txtGear2.value;
			third = document.vel.txtGear3.value;
			fourth = document.vel.txtGear4.value;
			fifth = document.vel.txtGear5.value;
			six = document.vel.txtGear6.value;

			var mensagem = "";

			if(rpm.length == 0 || rpm == "" || isNaN(rpm)) {
				mensagem=mensagem+"* You must fill correctly the RPM value.\n";
				document.vel.txtRPM.style.borderColor='red';
				document.vel.txtRPM.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtRPM.style.borderColor='#000000';
				document.vel.txtRPM.style.backgroundColor='#9BCDFF';
			}
			
			if( rpm.indexOf(",") != -1 || rpm.indexOf(".") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the RPM value WITHOUT COMMAS or DOTS.\n";
				document.vel.txtRPM.style.borderColor='red';
				document.vel.txtRPM.style.backgroundColor='#FFB3B3';
			}
			else if ( rpm.indexOf(",") == 0 || rpm.indexOf(".") == 0 ){
				document.vel.txtRPM.style.borderColor='#000000';
				document.vel.txtRPM.style.backgroundColor='#9BCDFF';
			}
			
			if( perimeter.indexOf(",") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the PERIMETER value WITHOUT COMMAS.\n";
				document.vel.txtPerimeter.style.borderColor='red';
				document.vel.txtPerimeter.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtPerimeter.style.borderColor='#000000';
				document.vel.txtPerimeter.style.backgroundColor='#9BCDFF';
			}
			
			if(perimeter.length == 0 || perimeter < 140 || perimeter > 220 || isNaN(perimeter)) {
				mensagem=mensagem+"* You must fill correctly the PERIMETER value.\n";
				document.vel.txtPerimeter.style.borderColor='red';
				document.vel.txtPerimeter.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtPerimeter.style.borderColor='#000000';
				document.vel.txtPerimeter.style.backgroundColor='#9BCDFF';
			}
			
			if(primary.length == "" || primary < 0.15 || primary >0.8  || isNaN(primary)) {
				mensagem=mensagem+"* You must fill correctly the PRIMARY RATIO value.\n";
				document.vel.txtPrimary.style.borderColor='red';
				document.vel.txtPrimary.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtPrimary.style.borderColor='#000000';
				document.vel.txtPrimary.style.backgroundColor='#9BCDFF';
			}
			
			if( primary.indexOf(",") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the PRIMARY value WITHOUT COMMAS.\n";
				document.vel.txtPrimary.style.borderColor='red';
				document.vel.txtPrimary.style.backgroundColor='#FFB3B3';
			}
			else if ( primary.indexOf(",") == 0 || primary.indexOf(".") == 0 ){
				document.vel.txtPrimary.style.borderColor='#000000';
				document.vel.txtPrimary.style.backgroundColor='#9BCDFF';
			}

			if(secondary.length == "" || secondary < 0.15 || secondary >0.8 || isNaN(secondary)) {
				mensagem=mensagem+"* You must fill correctly the SECONDARY RATIO value.\n";
				document.vel.txtSecondary.style.borderColor='red';
				document.vel.txtSecondary.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtSecondary.style.borderColor='#000000';
				document.vel.txtSecondary.style.backgroundColor='#9BCDFF';
			}
			
			if( secondary.indexOf(",") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the SECONDARY value WITHOUT COMMAS.\n";
				document.vel.txtSecondary.style.borderColor='red';
				document.vel.txtSecondary.style.backgroundColor='#FFB3B3';
			}
			else if ( secondary.indexOf(",") == 0 ){
				document.vel.txtSecondary.style.borderColor='#000000';
				document.vel.txtSecondary.style.backgroundColor='#9BCDFF';
			}
				
			if(first.length == 0 || isNaN(first)) {
				mensagem=mensagem+"* You must fill correctly the 1st GEAR RATIO value.\n";
				document.vel.txtGear1.style.borderColor='red';
				document.vel.txtGear1.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtGear1.style.borderColor='#000000';
				document.vel.txtGear1.style.backgroundColor='#9BCDFF';
			}
			
			if( first.indexOf(",") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the 1st GEAR RATIO value WITHOUT COMMAS.\n";
				document.vel.txtGear1.style.borderColor='red';
				document.vel.txtGear1.style.backgroundColor='#FFB3B3';
			}
			else if ( first.indexOf(".") == 0 ){
				document.vel.txtGear1.style.borderColor='#000000';
				document.vel.txtGear1.style.backgroundColor='#9BCDFF';
			}
			
			if(second.length == 0 || isNaN(second)) {
				mensagem=mensagem+"* You must fill correctly the 2nd GEAR RATIO value.\n";
				document.vel.txtGear2.style.borderColor='red';
				document.vel.txtGear2.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtGear2.style.borderColor='#000000';
				document.vel.txtGear2.style.backgroundColor='#9BCDFF';
			}
			
			if( second.indexOf(",") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the 2nd GEAR RATIO value WITHOUT COMMAS.\n";
				document.vel.txtGear2.style.borderColor='red';
				document.vel.txtGear2.style.backgroundColor='#FFB3B3';
			}
			else if ( second.indexOf(".") == 0 ){
				document.vel.txtGear2.style.borderColor='#000000';
				document.vel.txtGear2.style.backgroundColor='#9BCDFF';
			}
			
			if(third.length == 0 || isNaN(third)){
				mensagem=mensagem+"* You must fill correctly the 3rd GEAR RATIO value.\n";
				document.vel.txtGear3.style.borderColor='red';
				document.vel.txtGear3.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtGear3.style.borderColor='#000000';
				document.vel.txtGear3.style.backgroundColor='#9BCDFF';
			}
			
			if( third.indexOf(",") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the 3rd GEAR RATIO value WITHOUT COMMAS.\n";
				document.vel.txtGear3.style.borderColor='red';
				document.vel.txtGear3.style.backgroundColor='#FFB3B3';
			}
			else if ( third.indexOf(".") == 0 ){
				document.vel.txtGear3.style.borderColor='#000000';
				document.vel.txtGear3.style.backgroundColor='#9BCDFF';
			}
			
			if(fourth.length == 0 || isNaN(fourth)){
				mensagem=mensagem+"* You must fill correctly the 4th GEAR RATIO value.\n";
				document.vel.txtGear4.style.borderColor='red';
				document.vel.txtGear4.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtGear4.style.borderColor='#000000';
				document.vel.txtGear4.style.backgroundColor='#9BCDFF';
			}
			
			if( fourth.indexOf(",") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the 4th GEAR RATIO value WITHOUT COMMAS.\n";
				document.vel.txtGear4.style.borderColor='red';
				document.vel.txtGear4.style.backgroundColor='#FFB3B3';
			}
			else if ( fourth.indexOf(".") == 0 ){
				document.vel.txtGear4.style.borderColor='#000000';
				document.vel.txtGear4.style.backgroundColor='#9BCDFF';
			}
			
			if(fifth.length == 0  || isNaN(fifth)){
				mensagem=mensagem+"* You must fill correctly the 5th GEAR RATIO value.\n";
				document.vel.txtGear5.style.borderColor='red';
				document.vel.txtGear5.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtGear5.style.borderColor='#000000';
				document.vel.txtGear5.style.backgroundColor='#9BCDFF';
			}
			
			if( fifth.indexOf(",") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the 5th GEAR RATIO value WITHOUT COMMAS.\n";
				document.vel.txtGear5.style.borderColor='red';
				document.vel.txtGear5.style.backgroundColor='#FFB3B3';
			}
			else if ( fifth.indexOf(".") == 0 ){
				document.vel.txtGear5.style.borderColor='#000000';
				document.vel.txtGear5.style.backgroundColor='#9BCDFF';
			}
			
			if(six.length == 0 || isNaN(six)){
				mensagem=mensagem+"* You must fill correctly the 6th GEAR RATIO value.\n";
				document.vel.txtGear6.style.borderColor='red';
				document.vel.txtGear6.style.backgroundColor='#FFB3B3';
			}
			else {
				document.vel.txtGear6.style.borderColor='#000000';
				document.vel.txtGear6.style.backgroundColor='#9BCDFF';
			}
			
			if( six.indexOf(",") != -1 ) {
				mensagem=mensagem+"* You must fill correctly the 6th GEAR RATIO value WITHOUT COMMAS.\n";
				document.vel.txtGear6.style.borderColor='red';
				document.vel.txtGear6.style.backgroundColor='#FFB3B3';
			}
			else if ( six.indexOf(".") == 0 ){
				document.vel.txtGear6.style.borderColor='#000000';
				document.vel.txtGear6.style.backgroundColor='#9BCDFF';
			}
			
			if(mensagem.length > 0){
				alert(mensagem);
				return false;
			}
			else
			{
							
			var constante = 0.0006;
			var Vel1 = parseInt(rpm * perimeter * primary * secondary * first * constante);
			var Vel2 = parseInt(rpm * perimeter * primary * secondary * second * constante);				
			var Vel3 = parseInt(rpm * perimeter * primary * secondary * third * constante);
			var Vel4 = parseInt(rpm * perimeter * primary * secondary * fourth * constante);
			var Vel5 = parseInt(rpm * perimeter * primary * secondary * fifth * constante);
			var Vel6 = parseInt(rpm * perimeter * primary * secondary * six * constante);
			
			document.vel.txtGear1Vel.value = Vel1;
			document.vel.txtGear2Vel.value = Vel2;
			document.vel.txtGear3Vel.value = Vel3;
			document.vel.txtGear4Vel.value = Vel4;
			document.vel.txtGear5Vel.value = Vel5;
			document.vel.txtGear6Vel.value = Vel6;
			}

			// Opções para o Gráfico
			var options = {
				grid: { clickable: true }
				//lines: { show: true, fill: true, fillColor: "rgba(220, 220, 220, 0.5)" },
				//points: { show: true },
//				bars: { show: true },
		    };
			
			// 5000 RPM
			var constante = 0.0006;
			var rpm5 = 5000;
			var Vel51 = parseInt(rpm5 * perimeter * primary * secondary * first * constante);
			var Vel52 = parseInt(rpm5 * perimeter * primary * secondary * second * constante);				
			var Vel53 = parseInt(rpm5 * perimeter * primary * secondary * third * constante);
			var Vel54 = parseInt(rpm5 * perimeter * primary * secondary * fourth * constante);
			var Vel55 = parseInt(rpm5 * perimeter * primary * secondary * fifth * constante);
			var Vel56 = parseInt(rpm5 * perimeter * primary * secondary * six * constante);
			
			// 8000 RPM
			var constante = 0.0006;
			var rpm8 = 8000;
			var Vel81 = parseInt(rpm8 * perimeter * primary * secondary * first * constante);
			var Vel82 = parseInt(rpm8 * perimeter * primary * secondary * second * constante);				
			var Vel83 = parseInt(rpm8 * perimeter * primary * secondary * third * constante);
			var Vel84 = parseInt(rpm8 * perimeter * primary * secondary * fourth * constante);
			var Vel85 = parseInt(rpm8 * perimeter * primary * secondary * fifth * constante);
			var Vel86 = parseInt(rpm8 * perimeter * primary * secondary * six * constante);
			
			// 10000 RPM
			var constante = 0.0006;
			var rpm10 = 10000;
			var Vel101 = parseInt(rpm10 * perimeter * primary * secondary * first * constante);
			var Vel102 = parseInt(rpm10 * perimeter * primary * secondary * second * constante);				
			var Vel103 = parseInt(rpm10 * perimeter * primary * secondary * third * constante);
			var Vel104 = parseInt(rpm10 * perimeter * primary * secondary * fourth * constante);
			var Vel105 = parseInt(rpm10 * perimeter * primary * secondary * fifth * constante);
			var Vel106 = parseInt(rpm10 * perimeter * primary * secondary * six * constante);
	
			var datasetvel = {
				color: "red",
				label: rpm + "rpm",
				lines: { show: true, fill: true, fillColor: "rgba(255, 0, 0, 0.3)" },
				points: { show: true },
				data: [[1, Vel1], [2, Vel2], [3, Vel3], [4, Vel4], [5, Vel5], [6, Vel6]]
			}
			
			var datasetvel10000 = {
				color: "yellow",
				label: "10000rpm",
				lines: { show: true, fill: true, fillColor: "rgba(255, 255, 0, 0.3)" },
				points: { show: true },
				data: [[1, Vel101], [2, Vel102], [3, Vel103], [4, Vel104], [5, Vel105], [6, Vel106]]
			}
			
			var datasetvel8000 = {
				color: "green",
				label: "8000rpm",
				lines: { show: true, fill: true, fillColor: "rgba(0, 255, 0, 0.3)" },
				points: { show: true },
				data: [[1, Vel81], [2, Vel82], [3, Vel83], [4, Vel84], [5, Vel85], [6, Vel86]]
			}
			
			var datasetvel5000 = {
				color: "blue",
				label: "5000rpm",
				lines: { show: true, fill: true, fillColor: "rgba(0, 0, 139, 0.3)" },
				points: { show: true },
				data: [[1, Vel51], [2, Vel52], [3, Vel53], [4, Vel54], [5, Vel55], [6, Vel56]]
			}
			
			$.plot($("#placeholder"), [ datasetvel, datasetvel10000, datasetvel8000, datasetvel5000 ], options);
			$("#placeholder").bind("plotclick", function (e, pos) {
       		 // the values are in pos.x and pos.y
			 	gear = pos.x.toFixed(2);
				GearCorrected = Math.round(gear);
       		 $("#result").text('Real Speed @ Gear ' + GearCorrected +  ' is ' + pos.y.toFixed(2) + ' km/h');
    });
}
			
function preenche(model,primary,first,second,third,fourth,fifth,six)
	{
		document.vel.txtModel.value = model;
		document.vel.txtPrimary.value = primary;
		document.vel.txtGear1.value = first;
		document.vel.txtGear2.value = second;
		document.vel.txtGear3.value = third;
		document.vel.txtGear4.value = fourth;
		document.vel.txtGear5.value = fifth;
		document.vel.txtGear6.value = six;
	}
	
function grafico()
{
			// Opções para o Gráfico
			var options = {
				grid: { clickable: true }
				//lines: { show: true, fill: true, fillColor: "rgba(220, 220, 220, 0.5)" },
				//points: { show: true },
//				bars: { show: true },
		    };
			
			var datasetvel = {
				color: "red",
				lines: { show: true, fill: true, fillColor: "rgba(255, 0, 0, 0.3)" },
				points: { show: false },
				data: [[1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0]]
			}
			
			$.plot($("#placeholder"), [ datasetvel ], options);
}
	
function caixas()
	{
		gear1 = document.gears.gear1.value;
		gear2 = document.gears.gear2.value;
		gear3 = document.gears.gear3.value;
		gear4 = document.gears.gear4.value;
		gear5 = document.gears.gear5.value;
		gear6 = document.gears.gear6.value;
		
		var mensagem = "";

			if(gear1.length == 0 || gear1 == "" || isNaN(gear1)) {
				mensagem=mensagem+"* You must fill correctly the 1st Gear value.\n";
				document.gears.gear1.style.borderColor='red';
				document.gears.gear1.style.backgroundColor='#FFB3B3';
			}
			else {
				document.gears.gear1.style.borderColor='#000000';
				document.gears.gear1.style.backgroundColor='#9BCDFF';
			}
			
			if(gear2.length == 0 || gear2 == "" || isNaN(gear2)) {
				mensagem=mensagem+"* You must fill correctly the 2nd Gear value.\n";
				document.gears.gear2.style.borderColor='red';
				document.gears.gear2.style.backgroundColor='#FFB3B3';
			}
			else {
				document.gears.gear2.style.borderColor='#000000';
				document.gears.gear2.style.backgroundColor='#9BCDFF';
			}
			
			if(gear3.length == 0 || gear3 == "" || isNaN(gear3)) {
				mensagem=mensagem+"* You must fill correctly the 3rd Gear value.\n";
				document.gears.gear3.style.borderColor='red';
				document.gears.gear3.style.backgroundColor='#FFB3B3';
			}
			else {
				document.gears.gear3.style.borderColor='#000000';
				document.gears.gear3.style.backgroundColor='#9BCDFF';
			}
			
			if(gear4.length == 0 || gear4 == "" || isNaN(gear4)) {
				mensagem=mensagem+"* You must fill correctly the 4th Gear value.\n";
				document.gears.gear4.style.borderColor='red';
				document.gears.gear4.style.backgroundColor='#FFB3B3';
			}
			else {
				document.gears.gear4.style.borderColor='#000000';
				document.gears.gear4.style.backgroundColor='#9BCDFF';
			}
			
			if(gear5.length == 0 || gear5 == "" || isNaN(gear5)) {
				mensagem=mensagem+"* You must fill correctly the 5th Gear value.\n";
				document.gears.gear5.style.borderColor='red';
				document.gears.gear5.style.backgroundColor='#FFB3B3';
			}
			else {
				document.gears.gear5.style.borderColor='#000000';
				document.gears.gear5.style.backgroundColor='#9BCDFF';
			}

		if(mensagem.length > 0)
		{
			alert(mensagem);
			return false;
		}
		else
		{
			ratio11 = (1 / gear1).toFixed(5);
			ratio12 = (1 / gear2).toFixed(5);
			ratio13 = (1 / gear3).toFixed(5);
			ratio14 = (1 / gear4).toFixed(5);
			ratio15 = (1 / gear5).toFixed(5);
			ratio16 = (1 / gear6).toFixed(5);
			
			document.gears.txtRatioGear1.value = ratio11;
			document.gears.txtRatioGear2.value = ratio12;
			document.gears.txtRatioGear3.value = ratio13;
			document.gears.txtRatioGear4.value = ratio14;
			document.gears.txtRatioGear5.value = ratio15;
			document.gears.txtRatioGear6.value = ratio16;
			
			abs11 = (ratio12 - ratio11).toFixed(3);
			abs12 = (ratio13 - ratio12).toFixed(3);
			abs13 = (ratio14 - ratio13).toFixed(3);
			abs14 = (ratio15 - ratio14).toFixed(3);
			abs15 = (ratio16 - ratio15).toFixed(3);
	
			document.gears.abs1.value = "-";
			document.gears.abs2.value = abs11;
			document.gears.abs3.value = abs12;
			document.gears.abs4.value = abs13;
			document.gears.abs5.value = abs14;
			document.gears.abs6.value = abs15;
			
			perc11 = ((abs11 / ratio11) * 100).toFixed(2) + "%";
			perc12 = ((abs12 / ratio12) * 100).toFixed(2) + "%";
			perc13 = ((abs13 / ratio13) * 100).toFixed(2) + "%";
			perc14 = ((abs14 / ratio14) * 100).toFixed(2) + "%";
			perc15 = ((abs15 / ratio15) * 100).toFixed(2) + "%";
			
			document.gears.perc1.value = "-";
			document.gears.perc2.value = perc11;
			document.gears.perc3.value = perc12;
			document.gears.perc4.value = perc13;
			document.gears.perc5.value = perc14;
			document.gears.perc6.value = perc15;
	
			setperc11 = ((abs11 / ratio11) * 100).toFixed(0);
			setperc12 = ((abs12 / ratio12) * 100).toFixed(0);
			setperc13 = ((abs13 / ratio13) * 100).toFixed(0);
			setperc14 = ((abs14 / ratio14) * 100).toFixed(0);
			setperc15 = ((abs15 / ratio15) * 100).toFixed(0);
	}
	var options = {
				lines: { show: false },
				points: { show: false },
				bars: { show: true }
				
		};
		
		var datasetcaixas0 = {
			color: "blue",
			data: [[0, 0]]
		}
		
		var datasetcaixas1 = {
			color: "blue",
			data: [[1, 0]]
		}
		
		var datasetcaixas2 = {
			color: "brown",
			data: [[2, setperc11]]
		}
		
		var datasetcaixas3 = {
			color: "green",
			data: [[3, setperc12]]
		}

		var datasetcaixas4 = {
			color: "yellow",
			data: [[4, setperc13]]
		}

		var datasetcaixas5 = {
			color: "blue",
			data: [[5, setperc14]]
		}
		
		var datasetcaixas6 = {
			color: "red",
			data: [[6, setperc15]]
		}

		$.plot($("#gearjumps"), [ datasetcaixas1, datasetcaixas2, datasetcaixas3, datasetcaixas4, datasetcaixas5, datasetcaixas6 ], options);
}

function preenchegear(model,first,second,third,fourth,fifth,six)
	{
		document.gears.gearModel.value = model;
		document.gears.gear1.value = first;
		document.gears.gear2.value = second;
		document.gears.gear3.value = third;
		document.gears.gear4.value = fourth;
		document.gears.gear5.value = fifth;
		document.gears.gear6.value = six;
	}

function graficocaixas()
{
			// Opções para o Gráfico
			var options = {
				grid: { clickable: true }
				//lines: { show: true, fill: true, fillColor: "rgba(220, 220, 220, 0.5)" },
				//points: { show: true },
//				bars: { show: true },
		    };
			
			var datasetvel = {
				color: "red",
				lines: { show: true, fill: true, fillColor: "rgba(255, 0, 0, 0.3)" },
				points: { show: false },
				data: [[1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0]]
			}
			
			$.plot($("#gearjumps"), [ datasetvel ], options);
}

	
function disableRightClick(e)
	{
	  var message = "Right click disabled";
	  
	  if(!document.rightClickDisabled) // initialize
	  {
		if(document.layers) 
		{
		  document.captureEvents(Event.MOUSEDOWN);
		  document.onmousedown = disableRightClick;
		}
		else document.oncontextmenu = disableRightClick;
		return document.rightClickDisabled = true;
	  }
	  if(document.layers || (document.getElementById && !document.all))
	  {
		if (e.which==2||e.which==3)
		{
		  alert(message);
		  return false;
		}
	  }
	  else
	  {
		alert(message);
		return false;
	  }
	}
disableRightClick();