http://learn.javascript.ru/play/38hZ8b
<!DOCTYPE HTML>
<html>
<head></head>
<body>
<input id="mig" type="text">
<input onclick="setMig()" type="button" value="SET">
<script>
var mig = document.getElementById('mig'),
body = document.body || document.getElementsByTagName('body')[0],
migInt;
function setMig() {
var n = +mig.value, f;
if(!n) return;
if(migInt) clearInterval(migInt);
migInt = setInterval(function() {
body.bgColor = (f ^= 1) ? '#FF0000' : '#FFF';
if(!--n) {
clearInterval(migInt);
migInt = null;
}
}, 1000);
}
</script>
</body>
</html>