﻿// JScript File
/********** PREVENTING MOUSE DOUBLE CLICKS *****************/

/*Usage: 
    <asp:Button runat="server" Text="My Button" OnClientClick="disableButton(this,30000);" />
*/

function disableButton(button, resetDelay)
    {
        button.enabled = false;
        button.oldonclick = button.onclick;
        button.onclick=noClick; //new Function("return false;";
        button.oldCursorStyle = document.body.style.cursor;
        document.body.style.cursor = "wait";        
        setTimeout("enableButton('"+ button.id + "');", resetDelay);                                    
    }
function noClick()
    {
        //alert("don't double click");
        return false;
    }
function enableButton(buttonId)
    {
        var button = document.getElementById(buttonId);
        if(button!=null)
        {
            button.onclick = button.oldonclick;
            document.body.style.cursor = button.oldCursorStyle;
            button.enabled = true;
        }
    } 




/************* MOUSE POSITION ****************/
function startCheckMousePos()
{
     // Start detecting where the mouse is.
     
     // Detect if the browser is IE or not.
     // If it is not IE, we assume that the browser is NS.
     var IE = document.all?true:false;
     
     // If NS -- that is, !IE -- then set up for mouse capture
     if (!IE) document.captureEvents(Event.MOUSEMOVE);
     
     // Set-up to use getMouseXY function onMouseMove
     document.onmousemove = this.getMouseXY;
}

function stopCheckMousePos()
{
     // Stop detecting where the mouse is.
     
     // Detect if the browser is IE or not.
     // If it is not IE, we assume that the browser is NS.
     var IE = document.all?true:false;
     
     // If NS -- that is, !IE -- then set up for mouse capture
     if (!IE) document.releaseEvents(Event.MOUSEMOVE);
     
     document.onmousemove = null;
}


// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {

    // Temporary variables to hold mouse x-y pos.s
    var tempX = 0;
    var tempY = 0;

  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //document.getElementById('MouseX').value = tempX + "px";
  //document.getElementById('MouseY').value = tempY + "px";
  
  //Assign tempX or tempY to something;
  
  var tempxX = tempX + 5;
  var tempyY = tempY + 5;
  var maxX = getClientWidth() - parseInt(getLocalElement("enlargeImageBox").style.width)
  var maxY = getClientHeight() - parseInt(getLocalElement("enlargeImageBox").style.height)
  if (tempyY > maxY)
  {
    tempyY = maxY;
  }
  if (tempxX > maxX)
  {
    tempxX = maxX;
  }
  $$('enlargeImageBox').style.left = tempxX + "px";
  $$('enlargeImageBox').style.top = tempyY + "px";

  return true
}
/************* MOUSE POSITION END ****************/



