	/*************************************************************************
	 *
	 * This file contains functions used throughout the samariis web site:
	 * 1. Function to detect the browser capabilities to retrieve elements
	 * 2. Functions to manage table display (onmouseover change row color)
	 * 3. Functions to manage satellite windows
	 *
	 * Copyright samariis
	 *
	 *************************************************************************/
	
	
	/*************************************************************************
	 * Functions to manage browser capabilities to find elements
	 *************************************************************************/
	// Global variables to detect browser capabilities to manage elements
	var use_gebi = false, use_css = false, use_layers = false;
	
	// Find browser capabilities
	// This function is called on load of index.php, and results will
	// be used throughout all site
	function checkBrowser() {
		if (document.getElementById) {
			// Safari
			window.top.use_gebi = true;
		}
		else if (document.all) {
			window.top.use_css = true;
		}
		else if (document.layers) {
			window.top.use_layers = true;
		}
	}
	
	function getWinW() {
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			winW = window.innerWidth;
		}
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			winW = document.documentElement.clientWidth;
		}
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			winW = document.body.clientWidth;
		}
		
		return winW;
	}
	
	/*************************************************************************
	 * Functions to manage table display
	 *************************************************************************/
	// set background color of an object (table row etc)
	function setBgColor(obj, color) {
		obj.style.backgroundColor = color;
	}

	function colUp(obj) {
		obj.old_backgroundColor = obj.style.backgroundColor;
		obj.style.backgroundColor = '#FFE7A7';
	}

	function colDown(obj) {
		obj.style.backgroundColor = obj.old_backgroundColor;
	}

	/*************************************************************************
	 * Functions to manage city navigation
	 *************************************************************************/
	// navigate to selected image in city
	var adrClans = new Array();
	adrClans['politique'] = "6115.jpg";
	adrClans['marchand'] = "3304.jpg";
	adrClans['savant'] = "2206.jpg";
	adrClans['militaire'] = "5003.jpg";
	adrClans['religieux'] = "4208.jpg";
	adrClans['artistique'] = "8403.jpg";
	function gotoAddress(imgNb) {
		if (imgNb.substring(0, 8) == "##clan##") {
			frames['cityFrame'].location.href = "/ville/visit.php?img=" + adrClans[imgNb.substring(8)];
		}
		else {
			frames['cityFrame'].location.href = "/ville/visit.php?img=" + imgNb;
		}
	}
	
	/*************************************************************************
	 * Functions to manage satellite windows (city window, minisite windows... 
	 *************************************************************************/
	// variable to keep link to new window
	//var satelliteWin = new Array();
	//top.satelliteWin = new Array();
	function openWinWH(URL, name, params) {
		var test = window.open(URL, name, params);
		if (window.focus) {
			test.focus();
		}
	}
	/*
	top.document.satelliteWin = new Array();
	function openWinWH(URL, name, params) {
		var first = true;
		if (top.document.satelliteWin[name] == null) {
			top.document.satelliteWin[name] = window.open(URL, name, params);
		}
		if (window.focus) {
			try {
				top.document.satelliteWin[name].focus();
			}
			catch (err) {
				if (first) {
					first = false;
					top.document.satelliteWin[name] = null;
					top.document.satelliteWin[name] = openWinWH(URL, name, params);
				}
				first = true;
			}
		}
	}
	*/
	
	function openSamWin(URL) {
		openWinWH(URL, 'Samariis', 'width=800,height=600');
		if (URL.substring(0, 17) == 'cadredef.php?img=') {
			//top.document.satelliteWin[name].location = URL;
		}
	}
	
	function openClanWin(URL) {
		openWinWH(URL, 'clan', 'width=800,height=600');
	}
	
	function openWin(URL, name) {
		openWinWH(URL, name, 'width=800,height=600');
	}
	
	function openChatWin(URL, name) {
		openWinWH(URL, name, 'width=650,height=650');
	}
	
	function openHelpWin(pageName, name) {
		openWinWH('/aides_jeu/general/index.php?page=' + pageName, name, 'width=550,height=600,scrollbars=1');
	}
	
	function openRegleWin(URL, name) {
		openWinWH(URL, name, 'width=800,height=600,scrollbars=1');
	}
	
	function openSimpleWin(URL, name) {
		openWinWH(URL, name, 'width=800,height=600,scrollbars=1,resizable=1');
	}
	
	function openSmallWin(URL, name) {
		openWinWH(URL, name, 'width=450,height=350,scrollbars=1,resizable=1');
	}
	
	function openNavWin(URL, name) {
		openWinWH(URL, name, 'width=638,height=600');
	}
	
	function popup(title, labels, datas) {
		fenetre = window.open('','','width=400,height=650,scrollbars=1');
		fenetre.focus();
		var texte = "";
		
		// On n'oublie pas la feuille de style
		texte = texte + "<body onBlur=\"window.focus();\">";
		texte = texte + "<link rel=\"stylesheet\" href=\"/style.css\" type=\"text/css\">";
		texte = texte + "<p class=\"titre\">" + title + "</p>";
		texte = texte + "<p class=\"subTitle\" align=\"center\">Détails</p>";
		texte = texte + "<br>&nbsp;";
		texte = texte + "<table align=\"center\" cellpadding=\"3\" cellspacing=\"3\" border=\"0\" width=\"90%\">";
		
		// Maintenant on construit la table de contenu
		for (var i = 0; i < labels.length; i++) {
			if (datas[i] == "") {
				texte = texte + "<tr><td colspan=\"2\" class=\"subTitle\">" + labels[i] + "</td></tr>";
			}
			else {
				texte = texte + "<tr><th>" + labels[i] + "</th><td>" + datas[i] + "</td></tr>";
			}
		}
		texte = texte + "</table>";
		texte = texte + "<p>&nbsp;</p>";
		texte = texte + "<p align=\"center\"><a href=\"#\" onclick=\"window.close()\">Fermer la fenêtre</a></p>";
		
		fenetre.document.open();
		fenetre.document.write(texte);
		fenetre.document.close();
	}
	
	/*************************************************************************
	 * Functions to manage display (elements to be hidden / shown, 
	 * layers in which text must be written...)
	 *************************************************************************/
	function getEl(n, d) {
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x = getEl(n,d.layers[i].document);
	  if(!x && document.getElementById) x=document.getElementById(n); return x;
	}
	
	function showEl(elt) {
	  var obj;
	  if ((obj = getEl(elt)) != null) {
	    if (obj.style) { 
		  obj = obj.style; 
		}
		obj.display = 'block';
	  }
	}
	
	function showRowEl(elt) {
	  var obj;
	  if ((obj = getEl(elt)) != null) {
	    if (obj.style) { 
		  obj = obj.style; 
		}
		obj.display = 'block';
		// firefox display for rows
		try {
			obj.display = 'table-row';
		} catch(e) {}
	  }
	}
	
	function hideEl(elt) {
	  var obj;
	  if ((obj = getEl(elt)) != null) {
	    if (obj.style) { 
		  obj = obj.style; 
		}
		obj.display = 'none';
	  }
	}
	
	
	function setTextOfLayer(objName,x,newText) {
		if ((obj=getEl(objName))!=null) with (obj)
			if (document.layers) {document.write(unescape(newText)); document.close();}
			else innerHTML = unescape(newText);	
	}
	
	function preloadImages() {
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	function swapImgRestore() {
		var i,x, a = document.rollOverImgs;
		for(i = 0; a && i < a.length && (x=a[i]) && x.oSrc; i++) {
			x.src = x.oSrc;
		}
	}
	
	function swapImage() {
		var i,j=0,x,a=swapImage.arguments;
		
		document.rollOverImgs = new Array;
		for(i=0;i<(a.length-2);i+=3) {
			if (((x=getEl(a[i]))!=null) && (selectedImg != a[i])){
				document.rollOverImgs[j++]=x; 
				if (!x.oSrc) {
					x.oSrc=x.src;
				}
				x.src=a[i+2];
			}
		}
	}
	
	var selectedImg;
	function setSelected(selected) {
		if (selectedImg == selected) {
			return;
		}
		
		selectedImg = selected;
		// On recupere l'ancienne image selectionnee...
		var aux = new Array;
		aux = document.selectedImgs;
		
		// On stocke la nouvelle image selectionnee...
		document.selectedImgs = new Array;
		document.selectedImgs = document.rollOverImgs;
		document.rollOverImgs = new Array;
		
		// On stocke l'ancienne ds le tableau des rollovers...
		document.rollOverImgs = aux;
		swapImgRestore();
	}

/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var offsetxpoint = -260 //Customize x offset of tooltip
var offsetypoint = 20 //Customize y offset of tooltip
var tipobj;

var enabletip = false

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth){
	if (typeof tipobj == "undefined") {
		if (window.top.use_css || window.top.use_gebi) {
			tipobj = document.all ? document.all["dhtmltooltip"] : document.getElementById ? document.getElementById("dhtmltooltip") : ""
		}
	}
	
	if (window.top.use_gebi || window.top.use_css) {
		offsetxpoint = -260;
		if (typeof thewidth!="undefined") {
			offsetxpoint = 60 - thewidth;
			tipobj.style.width = thewidth + "px"
		}
		tipobj.innerHTML = thetext
		enabletip = true
		return false
	}
}

function positiontip(e) {
	if (enabletip) {
		e = e || window.event;
		var curX = (!window.top.use_gebi) ? e.pageX : e.clientX + ietruebody().scrollLeft;
		var curY = (!window.top.use_gebi) ? e.pageY : e.clientY + ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge = window.top.use_css && !window.opera ? ietruebody().clientWidth - event.clientX-offsetxpoint : window.innerWidth - e.clientX - offsetxpoint - 20
		var bottomedge = window.top.use_css && !window.opera ? ietruebody().clientHeight - event.clientY-offsetypoint : window.innerHeight - e.clientY - offsetypoint - 20
		
		var leftedge = (offsetxpoint < 0) ? offsetxpoint*(-1) : -1000
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge < tipobj.offsetWidth)
		//move the horizontal position of the menu to the left by it's width
			tipobj.style.left = window.top.use_css ? ietruebody().scrollLeft + event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		else if (curX < leftedge)
			tipobj.style.left = "5px"
		else {
			tipobj.style.left = curX + offsetxpoint + "px" //position the horizontal position of the menu where the mouse is positioned
		}
		
		//same concept with the vertical position
		if (bottomedge < tipobj.offsetHeight)
			tipobj.style.top = window.top.use_css ? ietruebody().scrollTop + event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
		else
			tipobj.style.top = curY + offsetypoint + "px"
		tipobj.style.visibility = "visible"
	}
}

function hideddrivetip() {
	if (window.top.use_gebi || window.top.use_css){
		enabletip=false
		tipobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}

document.onmousemove = positiontip


function resizeCaller() {
	var dyniframe=new Array()
	for (i=0; i<iframeids.length; i++){
		if (document.getElementById) {
			resizeIframe(iframeids[i])
		}
	}
}

/****************************************************
 * Resize-frame functionnality
 ****************************************************/
function resizeIframe(frameid){
	var currentfr = parent.document.getElementById(frameid);
	if (currentfr && !window.opera) {
		currentfr.style.display="block"
		if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
			currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight + 30;
		}
		else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
			currentfr.height = currentfr.Document.body.scrollHeight + 30;
		}
		if (currentfr.addEventListener) {
			currentfr.addEventListener("load", readjustIframe, false)
		}
		else if (currentfr.attachEvent){
			currentfr.detachEvent("onload", readjustIframe) // Bug fix line
			currentfr.attachEvent("onload", readjustIframe)
		}
	}
}

function readjustIframe(loadevt) {
	var crossevt=(window.event)? event : loadevt
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
	if (iframeroot) {
		resizeIframe(iframeroot.id);
	}
}

function loadintoIframe(iframeid, url){
	if (document.getElementById) {
		document.getElementById(iframeid).src=url
	}
}