  $(function(){
    // Dialog
    $('#dialog').dialog({
      autoOpen: false,
      width: 600,
      buttons: {
        "Ok": function() {
          $(this).dialog("close");
        }
      }
    });

    // Dialog Link
    $('#dialog_link').click(function(){
    //fill fields in results dialog
      var sex = $('#sex').val();
      var C5 = $('#age').val();
      var C6 = $('#weight').val();
      var C7 = $('#height').val();
      var C8 = $('#pulse').val();
      var C9 = $('#wrist').val();
      var C10 = $('#waist').val();
      var C11 = $('#leg').val();
      var C12 = $('#fore_arm').val();
      var C18 = 0;
      var C19 = 0;
      var C20 = 0;
      var C23 = 0;
      var C28 = 0;
      var C29 = 0;
      var C30 = 0;
      var C31 = 0;
      var C32 = 0;
      var C33 = 0;
      var C38 = 0;
      var C39 = 0;
      var C40 = 0;
      var C42 = 0;
      var C43 = 0;
      var C35 = 0;
      var C34 = 0;
/*      var C38 = 0;
      var C38 = 0;
      var C38 = 0;
*/            
      
      if(sex == 'f'){
        C18 = (((C6*2.2*0.732+8.987)+(C9/2.54/3.14)-(C10/2.54*0.157)-(C11/2.54*0.249)-(C12/2.54*0.434))/2.2).toFixed(2);
        C23 = ( ((9.99*C6)+(6.25*C7)-(4.92*C5)-161) ).toFixed(2);
	C34 = (-2.097 + (0.1069*C7)+(0.2466*C6)).toFixed(2);
	C35 = ( 45.5+2.3*(C7/2.54-60) ).toFixed(2);
	
      }else{
        C18 = (((C6*2.2*1.082)+94.42-(C10/2.54*4.15))/2.2).toFixed(2) ;
	C23 = ( ((9.99*C6)+(6.25*C7)-(4.92*C5)+5) ).toFixed(2) ;
	C34 = ( 2.447 - 0.09156*C5 + 0.1074*C7+0.3362*C6).toFixed(2);		
	C35 = ( 50+2.3*(C7/2.54-60) ).toFixed(2);
      }

      
      C19 = ( C6-C18 ).toFixed(2) ;
      C20 = ( C19*100/C6 ).toFixed(2) ;
      C28 = ( C23*1.2 ).toFixed(2) ;
      C29 = ( C23*1.375 ).toFixed(2);
      C30 = ( C23*1.55 ).toFixed(2);
      C31 = ( C23*1.725 ).toFixed(2);
      C32 = ( C23*1.9 ).toFixed(2);
      C38 = ( 0.2*C28/9 ).toFixed(2);
      C39 = ( 0.5*C28/4 ).toFixed(2);
      C40 = ( 0.3*C28/4 ).toFixed(2);
      C42 = 220*0.7 - C5*0.7 + C8*0.3;//((220-C5)-C8)*0,7+C8
      C43 = 220*0.8 - C5*0.8 + C8*0.2;
	      
      $('#imt').html((C6/C7/C7*10000 ).toFixed(2) );
      $('#tmt').html( C18 );
      $('#jmt').html( C19 );
      $('#jvo').html( C20 );
      $('#bmr').html( C23 );
      $('#pkp').html( C28 );
      $('#sa').html( C29 );
      $('#uo').html( C30 );
      $('#oa').html( C31 );
      $('#io').html( C32 );
      $('#fat').html( C38 );
      $('#carb').html( C39 );
      $('#prot').html( C40 );
      $('#ipulse').html( C42 + " - " + C43);
      $('#jvo').html( C20 );      
      $('#wio').html( C34 );
      $('#im').html( C35 );

      $('#dialog').dialog('open');
      return false;
    });
  });

$(document).ready(function(){
  $("select").change(function () {
//alert($("select").val());
    if($("select#sex").val() == "f")
      $("table#hc tr.ow").show()
    else 
      $("table#hc tr.ow").hide();
    })

});
