// home

var timer;
function animHome(n) {
	clearTimeout (timer);

	nMax = 0;
	for (i=5; i>=1; i--) {
		if (document.getElementById('homegrand'+i) != null) {
			nMax = i;
			break;
		}
	}

	if (n>nMax)
		n=1;
	for (i=1; i<=nMax; i++) {
		if (i==n)  {
			document.getElementById('homegrand'+i).style.display = "block";
			document.getElementById('homepetit' + i).className = "homepetitover";
		}
		else {
			document.getElementById('homegrand'+i).style.display = "none";
			document.getElementById('homepetit' + i).className = "homepetit";
		}
	}
	timer = setTimeout ("animHome("+(++n)+")",8000);
}

function changeColor (e)
{
	var a = document.getElementsByTagName("a");
	for (i=0; i< a.length; i++) {
		if (a[i].className == "recherchered")
			a[i].className="recherche"; 
	}
	e.className="recherchered";
}

function changeLettre(a) {
    for (i = 65; i <= 90; i++) {
        document.getElementById(String.fromCharCode(i)).className = "";
    }
    document.getElementById(a).className = "bleu";
}

function changeEncyclo(e) {
	document.getElementById('encyclo-motscles').style.display = "none";
	document.getElementById('encyclo-alpha').style.display = "none";
	document.getElementById('encyclo-qr').style.display = "none";
	document.getElementById('encyclo-'+e).style.display = "block";

	document.getElementById('btencyclo-motscles').className = "encyclorouge";
	document.getElementById('btencyclo-alpha').className = "encyclorouge";
	document.getElementById('btencyclo-qr').className = "encyclorouge";
	document.getElementById('btencyclo-' + e).className = "encyclobleu";
}

function changeOnglet(a,b) {
    for (i = 1; i <= 3; i++) {
        if (document.getElementById('onglet' + a + 'a' + i) != null)
            document.getElementById('onglet' + a + 'a' + i).style.display = "none";
        if (document.getElementById('onglettitre' + a + 'a' + i) != null)
            document.getElementById('onglettitre' + a + 'a' + i).className = "";
        if (document.getElementById('ongletplus' + a + 'a' + i) != null)
            document.getElementById('ongletplus' + a + 'a' + i).style.display = "none";
    }
    document.getElementById('onglet' + a + 'a' + b).style.display = "block";
    if (document.getElementById('onglettitre' + a + 'a' + b) != null)
        document.getElementById('onglettitre' + a + 'a' + b).className = "over";
    document.getElementById('ongletplus' + a + 'a' + b).style.display = "block";
    document.getElementById('onglettitre' + a + 'a1').scrollIntoView(true);
}

function changeAlaune(a) {
    for (i = 1; i <= 4; i++) {
        if (document.getElementById('alaune' + i) != null)
            document.getElementById('alaune' + i).style.display = "none";
        if (document.getElementById('alaunebulle' + i) != null)
            document.getElementById('alaunebulle' + i).style.backgroundImage = "url(img/bulle1.gif)";
    }
    document.getElementById('alaune' + a).style.display = "block";
    document.getElementById('alaunebulle' + a).style.backgroundImage = "url(img/bulle2.gif)";
}

function changeEncycloune(a) {
    for (i = 1; i <= 6; i++) {
        if (document.getElementById('encycloune' + i) != null)
            document.getElementById('encycloune' + i).style.display = "none";
        if (document.getElementById('encyclounebulle' + i) != null)
            document.getElementById('encyclounebulle' + i).style.backgroundImage = "url(img/bulle1.gif)";
    }
    document.getElementById('encycloune' + a).style.display = "block";
    document.getElementById('encyclounebulle' + a).style.backgroundImage = "url(img/bulle2.gif)";
}
function animEncycloune(n) {
    clearTimeout(timer);

    nMax = 0;
    for (i = 6; i >= 1; i--) {
        if (document.getElementById('encycloune' + i) != null) {
            nMax = i;
            break;
        }
    }

    if (n > nMax)
        n = 1;
    changeEncycloune(n);

    timer = setTimeout("animEncycloune(" + (++n) + ")", 6000);
}

// chat

function ChatValidSupp (idmessage) {
    var retour;
    retour = confirm("Etes-vous sûr de vouloir supprimer cette ligne ?");
    if (retour)
        location.href = "chat-validsuppmessage.asp?idmessage=" + idmessage;
}
function ChatResizeReponseType() {
    if (document.documentElement.clientHeight - 380 > 50) {
        document.getElementById('messages').height = document.documentElement.clientHeight - 380;
    }
}
function ChatReponseType () {
    texte = document.theForm.idreponsetype.options[document.theForm.idreponsetype.selectedIndex].value;
    document.theForm.message.value = texte;
}
function ChatSynchro (idmessage, question, reponse) {
    document.theForm.question.value = question;
    document.theForm.idreponsetype.options[0].selected = true;
    document.theForm.idmessage.value = idmessage;
    document.theForm.message.value = reponse;
}
function chatResize () {
	if (document.documentElement.clientHeight - 400 > 50) {
		document.getElementById ('messages').height = (document.documentElement.clientHeight - 400)/2;
		document.getElementById ('reponses').height = (document.documentElement.clientHeight - 400)/2;
	}
}
function ChatResize3 () {
    if (document.documentElement.clientHeight - 480 > 50) {
        document.getElementById('reponses').height = (document.documentElement.clientHeight - 480);
    }
}

function scrollToBottom ()
{
	if (document.documentElement.scrollHeight - document.documentElement.clientHeight > 0)
		window.scrollTo (0,document.documentElement.scrollHeight - document.documentElement.clientHeight);
}
function chatRefresh2() {
    document.location = "chat-reponses.asp?scrollTop=" + document.documentElement.scrollTop + "&scrollMax=" + (document.documentElement.scrollHeight - document.documentElement.clientHeight);
}
function chatOnload(scrollTop, scrollMax) {
    if (scrollTop > 0) {
        if (scrollTop == scrollMax) {
            scrollToBottom();
        }
        else {
            window.scrollTo(0, scrollTop);
        }
    }
}

function insertEmoticon (text) {
	var txtarea = document.theForm.message;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} 
	else {
		txtarea.value += text;
		txtarea.focus();
	}
}


// savoir plus

function adjustIFrameSize (iframeWindow)
{
	if (iframeWindow.document.height) {
		var iframeElement = document.getElementById (iframeWindow.name);
		iframeElement.style.height = iframeWindow.document.height+18 + 'px';
	}
	else if (document.all) {
		var iframeElement = document.all[iframeWindow.name];
		if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') {
			iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
		}
		else {
			iframeElement.style.height = iframeWindow.document.body.scrollHeight + 5 + 'px';
		}
	}
}

function ForumInsertEmoticon (text) {
	var txtarea = document.theForm.chat;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} 
	else {
		txtarea.value += text;
		txtarea.focus();
	}
}


// signaler

function Signaler (id,table) {
	if (confirm("Si le contenu de ce message vous paraît aller à l'encontre de la loi et du respect d'autrui, merci de nous alerter.")) {
		document.getElementById("signaler").src = "signaler.asp?Id=" + id + "&Table=" + table;
	}
}

function Citer(id, table) {
    if (table == "commentaire")
        document.getElementById("signaler").src = "article-citer.asp?Id=" + id;
    else
        document.getElementById("signaler").src = "forum-citer.asp?Id=" + id + "&Table=" + table;
    document.getElementById('saisie').scrollIntoView(true);
}

function limitLength (text,length) {
	if (text.value.length>length) 
		text.value = text.value.substr(0,length); 
}

function ChangeColor2(place, place2) {
/*
    document.getElementById('menu1').style.backgroundImage = 'url(img/fond-menu.jpg)';
    document.getElementById('menu2').style.backgroundImage = 'url(img/fond-menu.jpg)';
    document.getElementById('menu3').style.backgroundImage = 'url(img/fond-menu.jpg)';
    document.getElementById('menu4').style.backgroundImage = 'url(img/fond-menu.jpg)';
    document.getElementById('menu5').style.backgroundImage = 'url(img/fond-menu.jpg)';
    document.getElementById('menu6').style.backgroundImage = 'url(img/fond-menu.jpg)';

    document.getElementById('menu' + place).style.backgroundImage = 'url(img/fond-menu-vert.jpg)';
    document.getElementById('menu' + place2).style.backgroundImage = 'url(img/fond-menu-vert.jpg)';
*/
}
