
#import "BMIimperialObject.h"

@implementation BMIimperialObject

- Calc:sender
{
 
// Decalare Variables

    float weight;
    float height;
    float heightInt;
    float index;   
    float gender;
    float agegroup;
    float dummyValue;

// Assign variables
       
        heightInt = [Height intValue];
	weight = [Weight intValue];
	
// Calculatate BMI and display BMI

	// Convert Inches into feet
        height = heightInt / 12;
 
	// From Pound to Kilogram
	dummyValue = (weight*0.453);
	weight = dummyValue;

	// From Feet to Meter
	dummyValue = (0.3048*height);
        height = dummyValue;

	index = (weight/(height*height));

        // Display BMI index number
	[Index setDoubleValue:index];// Display result
	[Index display];
	[IndexGauge setDoubleValue:index];// Display result
	[IndexGauge display];


	// Gender Male = 1, female = 2
    	gender = [GenderButton selectedTag]; 

	// Age Group < 18 = 1, 20-29 = 2, >29 = 3
    	agegroup = [AgeGroupButton selectedTag];
   
        // Figure out in what category the person is in
        // and display the status for that person.

        // Below 18, male, normal
   	if ((agegroup == 1) && (gender == 1) && (index < 22))	
	{
	[Status setStringValue:"Normal"];
        [Status setTextColor:NX_COLORGREEN];
	};

        // Below 18, male, overweight
   	if ((agegroup == 1) && (gender == 1) && (index > 22))	
	{
	[Status setStringValue:"Over weight"];
        [Status setTextColor:NX_COLORRED];
	};

        // Below 18, female, normal
   	if ((agegroup == 1) && (gender == 2) && (index < 20))	
	{
	[Status setStringValue:"Normal"];
        [Status setTextColor:NX_COLORGREEN];
	};

        // Below 18, female, overweight
   	if ((agegroup == 1) && (gender == 2) && (index > 20))	
	{
	[Status setStringValue:"Over weight"];
        [Status setTextColor:NX_COLORRED];
	};



        // 20-29, Male, under weight
   	if ((agegroup == 2) && (gender == 1) && (index < 20))	
	{
	[Status setStringValue:"Under weight"];
        [Status setTextColor:NX_COLORYELLOW];
	};

        // 20-29, male, normal
   	if ((agegroup == 2) && (gender == 1) && (index < 27.8) && (index > 20))
	{
	[Status setStringValue:"Normal"];
        [Status setTextColor:NX_COLORGREEN];
	};

        // 20-29, male, over weight
   	if ((agegroup == 2) && (gender == 1) && (index > 27.8))
	{
	[Status setStringValue:"Over weight"];
        [Status setTextColor:NX_COLORRED];
	};

        // 20-29, female, under weight
   	if ((agegroup == 2) && (gender == 2) && (index < 20))	
	{
	[Status setStringValue:"Under weight"];
        [Status setTextColor:NX_COLORYELLOW];
	};


        // 20-29, female, normal
   	if ((agegroup == 2) && (gender == 2) && (index < 27.3) && (index > 20))
	{
	[Status setStringValue:"Normal"];
        [Status setTextColor:NX_COLORGREEN];
	};

        // 20-29, female, over weight
   	if ((agegroup == 2) && (gender == 2) && (index > 27.3))
	{
	[Status setStringValue:"Over weight"];
        [Status setTextColor:NX_COLORRED];
	};



        // Over 29, Male, under weight
   	if ((agegroup == 3) && (gender == 1) && (index < 20))	
	{
	[Status setStringValue:"Under weight"];
        [Status setTextColor:NX_COLORYELLOW];
	};


        // Over 29, male, normal
   	if ((agegroup == 3) && (gender == 1) && (index < 25) && (index > 20))
	{
	[Status setStringValue:"Normal"];
        [Status setTextColor:NX_COLORGREEN];
	};

        // Over 29, male, over weight
   	if ((agegroup == 3) && (gender == 1) && (index > 25))
	{
	[Status setStringValue:"Over weight"];
        [Status setTextColor:NX_COLORRED];
	};

        // Over 29, female, under weight
   	if ((agegroup == 3) && (gender == 2) && (index < 20))	
	{
	[Status setStringValue:"Under weight"];
        [Status setTextColor:NX_COLORYELLOW];
	};


        // Over 29, female, normal
   	if ((agegroup == 3) && (gender == 2) && (index < 24) && (index > 20))
	{
	[Status setStringValue:"Normal"];
        [Status setTextColor:NX_COLORGREEN];
	};

        // Over 29, female, over weight
   	if ((agegroup == 3) && (gender == 2) && (index > 24))
	{
	[Status setStringValue:"Over weight"];
        [Status setTextColor:NX_COLORRED];
	};


    return self;

}



- HeightRadioInput:sender
{

	// Assign variables
     	int feetinput;   
    	int inchesinput;
    	float convertedinches;
    	float height;

	// Assigns the value of the currently selected button
    	feetinput = [FeetButton selectedTag]; 

	// Assigns the value of the currently selected button
    	inchesinput = [InchesButton selectedTag]; 

	// Convert inches fraction (5/10) to floating point (0.50)

        convertedinches = feetinput * 12;
        height = inchesinput + convertedinches;

        // Display Height in the Height textfield
	[Height setIntValue:height];// Display result
	[Height display];


   return self;
}


// AWAKEFROMNIB
// This is one of the last methods executed after the nib file is loaded.
// This is the BEST way I know how to initialize an object and jump into
// a method after the nib file was loaded, because you are all the methods
// and variables needed can be used. (Unlike init which is not compeletly
// ready when that message is sent
- awakeFromNib
{
 
	[BMIPanel makeKeyAndOrderFront:NULL];
	[Height selectText:self];

    	return self;
}



@end
