<?php
header("Content-Type: text/html;charset=windows-1251");
define('MAX_SPEED', 1500);
define('MAX_LINE_WIDTH', 400);

function getWidth($current, $max) {
	return round((MAX_LINE_WIDTH / $max)*$current);
}
function getImage($speed) {
	if ($speed<56) return '1.gif';
	if ($speed<384) return '2.gif';
	if ($speed<768) return '3.gif';
	if ($speed<1500) return '4.gif';
	return '5.gif';
}

function showMySpeed($mySpeed, $maxSpeed) {
	$width = getWidth($mySpeed, $maxSpeed);
	$image = "my.gif";
	return "<tr>\n<td align=\"left\" width=\"150px\"><b>$mySpeed kbps</b></td>\n<td align=\"center\"><b>Моя скорость</b></td>\n<td align=\"left\"><img src=\"images/$image\" height=\"10\" width=\"$width\">\n</td>\n</tr>";
}

function showSpeed($fixedSpeed, $mySpeed, $name, $maxSpeed, &$shown) {
	$str = '';
	if ($mySpeed < $fixedSpeed && !$shown) {
		$shown = TRUE;
		$str .= showMySpeed($mySpeed, $maxSpeed); 
	}
	
	$width = getWidth($fixedSpeed, $maxSpeed);
	$image = getImage($fixedSpeed);
	$str .= "<tr>\n<td align=\"left\" width=\"150px\">$fixedSpeed kbps</td>\n<td align=\"center\">$name</td>\n<td align=\"left\"><img src=\"images/$image\" height=\"10\" width=\"$width\">\n</td>\n</tr>";
	
	return $str;
}

if (isset($_REQUEST['speed']) && $_REQUEST['speed']!='') {
	$speed = $_REQUEST['speed'];
	$speed = round(8*$speed,1);
	$shown = FALSE;
	$str = '';
	if ($speed > MAX_SPEED) $maxSpeed = $speed; else $maxSpeed = MAX_SPEED;
	
	$str .= "Ваша скорость <b>$speed кбит/cек</b>, это <b>".round($speed/8,1)." КБайт/сек</b><br/><br />";
/**	$str .= '<table>';
	$str .= showSpeed(28.8, $speed, 'dial-up', $maxSpeed, $shown);
	$str .= showSpeed(33.6, $speed, 'dial-up', $maxSpeed, $shown);
	$str .= showSpeed(53.3, $speed, 'dial-up', $maxSpeed, $shown);
	$str .= showSpeed(56, $speed, 'ISDN', $maxSpeed, $shown);
	$str .= showSpeed(128, $speed, 'ISDN', $maxSpeed, $shown);
	$str .= showSpeed(384, $speed, 'DSL', $maxSpeed, $shown);
	$str .= showSpeed(768, $speed, 'DSL', $maxSpeed, $shown);
	$str .= showSpeed(1000, $speed, 'DSL', $maxSpeed, $shown);
	$str .= showSpeed(1500, $speed, 'T1/Cable Modem', $maxSpeed, $shown);
	
	if (!$shown) $str .= showMySpeed($speed, $maxSpeed);
	$str .= '</table>';
 */
	$str .= '<br /><br /><a href="javascript:NewTest();">Проверить еще раз</a>';
	echo $str;
	
} else {
	echo 'Во время выполнения произошла ошибка';
}
?>
