var	defTable	= "";;
var defHauteur	= 0;
var NewWindow	= "";
//---------------------------------------------------------------
function windowOpen(nom){
	if (typeof(aquarium) != "undefined"){
		if (aquarium.loginEnCours) return;
	}
    var win_opt= "toolbar=0,location=0,directories=0,status=0,menubar=0,";
    win_opt += "scrollbars=1,resizable=1,copyhistory=0,";
    win_opt += "width=1100,height=800";
    var filename = HrefCgiShow+"main?"+HrefParamFixe+"&tpl="+nom+"&lng="+joueurLang;
	if (NewWindow) window.NewWindow.close();
    NewWindow= window.open(filename,"",win_opt);
    NewWindow.creator= self;
}
//---------------------------------------------------------------
function tutorial(no){
	document.location = HrefCgiShow+'main?'+HrefParamFixe+'&amp;tpl=tuto'+no;
}
//---------------------------------------------------------------
function startGame(){
	top.location = HrefCgiShow+'main?'+HrefParamFixe+'&amp;tpl=index';
}
//---------------------------------------------------------------
function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value) + "; domaine=."+ window.location.hostname + "; path=/;" + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}
//---------------------------------------------------------------
function getCookie(Name) {   
	var search = Name + "=";
	if (document.cookie.length > 0) { 
		// if there are any cookies      
		var offset = document.cookie.indexOf(search); 
		if (offset != -1) { 
			// if cookie exists          
			offset += search.length;
			// set index of beginning of value         
			var end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));   
		}    
	}
	return "";
}
//---------------------------------------------------------------
var chrsIso=new Array('é','è','ê','î','ï','à','â','û','ç','©',' ','°','æ','ô');
var chrsUni=new Array('u00E9','u00E8','u00EA','u00EE','u00EF','u00E0','u00E2','u00FB','u00E7','u00A9','u00A0','u00B0','u00E6','u00F4');
//---------------------------------------------------------------
String.prototype.iso2uni=function(){
	var chrsCnt=chrsIso.length;
	var out=this;
	for(var k=0;k<chrsCnt;k++){
		out=this.replace(chrsIso[k],chrsUni[k]);
	}
	return out;
}
//---------------------------------------------------------------
String.prototype.alert=function(){
	alert(this.iso2uni());
}
//---------------------------------------------------------------
function afficheAction(){ 
	var Arg = arguments;
	var Obj;
	cacheActions();
	for(var i=0; i<Arg.length; i++){
		Obj = document.getElementById(Arg[i]);
		if (Obj) {
//			Obj.style.visibility = "visible";
			Obj.style.display = "block";
			Obj.style.opacity = 1;
		}
	}
}
//---------------------------------------------------------------
function cacheActions(){
	var actions = document.getElementsByName("action");
	for (var a=0;a<actions.length;a++) {
		actions[a].style.visiblity = "hidden";
		actions[a].style.display = "none";
	}
}
//---------------------------------------------------------------
function afficheDiv(){
	var Arg = arguments;
	var Obj;
	for(var i=0; i< Arg.length; i++){
		Obj = document.getElementById(Arg[i]);
		if (Obj) {
//			Obj.style.visibility = "visible";
			Obj.style.display = "block";
		}
	}
}
//---------------------------------------------------------------
function cacheDiv(){
	var Arg = arguments;
	var Obj;
	for(var i=0; i< Arg.length; i++){
		Obj = document.getElementById(Arg[i]);
		if (Obj) {
//			Obj.style.visibility = "hidden";
			Obj.style.display = "none";
		}
	}
}
//---------------------------------------------------------------
function getMouseCoord(e,type) {
	var posx = 0;
	var posy = 0;
	if (!e) e = window.event;
	if (e.pageX || e.pageY){
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY){
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
	}

	if (type == 'x' ) return posx;
	if (type == 'y' ) return posy;
	return 0;
}
//---------------------------------------------------------------
function afficheBulle(action, contenu){  
	var Obj = document.getElementById("bulle");

    if (action == "cache"){
		Obj.style.visibility = "hidden";
		document.getElementById("bulle_info").innerHTML = "";
		document.removeEventListener('mousemove', mouseMoveBulle, false);
    }
	else {
		document.getElementById("bulle_info").innerHTML = contenu.iso2uni();
		document.addEventListener('mousemove', mouseMoveBulle, false);
	}
}
//---------------------------------------------------------------
function mouseMoveBulle(e) {
	var Obj = document.getElementById("bulle");

	if (Obj) {
		Obj.style.top  = getMouseCoord(e,'y') - Obj.offsetHeight + "px";
		Obj.style.left = getMouseCoord(e,'x') - 45 +"px";
		Obj.style.visibility = "visible";
	}
}
//---------------------------------------------------------------
function closeCarte(div){
	var Obj = document.getElementById(div);
	if (Obj){
		var nbc = Obj.childNodes.length;
		for (var i=nbc-1;i>=0; i--) {
			if (Obj.childNodes[i].id != undefined && Obj.childNodes[i].id == "cartePhoto"){
				Obj.childNodes[i].innerHTML = "";
			}
		}
		Obj.style.display = "none";
	}
}
//---------------------------------------------------------------
function formatNb(nombre) {
	nombre = String(nombre);
	var car3;
	var conserv;
	var elements = nombre.split(".");

	if (elements.length > 1) {
		if (elements[1].length>2) {
			car3 = elements[1].charAt(2);
			if (parseInt(car3,10)>=5) {
				conserv = elements[1].substring(0,2);
				conserv = parseInt(conserv,10) + 1;
			}
			else {
				conserv = elements[1].substring(0,2);
			}
			nombre = elements[0] + "." + conserv;
		}
		else {
			if (elements[1].length == 1) {
				nombre += "0";
			}
			if (elements[1].length == 0) {
				nombre += ".00";
			}
		}
	}
	else nombre += ".00";
	return nombre;
}
//---------------------------------------------------------------
function ouvreTable(table, hauteur){
	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++) if ((divs[i].id).indexOf("tableau_") != -1) divs[i].style.height = 1+'px';
	var Obj = document.getElementById(table);
	if (Obj){
		defTable 	= Obj;
		defHauteur 	= hauteur;
		afficheTable();
	}
}
//---------------------------------------------------------------
function afficheTable(){
	var timeout;
	if (defTable){
		var haut = parseInt(defTable.offsetHeight);
		if (Math.abs(haut- defHauteur) > 10){
			if (haut <= defHauteur) defTable.style.height = haut+10+'px';
			if (haut  > defHauteur) defTable.style.height = haut-10+'px';
			timeout=setTimeout('afficheTable()', 2);
		}
	}
}
//---------------------------------------------------------------
function createXHR() {
	var request = null;

	try {
		request = new ActiveXObject('Msxml2.XMLHTTP');
		}
	catch (err1) {
		try {
			request = new ActiveXObject('Microsoft.XMLHTTP');
			}
		catch (err2) {
			try {
				request = new XMLHttpRequest();
				}
			catch (err3) {
				alert("Your browser must support XMLHttpRequest !");
				request = null;
				}
			}
		}
	return request;
	}
//---------------------------------------------------------------
function ligneTab() {
	var origine = "";
	var trs = document.getElementsByTagName('tr');
	for (var i=1;i<trs.length;i++) {
		trs[i].onmouseover = function (event) {
			if (origine == "") origine = this.style.background;
			this.style.background = 'white';
		}
		trs[i].onmouseout = function (event) {
			this.style.background = origine;
		}
	}
}
//---------------------------------------------------------------
function loadMouseMove(){
	if (document.addEventListener){
		document.addEventListener('mousemove', mouseMoveAnimal, false);
	} else if (document.attachEvent) {
		document.attachEvent('mousemove', mouseMoveAnimal);
	}
}
//---------------------------------------------------------------
function unLoadMouseMove(){
	if (document.removeEventListener){
		document.removeEventListener('mousemove', mouseMoveAnimal, false); 
	} else if (document.detachEvent) {
		document.detachEvent('mousemove', mouseMoveAnimal);
	}
}
//---------------------------------------------------------------
function disableselect(e){
	return false;
}
function reEnable(){
	return false;
}
function selectStart(on){
	if (on) {
		document.onselectstart=new Function ("return false");
		if (window.sidebar){
			document.onmousedown=disableselect;
			document.onclick=reEnable;
		}
	}
	else {
		document.onselectstart=null;
		if (window.sidebar){
			document.onmousedown=null;
			document.onclick=null;
		}
	}
}

