/* AUTHOR: INFO SERVICE */
/* CREATION DATE: 16/09/2002 */
var cook = 'Pas*d\'utilisateur';
var rights = '';
var droits = new Array;
var droits2 = new Array;
var password = '';
var dom = '0';
var dom2 = '0';
var bid=false;

function SetCookie(name, value, path, expires, domain, secure) 
{ document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null)    ? "" : "; path=" + path) +
  ((domain == null)  ? "" : "; domain=" + domain) +
  ((secure == null)  ? "" : "; secure");
}

function GetCookie(name) {
 var cname = name + "=";  
 var dc = document.cookie;    
  if (dc.length > 0) 
  { begin = dc.indexOf(cname);       
    if (begin != -1) 
    { begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
      return unescape(dc.substring(begin, end));
    } 
  }
  return 'pas*d\'utilisateur';
}



function Set_Cookie2(nom) {
cook = nom;
var expiration = new Date();
expiration.setTime(expiration.getTime() + 365*24*60*60*1000);
SetCookie('user',cook,'/');
SetCookie('current',cook,'/');
SetCookie('last',cook,'/',expiration);
}

function Set_Cookie4(nom2) {
cook2 = nom2;
var expiration = new Date();
expiration.setTime(expiration.getTime() + 365*24*60*60*1000);
SetCookie('domaine',cook2,'/');
}

function Set_Cookie5(nom5) {
cooky = nom5;
var expiration = new Date();
expiration.setTime(expiration.getTime() + 365*24*60*60*1000);
SetCookie('password',cooky,'/');
}

function Set_Cookie3(nom) {
cook = nom;
var expiration = new Date();
expiration.setTime(expiration.getTime() + 365*24*60*60*1000);
SetCookie('current',cook,'/');
}

//Lecture du cookie permettant de stocker les variables de l'utilisateur
function Get_Cookie2() {
dom2 = GetCookie('domaine');
dom =dom2;
nom = GetCookie('user').toLowerCase();
currentnom = GetCookie('current').toLowerCase();
lastnom = GetCookie('last').toLowerCase();
password = GetCookie('password').toLowerCase();
}

function Delete_Cookie2() {
var expiration = new Date();
expiration.setTime(expiration.getTime() + 365*24*60*60*1000);
SetCookie('user','pas*d\'utilisateur','/',expiration);
SetCookie('current','pas*d\'utilisateur','/',expiration);
SetCookie('domaine','0','/',expiration);
}


function initb() {
Get_Cookie2();
if ((nom != 'pas*d\'utilisateur')&&(nom != '')) {document.saisie.login.value=nom;log=nom;}
else {document.saisie.login.value='Pas connecté';log='Pas connecté';
if (!bid){top.main.location.href='../cgi-local/ainput.pl';}
}
getrights();
}



//Fermeture d'une session utilisateur
function closeid() {
Delete_Cookie2();
Get_Cookie2();

alert (lastnom + "La session est fermée.\nL'accès à vos droits est désormais impossible.\n\nVous pouvez saisir un nouvel utilisateur.");

top.main.location.href='/cgi-local/mapa/ainput.pl';
return false;
}


function checkrights() {
i=0;
Get_Cookie2();
while (i <auth.length) {
author=auth[i].toLowerCase();
if (author == nom) {rights = auth[i+1]}
i++;i++;}
if (((rights.charAt(0) == '0')&&(rights.charAt(1) != '0'))||(rights.charAt(0) == '')) {
self.location.href='/cgi-local/mapa/areject.pl'}

}


function getrights() {
i=0;
Get_Cookie2();
while (i <auth.length) {
author=auth[i].toLowerCase();
if (author == nom) {rights = auth[i+1]}
i++;i++;}
}

function checkrights2() {
i=0;
Get_Cookie2();
while (i <auth.length) {
author=auth[i].toLowerCase();
if (author == nom) {rights = auth[i+1]}
i++;i++;}
droits = rights.split('+');
k = 0;
l = 0;
while (k < droits.length) {
if ((droits[k] == '0002')||(droits[k] == '0001')||(droits[k] == '0000')) {droits2[l] = '*';l++;}
if ((droits[k].charAt(3) == '1')||(droits[k].charAt(3) == '2')) {droits2[l] = droits[k].charAt(0)+droits[k].charAt(1)+droits[k].charAt(2);l++;}
if (((droits[k].charAt(3) == '1')||(droits[k].charAt(3) == '2'))&&(droits[k].charAt(2) == '0')) {droits2[l] = droits[k].charAt(0)+droits[k].charAt(1);l++;}
if (((droits[k].charAt(3) == '1')||(droits[k].charAt(3) == '2'))&&(droits[k].charAt(2) == '0')&&(droits[k].charAt(1) == '0')) {droits2[l] = droits[k].charAt(0);l++;}
if (((droits[k].charAt(0) == '0')&&(droits[k].charAt(1) == '1'))||(droits[k].charAt(0) == '')){self.location.href='/cgi-local/mapa/areject.pl';}
k++;
}
if (droits2.length <= 0) {self.location.href='/cgi-local/mapa/areject.pl';}
}

function checkrights3() {
i=0;
Get_Cookie2();
while (i <auth.length) {
author=auth[i].toLowerCase();
if (author == nom) {rights = auth[i+1]}
i++;i++;}
droits = rights.split('+');
k = 0;
l = 0;
while (k < droits.length) {
if ((droits[k] == '0002')||(droits[k] == '0001')||(droits[k] == '0000')) {droits2[l] = '*';l++;}
k++;
}
if (droits2.length <= 0) {self.location.href='/cgi-local/mapa/areject.pl';}
}


function send_login(x) {
var i=0;var u='';
while (i <document.links.length) {nomlien = document.links[i].name;
if (nomlien == x) {u=i;} i++;}
document.links[u].href += 'login='+nom;
}

function checkrightsmenu() {
i=0;
Get_Cookie2();
while (i <auth.length) {
author=auth[i].toLowerCase();
if (author == nom) {rights = auth[i+1]}
i++;i++;}
droits = rights.split('+');
k = 0;
while (k < droits.length) {
if ((droits[k] == '0002')||(droits[k] == '0001')||(droits[k] == '0000')) {menudroits = '*';}
else if (droits[k].charAt(3) == '2') {menudroits = '*';}
k++;
}
}

