﻿
var Seavus = {};

Number.prototype.NaN0=function(){return isNaN(this)?0:this;}

function getPosition(e)
{
	var left = 0;
	var top  = 0;
	while (e.offsetParent)
	{
		left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
		top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
		e     = e.offsetParent;
	}


	left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
	top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);

	return {x:left, y:top};

}

//general onclick function
/*
function documentClick(exceptionType)
{
    //all code should be in try block
    try
    {
        if(document.activeFilter && exceptionType != "excelFilter")
        {
            document.activeFilter.Hide();
        }
        
        if(document.actionCombo && exceptionType != "actionCombo")
        {  
            document.actionCombo.style.display = "none";
            //alert("gafdgfdgafdG");
        }
        //alert("document");
    }
    catch(e)
    {
    }
}
*/

//Seavus.prototype.lastAccessTime;

Seavus.KeepSessionTimer = 3000;

Seavus.SetLastAccessTime = function(accessTime)
{
    if(opener)
    {
        if(opener.top.Seavus)
        {
            opener.top.Seavus.lastAccessTime = accessTime;
        }
    }
    
    if(top.Seavus)
    {
        top.Seavus.lastAccessTime = accessTime;
    }
    
    Seavus.lastAccessTime=accessTime;
}


Seavus.KeepMeAlive = function()
{
    var postString = "lastAccessTime=" + Seavus.lastAccessTime;
    new Ajax.Request('../Handlers/KeepMeAlive.ashx', {
	            method:'post',
				postBody:postString,
			  onSuccess: function(transport) { Seavus.KeepMeAliveHandler(transport.responseText);},
			  onFailure: function(){ Seavus.AjaxError("KeepMeAlive",""); },
			  onException: function(req,exception){ Seavus.AjaxError("KeepMeAlive","",exception); }
			});
}

Seavus.KeepMeAliveHandler = function(jsonString)
{
    if (jsonString == "")
	{
	  return;
	}
	
	this.data = jsonString.evalJSON();
	
	if(this.data.sessionExpired)
	{
		Seavus.SessionExpired();
		return;
	}
	else
	{
	    setTimeout("Seavus.KeepMeAlive()", Seavus.KeepSessionTimer);
	}
}