﻿var altKey = false;
var keyCode = 0;
var myevent = true;
function closeSession(evt) {
    if (myevent == true) {
        evt = (evt) ? evt : event;

        clickY = evt.clientY;
        altKey = evt.altKey;
        keyCode = evt.keyCode;

        if (!evt.clientY) {
            // Window Closing in FireFox 
            // capturing ALT + F4 
            keyVals = document.getElementById('ffKeyTrap');
            if (keyVals.value == 'true115') {
            statuschange(myevent);
               // window.open("sessionabondan.aspx", null, "height = 1,width=1");
//                return 'close 1';
            }

            if (keyVals.value == '') {
                // capturing a window close by "X" ?
               // window.open("sessionabondan.aspx", null, "height = 1,width=1");
                statuschange(myevent); 
                
//                return 'close 2';
            }

        } else {
            // Window Closing in IE 
            // capturing ALT + F4 
            if (altKey == true && keyCode == 115) {
               // window.open("sessionabondan.aspx", null, "height = 1,width=1");
                
                 statuschange(myevent);
                // capturing a window close by "X" 
            } else if (clickY < 0) {
           // window.open("sessionabondan.aspx", null, "height = 1,width=1");
               
             statuschange(myevent);
                // simply leaving the page via a link 
            } else {
                //alert('close 3'); 
                return void (0);
            }
        }
      
    }

    myevent = true;
}

function whatKey(evt) {
    evt = (evt) ? evt : event;
    keyVals = document.getElementById('ffKeyTrap');
    altKey = evt.altKey;
    keyCode = evt.keyCode;
    if (altKey && keyCode == 115) {
        keyVals.value = String(altKey) + String(keyCode);
    }
}
function makemyeventfalse() {
     myevent = false;

}
var xmlHttp

function statuschange(str)
{ 

//alert(str);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="showClient.aspx";
url=url+"?id="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
window.onkeydown = whatKey;
window.onbeforeunload = closeSession;

