<?PHP

if ($_POST['coordinates'] == 'serotta_xy') {
        
        foreach ( $_POST as $key )
        {
            
        }
        

        $xser = (float)$_POST['serottaX'];
        $yser = (float)$_POST['serottaY'];
        $stemlength = (float)$_POST['stem_length'];
        $headangle = (float)$_POST['head_angle'];
        $stemangle = (float)$_POST['stem_angle'];
        $clamp = (float)$_POST['clamp'];
        $spacer = (float)$_POST['spacer'];
        $headset = (float)$_POST['headset'];

        $reach = 0;
        $stack = 0; 

        // calculate stack and reach
        $reach = $xser - ($stemlength*cos(deg2rad(90-$headangle+$stemangle))) + (($clamp/2) + $spacer + $headset)*cos(deg2rad($headangle));
        $stack = $yser - ($stemlength*sin(deg2rad(90-$headangle+$stemangle))) - (($clamp/2) + $spacer + $headset)*sin(deg2rad($headangle));     

        //echo($xser." - (".$stemlength."*cos(deg2rad(90-".$headangle."+".$stemangle."))) - ((".$clamp."/2) + ".$spacer." + ".$headset.")*cos(deg2rad(".$headangle."))");
        //$stack = $yser - ($stemlength*sin(deg2rad(90-$headangle+$stemangle))) - (($clamp/2) + $spacer + $headset)*sin(deg2rad($headangle));   
        
        $reach = round($reach, 0);
        $stack = round($stack, 0);
        
        //echo ("STACK: ".$stack);
        //echo ("REACH: ".$reach);
        //exit();
} else {
        $stack = (float)$_POST['stack'];
        $reach = (float)$_POST['reach'];
}
$seat_angle = (float)deg2rad((float)$_POST['seat_angle']);
$head_angle = (float)deg2rad((float)$_POST['head_angle']);
$fork_offset = (float)$_POST['fork_offset'];
$fork_length = (float)$_POST['fork_length'];
$bb_drop = (float)$_POST['bb_drop'];
$chain_stay = (float)$_POST['chain_stay'];
$rear_wheel = (float)$_POST['rear_wheel'];
$hs_lower_stack = (float)$_POST['hs_lower_stack'];
$wheel_size = (int)$_POST['wheel_size'];

$bb_height = round($rear_wheel - $bb_drop, 1);

$trail = round(($rear_wheel * cos($head_angle) - $fork_offset) / sin($head_angle), 1);

$tt_eff = round($reach + $stack / tan($seat_angle), 1);

$ht_length = round(($stack - $bb_drop) / sin($head_angle) + $fork_offset / tan($head_angle) - $fork_length - $hs_lower_stack, 1);

$front_center = round(pow(pow(($reach + ($stack - $bb_drop) / tan($head_angle) + $fork_offset / sin($head_angle)), 2) + pow($bb_drop, 2), 0.5), 1);

$wheelbase = round(pow(pow($chain_stay, 2) - pow($bb_drop, 2), 0.5) + pow(pow($front_center, 2) - pow($bb_drop, 2), 0.5), 1);
?>
<?PHP include("config.php"); ?>
<!DOCTYPE html >
<html lang="en">
<head>
<title>&lt;:: Welcome to Slowtwitch.com ::&gt;: Custom Tri Geometry Calculator</title>
<meta name="KEYWORDS" content="bike, geometry, custom" />
<meta name="DESCRIPTION" content="Are you trying to find custom geometry based off a fitting session? Use our calculator to help."/>
<? include($common_path . "/templates/include_global_head.php"); ?>
<? include($common_path . "/templates/google_analytics.html"); ?>
<script src="js/fit_calculator.js" type="text/javascript" language="JavaScript"></script>
</head>

<body id="home">
  <? include($common_path . "/ads/ad_wallpaper.html"); ?>

  <div class="container">
    <? include($common_path . "/templates/include_header.php"); ?>
    <div class="main">
      <div class="contentwrapper clearfix">
        <? include("include_breadcrumb.php"); ?>

        <section class="section listings section-has-widgets section-static remove-sidebar">
          <div class="sidebar-b">
            <? include("include_sidebar.php") ?>
          </div>

          <div class="content content-has-widgets">
            <div class="grid">
              <h1>F.I.S.T Custom Bike Calculator</h1>
              <div class="clearfix">
                <div class="col-1-2">
                  <h3 class="section-title">Input</h3>
                  <div class="dtable form">
                    <div class="drow">
                      <div class="dcell name">Stack</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo $stack; ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Reach</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo $reach; ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Seat Angle</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo rad2deg($seat_angle); ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Head Tube Angle</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo rad2deg($head_angle); ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Fork Offset</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo rad2deg($fork_offset); ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Fork Length</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo rad2deg($fork_length); ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">BB Drop</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo rad2deg($bb_drop); ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Chainstay</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo rad2deg($chain_stay); ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Rear Wheel</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo rad2deg($rear_wheel); ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Headset Lower Stack</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo rad2deg($hs_lower_stack); ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Wheel Size</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo rad2deg($wheel_size); ?></div>
                    </div>
                  </div>
                </div>
                <div class="col-1-2">
                  <h3 class="section-title">Frame Measurements</h3>
                  <div class="dtable form">
                    <div class="drow">
                      <div class="dcell name">BB Height</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo $bb_height; ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Trail</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo $trail; ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Eff. Top Tube Length</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo $tt_eff; ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Head Tube Length</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo $ht_length; ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Wheelbase</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo $wheelbase; ?></div>
                    </div>
                    <div class="drow">
                      <div class="dcell name">Front Center</div>
                      <div class="dcell divider"></div>
                      <div class="dcell value"><? echo $front_center; ?></div>
                    </div>
                  </div>
                </div>
              </div>
              <?
              if( ($front_center < 560) && ($wheel_size == 700) ){
                echo '<p class="error"><strong>WARNING: Your front center is too short!</strong></p>';
              }

              if( ($front_center < 525) && ($wheel_size == 650) ){
                echo '<p class="error"><strong>WARNING: Your front center is too short!</strong></p>';
              }

              ?>
              <div class="center">
                  <a href="fit_calculator.php" class="btn default">Return to the Geometry Calculator</a>
              </div>

            </div><!-- end grid -->
          </div><!-- end content -->
        </section>

      </div><!-- end contentwrapper -->
    </div> <!-- end main -->

  <? include($common_path . "/templates/include_footer.php") ?>
  </div> <!-- container  -->
</body>
<? include($common_path . "/templates/include_global_js.php") ?>
</html>

