$(document).ready(function() {
$().onUserExit({
execute: function()
{
   $.post(getASHXpath(), { user_data: ("99*"+ClientTime()+"****"+getPageName())}, function(output){});
},
internalURLs: "http://www.shieldhotels.com|http://shieldhotels.com"

});

});
function logSiteLink(linkTaken)
{ 
 var aposition=linkTaken.indexOf("shieldhotels.com");
 if( aposition ==-1 )
    {
     $(document).ready(function ()
     {
        $.post(getASHXpath(), { user_data: ("2*"+ClientTime()+"*"+sGeobytesCity+"*"+sGeobytesRegion+"*"+sGeobytesCountry+"*"+linkTaken)}, function(output){});});
     }
}

function logPageVisit()
{
    $(document).ready(function ()
     {
        $.post(getASHXpath(), { user_data: (getPageNumber()+"*"+ClientTime()+"*"+sGeobytesCity+"*"+sGeobytesRegion+"*"+sGeobytesCountry+"*"+getPageName())}, function(output){});});
} 
function getASHXpath()
{
var sPath = window.location.pathname;
var sCount=sPath.split("/").length - 1;
var ASHXpath="";
if(sCount>=2)
    {  
       ASHXpath="../user_Login.ashx";
    }
    else
    {
    ASHXpath="user_Login.ashx";
    }
    return(ASHXpath);
    }
function getPageNumber()
{
    var sPath = window.location.pathname;
    var sCount=sPath.split("/").length - 1;
    var pageNumber="";
    if(sCount>=2)
    {
        pageNumber="3";
    }
    else
    {
        pageNumber="1";
    }
    return(pageNumber);
}

function getPageName()
{
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    var sCount=sPath.split("/").length - 1;
    var pageName="";    
    if(sPage=="")
    {
       sPage="default.aspx";
    }
    if(sCount>=2)
    {
        var dirs=window.location.href.split('/'),cdir=dirs[dirs.length-2];
         pageName=cdir;
    }
    else
    {
        pageName=sPage;
    }
    return(pageName);
}
function ClientTime()
{   
        var currentTime = new Date();
        var hours = currentTime.getHours()
        var minutes = currentTime.getMinutes()
        var seconds = currentTime.getSeconds()
        var year= currentTime.getFullYear()
        var suffix = "AM";
        if (hours >= 12) 
        {
           suffix = "PM";
           hours = hours - 12;
        }
        if (hours == 0) 
        {
            hours = 12;
        }
        if (minutes < 10)
        {
            minutes = "0" + minutes
        }
        var month= currentTime.getMonth() +1;
        var date = currentTime.getDate();
        var clientTime= month+"*"+date+"*"+year+"*"+hours+":"+minutes +":"+seconds+" "+suffix; 
        return clientTime;
}
$(document).ready(function() {
   // $('a[rel!=noreferrer]').click(function() { window.onbeforeunload = null; });
   // $('a[rel!=ext]').click(function() { window.onbeforeunload = null; });
    $('a').click(function(){ logSiteLink(($(this).attr('href'))); });
    $(window).load( function () { logPageVisit(); } );
   // $('form').submit(function() { window.onbeforeunload = null; });
});

