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;
				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) {
			var fPos = fCookie.indexOf("iosis");
			if (fPos >= 0) {
				if (parseInt(fCookie.charAt(fPos+7)) == 2) {
					fNoflash = 1;
				}
			}
			fPos = fCookie.indexOf("noflash");
			if (fPos >=0 ) {
				fNoflash = parseInt(fCookie.charAt(fPos+8));
			}
		}
	} catch (e) {
			
	}
	
	if (fForceflash > 0) fNoflash = parseInt(fLoc.charAt(fForceflash + 10));
	
	if (fNoflash == 0) {
		var Fversionfull = deconcept.SWFObjectUtil.getPlayerVersion();
		var Fversion = Fversionfull['major'];
		//document.title = document.title + " (Flash plugin version " + Fversionfull['major'] + ")";
		if (Fversion >= 8) {
			Fversion = 8;
			var Fflashcontent = document.getElementById("content");			
			var Fdata =dumpXML(document.documentElement);
			var fo = new SWFObject("htmlRender.swf", "htmlRender", "100%", "100%", Fversion, "#FFFFFF");
			fo.addVariable("flashData", encodeURIComponent(Fdata));
			fo.addVariable("siteVersion", gSiteVersion);
			fo.addVariable("documentLocation", encodeURIComponent(fLoc));
			//fo.addVariable("ignoreClasses", "tbse"); // ignore tags with class="tbse ...
			fo.setAttribute("SWLIVECONNECT", "true");
			fo.addVariable("cookie", encodeURIComponent(document.cookie)); // à voir, possible source d'erreur d'encoder
			fo.addParam("scale", "noscale");
			fo.addParam("salign", "TL");
			fo.addParam("allowScriptAccess", "always");
			fo.write(Fflashcontent);
			EdaHistory.start(callFlash);
			/*
			Fflashcontent.style.visibility = "hidden";
			var fMiddle = document.getElementById("middleContent");
			if (fMiddle != null) {
				var fWait = document.createElement("img");
				
				fWait.src="img/wait.gif";
				fWait.className = "imgwaitflashload";
				fMiddle.appendChild(fWait);
				fMiddle.waitlogo = fWait;
			}
			*/
		} else if (Fversion >= 6) {
			var fExpress = document.getElementById("flashexpressinstall");
			var fo = new SWFObject("expressinstall.swf", "expressInstall", "319", "175", "6.0.65");
			fo.xiSWFPath = "expressinstall.swf";
			fo.setAttribute("SWLIVECONNECT", "true");
			fo.addParam("scale", "noscale");
			fo.addParam("salign", "TL");
			fo.addParam("allowScriptAccess", "always");
			fo.setAttribute('xiRedirectUrl', window.location);
			fo.setAttribute('doExpressInstall', true);
			fo.addVariable("MMredirectURL", escape(fo.getAttribute('xiRedirectUrl')));
			fo.addVariable("MMdoctitle", document.title);
			fo.write(fExpress);
		}
	}
}

var gFlashUrl;
function setFlashUrl(pUrl, pTitle) {
	pUrl = Utils.splitPath(pUrl)[1];
	var fUrl = gFlashUrl;
	gFlashUrl = pUrl;
	if (!EdaHistory.unsupported && fUrl != pUrl) {
		EdaHistory.set(pUrl, pTitle);
	}
}

function callFlash(pUrl) {
	var fSwfObject = window.parent.document.getElementById("htmlRender");
	if (fSwfObject == null) return;
	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("iosis=");
			if (fPos >= 0) {
				if (parseInt(fCookie.charAt(fPos+6)) > 0) {
					fLogged = true;
				}
			}
		}
	} catch (e) {}
	return fLogged;
}

function resizeBlock(pMoins) {
	/*
	1) on récupère la hauteur du contenu
	2) on calcule la hauteur maximale
	Cas 1 : maxHeight >= scrollHeight
		alors height = scrollHeight
	Cas 2 : maxHeight < scrollHeight
		alors height = maxHeight
	*/
	if (isAdmin()) return;
	var fVp = getViewport();
	var fDiv = document.getElementById("mainBlock");
	if (fDiv == null) return;
	var fChilds = fDiv.childNodes;
	var fInnerHeight = 0;

	for (var i=0;i<fChilds.length;i++) {
		var lElem = fChilds.item(i);
		if (lElem.nodeType != 1) continue;
		if (window.getComputedStyle != null) {
			if (getComputedStyle(lElem, null)['position'] != "relative") continue;
		} else if (lElem.currentStyle != null) {
			if (lElem.currentStyle['position'] != "relative") continue; 
		}
		if (lElem.offsetHeight != null) fInnerHeight += lElem.offsetHeight;		
		//else if (fChilds[i].innerHeight != null) fInnerHeight += fChilds[i].innerHeight;
	}
	var fPos = findPos(fDiv);
	if (! pMoins) pMoins = 0;
	var fMaxHeight = fVp[1] - 84 - fPos[1] - pMoins;
	var fScrollHeight = fInnerHeight;
	var fHeight;
	if (fMaxHeight >= fScrollHeight) {
		fHeight = fScrollHeight;
	} else {
		fHeight = fMaxHeight;
	}
	fDiv.style.height = fHeight + "px";
}

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?referer=" + encodeURIComponent(gFlashUrl);
			}
		} else {
			if (confirm("Voulez-vous vous déconnecter ?")) {
				document.location = "adminout.php?referer=" + encodeURIComponent(document.location.toString());
			}
		}
	}
}

function showSearchBar(pNode) {
	pNode.style.display = "none";
	while (pNode.nextSibling.nodeType != 1) pNode = pNode.nextSibling;
	show(pNode.nextSibling);
	document.getElementById('searchInput').focus();
	searchFlashInstall();
	captureEnterSearch();
}

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";
}

