// JavaScript Document

function ajax(frame, where)
{
	var xhr=null;
    if (window.XMLHttpRequest) 
        xhr = new XMLHttpRequest();
    else if (window.ActiveXObject) 
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    xhr.onreadystatechange = function() { ajax_callback(xhr, where , frame + "&ajax=yes"); };
	xhr.open("GET", frame + "&ajax=yes", true);
	xhr.send(null);
}

function ajax_callback(xhr, where, frame)
{
	var res = xhr.responseText;
	if (xhr.readyState == 4  &&  xhr.status == 200)
	{
		if (frame.match("voir"))
		{
			document.getElementById('tr' + where).style.display = '';
		}
		if(frame.match("creerancien") || frame.match("creeroffre"))
		{
			removehelp();
		}
		document.getElementById(where).innerHTML = res;
	}
}

function check_color_menu(indexid)
{
	document.getElementById("omaccueil").style.backgroundColor = "#ABC578";
	document.getElementById("ompresentation").style.backgroundColor = "#ABC578";
	document.getElementById("omteam").style.backgroundColor = "#ABC578";
	document.getElementById("omindustriels").style.backgroundColor = "#ABC578";
	document.getElementById("omliens").style.backgroundColor = "#ABC578";
	document.getElementById("ompartenaires").style.backgroundColor = "#ABC578";
	if (document.getElementById("omprofil"))
		document.getElementById("omprofil").style.backgroundColor = "#ABC578";
	if (document.getElementById("omadmin"))
		document.getElementById("omadmin").style.backgroundColor = "#ABC578";
	if (document.getElementById("omoffres"))
		document.getElementById("omoffres").style.backgroundColor = "#ABC578";
	document.getElementById("om" + indexid).style.backgroundColor = "#514F1C";
}

function my_confirm(type, id, name)
{
	if (type == 'e')
	{
		if (confirm("Etes vous sur de vouloir supprimer l'étudiant " + name + " ?"))
	   		document.location.href='index.php?pgid=admin&frame=etudiants&sup=' + id;
	}
	if (type == 'o')
	{
		if (confirm("Etes vous sur de vouloir supprimer l'offre du laboratoire " + name + " ?"))
	   		document.location.href='index.php?pgid=admin&frame=offres&sup=' + id;
	}
	if (type == 'm')
	{
		if (confirm("Etes vous sur de vouloir enlever les droits de membre AJE à " + name + " ?"))
	   		document.location.href='index.php?pgid=admin&frame=membres&sup=' + id;
	}
	if (type == 'a')
	{
		if (confirm("Etes vous sur de vouloir supprimer l'ancien membre AJE " + name + " ?"))
	   		document.location.href='index.php?pgid=admin&frame=anciens&sup=' + id;
	}
	if (type == 's')
	{
		if (confirm("Etes vous sur de vouloir souscrire à l'offre de " + name + " ?"))
	   		document.location.href='index.php?pgid=offres&frame=offres&validate=' + id;
	}
	if (type == 'f')
	{
		if (confirm("Etes vous sur de vouloir finir l'offre de " + name + " ?"))
	  		document.location.href='index.php?pgid=admin&frame=offres&finish=' + id;
	}
	if (type == 'z')
	{
		if (confirm("Etes vous sur de vouloir vous désinscrire de l'offre de " + name + " ?"))
	  		document.location.href='index.php?pgid=offres&frame=offres&desinscrire=' + id;
	}
}

function my_confirm2(type, id, id2, name)
{
	if (type == 'd')
	{
		if (confirm("Etes vous sur de vouloir supprimer de cette offre l'étudiant " + name + " ?"))
	  		document.location.href='index.php?pgid=admin&frame=offres&change=' + id + '&user=' + id2;
	}
	if (type == 'v')
	{
		if (confirm("Etes vous sur de vouloir valider l'étudiant " + name + " pour cette offre ?"))
	  		document.location.href='index.php?pgid=admin&frame=offres&accept=' + id + '&user=' + id2;
	}
}

function addannee(idx)
{
	var newidx = Math.round(parseInt(idx) + 1);
	var res = "<table class='tableadmin'>";
	var nb = Math.round(idx % 2);
	if (nb == 1)
		res += "<tr style='background-color:#FFFFFF'>";
	if (nb == 0)
		res += "<tr style='background-color:#eeeeee'>";
	res += "<td><input type='text' name='annee" + newidx + "' size=5></td><td><select name='status" + newidx + "'><option value='b'>Bureau</option>";
	res += "<option value='m'>Membre</option></select></td><td><input type='text' name='detailstatus" + newidx + "'></td><td width=5%></td></tr></table>";
	res += "<div id='ancien" + newidx + "'></div>";
	
	//res += "<td><input type='text' name='annee" + newidx + "' size=5></td><td>{html_options name=thename options=$options_status selected=$res.Status}";
	//res += "</td><td><input type='text' name='detailstatus" + newidx + "'></td><td width=5%></td></tr></table>";
	//res += "<div id='ancien" + newidx + "'></div>";
	
	document.getElementById("ancien" + idx).innerHTML = res;
	document.getElementById("plus").href = "javascript:addannee(" + newidx + ");";
}

function rembobine(id)
{
	document.getElementById("tr" + id).style.display='none';
}

function removehelp()
{
	document.getElementById("help").style.display='none';
}
