var isFlashing = false;
var tCntr = 0;
var flashTimerID = '';
var flashObj;
var flashTime = 500;
var flashCycle = 0;

function fnRecycle() {
  if (window.flashObj.style.visibility == 'hidden') {
    window.flashObj.style.visibility = 'visible';
    window.tCntr = window.flashCycle;
    }
  else if (window.tCntr < window.flashCycle) {
    window.flashObj.style.visibility = 'hidden';
    window.tCntr = window.flashCycle;
    }
  else {
    window.tCntr--;
    }
}
function stopFlash()  {
  if (window.flashTimerID > '')
    window.clearInterval(window.flashTimerID);
}

function doToggle(tObj, tTime, tCycle, tMax) {
  window.flashObj = tObj;
  if (tTime) window.flashTime = tTime;
  if (tCycle) window.flashCycle = tCycle;
  if (window.isFlashing) {
    stopFlash();
    window.isFlashing = false;
    window.flashObj.style.visibility='hidden';
    }
  else {
    window.flashObj.style.visibility='visible';
    window.isFlashing = true;
    window.flashTimerID = window.setInterval('fnRecycle()', window.flashTime);
    if (tMax) {
      window.setTimeout("stopFlash(); window.flashObj.style.visibility='visible'; window.isFlashing=false;", tMax);
      }
    }
}
