/* Start of Calcultae BMI page scripting */

function ShowBMIResults()
{
      document.getElementById('resultContent').style.visibility = "visible";

      document.getElementById('bulletBorder').style.visibility = "visible";

      document.getElementById('linksSection').style.visibility = "visible";

      document.getElementById('rightContent').style.display = "block";

}

/* End of Calcultae BMI page scripting */


/// Added by Rakesh to calculate BMI

//function to calculate BMI
function mod(div,base)
 {
    return Math.round(div - (Math.floor(div/base)*base));
 }

function calculateBmi(isCalculateBMIPage)
{
         weight = document.getElementById("weight").value;
         HeightFeetInt = document.getElementById("htf").value;
         HeightInchesInt = document.getElementById("hti").value;
         IsNumberValid = new RegExp("^[0-9]+$");
         IsInchesValid= new RegExp("")
        

    if(isNaN(HeightFeetInt || HeightInchesInt))
 	 {
  		  alert("Invalid Height values." + '\n' + "Please enter only digits! ");
  	 }
  	else if(HeightFeetInt=="" ||  HeightFeetInt==null  )
        {
            alert ("A value for height in feet is required.");   
        } 
    else if(!IsNumberValid.test(HeightFeetInt))
	    {
	        alert("Invalid value for feet." + '\n' + " Please enter only digits!"); 
	    }    
    else if(HeightFeetInt < 0 )
        {
            alert ("Invalid.Height cannot take negative values." + '\n' + " Please check and re-enter!");
        }
        
    else if(HeightInchesInt!="" && !IsNumberValid.test(HeightInchesInt))
	        {
	             alert("Invalid inches." + '\n' + " Please enter only digits!"); 
	        }
        
    else if(HeightInchesInt < 0 )
        {
            alert ("Invalid. Inches cannot take negative values." + '\n' + " Please check and re-enter!");
        }
	else if ((HeightFeetInt <= 48) && (HeightFeetInt >= 57) ) 
        {
            alert ("Invalid Height." + '\n' + " Please check and re-enter!"); 
        }
        
        
//     else if (HeightInchesInt > 11)
//        {          
//            alert("12 inches should be converted into feet. Please check and re-enter!");
//            
//        }


    else if (HeightFeetInt == 0 && HeightInchesInt == 0)
        {
           alert ("Invalid. Feet and Inches both cannot be zero." + '\n' + " Please check and re-enter!"); 
        }
    
    else if (HeightFeetInt > 10)
    {
           alert ("Invalid. Height cannot be greater than 10." + '\n' + " Please check and re-enter!"); 
    }
    
    else if(weight=="" ||  weight==null )
        {
            alert ("A value for weight in pounds is required.");
        }  
    else if(isNaN(weight))
 	 {
  		  alert("Invalid Weight." + '\n' + " Please check and re-enter!");
  	 }

    else if(!IsNumberValid.test(weight))
	{
	    alert("Invalid Weight." + '\n' + " Please enter only digits!"); 
	}
//  	else if(weight == 0)
//        {
//            alert ("Invalid. Weight cannot be zero." + '\n' + "Please check and re-enter!");
//        }
	else if ((weight < 0) || (weight > 999)) 
        {
            alert ("Invalid Weight." + '\n' + " Please check and re-enter!"); 
        }
        else
        {
           weight = document.getElementById("weight").value *1;
           HeightFeetInt = document.getElementById("htf").value *1;
           HeightInchesInt = document.getElementById("hti").value *1;
           HeightFeetConvert = HeightFeetInt * 12;
           height = HeightFeetConvert + HeightInchesInt;
           displaybmi1 = ((weight * 703) / (height * height));
           displaybmi= Math.round(displaybmi1*100)/100; 
          
            if (HeightInchesInt > 11)
            {
                reminderinches = mod(HeightInchesInt,12);
                document.getElementById("hti").value = reminderinches;
                document.getElementById("htf").value = HeightFeetInt + 
                ((HeightInchesInt - reminderinches)/12);
            }
            
           document.getElementById('resultContent').style.visibility = "visible";
           document.getElementById("answer").innerHTML = "Your BMI is <font size='2.1em'>" + displaybmi + "</font>";
           
           if(isCalculateBMIPage)
			{
				document.getElementById('quizTopicEditor').style.display = "block";
				document.getElementById('rightContent').style.display = "block";
			}
           
           if (browserSniffer(1, 0))
				document.getElementById("answer").style.marginTop = "-16px";
           
        }
        return false;
}
