javascript does not support sleep function, using setTimeout is a very good way to implement sleep functionality, otherwise, you have to resort to an ugly implementation likefunction sleep(nMillis)
{
  var dt1 = new Date();
  for (;;)
  {
var dt2 = new Date();
if ((dt2.getTime()-dt1.getTime()) >= nMillis)
break;
  }
}