// INITIALISATION DE TINYMCE (EDITEUR WYSIWYG)
tinyMCE.init({
	mode : 'exact',
	elements : 'txt_intro, txt_text',
	theme : 'advanced',
	language : 'fr',
	width : '500',
	height : '300',
	
	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,forecolor,backcolor",
	theme_advanced_buttons3 : ""
});

function submit() {
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xhr.onreadystatechange = function() { changeContents(xhr); };
	xhr.open('GET', url, true);
	xhr.send(null);
}

function changeContents(xhr,elt) {
	if (xhr.readyState == 4) {
		if (xhr.status == 200) {
			//alert(xhr.responseXML);
			
			//document.getElementById(elt).style.background-image = 'url('+elt+'.jpg)'; 
			
			//var docXML= xhr.responseXML;
			//var items = docXML.getElementsByTagName("donnee")


		} else {
			alert('Un problème est survenu avec la requête.');
		}
	}
}


function verticalSlideRubrique(rankRubrique) {
	var sousRubrique = document.getElementById('sous_rubrique' + rankRubrique);
	var slide = new Fx.Slide(sousRubrique);
	slide.toggle();
}

// AFFICHE LA FENETRE D'EDITION
function showWindow(idWindow) {
	var window = document.getElementById(idWindow);
	var div = document.getElementsByTagName('div');
	for(i in div)
		if(div[i].className == 'window_edit')
			div[i].style.display = 'none';
	window.style.display = 'block';
	upWindow(idWindow);
}

// CACHE LA FENETRE D'EDITION
function hideWindow(idWindow) {
	var window = document.getElementById(idWindow);
	window.style.display = 'none';
}

// REMONTE LA FENETRE D'EDITION ET SES PARENTS AU DESSUS DES AUTRES ELEMENTS
function upWindow(idWindow) {
	var windowUp = document.getElementById(idWindow);
	var conteneur = document.getElementById('conteneur');
	var eltUp = windowUp.parentNode;
	
	while(eltUp != conteneur) {
		//alert(eltUp.id);
		eltUp.style.zIndex = 10;
		var eltLeft = eltUp.previousSibling;
		var eltRight = eltUp.nextSibling;
		while(eltLeft) {
			if(eltLeft.nodeType == 1) {
				//alert('down left' + eltLeft.id);
				eltLeft.style.zIndex = 0;
				}
			eltLeft = eltLeft.previousSibling;
		}
		while(eltRight) {
			if(eltRight.nodeType == 1) {
				//alert('down right' + eltRight.id);
				eltRight.style.zIndex = 0;
				}
			eltRight = eltRight.nextSibling;
		}
		eltUp = eltUp.parentNode;
	}
}

// AFFICHE UNE SOUS RUBRIQUE
function afficheSousRubrique(rankRubrique) {
	var menu = document.getElementById('menu');
	menu.style.zIndex = 20;
	for(var i = 1; i <= 4; i++) {
		var rubrique = document.getElementById('rubrique' + i);
		var sousRubrique = document.getElementById('sous_rubrique' + i);
		if(i == rankRubrique) {
			rubrique.style.zIndex = 20;
			sousRubrique.style.zIndex = 20;
			sousRubrique.style.display = 'block';
		}
		else {
			rubrique.style.zIndex = 0;
			sousRubrique.style.zIndex = 0;
			sousRubrique.style.display = 'none';
		}
	}
}

// CACHE UNE SOUS RUBRIQUE
function cacheSousRubrique(rankRubrique) {
	var sousRubrique = document.getElementById('sous_rubrique' + rankRubrique);
	sousRubrique.style.display = 'none';
}