| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 
 | /* --------------------------------------------------------------------------------- *
 * Generic content loading methods.
 * --------------------------------------------------------------------------------- */
 
loadPageToId	= function (pageUrl, elementId) {
	loadPageToElement(pageUrl, elementId, "loadingIndicator"); 
}
 
 
/* --------------------------------------------------------------------------------- *
 * Tabs management.
 * --------------------------------------------------------------------------------- */
 
var tabIds			= ["tab1", "tab2", "tab3"];
var curTab			= "";
 
loadTabContent	= function (tabId) {
	var curTab	= tabId;
	for (var isz=0; isz<tabIds.length; isz++) {
		if (tabId==tabIds[isz])
			document.getElementById(tabIds[isz]).className	= "current";
		else
			document.getElementById(tabIds[isz]).className	= "";
	}
	pageToLoad	= document.getElementById(tabId).getAttribute("rel");
	loadPageToElement(pageToLoad, "tabbedContent", "loadingIndicator"); 
}
 
loadPreviousTab	= function () {
	var curIndex	= tabIds.indexOf(curTab)
	if (curIndex<=0)
		curIndex	= tabIds.length;
	loadTabContent(tabIds[curIndex-1]);
}
loadNextTab	= function () {
	var curIndex	= tabIds.indexOf(curTab)
	if (curIndex>=tabIds.length-1)
		curIndex	= -1;
	loadTabContent(tabIds[curIndex+1]);
}
 
 
/* --------------------------------------------------------------------------------- *
 * Generic functions.
 * --------------------------------------------------------------------------------- */
 
var loadError	= "Erreur lors du chargement de la page.";
 
function setInnerHTML (pDivObject, pHTML) {
	pDivObject.innerHTML	= pHTML; 
	var All					= pDivObject.getElementsByTagName("*");
	for (var i=0; i<All.length; i++) {
		All[i].id			= All[i].getAttribute("id");
		All[i].name			= All[i].getAttribute("name");
		All[i].className	= All[i].getAttribute("class");
	}
	var AllScripts			= pDivObject.getElementsByTagName("script");
	for (var i=AllScripts.length-1; i>=0; i--) {
		var s = AllScripts[i];
		var oScript = document.createElement("script");
		oScript.type='text/javascript';
		if (s.src && s.src!="") {
			oScript.src = s.src;
		} else {
			oScript.innerHTML = s.innerHTML;
		}
		document.body.appendChild(oScript);
		pDivObject.removeChild(s);
	}
}
 
var loadPageToElement	= function (url, pageElement, loadingIndicator) {
	document.getElementById(loadingIndicator).style.visibility	= "visible";
	document.getElementById(pageElement).innerHTML				= "";
	try {
		req = new XMLHttpRequest();
	} catch(e) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				req = false;
			} 
		} 
	}
	req.onreadystatechange = function() {
		xmlHttpRequestEnded(pageElement, loadingIndicator);
	};
	req.open("GET",url,true);
	req.send(null);
}
 
var xmlHttpRequestEnded	= function (pageElement, loadingIndicator) {
	if(req.readyState==4) {
		if(req.status==200) {
			document.getElementById(loadingIndicator).style.visibility	= "hidden";
			setInnerHTML(document.getElementById(pageElement), req.responseText);
		} else {
			document.getElementById(loadingIndicator).style.visibility	= "visible";
			setInnerHTML(document.getElementById(pageElement), loadError);
		}
	}
} | 
Partager