function ajaxPopUp(url) {
	document.write('<div id="ajaxpopup"><a onclick="$(\'ajaxpopup\').style.display=\'none\'">Fermer</a></div>');
}


function setDisplayBlock(id) {	
	$(id).style.display = "block";
}

function setDisplayNone(id) {
	$(id).style.display = "none";
}

function switchVis(id) {
	if($(id).style.display == "block") {
		setDisplayNone(id);
	}
	else {
		setDisplayBlock(id);
	}
}


// fonction de requete ajax pour le select des profs dans l'ajout de perms (cote administration)
function getProfs(param) {
		new Ajax.Updater('prof',
						'ajax/getProfsByMatiere.php',
				        { 
							method       : "get",
							parameters   : "matiere="+ param
						}
					) ;
}


//fonction de requete ajax pour le select des profs dans la resa de perm (coté eleve)
function getProfsPerm(param, div) {
//	if(param == 'choix') {
//		$(div).style.visibility = 'hidden';
//	}
//	else {
//		$(div).style.visibility = 'visible';
//	}
	
	new Ajax.Updater(
			div,
			'ajax/getProfsPerm.php',
			{
				method: 'get',
				parameters   : "perms="+ param
			}
		);

}


function CalendarClick(e, obj, btn) {
	  if (Element.visible(obj.container)) {
	    obj.close();
	  } else {
	    RicoUtil.positionCtlOverIcon(obj.container, $(btn));
	    obj.open();
	  }
	  Event.stop(e);
}

function popupListing(mode, jour, param) {
	window.open('listing.php?mode='+ mode +'&jour='+ jour +'&param='+ param, 'listing', 'width=660,height=500,scrollbars=1');
}

function printPage()
{
    // Do print the page
    if (typeof(window.print) != 'undefined') {
        window.print();
    }
}

function print_resas(idr, lundi) {
	window.open('print_resas.php?idr='+idr+'&l='+lundi, 'print_resas', 'width=50,height=50,scrollbars=0');
}


// fonction de verif du form de resa de perm
function verifResa(data) {
	
	//verification si la perm a été choisie
	if(data == 'choix') {
		alert('Veuillez renseigner la permanence ŕ reserver');
		return false;
	}
	else {
		var retour = true;
		new Ajax.Request('ajax/afficheComm.php',
				        { method       : "get",
				          parameters   : "idp="+ data,
			 	          onComplete   : function(remote) {
			 	          	if(remote.responseText != '') retour = confirm ("Commentaire concernant cette permanence :\n\n'"+ remote.responseText +"'\n\nVoulez vous continuer ?");
			 	          },
				          asynchronous : false }) ;
		return retour;
	}
}

//fonction ajax liste de noms
function getNoms(str) {
	ajax = new Ajax.Request('ajax/getNoms.php',
				        { method       : "get",
				          parameters   : "str="+ str,
			 	          onComplete   : getNomsFini,
				          asynchronous : true }) ;
}

function getNomsFini(remote) {
	eval(remote.responseText);
	writeNameSpans(names);
	createDraggables(names);
}

function copieContenu(depart, arrivee) {
	$(arrivee).innerHTML = $(depart).innerHTML;
}

function commentaireExists(idp, div) {
	if(idp != 'choix')
		new Ajax.Updater(
				"comm"+ div,
				'ajax/getCommentaire.php',
				{
					method: 'get',
					parameters   : "idp="+ idp
				}
			);

}

function cleanComm(uid) {
	$('comm'+uid).innerHTML = '';
}

function popupCom(idp) {
	window.open('comm.php?idp='+ idp, 'comm', 'width=450,height=300,scrollbars=1');
}

function popupComR(idr) {
	window.open('comm.php?idr='+ idr, 'comm', 'width=450,height=300,scrollbars=1');
}

function popupStats(idd) {
	window.open('stats.php?idd='+ idd, 'stats', 'width=550,height=450,scrollbars=1');
}

function concatene(jour, d, f) {
		$('debut_creneau').value = jour.value +'-'+ d.value;
		$('fin_creneau').value = jour.value +'-'+ f.value;
}

function changeLieu(idl) {
	
	new Ajax.Updater(
			'selectReservable',
			'ajax/changeLieu.php',
			{
				method: 'get',
				parameters   : "idl="+ idl
			}
		);

}

function inscrireEleve(idp, ide, uid) {
	if(idp != 'choix') {
		$(uid).disabled = 'disabled';
		$(uid).value = 'Patientez...';
		new Ajax.Updater(
				'div'+uid,
				'ajax/inscrireEleve.php',
				{
					method: 'get',
					parameters   : "idp="+ idp +"&ide="+ ide
				}
			);
	}

}

function desinscrire(idr, uid) {
	new Ajax.Updater(
			'div'+uid,
			'ajax/desinscrire.php',
			{
				method: 'get',
				parameters   : "idr="+ idr
			}
		);

}

function coche(coche) {

	  tabInput=document.getElementsByTagName("input");
	  n=tabInput.length;
	  
	  for(i=0;i<n;i++)
	  {
	  	if(tabInput[i].type=='checkbox')
	  	{
	  		tabInput[i].checked=coche;
	  	}
	  		
	  }

}


function afficheTableauQuota(classe) {
	new Ajax.Updater(
			'tableauquotas',
			'ajax/afficheTableauQuota.php',
			{
				method: 'get',
				parameters   : "idc="+ classe
			}
		);
}

