function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function ValidarIMC()
{
if (document.frmIMC.txtEstatura.value == "")
{
	alert('Debes indicar tu estatura');
	document.frmIMC.txtEstatura.focus();
	return false;
}
else if (!(document.frmIMC.optEstatura[0].checked) && !(document.frmIMC.optEstatura[1].checked))
{
	alert('Debes indicar la unidad de medida de tu estatura');
	document.frmIMC.optEstatura[0].focus();
	return false;
}
else if (document.frmIMC.txtPeso.value == "")
{
	alert('Debes indicar tu peso');
	document.frmIMC.txtPeso.focus();
	return false;
}
else if (!(document.frmIMC.optPeso[0].checked) && !(document.frmIMC.optPeso[1].checked))
{
	alert('Debes indicar la unidad de medida de tu peso');
	document.frmIMC.optPeso[0].focus();
	return false;
}
else if (document.frmIMC.txtEdad.value == "")
{
	alert('Debes indicar tu edad');
	document.frmIMC.txtEdad.focus();
	return false;
}
else if (!(document.frmIMC.optSexo[0].checked) && !(document.frmIMC.optSexo[1].checked))
{
	alert('Debes indicar tu sexo');
	document.frmIMC.optSexo[0].focus();
	return false;
}
else
{
	CalcularIMC();
}	
return true;
}

function CalcularIMC() {

var peso = (document.frmIMC.optPeso[1].checked) ? document.frmIMC.txtPeso.value / 2.2 : document.frmIMC.txtPeso.value;
var alto = (document.frmIMC.optEstatura[1].checked) ? document.frmIMC.txtEstatura.value * .0254 : document.frmIMC.txtEstatura.value;

if (document.frmIMC.optSexo[0].checked) //Femenino
{  

	document.frmIMC.txtImc.value = Math.round ((peso / alto / alto * 10) / 10 ) - 1;
}
else //Masculino
{ 
	document.frmIMC.txtImc.value = Math.round (peso / alto / alto * 10) / 10;
}

if (document.frmIMC.txtImc.value < 20)
{
   	mensaje = "Peso bajo";
}
else if (document.frmIMC.txtImc.value < 25)
{
  	mensaje =  "Saludable";
}
else if (document.frmIMC.txtImc.value < 30)
{
  	mensaje = "Sobrepeso";
}
else if (document.frmIMC.txtImc.value < 40)
{
   	mensaje = "Sobrepeso severo / obeso";
}
else
{
   	mensaje =  "Severamente obeso";
}
document.frmIMC.txtMensImc.value = mensaje;

if (document.frmIMC.txtEdad.value < 19)
{
    	document.frmIMC.txtMensImc.value = "(es menor de edad)";
}
else
{
 if (document.frmIMC.txtEdad.value > 75) document.frmIMC.txtEdad.value = 75;
 document.frmIMC.txtImcEdad.value = Math.round((document.frmIMC.txtImc.value - (document.frmIMC.txtEdad.value - 30) / 10) * 10) / 10;
}
}
function LimpiarIMC()
{
	document.frmIMC.txtEstatura.value = "";
	document.frmIMC.txtPeso.value = "";
	document.frmIMC.txtEdad.value = "";
	document.frmIMC.txtImc.value = "";
	document.frmIMC.txtImcEdad.value = "";
	document.frmIMC.optSexo[0].checked = false;
	document.frmIMC.optSexo[1].checked = false;
	document.frmIMC.optEstatura[0].checked = true;
	document.frmIMC.optPeso[0].checked = true;
	document.frmIMC.optPeso[1].checked = false;
	document.frmIMC.txtEstatura.focus();
}