function show_km()
{
var mil = document.distin_mile.mile_km.value
var dist = (mil * 1.61)
document.distin_mile.km.value = dist
}

function show_mile()
{
var km = document.distin_km.km_mile.value
var dist = (km * 0.6211)
document.distin_km.mil.value = dist

}

function show_ps()
{
var kw = document.distin_ps.kw1.value
var dist = Math.ceil(kw*1.359622-0.5)
document.distin_ps.ps1.value = dist
}

function show_kw()
{
var ps = document.distin_kw.ps2.value
var dist = Math.ceil(ps*0.735499-0.5)
document.distin_kw.kw2.value = dist
}


function getImageName(name)
{
		
		var fulldata=unescape(window.location.search);
		var startOfImageName=fulldata.indexOf(name);
		
	if(startOfImageName != -1)
	{
		var endOfImageName = fulldata.indexOf("&",startOfImageName+6);
		var imageName = fulldata.substring(startOfImageName+6,endOfImageName);
	}
	else
		imageName= "missing";
		return imageName;
}

var ConvertMe = new Array(0.0680460, 760, 1.333224/1000, 1e+03, 1e+02, 1e-03, 1e-03, 1e-03, 0.1450376264514975*1e+06);

	// Double the array; makes this easier.
	var ArrayLength = ConvertMe.length;
	for(count = 0;  count <= ArrayLength; count++)
		ConvertMe[count + ArrayLength] = ConvertMe[count];

function chkChar(evt)
{
	var charCode=evt.which; // For Netscape
	if (isNaN(charCode)) {charCode = evt.keyCode;} // For IE
		if (charCode==13 | charCode==3) {return calculator();}
	else {return true;}
}

function calculator()

{
	
	// Make sure the input is a number; if not, prompt user
	if (isNaN(document.pressure.oldpressure.value)) {
		document.pressure.newpressure.value = "Type numbers, not letters!";
		if (document.pressure.oldpressure.value.search(/,/i) != -1)
			{document.pressure.newpressure.value = "Omit commas in input.";}
		if (document.pressure.oldpressure.value.search(/x/i) != -1)
			{document.pressure.newpressure.value = "Enter 'e' instead of 'x10'.";}
	return false;}

	// Ralph is the container used to hold our answer.  Initialize with input value.
	var Ralph = document.pressure.oldpressure.value;

// Set start and end of conversion chain
	var StartHere = document.pressure.oldunit.selectedIndex;
	var EndHere = document.pressure.newunit.selectedIndex;
	
	if (StartHere > EndHere) {  // This is why we doubled the array.  Conversion works left to right.
		EndHere = EndHere + ArrayLength;}  

	// This runs through every calc between the starting unit and ending unit, but only if needed.
	if (StartHere !=  EndHere) {
		for(count = StartHere; count < EndHere; count++) 
		Ralph = Ralph*ConvertMe[count]; }

	// Cut decimal places to 7; this even cleans up big mantissas!
		var RalphClone = Ralph + "";    // Makes it copy of Ralph as a string to find e

		if (RalphClone.search(/e/i) == -1) {Ralph = Math.round(Ralph*1e7)/1e7;}
		else {
			var CutHere = RalphClone.split("e");
			CutHere[0] = Math.round(CutHere[0]*1e7)/1e7;
			Ralph = CutHere[0] + "e" + CutHere[1];
		}
	// Commas are fun, but a pain!  Why didn't they set a Number Format property in Javascript?
		RalphClone = Ralph + "";  // Make him a string again		
	
		CutHere = RalphClone.split(".");
		if (typeof CutHere[1] == "undefined") {CutHere[1] = "";}  // in case answer is integer.
			else {CutHere[1] = "." + CutHere[1];}

		var duh = 0;   // placeholder for comma loop; increments once for each comma inserted.
		var ThisLong = CutHere[0].length + Math.floor(CutHere[0].length/3); 
		var CommaStart = CutHere[0].length % 3;   // Starting position for comma
		if (CommaStart == 0) {CommaStart=3;}  // Keeps us from making numbers like ",123"
		Ralph = "";   
	
		if (CutHere[0].search(/e/i) == -1)   // exponents here would mess up the commas, so skip.
		{
		for(count = 0; count < ThisLong; count++) { 
			if (count == CommaStart + duh * 4) {
				if (count < ThisLong - 1) {Ralph = Ralph + ",";}
				duh = duh + 1;}
			else {
				Ralph = Ralph + CutHere[0].substring(count-duh, count+1-duh);}
			}
		}  else
			Ralph = CutHere[0];
		Ralph = Ralph + "" + CutHere[1];  // Slap the decimals back on.
	// Just to be picky, add a leading zero if first character is a decimal.
		if (Ralph.substring(0,1) == ".") {Ralph = "0" + Ralph};
		
	// Write result to the output field.
		document.pressure.newpressure.value = Ralph;
	return false;
}

function tyre_fnc(form)
  {
  var povodny=(form.rozmer1.value*25.4/2) + (form.et1.value*1);
  var novy=(form.rozmer2.value*25.4/2) + (form.et2.value*1);
  var temp1=(form.rozmer1.value*25.4) - (povodny);
  var temp2=(form.rozmer2.value*25.4) - (novy);
  var vysledok=temp2-temp1;
  document.all.v.innerHTML='<b>Výsledok:</b><br>Nové koleso vystúpi / vpadne von / dnu o <b> '+Math.round(vysledok)+' mm</b>.';
  }




function spoctikola(form){

  var r1=form.D1.value*form.D2.value/100+(form.D3.value*12.6);
  var r2=form.D4.value*form.D5.value/100+(form.D6.value*12.6);
  
 
    
  if (r1>r2) {
     var vyska="zníži";
     var tacho="vyššie";
     }
  else {
     var vyska="zvýši";
     var tacho="nižšie";
     }
  
  dif=Math.round(Math.abs(r1-r2));
  
  proc=Math.round(Math.abs((r1/r2-1)*100));
    
  if (proc <5) var tolerance="je";
  else var tolerance="nie je";

  var prevodtext='tak isto o <b>'+proc+'% '+tacho+'</b>.';

  if (1!=1) {
     var preproc=((form.D8.value/1)-1)*100+((r1/r2-1)*100);
     if (preproc>0) var prevod="väčšie";
     else var prevod="menšie"
     var preproc=Math.round(Math.abs(preproc));
     
     prevodtext='a prevodovky o <b>'+preproc+'% '+prevod+'</b>.';
     }


  document.all.script.innerHTML='<b>Výsledky:</b><br>Polomer starého kolesa je <b>'+Math.round(r1)+' mm</b>, polomer nového kolesa je <b>'+Math.round(r2)+' mm</b>.<br>\
  Podvozok sa <b>'+vyska+' o '+dif+' mm</b>.<br>\
  Tachometer bude ukazovať o <b>'+proc+'% '+tacho+' rýchlosť</b>, čo '+tolerance+' v povolenej 5% tolerancii.<br>\
  Sila prenášaná na vozovku bude pri zmene kolies '+prevodtext;
  }
  
