/**
 * stockage d'un cookie
 */
function set_cookie(name, value, days) {
	var today = new Date();
	var expire = new Date();
	if (days == null || days == 0) days = 1;
	expire.setTime(today.getTime() + 3600000*24*days);
	document.cookie = name + "=" + escape(value) + ";path=/;expires=" + expire.toGMTString();
}

/**
 * effacement d'un cookie
 */
function erase_cookie(name) {
	set_cookie(name, "", -1);
}

/**
 * lecture d'un cookie
 */
function read_cookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


//////////////////////////////////////////
/*
class Bulle = creer une bulle d'info sur l'element indiqué si le nom d'un id commence par 'h_' l'evenement sera mouseover sinon focus
::_donnee = stucture : nom prop=id de l'element, val prop=texte a afficher
::_esp = _espace par rapport a l'element en px
::_css = class css(facultatif)
*/
function Bulle(_donnee, _esp, _css){  	
	this.bulle_html;
    this.tmp; 
	this.donnee;
	this.esp;
	this.css;
	var _this;
	
    this.init = function(){			
		this.donnee=_donnee;		
		this.esp=_esp;
		this.css=_css;
		this.tmp=0; 
		this.bulle_html='<iframe  id="ifr_bul" frameborder="0" scrolling="no" style="position:absolute;width:0px;height:0px;display:none;z-index:10000"></iframe><div class="transp30"  style="background-color:#000000;display:none;position:absolute;z-index:10005;top:0px;left:0px" id="div_ombre"></div><div '+((this.css && this.css!='')?' class="'+this.css+'" ':'')+' style="display:none;width:auto;position:absolute;z-index:10010;top:0px;left:0px" id="div_bul"></div>';
		_this=this;
		$('body').prepend(this.bulle_html);
        for(var p in this.donnee){	
            if(p.indexOf('h_')!=-1){
				$('#'+p).mouseover(_this.showBull);
				$('#'+p).click(_this.hideBull);
			}else{
				$('#'+p).focus(_this.showBull);
			}
			$('#'+p).mouseout(_this.fadeOutBull);
            $('#'+p).blur(_this.hideBull);			
						
        }
        if(!this.css || this.css==''){
			$('#div_bul').css('border','1px solid #CCCCCC').css('background-color','#FFFFFF');
		}	
		window.document.onmousedown = function(){_this.hideBull();}
    }
    
    this.showBull = function(ev){ 		
		if(!ev.target.activ){
			_this.hideBull();							
			$('#div_bul').html(_this.donnee[ev.target.id]);
			$('#div_bul').show();	
			_this.posBull(ev);
			$('#div_bul,#ifr_bul,#div_ombre').show();
			ev.target.activ=1;
		}
    }
    
    this.fadeOutBull = function(e){
		switch(e.type){
			case 'mouseout':
				temp=2000;
			break;
			case 'click':
				temp=100;
			break;
			case 'blur':
				temp=100;
			break;
			default:
				temp=3000;
			break;
		}
		if(_this.tmp>0){clearTimeout(_this.tmp);_this.tmp=0;}
		if($('#div_bul')[0].style.display!='none')_this.tmp = setTimeout(function(){$('#div_bul,#ifr_bul,#div_ombre').fadeOut('speed')},temp);
	}
	
     this.hideBull = function(){
		 if(_this.tmp>0){clearTimeout(_this.tmp);_this.tmp=0;}
		 $('#div_bul,#ifr_bul,#div_ombre').hide();
	}
	 
    this.posBull = function(ev){
		var mouse_top = (document.all)?mousey:mousey-window.document.body.scrollTop;
		var mouse_left = (document.all)?mousex:mousex-document.body.scrollLeft;
		var fen_width = document.body.clientWidth;
		var div_h = $('#div_bul').height(); 
		var div_w = $('#div_bul').width();
		var _top = (mouse_top < div_h+this.esp)?mouse_top+document.body.scrollTop+(this.esp/2):mouse_top+document.body.scrollTop-(this.esp+div_h);
		var _left = (fen_width < mouse_left+div_w)?mouse_left+document.body.scrollLeft-div_w:mouse_left+document.body.scrollLeft-20;	
		$('#div_bul,#ifr_bul').css('top',_top);
		$('#div_bul,#ifr_bul').css('left',_left); 
		$('#div_ombre').css('top',_top+4);
		$('#div_ombre').css('left',_left+4);
		setTimeout(function(){
			div_h = $('#div_bul').height(); 
			div_w = $('#div_bul').width();
			$('#ifr_bul,#div_ombre').height(div_h+parseInt($('#div_bul').css('padding-bottom'))+parseInt($('#div_bul').css('padding-top')));
			$('#ifr_bul,#div_ombre').width(div_w+parseInt($('#div_bul').css('padding-left'))+parseInt($('#div_bul').css('padding-right')));
							},10);
	}    	
    this.init();
}

 
 
 /*
class Astuce = affiche les astuces
::donnee = proprietes : indexées à partir de 1 contenant les textes des astuces 
::nb_jour = entier : indiquant le nombre de jours que l'astuce n'apparaît pas
*/
var Astuce = function (donnee,nb_jour,lang){  
	idx = total_prop=0;
	page_name = document.title;
    init = function(){
		for(var p in donnee)total_prop++;  
		astuce_html='<div id="div_astuce_fond" class="transp80" style="background-color:#DDD;position:absolute"></div>'
					+'<div align="center" class="arial_vert_gras" style="display:block;position:absolute;margin:10% 15% 20% 15%;top:0px;left:0px;z-index:1000;background-color:#ffe7ce;color:#FF0000;width:70%;height:auto" id="div_astuce">'
					+'<div  style="border:2px solid #000000;width:100%;height:100% " >INFORMATION<div class="mini_mini"  style="margin:10% 10%" id="div_astuce_content">'+donnee[++idx]+'</div>';
		if(total_prop>1)astuce_html+='<a id="g" href="javascript:void(0)" style="margin-right:50px"><<</a><a id="d"  href="javascript:void(0)">>></a>';
		astuce_html+='<div id="close_astuce" class="indice_page" style="margin:10px;cursor:pointer">FERMER</div></div></div>';
		$('body').prepend(astuce_html);	
		setTimeout(function(){$('#div_astuce_fond').height('100%').width('100%');},300);
		$('#div_astuce a').each(function(e){this.onclick = switchAstuce;});
		$('#div_astuce #close_astuce').click(closeAstuce); 		
    }    
   
   switchAstuce = function(){
		if(this.id=='d' && idx<total_prop)$('#div_astuce_content').fadeIn(250).html(donnee[++idx]); else if(this.id=='g' && idx>1) $('#div_astuce_content').fadeIn(250).html(donnee[--idx]);
	}
   
   closeAstuce = function(){
		$('#div_astuce').fadeOut('speed');
		$('#div_astuce_fond').fadeOut('speed');
		set_cookie('astuce_'+page_name, 1, nb_jour);
	}
    if(read_cookie('astuce_'+page_name)==null)init();
}


 /*
class Aide = affiche l'aide onpress de la touche " ² " et au survol de l'element ou  sur le focus, mais l'aide reste bloquée sur l'element focussé
::donnee = stucture : nom prop=id de l'element, val prop=texte a afficher
::css = class css (facultatif)
*/
var Aide = function (donnee,css){  	
	aide_html='<div align="center" style="display:none;position:absolute;width:100%;height:100%;top:0px;left:0px;z-index:1000;background-color:#DDDDDD" id="div_aide">'
				+'AIDE<div '+((css && css!='')?' class="'+css+'" ':'')+' style="margin:20% 0" id="div_aide_content"></div><div id="close_aide" style="margin:10px;cursor:pointer">FERMER AIDE</div></div>';
	id_activ = '';
	bloc_aide_focus=false;
	
    init = function(){
		$('body').prepend(aide_html); 
		$('#div_aide #close_aide').click(closeAide); 
		for(var p in donnee){                 
            $('#'+p).focus(activId);
            $('#'+p).blur(deActivId); 
            $('#'+p).mouseover(activId);   
            $('#'+p).mouseout(deActivId);       
        }
		
    }    
	
	activId = function(e){
		if(!bloc_aide_focus)id_activ = e.target.id;
		if(e.type == 'focus')bloc_aide_focus=true;	
	}
	
	deActivId = function(e){
		if(e.type == 'blur')bloc_aide_focus=false;
		if(!bloc_aide_focus)id_activ = '';		
	}
   
   
    matchKey = function(e){
		var code = (window.Event)? e.which : event.keyCode;
		if(code==178)showAide();
	}
	
   showAide= function(){
		if(id_activ!='')$('#div_aide #div_aide_content').text(donnee[id_activ]).parent().show();
	}
   
    closeAide = function(){
		$('#div_aide').fadeOut('speed');
	}
	
	if(window.Event)document.captureEvents(Event.KEYPRESS); 
	document.onkeypress = matchKey;
    init();
}


