function ButtonLoader()
{
    this.ImagePath = "/images/misc/animating_loader.gif";
    this.Width = "28px";
    this.Height = "28px";
    this.OutOfScope = false;
}

ButtonLoader.prototype.OnClick = function(p_Object)
{
    var l_Image = document.createElement("img");
    l_Image.src = this.ImagePath;
    l_Image.style.width = this.Width;
    l_Image.style.height = this.Height;
    p_Object.parentNode.insertBefore(l_Image, p_Object);
    p_Object.style.display = "none";
    g_ButtonLoaderTimeoutHandle = setTimeout(
	function()
	{
		l_Image.style.display = "none";
		p_Object.style.display = "block";
		g_ButtonLoaderTimeoutHandle = null;
	}, 100);
    window.onbeforeunload = function() 
	{ 
		//this.CheckBackButton(p_Object, l_Image, this); 
		setTimeout ( function() 
			{ 
				this.OutOfScope = true; 
				l_Image.style.display = "none"; 
				p_Object.style.display = "block";  
			} 
			, 1000) 
	};
}


ButtonLoader.prototype.CheckBackButton = function(p_Button, p_Image, p_Instance)
{
	alert(p_Instance,OutOfScope);
	if (p_Instance.OutOfScope == true)
	{
		p_Image.style.display = "none"; 
		p_Object.style.display = "block";
		return;
	}
	setTimeout( function() { p_Instance.CheckBackButton(p_Button, p_Image, p_Instance) }, 1000);
}