//Get Cookie Function
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 null;
}

//Set Cookie Function
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
}

//Delete Cookie Function
function delCookie (name,path,domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path == null) ? "" : "; path=" + path) +
		((domain == null) ? "" : "; domain=" + domain) +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

//Get Advertisement from Array Function
function getAdv(name) {
	var adv = "";

	for(var i = 0;i < seglist.length ;i+=3) {
		if(name == seglist[i]) {
			adv = seglist[i + 2];

			return adv;
		}
	}

	return null;
}


var today = new Date();

var dt = today.getDate();
var dy = today.getDay();

var year = today.getFullYear();
var months = new Array("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre");
var monthsNoPrint = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var monthlen = new Array(31,checkLeapYear(year),31,30,31,30,31,31,30,31,30,31);
var days = new Array("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche");

var child = "";

function checkLeapYear(theyear) {
	// 1.Years divisible by four are leap years, unless...
	// 2.Years also divisible by 100 are not leap years, except...
	// 3.Years divisible by 400 are leap years.

	if ( ((theyear % 4 == 0) && (theyear % 100 != 0)) || (theyear % 400 == 0) ) {
		return("29");
	} else {
		return("28");
	}
}


function open_window(url,width, height, resize, scroll) {
	child = window.open(url,"newwindow", "width=" + width + ",height=" + height + ",resizable=" + resize + ",scrollbars=" + scroll + "");
}

var mo = "";
var year = "";
var currentmonth = today.getMonth();
var currentyear = today.getFullYear();

//cookies are not found
if(document.cookie == "") {
        mo = today.getMonth();
        year = today.getFullYear();
} else {
        mo = getCookie('whichmonth');
        //correct cookie is NOT set
        if(mo == null) {
                mo = today.getMonth();
                year = today.getFullYear();
                //alert number of reminders to user
                alertReminders();
        }
        //correct cookie is set
        else {
                mo = getCookie('whichmonth');
                year = getCookie('whichyear');
        }
}



//set a session cookie
setCookie('whichmonth',mo);
setCookie('whichyear', year);

//backup one month and refresh
function backup(url) {
        //check for a new year being set
        if(mo > 0) {
                mo--;
        } else {
                mo = 11;
                //check for 19**
                if(year == 2000) {
                        year = 1999;
                } else if(year <= 1999) {
                        syear = year.substring(2,year.length);
                        syear--;
                        year = "19" + syear;
                        Number(year);
                } else {
                        year--;
                }
        }
        setCookie('whichmonth',mo);
        setCookie('whichyear', year);

        //check for open child windows and close.
        if(child && !child.closed) {
                child.close();
        }

        document.location=url;
}

//go forward one month and refresh
function stepup(url) {
        //check for a new year being set
        if(mo <  11) {
                mo++;
        } else {
                mo = 0;
                year++;
        }
        setCookie('whichmonth',mo);
        setCookie('whichyear', year);

        //check for open child windows and close.
        if(child && !child.closed) {
                child.close();
        }

        document.location=url;
}



function open_all(url) {
        child = window.open(url,"allreminders", "width=430,height=400,resizable=0,scrollbars=1");
}

function alertReminders() {

        var alertit = getCookie(months[today.getMonth()] + dt);

        if(alertit != null) {
                alertit = alertit.split("|");

                //write out reminders into a string for display
                textit = "  1. " + alertit[0];
                for(var i = 1; i < alertit.length; i++) {
                        textit += "\n  " + (i + 1) + ". " + alertit[i];
                }

                //alert user of number of reminders for which day and display those reminders
                alert("You have " + alertit.length + " reminder(s) for " + months[today.getMonth()] + " " + dt + ".\n\n" + textit);
        }
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

var isNS4=(document.layers) ? 1 : 0;
var isIE4=(document.all)? 1 : 0;
var isMoz=((document.getElementById) && !(isIE4)) ? 1 :0;


function ShowNavigateur()
{
	alert(isNS4);
	alert(isIE4);
	alert(isMoz);
}

function activate_mousemove(function_mouse)
{
	if(isNS4||isMoz)
		document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = function_mouse;
}

function get_mouse(e)
{
	var mouse=new Array();
	mouse.x=0; mouse.y=0;
	if(isNS4||isMoz){
		mouse.x=e.pageX; mouse.y=e.pageY;
	}else if(isIE4){
		mouse.x=event.x+document.body.scrollLeft; mouse.y=event.y+document.body.scrollTop;
	}
	return mouse;
}

function get_layer(name)
{
	if(isNS4){
		layer=findLayer(name, document);
		//if(layer==null)
		//alert('Pb de layer');
		return layer;
	} else if (isIE4){

		//window.status=document.all[name];
		return document.all[name];
	} else if (isMoz) {
		return document.getElementById(name);
	}
	//alert('Pb de noms');
	return null;
}


function findLayer(name, doc) {
	var i, layer;
	//alert(doc.layers.length);
	for (i = 0; i < doc.layers.length; i++) {
	layer = doc.layers[i];
	//alert(layer.name);
	if (layer.name == name)
		return layer;
	if (layer.document.layers.length > 0)
		if ((layer = findLayer(name, layer.document)) != null)
	        	return layer;
  	}
  return null;
}





function hide_layer(layer)
{
	if(layer==null){
		//window.status="Pas de layer à cacher";
		return;
	}
	if (isNS4){
		layer.visibility = "hide";
	}
	if (isIE4||isMoz){
		layer.style.visibility = "hidden";
	}
}

function show_layer(layer) {
	if(isNS4){
		layer.visibility = "show";
	}
	if(isIE4||isMoz){
		layer.style.visibility = "visible";
	}
}

function move_layer_to(layer, x, y)
{
	//window.status=layer;
	if (isNS4){
		layer.moveTo(x, y);
        }
	if (isIE4){
		layer.style.left = x;
		layer.style.top  = y;
	}
	if (isMoz){
		//window.status=layer.style;
		layer.style.left = x+'px';
		layer.style.top  = y+'px';
	}
}

function setzIndex(layer, z) {
	if(isNS4)
		layer.zIndex = z;
	if(isIE4||isMoz)
		layer.style.zIndex = z;
}

function modify_content_layer(layer,content)
{
	if(isNS4){
		layer.document.write(content);
		layer.document.close();
	} else if(isIE4||isMoz){
		layer.innerHTML=content;
	}
}

MM_reloadPage(true);


activate_mousemove(get_mouse2);

function tux(title, text){
var content;
content = "<table border=0 cellpadding=2 cellspacing=0><tr><td class=popup>"+unescape(title)+"</td></tr><tr><td class=popup2>"+unescape(text)+"</td></tr></table>";

l=get_layer("topdeck");
modify_content_layer(l,content)
show_layer(l);
}

function get_mouse2(e)
{
mouse=get_mouse(e);
l=get_layer("topdeck");
var x = mouse.x;
var y = mouse.y;
x=x+15;
move_layer_to(l,x,y);
}


function kill()
{
l=get_layer("topdeck");
hide_layer(l);
}

function convertRewriting(val){
	var value = ""; 
	
	if(val.length > 200)
		value = val.substring(0, 200);		
	else
		value = val;
	value = value.toLowerCase();
	
	value = value.replace(/\n/, '-');
	value = value.replace(/\r/, '-');
	value = value.replace(/\v/, '-');
	value = value.replace(/\s/, '-');
	value = value.replace(/\t/, '-');
	value = value.replace(/é/g, "e");
	value = value.replace(/è/, "e");
	value = value.replace(/ê/, "e");
	value = value.replace(/ë/, "e");
	value = value.replace(/à/, "a");
	value = value.replace(/ô/, "o");
	value = value.replace(/ö/, "o");
	value = value.replace(/°/, "");
	value = value.replace(/,/, "");
	value = value.replace(/:/, "");
	value = value.replace(/î/, "i");
	value = value.replace(/ï/, "i");	
	/*
	value = value.replace(/\\?/, "");
	value = value.replace(/!/, "");
	value = value.replace(/&/, " ");

	*/
	return value;
}
	
function listEvenement(tab,  year, mo, count){
	var affich = "";


	mo++;
	if (mo < 10)
        	mo = "0"+mo;
	if (count < 10)
		count = "0"+count;

	currentDate = year+""+mo+""+count;
	
	for (var i = 0; i < tab.length; i++){
		var contenu = tab[i];
				
		if (parseInt(contenu[0]) == parseInt(currentDate)){
			var lien = convertRewriting(contenu[1])+".html";
	 		contenu[1] = escape(contenu[1]);
			contenu[3] = escape(contenu[3]);
			
			var url = contenu[2].substring(0,contenu[2].lastIndexOf('/'));
			//contenu[2].substring((contenu[2].lastIndexOf('/')+1), contenu[2].length);
			
			
			affich += "<a href=\""+url+"-"+contenu[4]+"/"+lien+"\" onmouseout=\"javascript:kill()\" onmouseover=\"javascript:tux('"+contenu[1]+"', '"+contenu[3]+"')\">"+contenu[5]+"</a>";
		}
	}
	
	
	
	return affich;
}


