
var url = "/" ;
var expDays = 360;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {

	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value ) {

	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {

	var exp = new Date();
	exp.setTime (exp.getTime() - 10 );
	var cval = GetCookie (name);
	document.cookie = name + "=\"bonjours\"; path=/; expires Thu, 01-Jan-1970 00:00:00 GMT";
}

function WriteCookies ( nom1, val1, nom2, val2, nom3, val3, nom4, val4 ) {

	SetCookie(nom1 , val1 , exp, '/cgi-bin/') ;
	SetCookie(nom2 , val2 , exp, '/cgi-bin/') ;
	SetCookie(nom3 , val3 , exp, '/cgi-bin/') ;
	SetCookie(nom4 , val4 , exp, '/cgi-bin/') ;
}

function DeleteCookies ( nom1, nom2, nom3, nom4 ) {

	DeleteCookie(nom1) ;
	DeleteCookie(nom2) ;
	DeleteCookie(nom3) ;
	DeleteCookie(nom4) ;
}

// ----------------------------------------- //
// Fonctionnalites rajoutees par Jo
// 17 Avril 2002
// Permet de gerer facilement les cookies du devoir
// ------------------------------------------------ //
// EXEMPLE D'UTILISATION :
//

// GetValue ( GetCookie ("userinfo") ) ;
// document.write ( "le NOM : " ) ;
// document.write ( oCurrentCookie["nom"] ) ;
// document.write ( "<BR>" ) ;
// document.write ( "le PRENOM : " ) ;
// document.write ( oCurrentCookie["prenom"] ) ;
// document.write ( "<BR>" ) ;


function SetNom ( nom )
{
   this.nom = nom ;
}

function SetPrenom ( prenom )
{
   this.prenom = prenom ;
}

function SetEmail ( email)
{
   this.email = email;
}

function SetSessionKey ( sessionkey )
{
   this.sessionkey = sessionkey ;
}

function SetCRC ( crc )
{
   this.crc = crc ;
}

function SetT ( t )
{
   this.t = t ;
}


function MyCookie ( nom, prenom, email, sessionkey, crc, t )
{
   this.nom = nom ;
   this.prenom = prenom ;
   this.email  = email ;
   this.sessionkey = sessionkey ;
   this.crc = crc ;
   this.t = t ;

   this.SetNom = SetNom  ;
   this.SetPrenom = SetPrenom  ;
   this.SetEmail = SetEmail ;
   this.SetSessionKey = SetSessionKey  ;
   this.SetCRC = SetCRC ;
   this.SetT = SetT ;

}

var oCurrentCookie = new MyCookie ( "", "", "", "na", "", "" ) ;

function GetLeDevoirCookieValue ( valeur )
{
 if ( valeur != null )
  {
    tab = valeur.split ( "&" ) ;

    for ( i = 0 ; i < tab.length  ; i++ )
        {
           couple = tab[i].split ( "+" ) ;
           if ( couple[0] == "nom" )
             {
               oCurrentCookie.SetNom ( couple[1] ) ;
             }
           else if ( couple[0] == "prenom" )
             {
               oCurrentCookie.SetPrenom ( couple[1] ) ;
             }
           else if ( couple[0] == "email" )
             {
               oCurrentCookie.SetEmail ( couple[1] ) ;
             }
           else if ( couple[0] == "sessionkey" )
             {
               oCurrentCookie.SetSessionKey ( couple[1] ) ;
             }
           else if ( couple[0] == "crc" )
             {
               oCurrentCookie.SetCRC ( couple[1] ) ;
             }
           else if ( couple[0] == "t" )
             {
               oCurrentCookie.SetT ( couple[1] ) ;
             }

        }
   }
   else
   {
     oCurrentCookie.SetSessionKey ( "na" ) ;
     oCurrentCookie.SetEmail ( "na" ) ;
   }

}

/*function cuireImages(biscuit, doc, preURL , postURL) {
       GetLeDevoirCookieValue ( GetCookie ( "userinfo" )  ) ;

	var preURL = document.location.protocol + "\/\/" + document.location.hostname + "\/images\/cadenas_ferme.gif"
	var postURL = document.location.protocol + "\/\/" + document.location.hostname + "\/images\/cadenas_ouvert.gif"
	for(i=0; i<doc.length; i++) {
		if ( (doc[i].src == preURL) && ( oCurrentCookie["sessionkey"] != "na" ) ) 
                    { 
                      doc[i].src = postURL 
                    }
	}
}*/

//Chaque cadenas à une propriété name (soit 1 ou 5) selon qu'il est publié la semaine (5) ou la fin de semaine (1)
//On compare le cookie de l'abonné avec le nom de l'image pour l'affichage du cadenas débarré.

function cuireImages(biscuit, doc, preURL , postURL){
	GetLeDevoirCookieValue ( GetCookie ( "userinfo" )  ) ;
	//alert(oCurrentCookie["t"])
	var preURL = document.location.protocol + "\/\/" + document.location.hostname + "\/images\/cadenas_ferme.gif"
	var postURL = document.location.protocol + "\/\/" + document.location.hostname + "\/images\/cadenas_ouvert.gif"
	for(i=0; i<doc.length; i++) {
		if ( (doc[i].src == preURL) && (oCurrentCookie["t"] == 'papier1') && (doc[i].name == '1') || (doc[i].src == preURL) && (oCurrentCookie["t"] == 'pdf1') && (doc[i].name == '1'))
                    { 
                      doc[i].src = postURL 
                    }
		else if ( (doc[i].src == preURL) && (oCurrentCookie["t"] == 'papier5') && (doc[i].name == '5') || (doc[i].src == preURL) && (oCurrentCookie["t"] == 'pdf5') && (doc[i].name == '5'))
                    { 
                      doc[i].src = postURL 
                    }
		else if ( (doc[i].src == preURL) && (oCurrentCookie["t"] == 'papier6' || oCurrentCookie["t"] == 'pdf6' ))
                    { 
                      doc[i].src = postURL 
                    }
		
	}
}

//open pop-up, center window on screen
function popUpWin(url,vwidth,vheight,scroll) {	
	
var w = vwidth;
var h = vheight;
var x = (screen.width - w)/2;
var y = (screen.height - h)/2;			
var s = scroll;
var n = name;

if ((s == 0) || (s == "") || (s == null)) {
	s = "no"
}
else {
	s = "yes"
}
		
popupWin = window.open(url, 'cookie',  'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars='+s+',resizable=no,width='+w+',height='+h+',left='+x+',top='+y+'')
}	

// supprimer le anciens cookies
var cookieVal = document.cookie;
if (((cookieVal.indexOf("t+papier") != -1) || (cookieVal.indexOf("t+default") != -1)) && (cookieVal.indexOf("t+papier1") == -1) && (cookieVal.indexOf("t+papier5") == -1) && (cookieVal.indexOf("t+papier6") == -1) && (cookieVal.indexOf("t+pdf1") == -1) && (cookieVal.indexOf("t+pdf5") == -1) && (cookieVal.indexOf("t+pdf6") == -1)) {
	DeleteCookie("userinfo");
	popUpWin("/cookie.html",500,400,1);
	window.location.reload();
}

