
document.write('<scr'+'ipt type="text/javascript" src="https://www.idigbio.org/login/javascripts/async.js?1444144537" ></scr'+'ipt>');
document.write('<scr'+'ipt type="text/javascript" src="https://www.idigbio.org/login/javascripts/url.js?1444144537" ></scr'+'ipt>');

var logouts = {
    drupal: function(callback){
        jQuery.get('/?q=user/logout',function(resp){
            callback(null,'done');
        }).error(callback(null,'done'));
    },
    wiki: function(callback){
        jQuery.get('/wiki/index.php?title=Special:UserLogout&returnto=Main+Page',function(resp){  
            callback(null,'done');
        }).error(callback(null,'done'));
    },
    portal: function(callback){
        jQuery.get('/portal/logout',function(resp){  
            callback(null, 'done');
        }).error(callback(null, 'done'));
    },
    
    auth: function(callback){
        jQuery.get('/login/sessions/destroy',function(resp){
            callback(null,'done');
        }).error(callback(null, 'done'));
    }
};

function callLogout(url){
    var endcb = function(err,res){
        setTimeout(function(){
            if(typeof url === 'string' && document.location !== url){
                document.location = url;
            }else if(typeof url === 'undefined' || document.location === url){
                location.reload();
            }
        },700);
    }
    async.series(logouts,endcb);
    return false;
}
//returns true if its above threshold for auto login loop, false otherwise
//defaults to 5000 milliseconds unless specified by thresh
function lastLoginPush(thresh){
    if(typeof thresh === 'undefined'){
        thresh = 5000;
    }
    if(typeof localStorage.last_login_push === 'undefined'){
        localStorage.setItem('last_login_push', (Date.now()-(thresh*3)).toString());
    }
    var last ='';
    if(localStorage && localStorage.last_login_push){
        var last = localStorage.getItem('last_login_push');
    }
    var current = Date.now();

    var dif = current - parseInt(last);

    if(dif>thresh){
        if(localStorage){
            localStorage.setItem('last_login_push', current.toString());
        }
        return true;
    }else{
        if(localStorage){
            localStorage.setItem('last_login_push', current.toString());
        }

        // alert("There is a problem with your account! Please notify us about the issue.");
        
        return true;//false;
    }
    //return true;
}
//var message = 'Outage Notification Test!';
//jQuery('body').prepend('<div style="width:99%;height:50px;background-color:yellow;border:2px solid red;font-size:16px;color:#666;">'+message+'</div>');
jQuery(document).ready(function(){
jQuery('#pt-logout').hide();
    if(jQuery('#pt-logout').length > 0){
        callLogout();
    }
    jQuery('#pt-anonlogin, #pt-openidlogin, #pt-login').hide();
    if(jQuery('#userloginForm').length > 0){
        jQuery('#userloginForm').hide();
        jQuery('#userloginForm').after('<div style="padding:8px;border:2px solid darkblue;margin:10px;">This Login Form Has Been Disabled.<br>Please visit the <a href="/login/sessions/new">main iDigBio Log In</a>.</div>');
    }
});