﻿function valButton1(btn) 
   {
	var cnt = -1;
	for (var i=btn.length-1; i > -1; i--) 
		{   
		if (btn[i].checked) 
			{cnt = i; i = -1;}
		}

	if (cnt > -1) 
		return btn[cnt].value;
	else return null;
   }

function stripBlanksx(fld) 
	{
	var result = "";
	var c = 0;

	for (i=0; i < fld.length; i++) 
		{if (fld.charAt(i) != " " || c > 0) 
			{result += fld.charAt(i);
			if (fld.charAt(i) != " ") 
				c = result.length;
			}
		}
	return result.substr(0,c);
	}

function maleIdW(h) 
	{
	return kerek(50+2.3*(h/2.54-60));
	}

function femaleIdW(h) 
	{
	return kerek(49+1.7*(h/2.54-60));
	}

function kerek(n) 
	{
	return Math.round(n*10)/10+' kg';
	}

function calc1(thisform) 
	{
	var s = valButton1(thisform.s);
	if (s == null) 
		{
		alert("Kérem adja meg a nemét!");
		thisform.s.focus();
		return false;
		}
		
	var h = stripBlanksx(thisform.h.value);
	if (h == '') 
		{
		alert("Kérem, adja meg a magasságát!");
		thisform.h.focus();
		return false;}

	if (h != Number(h) || (h = Number(h)) < 100 || h > 250) 
		{
		alert("Hibás magasság! (100cm-250cm közötti értéket kérek)");
		thisform.h.focus();
		return false;
		}

	switch(s) 
		{
		case 'm': thisform.idw.value = maleIdW(h); break; 
		case 'f': thisform.idw.value = femaleIdW(h);
		};
	}
                    

