
var prm = Sys.WebForms.PageRequestManager.getInstance();

if (prm != null)
{
    prm.add_beginRequest(InitializeRequest);
    prm.add_endRequest(InitializeModalForm);
}

function InitializeRequest(sender, args) {

    var alp = document.getElementById('AjaxLoadingProgress');
    if (alp != null)
    {
          if (TT.TransparentProgress) //tooltip
          {
             alp.style.backgroundColor = "transparent";  
             TT.TransparentProgress = false;
             document.MouseCoords = TT.CurrPos; //tooltip is shown on mouseover instead of mousedown             
          }    
          else  
          {
            //rating
            var pbElem = args.get_postBackElement();
            if (pbElem 
               && pbElem.parentNode 
               && pbElem.parentNode.parentNode 
               && pbElem.parentNode.parentNode.parentNode 
               && pbElem.parentNode.parentNode.parentNode.parentNode 
               && pbElem.parentNode.parentNode.parentNode.parentNode.parentNode
               && pbElem.parentNode.parentNode.parentNode.parentNode.parentNode.className == "rating_tbl")
            {
               alp.style.backgroundColor = "transparent";  
            }
            else   
            {
               alp.style.backgroundColor = "#ffffff";      
            }
         }
       
         alp.style.height = document.body.scrollHeight + 'px';
         alp.style.width = document.body.scrollWidth + 'px';
         for(var i=0; i<alp.childNodes.length; i++)
         {
            var child = alp.childNodes[i];
            if (child.tagName == "IMG")
            {
               
                if (!document.MouseCoords)
                {
                    child.style.position = "relative";
                    child.style.top = (document.body.clientHeight/2 + document.body.scrollTop) + 'px';
                }
                else
                {
                    child.style.position = "absolute";
                    if (br_ie)
                    {
                        child.style.left = (document.MouseCoords.X - parseInt(child.style.width)/2) + 'px';
                        child.style.top = (document.MouseCoords.Y - parseInt(child.style.height)) + 'px';
                    }
                    else
                    {
                        child.style.left = (document.MouseCoords.X - child.width/2) + 'px';
                        child.style.top = (document.MouseCoords.Y - child.height) + 'px';
                    }
                }
                
                break;
            }
         }
    }    
}

function InitializeModalForm(){
   if (typeof(MF) != 'undefined')
     MF.initModalForm();
   if (typeof(TT) != 'undefined')
     TT.Restore();  
}

function storeMouseDownCoordinates(e)
{
   if (!e)
      e = window.event;
   
   if (e.pageX)
   {
      document.MouseCoords = new Object();
      document.MouseCoords.X = e.pageX;
      document.MouseCoords.Y = e.pageY;
   }  
   else
   {
      document.MouseCoords = new Object();
      document.MouseCoords.X = e.clientX + document.body.scrollLeft;
      document.MouseCoords.Y = e.clientY + document.body.scrollTop;
   } 
}

function trackMouseDownForDocument()
{
   if (document.attachEvent)
	  document.attachEvent('onmousedown', storeMouseDownCoordinates);
   else
	  document.addEventListener('mousedown', storeMouseDownCoordinates, false);
}

trackMouseDownForDocument();