﻿// JScript File

function GetWeight(ctrlSpanResult,ctrlRbtnlGender ,ctrlDdlWeight, ctrlDdlTall)
{
    ctrlSpanResult = document.getElementById(ctrlSpanResult);

    var ctrlRbtnlGender_M = document.getElementById(ctrlRbtnlGender + "_1");
    var ctrlRbtnlGender_F = document.getElementById(ctrlRbtnlGender + "_0");
    
     
     ctrlDdlWeight = document.getElementById(ctrlDdlWeight);
     ctrlDdlTall = document.getElementById(ctrlDdlTall);
 
    if( ctrlDdlWeight.options[ctrlDdlWeight.selectedIndex].value == -1 )
    {
        return false;
    }

    if( ctrlDdlTall.options[ctrlDdlTall.selectedIndex].value == -1 )
    {
        return false;
    }
            
       
    var weight = 0.0;
    var hight  = 0.0;
    var res  = 0.0;
    
    weight = ctrlDdlWeight.options[ctrlDdlWeight.selectedIndex].value;
    hight = ctrlDdlTall.options[ctrlDdlTall.selectedIndex].value;
    
    
      
    if(ctrlRbtnlGender_M.checked )
    {
    // M
        if( eval(hight) <= 5 )
            res = 50;
        else if( eval(hight) > 5 && eval(hight) < 6 )
            res = 50 + (2.3 * eval(hight.substring(2) ));
        else if( eval(hight) == 6 )
            res = 50 + (2.3 * 12);
        else if( eval(hight) > 6 && eval(hight) < 7 )
            res = 50 + (2.3 * eval(eval(hight.substring(2)) + 12));
        else if( eval(hight) == 7 )
            res = 50 + (2.3 * 24);
        else if( eval(hight) > 7 && eval(hight) < 8 )
            res = 50 + (2.3 * eval(eval(hight.substring(2)) + 24));
        else if( eval(hight) == 8 )
            res = 50 + (2.3 * 36);
        
        //Ctrl_CalcWeight_ResultBox1.w = res
        //If res = "" Then
        //    Ctrl_CalcWeight_ResultBox1.Msg = "please choose a gender first"
        //End If
       
   }
   else
    {
    
    
        if( ctrlRbtnlGender_F.checked) 
        {
        // F
            if ( eval(hight) <= 5 )
                res = 45.5;
            else if( eval(hight) > 5 && eval(hight) < 6 )
                res = 45.5 + (2.3 * eval( hight.substring(2) ));
            else if( eval(hight) == 6 )
                res = 45.5 + (2.3 * 12);
             else if( eval(hight) > 6 && eval(hight) < 7)
                res = 45.5 + (2.3 * eval(eval(hight.substring(2)) + 12));
            else if( eval(hight) == 7 )
                res = 45.5 + (2.3 * 24);
             else if( eval(hight) > 7 && eval(hight) < 8)
                res = 45.5 + (2.3 * eval(eval(hight.substring(2)) + 24));
             else if( eval(hight) == 8)
                res = 45.5 + (2.3 * 36);
            
            
        }
        
    }
    
    
    res = res.toString();
    if (res.length > 5)
    {
        res = res.substring(0,5)
    }
    
    
    
    ctrlSpanResult.innerHTML = res + " " + "كلغ";
    var resultDiv = document.getElementById("spanResultDiv");
		resultDiv.style.display="block";
		
    //alert("res: "+ res);
    return true;
}
