﻿  var state = null;
  var timerid = null;
  var statebar = null;
  var ad = null;
  function init()
  {
    ChangeState("START");
    update();
  }
  function update()
  {
    if(state=="START")
    {
      statebar.innerText='Please press and hold CTRL key';
      ad.innerText='Press CTRL';
    }
    else if(state=="CTRL_DOWN")
    {
      statebar.innerText='Keep hold and move mouse pointer to over the floating Ad now';
      ad.innerText = 'Move mouse pointer';
    }
    else if(state=="SWEEP")
    {
      statebar.innerText='Erasing...(Please make sure your Silence is active)';
      ad.innerText = 'Erasing'
    }
    else if(state=="DONE")
    {
      statebar.innerText=ad.innerText = 'Erase Successful!';
    }
    else
      statebar.innerText=ad.innerText = 'excepted case';
  }
  function ChangeState(s)
  {
    state = s;
  }
  function key_down()
  {
    if(state=='START')
    {
	  if(event.ctrlKey)
	  {
        ChangeState('CTRL_DOWN');
        update();
      }
    }
  }
  function key_up()
  {
    if(state=='CTRL_DOWN')
    {
      ChangeState('START');
      update();
    }
    else if(state=='SWEEP')
    {
      ChangeState('START');
      update();
    }
  }
  function onenter()
  {
    if(state=='CTRL_DOWN')
    {
      ChangeState('SWEEP');
      update();
    }
  }
  function ondone()
  {
    if(state=='SWEEP')
    {
      ChangeState('DONE');
      update();
      clearInterval(timerid);
    }
  }
  function check_done()
  {
    if(state=='SWEEP')
    {
	  	if(fad.style.display=='none')
	  	  ondone();
  	}
  }
  function start_learn()
  {
    statebar = document.getElementById('statebar');
    ad = document.getElementById('ad');
    start_ad();
    statebar.style.display='';
    clearInterval(timerid);
    timerid = setInterval('check_done()', 50);
    return init();
  }

