function dumpXML(Pxml) {
	var fTexteCont = document.createElement("p");
	var fTexte = document.createTextNode("");
	fTexteCont.appendChild(fTexte);
	var Fstr = '';
	Fstr = doNode(Pxml, Fstr);
	return Fstr;
	
	function doNode(Pnode, Pstr) {
		var Ftype = Pnode.nodeType;
		if (Ftype == 1) {
			var Ftagname = Pnode.tagName.toLowerCase();
			Pstr += '<' + Ftagname;
			var Fatt = Pnode.attributes;
			for (var i=0; i < Fatt.length; i++) {
				var Latt = Fatt.item(i);
				var Lval = Latt.nodeValue;
				if (Lval == null || Lval.toString().length == 0) continue;
				var Lname = Latt.nodeName.toLowerCase();
				if (Lname == "style") continue;
				//if (Lname == "href") alert(Lval);
				fTexte.nodeValue = Lval;
				Lval = fTexteCont.innerHTML;
				Pstr += ' ' + Lname + '="' + Lval + '"';
			}
			if (Pnode.style.cssText != null && Pnode.style.cssText.toString().length > 0) Pstr += ' style="' + Pnode.style.cssText + '"';

			var Fchilds = Pnode.childNodes;
			if (Fchilds.length == 0) {
				if (Ftagname == "title") {
					Pstr += ">" + Pnode.innerHTML + "</title>"; // another wonderful ie6 bug...
				} else Pstr += ' />';
			} else {
				Pstr += '>';
				for (var i = 0; i < Fchilds.length; i++) {
					Pstr = doNode(Fchilds.item(i), Pstr);
				}
				Pstr += '</' + Ftagname + '>';
			}
		} else if (Ftype == 3) {
			Pstr += Pnode.nodeValue;
		}
		return Pstr;
	}
}

function flashLoaded() {
}

function getQuery() {
	var fLoc = document.location.toString();
	var fParams = {};
	var fStart = fLoc.indexOf("?");
	if (fStart < 0) return fParams;
	var fEnd = fLoc.indexOf("#");
	if (fEnd < 0) fEnd = fLoc.length;
	var fQuery = fLoc.substring(fStart+1, fEnd);
	var fSplit = fQuery.split("&");
	for (var i=0; i < fSplit.length; i++) {
		var lSplit = fSplit[i].split("=");
		var lLeft = decodeURIComponent(lSplit[0]);
		if (lSplit.length == 2) fParams[lLeft] = decodeURIComponent(lSplit[1]);
		else fParams[lLeft] = true;
	}
	return fParams;
}

function goFlash(pForce) {
	var fLoc = document.location.toString();
	//if (fLoc.charAt(fLoc.length-1) == "/") fLoc += "index.php";
	//gFlashUrl = fLoc;
	var fForceflash = fLoc.indexOf("forceflash=");
	if (pForce == true && fForceflash < 0) {
		var fDiese = fLoc.indexOf("#");
		if (fDiese > 0) {
			fLoc = fLoc.substring(0, fDiese);
			fDiese = fLoc.substring(fDiese);
		} else fDiese = "";
		var fParam = fLoc.indexOf('noflash=');
		if (fParam > 0) {
			fParam += 8;
			fLoc = fLoc.substring(0, fParam) + "0" + fLoc.substring(fParam+1);
		} else if (fLoc.indexOf("?") > 0) {
			fLoc += "&noflash=0";
		} else {
			fLoc += "?noflash=0";
		}
		document.location = fLoc + fDiese;
		return;
	}

	var fCookie = document.cookie.toString();
	var fNoflash = 0;
	try {
		if (fCookie != null && fCookie.length > 0) {
			fPos = fCookie.indexOf("noflash");
			if (fPos >=0 ) {
				fNoflash = parseInt(fCookie.charAt(fPos+8));
			}
		}
	} catch (e) {
			
	}
	
	if (fForceflash > 0) fNoflash = parseInt(fLoc.charAt(fForceflash + 11));
	
	if (fNoflash == 0) {
		var Fversionfull = swfobject.getFlashPlayerVersion();
		var Fversion = Fversionfull['major'];
		if (Fversion < 6) return;
		if (Fversion >= 10) {
			gFlashStarted = true;
			var Fflashcontent = document.getElementById("content");			
			var Fdata = dumpXML(document.documentElement);
			Fflashcontent.innerHTML = "<div id='htmlRender'></div>";
			var fFlashvars = {
				'flashData' : encodeURIComponent(Fdata),
				'siteVersion' : gSiteVersion,
				'documentLocation' : encodeURIComponent(fLoc),
				'cookie' : encodeURIComponent(document.cookie)
			};
			var fParams = {
				'bgcolor' : "#FFFFFF",
				'scale' : "noscale",
				'salign' : "TL",
				'allowScriptAccess' : "always"
			};
			var fAttributes = {
				'SWLIVECONNECT' : "true"
			};
			
			swfobject.embedSWF("htmlRender.swf", "htmlRender", "100%", "100%", "10.0.0", "expressInstall.swf", fFlashvars, fParams, fAttributes);
			// htmlRender will manage scrollbar, so hide it.
			document.body.style.overflow = "hidden";
			EdaHistory.start(callFlash);
		} else {
			var fPlease = document.getElementById("updateFlash");
			fPlease.insertBefore(document.createTextNode(Fversion), fPlease.lastChild.previousSibling);
			fPlease.style.display = "block";
		}
	} else {
		// call stats...
		
	}
}

var gFlashUrl;
function setFlashUrl(pUrl, pTitle) {
	var fTitle = decodeURIComponent(decodeURIComponent(pTitle));
	gFlashUrl = decodeURIComponent(decodeURIComponent(pUrl));
	EdaHistory.set(gFlashUrl, fTitle);
}

function callFlash(pUrl) {
	var fSwfObject = window.parent.document.getElementById("htmlRender");
	if (fSwfObject == null) return;
	if (pUrl == null) pUrl = "";
	fSwfObject.SetVariable("gotoURL", pUrl);
	gFlashUrl = pUrl;
}


function getViewport() {
	var viewportwidth;
	var viewportheight;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0) {
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	// older versions of IE
	else {
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	return [viewportwidth, viewportheight];
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function isAdmin() {
	var fCookie = document.cookie.toString();
	var fLogged = false;
	try {
		if (fCookie != null && fCookie.length > 0) {
			var fPos = fCookie.indexOf("admin=");
			if (fPos >= 0) {
				if (parseInt(fCookie.charAt(fPos+6)) > 0) {
					fLogged = true;
				}
			}
		}
	} catch (e) {}
	return fLogged;
}


var gFastcom = null;

document.onkeypress = function(e) {
	var fCode;
	if (!e) var e = window.event;
	if (e.keyCode) fCode = e.keyCode;
	else if (e.which) fCode = e.which;
	var fChar = String.fromCharCode(fCode);
	if (fChar == "$") {
		gFastcom = '';
	} else if (gFastcom != null) {
		gFastcom += fChar;
		if (gFastcom.length > 5) gFastcom = null;
	}
	if (gFastcom == null) return;
	
	if (gFastcom.length == 5 && gFastcom == "admin") {
		gFastcom = null;
		if (!isAdmin()) {
			if (confirm("Voulez-vous vous logger en tant qu'administrateur ?")) {
				document.location = "adminlogin.php";
			}
		} else {
			if (confirm("Voulez-vous vous déconnecter ?")) {
				document.location = "logout.php";
			}
		}
	}
}

function showSearchBar(pNode) {
	pNode.style.display = "none";
	pNode.parentNode.style.width = "200px";
	while (pNode.nextSibling.nodeType != 1) pNode = pNode.nextSibling;
	pNode.nextSibling.style.display = "block";
	document.getElementById('searchInput').focus();
	searchFlashInstall();
	captureEnterSearch();
	return false;
}

function searchFlashInstall() {
	loadGoogleUDS();
}

function captureEnterSearch() {
	document.onkeydown = function(e) {
		var fCode;
		if (!e) var e = window.event;
		if (e.keyCode) fCode = e.keyCode;
		else if (e.which) fCode = e.which;
		if (fCode == 13) {
			googleSearch();
			return false;
		} else {
			document.getElementById("searchInput").style.backgroundColor = "#FFFFFF";
		}
	}
}

function loadGoogleUDS() {
	var fFrame = document.getElementById("googleFrame");
	if (fFrame != null) return;
	
	fFrame = document.createElement("iframe");
	fFrame.src = "searchframe.php";
	fFrame.setAttribute('id', "googleFrame");
	fFrame.style.visibility = "hidden";
	fFrame.style.display = "block";
	fFrame.style.width = "0px";
	fFrame.style.height = "0px";
	document.body.appendChild(fFrame);
}

function tryFlashSearch(pText) {
	try {
		googleFlashSearch(pText);
	} catch (e) {
		alert(e.toString());
	}
}

function trySearch() {
	try {
		googleSearch();
	} catch (e) {
		alert(e.toString());
	}
	return false;
}

function hide(pId) {
	if (typeof(pId) == "string") pId = document.getElementById(pId);
	pId.style.visibility = "hidden";
}

function show(pId) {
	if (typeof(pId) == "string") pId = document.getElementById(pId);
	pId.style.visibility = "visible";
}

var gCenterV, gBottom, gTop;
function fixResize() {
	var fH = gCenterV.offsetHeight;
	if (document.body.offsetHeight > fH + gBottom.offsetHeight + gTop.offsetHeight) {
		gCenterV.style.marginTop = -fH/2 + "px";
		gCenterV.style.top = "50%";
		gCenterV.style.position = "absolute";
		gBottom.style.position = "absolute";
	} else {
		gCenterV.style.position = "static";
		gCenterV.style.marginTop = "0px";
		gCenterV.style.top = "0px";
		gBottom.style.position = "static";
	}
}
function fixLayout() {
	gCenterV = document.getElementById("centerv");
	gBottom = document.getElementById("bottom");
	gTop = document.getElementById("top");
	if (!gTop || !gCenterV || !gBottom) return;
	fixResize();
	window.onresize = fixResize;
}


var gMapLocalisation, gMapFrame, gMapDiv;
function loadGoogleMaps(pLat, pLon, pLocalisation) {
	if (!pLocalisation) return;
	gMapLocalisation = [pLat, pLon, pLocalisation];
	if (gMapFrame != null) return;
	else {// refresh map
	}
	gMapFrame = document.createElement("iframe");
	gMapFrame.className = "googleMaps";
	gMapFrame.src = "googleMaps.php";
	gMapFrame.frameBorder = 0;
	gMapDiv = document.getElementById("googleMap");
	if (gMapDiv != null) {
		updatePositionGoogleMaps();
		window.onresize = updatePositionGoogleMaps;
	}
	document.body.appendChild(gMapFrame);
	var fPosition = "";
	if (window.getComputedStyle){
		fPosition = window.getComputedStyle(gMapFrame, null).position;
	} else if (gMapFrame.currentStyle){
		fPosition = gMapFrame.currentStyle["position"];
	}
	if (fPosition == "fixed") {
		window.onscroll = updatePositionGoogleMapsScroll;
	}
}
function unloadGoogleMaps() {
	if (gMapFrame != null) {
		window.onscroll = null;
		window.onresize = null;
		gMapFrame.parentNode.removeChild(gMapFrame);
		gMapFrame = null;
	}
}
window.top.getMapLocalisation = function() {
	return gMapLocalisation;
};
function positionGoogleMaps(pX, pY) {
	gMapFrame['_absx'] = pX;
	gMapFrame['_absy'] = pY;
	gMapFrame.style.top = pY + "px"; // borders
	gMapFrame.style.left = pX + "px";
}
function updatePositionGoogleMaps() {
	var fPos = getPagePosition(gMapDiv);
	positionGoogleMaps(fPos[0], fPos[1]);
}
function updatePositionGoogleMapsScroll() {
	var fTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
	var fLeft = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
	gMapFrame.style.top = (gMapFrame['_absy'] - fTop) + "px"; // borders
	gMapFrame.style.left = (gMapFrame['_absx'] - fLeft) + "px";
}

function getPagePosition(pNode) {
	var fX = fY = 0;
	if (pNode.offsetParent) {
		do {
			fX += pNode.offsetLeft;
			fY += pNode.offsetTop;
		} while (pNode = pNode.offsetParent);
	}
	return [fX+1,fY];
}

