﻿delayOver = false;

function pageLoad()
{
  btnDelayed = document.getElementById(btnDelayedID);
  hmePrefPublisherControl = Sys.Application.findComponent(hmePrefPublisher);

  if (hmePrefPublisherControl)
  {
    var hme = hmePrefPublisherControl._hoverBehavior;

    lbChangePreference = document.getElementById(lbChangePreferenceID);

    mouseOver = hmePrefPublisherControl._hoverHandler;
    hme.get_events().removeHandler("hover", hmePrefPublisherControl._hoverHandler);
    lbChangePreference.onmouseover = delayMouseOver;
  }

  if (btnDelayed && !delayOver) 
  {
    delayOver = true;
    btnDelayed.click();
  }

  lbAllAsyncHandled = document.getElementById(lbAllAsyncHandledID);

  var done = getInnerText(lbAllAsyncHandled) == "1";
  if (delayOver && done) 
  {
    lbPath = document.getElementById(lbPathID);
    window.location.replace(getInnerText(lbPath));
  }
}

function getInnerText(control) 
{
  return document.all? control.innerText: control.textContent;
}

function showUpdatingImage()
{
  document.body.style.cursor = 'wait';
  document.getElementById('spnUpdating').style.display = "";
  setTimeout('document.images["imgUpdating"].src="GetResource.aspx?path=images/CountdownDots.gif"', 200);
}

function unHover()
{
  var hme = Sys.Application.findComponent(hmePrefPublisher)._hoverBehavior;
  hme._hoverFired = false;

  var handler = hme.get_events().getHandler("unhover");

  if (handler)
    handler(hme, Sys.EventArgs.Empty);
}

function delayMouseOver()
{

  //alert("Hello");
  showTimerx = window.setTimeout(function()
  {
    //alert("mouseOver: " + mouseOver);
    //debugger;
    mouseOver();
  }, 1000);
}

function ItemMouseOut()
{
  if (showTimerx) {
    window.clearTimeout(showTimerx);
    showTimerx = null;
  }
}
