var monHisto=new Array();

/* ************  TEST NAVIG COMPLIANCE ********* */
function testeNav(){
var lim=0;
//return(true); /* r\u00E9activer pour supprimer le filtre des navigateurs */
	if($.browser.safari)
		{//version sup \u00E0 533
		lim=533;
		if(parseInt($.browser.version, 10)<lim) {
			alertVersion("Safari",parseInt($.browser.version, 10));
			return(false);
			}
		}
	if($.browser.msie)
		{//version sup \u00E0 9
		lim=9;
		if(parseInt($.browser.version, 10)<lim) {
			alertVersion("Internet Explorer",parseInt($.browser.version, 10));
			return(false);
			}
		}	
	if($.browser.opera)
		{//version sup \u00E0 11
		lim=11;
		if(parseInt($.browser.version, 10)<lim) {
			alertVersion("Opera",parseInt($.browser.version, 10));
			return(false);
			}
		}	
	if($.browser.chrome)
		{//version sup \u00E0 10
		lim=10;
		if(parseInt($.browser.version, 10)<lim) {
			alertVersion("Chrome",parseInt($.browser.version, 10));
			return(false);
			}
		}
	if($.browser.mozilla)
		{//version sup \u00E0 5
		//alert(parseInt($.browser.version, 10));
		//return(true);
		lim=5;
		if(parseInt($.browser.version, 10)<lim) {
			alertVersion("Firefox",parseInt($.browser.version, 10));
			return(false);
			}
		}
	if($.browser.webkit)
		{//version sup \u00E0 533
		lim=533;
		if(parseInt($.browser.version, 10)<lim) {
			alertVersion("webkit",parseInt($.browser.version, 10));
			return(false);
			}
		}
		return(true);
	}
// ALERTVERSION
function alertVersion(l,v){
	CookieTXT = getCookie("AlerteNav") ;
	//-- plus de teste de'avertissement d\u00E9j\u00E0 donn\u00E9, la site mobile est obligatoire
	//if (CookieTXT==null)
		{
		$('#alertenav').show();
		setCookie ("AlerteNav", '1' ,1);
		}
	//else
		{
		
		//alert(GetCookie("AlerteNav")); 
		}
	}


/* *********  WAIT *****************/
function pause( iMilliseconds )
{
  var sDialogScript = 'window.setTimeout( function () { window.close(); }, ' + iMilliseconds + ');';
  window.showModalDialog('javascript:document.writeln ("<script>' + sDialogScript + '<' + '/script>")');
}


function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
		{
  		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  		x=x.replace(/^\s+|\s+$/g,"");
  		if (x==c_name)
		    {
    		return unescape(y);
    		}
  		}
	}
/* ***** FIN COOKIE **********************/

/* ********  HOW TO **********************/
function checkHowTo()
{
var ht=getCookie("ht");
  if (ht!=null && ht!="")
  {
  // cookie pr\u00E9sent, on ne fixe pas le cookie
	 // alert(ht);
  }
else
  {
  //cookie introuvable, on le met et on montre
  setCookie("ht",'1',1);
  showHowTo();
  }
}
function showHowTo(){
$('#howto>div').css({
	'margin-top':'',
	'margin-bottom':'',
       'height': '',
       'font-size':'',
       'padding-top':''});
       
//$('#howto').show();
//setTimeout("hideHowTo()", 2000);
	$('#htcloseimg').click(function(){
	hideHowTo();
 //$('#howto').css('display','none');
	});
/*
$('#howto').animate({
	top:'0',
	right:'18px',
     height:95+'%',
     width:95+'%'
  }, 500, function() {
  
  $('#howto>div').fadeIn('fast');
 	$('#htcloseimg').click(function(){
	hideHowTo();
 //$('#howto').css('display','none');
	});
  
  });
  
//$('#howto').fadeIn('slow');

//Evenemeent de Masquage manuel du HowTo
*/
}

function hideHowTo(){
$('#howto').fadeOut('slow');
	}
	
	

function hideHowTo2(){
var alti=200;
$('#howto>div').animate({
	'margin-top':'0.1%',
	'margin-bottom':'0.1%',
       height: '10%',
       'font-size':'0.5em',
       'padding-top':'15px'
  }, 500, function() {
    $('#howto').animate({
		top:'10%',
       height: '12%',
       padding:'1px'
  }, 500, function() {
    $('#howto>div').fadeOut('fast');
    // replie le howto vers la droite
    $('#howto').animate({
	'top':'10%',
    'left':'95%'
  }, 50, function() {
  $('#howto').animate({
	'width':'10%'
  }, 500, function() {$('#howto').css('display','none');});
    
    
  });
  });
  });

  

  
  /*
   $('#httext').animate({
	'margin':'0.01%',
	'height':'0.1em',
	'font-size':'5em',
	padding:'1px'
  }, 500, function() {
    // Animation complete.
  });
*/
}


/* ********  FIN HOW TO **********************/	
	

function sortHisto(){
	var tmp='';
	monHisto.sort();
	// il est tri\u00E9, on va le d\u00E9doublonner
	for(i=0;i<monHisto.length;i++){
		if(i>0){
			tmp=monHisto[i-1];
			if (tmp==monHisto[i]){
				monHisto.splice(i,1);
				//alert(i);
				}
			}
		}
	// \u00E9limine les entr\u00E9es insignifiantes (sans la page #)
	for(i=0;i<monHisto.length;i++){
		if (monHisto[i].indexOf('#')<0){
			monHisto.splice(i,1);
			//alert(i);
			}		
		}
	// \u00E9limine les entr\u00E9es insignifiantes (sans la page \u00A3)
	for(i=0;i<monHisto.length;i++){
		if (monHisto[i].indexOf('\u00A3')<0){
			monHisto.splice(i,1);
			//alert(i);
			}		
		}
	// \u00E9limine les entr\u00E9es insignifiantes (sans la page html)
	for(i=0;i<monHisto.length;i++){
		if (monHisto[i].indexOf('.html')<0){
			monHisto.splice(i,1);
			//alert(i);
			}		
		}
}
	
function histoHTML(){
var st='<ul>';
var ligne='';
var pl='';
var pg='';
var i=0;

for(i=0;i<monHisto.length;i++){
	// isole la planche
	ligne=monHisto[i];
	//alert(ligne);
	pg=ligne.substring(ligne.indexOf('\u00A3')+1,ligne.length);
	if(pl!=ligne.substring(0,ligne.indexOf('\u00A4')))
		{// premi\u00E8re planche ou changement de planche
		pl=ligne.substring(0,ligne.indexOf('\u00A4'));
		if(st.length>10){
			//chgt de planche ferme la pr\u00E9c\u00E9dente
			st=st+'</ul></li>';
			}
		st=st+'<li>'+pl+'<ul><li><a href="'+ligne.substring(ligne.indexOf('\u00A4')+1,ligne.indexOf('\u00A3'))+'">'+pg+'</a></li>';
		}
	else
		{
		st=st+'<li><a href="'+ligne.substring(ligne.indexOf('\u00A4')+1,ligne.indexOf('\u00A3'))+'">'+pg+'</a></li>';
		}

	}
	
st=st+'</ul>';
return(st);
}

// teste le local storage
var hasStorage = (function() {
      try {
        return !!localStorage.getItem;
      } catch(e) {
        return false;
      }
    }());

function marqueurVisite(){
// ne r\u00E9cup\u00E8re les donn\u00E9es utilisateurs que si l'url est r\u00E9solue
//alert(window.location.href);

if(window.location.href.indexOf('#')>0)
	{
	if (hasStorage)
		{
		if((localStorage.cleuser!=null)&&(localStorage.cleuser!='null')&&(localStorage.cleuser.length==32)) {
			// d\u00E9ja visiteur on soumet avec la clef
			pageactuelle=location.hash;
			
			// enregistre dans l'historique
			try 
				{
				eval(localStorage.getItem('histo'));
				}
			catch(err)
				{
				//efface l'historique
				//alert(err);
				localStorage.setItem('histo','');
				//alert('ok')
				}
			monHisto.push(window.document.title+'\u00A4'+window.location.href.substring(0,window.location.href.indexOf('#'))+pageactuelle+"\u00A3"+sectionsNFull[sections[pageactuelle]-1]);
			sortHisto();
			st='monHisto= new Array("'+monHisto.join('","')+'");';
			localStorage.setItem('histo',st);
			eval(localStorage.getItem('histo'));
			cleUser=localStorage.cleuser;
			
			$.post("../visite?Createdocument", 
	 			{ 	cleuser:cleUser , 
 					ip: ip, 
 					reso:reso,
 					navigateur: navigateur,
 					hostname: hostname,
 					Origine: origine,
 					Storage:'1',
 					PlancheActuelle:location.href,
 					PageActuelle:location.hash},
	   					function(data) {
	   					
	     					setCookie ("cleuser", cleUser ,365);
   						});
			}
		else
			{
			// premi\u00E8re visite, on demande une cleUSER
			
			$.post("../visiteur?Createdocument", 
	 			{ 	ip: ip, 
 					reso:reso,
 					navigateur: navigateur,
 					hostname: hostname,
 					Origine: origine,
 					Storage:'1',
 					Planche0:location.href,
 					Page0:location.hash},
 					
	   					function(data) {
   						//alert($(data).length);
	
	     				cleUser=$.trim($(data).text());
	     				localStorage.cleuser=cleUser;
	     				//alert('-'+cleUser+'-');
	     				
   						});
   					}
   			}
   	else 
   	{
		//teste si cleUser
		if (cleUser=='') cleUser=getCookie('cleuser');
		if(!(cleUser)||(cleUser==''))
			{
			//alert('pas de clesuser');
			// nouveau user sans LS
			$.post("../visiteur?Createdocument", 
	 			{ 	ip: ip, 
 					reso:reso,
 					navigateur: navigateur,
 					hostname: hostname,
 					Origine: origine,
 					Planche0: location.href,
 					Page0: location.hash,
 					Storage:'0'},
	   					function(data) {
	     				cleUser=$.trim($(data).text());
	     				// pas de localstorage alors cookie
	     				setCookie ("cleuser", cleUser ,365);
   						});
				
			}
		else
			{
			//user connu sans LS
			
			// nouveau user sans LS
			$.post("../visite?Createdocument", 
	 			{ 	cleuser: cleUser,
	 				ip: ip, 
 					reso:reso,
 					navigateur: navigateur,
 					hostname: hostname,
 					Origine: origine,
 					PlancheActuelle: location.href,
 					PageActuelle: location.hash,
 					Storage:'0'},
	   					function(data) {
	     				setCookie ("cleuser", cleUser ,365);
   						});
				
			
			
			}
		}
	}


}
// CE QUI EST FAIT APRES OUVERTURE DE LA PAGE
$(document).ready(function() {
	//$('#alertenav').show();
	//eval(localStorage.getItem('histo'));
	//alert('testnav');
	if(testeNav()) 
		{
		//alert('check');
		checkHowTo();
		//alert('checked');
		}
	//surveille le clic on vous rappelle

	
	
	//alert('fin');
	// Evalue le cookie de HowTo pour savoir si on le montre
	//checkHowTo();
	
	//signale la visite
	//marqueurVisite();
	//localStorage.histo="";
	//monHisto = ['Teebo','Eaulive','Asevere','Kalamit','Serge','Chat_Teigne','BmV']";
	
	//alert(monHisto.join("'],['"));
	});
