﻿// JScript File
var t, Stime, Rtime;
    
$(document).ready(function() {    
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});	
	    
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		    
		$('#mask').hide();
		$('.window').hide();
	});        
});

             
function ShowSessionExpMessage() {
    if ($('#ctl00_hdnUserLogin').val() == "true") { 
	    //Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	     
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	    
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$('#dialog').css('top',  winH/2-$('#dialog').height()/2);
		$('#dialog').css('left', winW/2-$('#dialog').width()/2);
	     
		//transition effect
		$('#dialog').fadeIn(2000);
		
		InitializeTimer();
    }
//    else 
//        alert($('#ctl00_hdnUserLogin').val());
}
    
function DisplayTimeOutAlert(IdleTime, RemainTime) {
        Stime=IdleTime;
        Rtime=RemainTime;
        t=setTimeout("ShowSessionExpMessage()",IdleTime);
} 

function GetMemberSession() {
    StopTheClock();
    var $urlToSend = "&random=" + Math.floor(Math.random() * 100001);
    $.ajax({
        type: "GET",
        url: "ResetMemberSession.ashx",
        data: $urlToSend,
        dataType: "text/plain",
        async: false,
        success: function(data) {
            $('#mask').click();
            //DisplayTimeOutAlert(Stime,Rtime);            
            DisplayTimeOutAlert(((20 * 60000) - 30000),30000);
            return false;
        },  
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(errorThrown);
        }   
    });     
}             

var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = ((Rtime-4000)/1000);//30;    
    StopTheClock();
    StartTheTimer();
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID);
    timerRunning = false;
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock();
        // Here's where you put something useful that's supposed to happen after the allotted time.
        location.href="signout.aspx?msg=s";
    }
    else
    {
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        $('#divTime').text(secs);
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}           