function help(quoi) {
  window.open("help.php?quoi="+quoi,"help","height=400,width=300,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=0,left="+(screen.width-320));
}
function launch_upload() {	
	if(document.getElementById("monfichier").value != ""){
		var style = "display:show;";
		document.getElementById("waiter").setAttribute("style", style);
		return true;
	}
}

function aff_cont(what){
	var conteneur = what+"_cont";
	var lien = what+"_lien";
	var etat = document.getElementById(lien).innerHTML;
	// alert(etat);
	if(etat == "[+]"){
		var nouveau = "[-]";
		var display = "display:inline;";
	}else{
		var nouveau = "[+]";
		var display = "display:none;";
	}
	document.getElementById(lien).innerHTML = nouveau;
	document.getElementById(conteneur).setAttribute("style", display);
}


function showValue () {
	var theForm = document.forms[0];
	theForm.elements['doc1'].value=document.title;

	var titleTag = document.getElementsByTagName('title')[0];
	theForm.elements['doc2'].value=titleTag.firstChild.nodeValue;
	theForm.elements['doc3'].value=titleTag.firstChild.data;
	theForm.elements['doc4'].value=titleTag.text;
}

function changePageTitle( method,content ) {
	// var titleTag = document.getElementsByTagName('title')[0];
	if(method=="new"){
		/*
		alert(	document.title ,
				titleTag.firstChild.nodeValue,
				titleTag.firstChild.data,
				titleTag.text
				);
		*/
		document.title = unescape(content);
	}else{
		// var titleTag = document.title;
		document.title += " "+ unescape(content);
	}
}	

function changeValue( theButtonNumber ) {
	var theForm = document.forms[0];
	var theValue = theForm['user' + theButtonNumber].value;

	var titleTag = document.getElementsByTagName('title')[0];

	switch( theButtonNumber ) {
		case 1: 
			document.title = theValue;
		break;

		case 2:
			titleTag.firstChild.nodeValue = theValue;
		break;

		case 3:
			titleTag.firstChild.data = theValue;
		break;

		case 4:
			titleTag.text = theValue;
		break;

	}

	showValue();
}

// utilise dans la gestion des rubriques
// la liste deroulante indique un id de rubrique devant recevoir la sous rubrique
function swap_page_for_rub(boxes_to_check) // on recoit la liste des checkbox a cocher
{
	// alert(boxes_to_check);
	var ln = document.form_rub.pages.value;
	var tab0 = ln.split("-");
	var tab = tab0[0].split(",");
	// reactivation de toutes les checkbox
	for(var z=1; z<tab.length; z++){
		var cible = "_idp_"+tab[z];
		document.form_rub[cible].checked = false;
		document.form_rub[cible].disabled = false;
	}
	if( boxes_to_check != 0){
		// desactivation de toutes les checkbox
		for(var z=1; z<tab.length; z++){
			var cible = "_idp_"+tab[z];
			document.form_rub[cible].checked = false;
			document.form_rub[cible].disabled = true;
		}
		
		// puis activation des checkbox indiquees
		var tab = boxes_to_check.split(",");
		for(var z=1; z<tab.length; z++){
			// message += ' - '+z+':'+tab[z]+' >';
			// alert(tab[z]);
			var cible = "_idp_"+tab[z];
			document.form_rub[cible].checked = true;
			document.form_rub[cible].disabled = false;
		}
		
	}
}
function reactivate(){
	var ln = document.form_rub.pages.value;
	var tab0 = ln.split("-");
	var tab = tab0[0].split(",");
	// reactivation de toutes les checkbox
	for(var z=1; z<tab.length; z++){
		var cible = "_idp_"+tab[z];
		document.form_rub[cible].disabled = false;
	}
	// alert('hop');
}
function check_checkboxes_status()
{
	var ln = document.form_rub.pages.value;
	var tab0 = ln.split("-");
	var tab = tab0[0].split(",");
	// reactivation de toutes les checkbox
	for(var z=1; z<tab.length; z++){
		var cible = "_idp_"+tab[z];
		document.form_rub[cible].checked = false;
		document.form_rub[cible].disabled = false;
	}
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// f : form
// p : select qui declanche
// v : valeur de selectedIndex a fixer
function set_selecteurs(f,p,v)
{
	// recuperer selectedIndex de 
	// var aff = f[p].options[f[p].selectedIndex].value;
	var aff = document[f][p].options[document[f][p].selectedIndex].value;
	// alert(aff);
	if ( aff != "" ){
		document[f]["wait_"+p].options.length=0;
		option = new Option("Peu importe","",true,true);
		document[f]["wait_"+p].options[0]=option;
		
		var tab = document[f]["les_"+ aff].value.split(",");
		var tab_nom = document[f]["les_"+aff+"_nom"].value.split("+");
		
		for (var z=0; z<tab_nom.length; z++){
			option = new Option(tab_nom[z],tab[z],true,true);
			document[f]["wait_"+p].options[z+1]=option;
		}
	}else{
		document[f]["wait_"+p].options.length=0;
		option = new Option("","",true,true);
		document[f]["wait_"+p].options[0]=option;
	}
	
	document[f]["wait_"+p].selectedIndex = v;
}

// f : form
// p : select qui declanche
// n : contenu de select a afficher
// d : select de destination pour le contenu
function change_select(f,p,d)
{
	var aff = f[p.name].options[f[p.name].selectedIndex].value;
	
	if ( aff != "" ){
		f[d].options.length=0;
		option = new Option("Peu importe","",true,true);
		f[d].options[0]=option;
		
		var tab = f["les_"+ aff].value.split(",");
		var tab_nom = f["les_"+aff+"_nom"].value.split("+");
		
		for (var z=0; z<tab_nom.length; z++){
			option = new Option(tab_nom[z],tab[z],true,true);
			f[d].options[z+1]=option;
		}
		
	}else{
		f[d].options.length=0;
		option = new Option("","",true,true);
		f[d].options[0]=option;
	}
	
	f[d].selectedIndex = 0;
}

	
function change_liste(theform,ancien,nouveau) {
	alert(document[theform]["les_"+nouveau].value);
	// o=new Option( l1.options[l1.options.selectedIndex].text , l1.options[l1.options.selectedIndex].value );
	// l2.options[l2.options.length]=o;
	document[theform][ancien]  = null;
	// document[theform][ancien] = unescape( document[theform]["les_"+nouveau].value );
	// document[theform][ancien] = unescape( document[theform]["les_"+nouveau].value );
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// Si vous utilisez ce script, merci de m'avertir !  < webmaster@toutjavascript.com >
// fonction pour interchanger les elements de deux listes
function select_all_in_list(l2) {
	for(var z=0; z<l2.options.length; z++){
		l2.options[z].selected = true ;
	}
}
function Deplacer(l1,l2) {
	if (l1.options.selectedIndex>=0) {
		if( l1.options[l1.options.selectedIndex].text.substr(0,1) != "x" ){
			o=new Option( l1.options[l1.options.selectedIndex].text , l1.options[l1.options.selectedIndex].value );
			l2.options[l2.options.length]=o;
			l1.options[l1.options.selectedIndex]=null;
		}
	}else{
		alert("Aucune entrée sélectionnée");
	}
	select_all_in_list(l1);
	select_all_in_list(l2);
	alert(theform);
	// compil(theform);
}

function compil(theform) {
	var sortie = "";
	var step = document[theform].nb_pages.value;
	for(var y=0; y<step; y++){
		var from = "inscrits"+y;
		var idpage = "idauth_"+y;
		for(var z=0; z<document[theform][from].options.length; z++){
			sortie += document[theform][idpage].value+"[]=";
			sortie += document[theform][from].options[z].value +"&" ;
		}
	}
	document[theform].description.value = sortie;
}
function compil_autorized(theform) {
	var sortie = "";
	//var step = document[theform].nb_pages.value;
	//for(var y=0; y<step; y++){
		// var from = "inscrits"+y;
		var from = "inscrits0";
		// var idpage = "idauth_"+y;
		sortie = ',';
		for(var z=0; z<document[theform][from].options.length; z++){
			// sortie += document[theform][idpage].value+"[]=";
			sortie += document[theform][from].options[z].value +"," ;
		}
	//}
	document[theform].description.value = sortie;
}
	
/*
	function select_all_in_list(l2) {
		for(var z=0; z<l2.options.length; z++){
			l2.options[z].selected = true ;
		}
	}
	function Deplacer(l1,l2) {
		if (l1.options.selectedIndex>=0) {
			o=new Option( l1.options[l1.options.selectedIndex].text , l1.options[l1.options.selectedIndex].value );
			l2.options[l2.options.length]=o;
			l1.options[l1.options.selectedIndex]=null;
		}else{
			alert("Aucune entrée sélectionnée");
		}
		select_all_in_list(l1);
		select_all_in_list(l2);
	}
	function compil(theform,l1,dest) {
		var sortie = ",";
		for(var z=0; z<document[theform][l1].options.length; z++){
			sortie += document[theform][l1].options[z].value +"," ;
		}
		document[theform][dest].value = sortie;
	}
*/



// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
function SetCookie (name, value) {

	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value) + 
			((expires==null) ? "" : ("; expires="+expires.toGMTString())) + 
			((path==null) ? "" : ("; path="+path))+ 
			((domain==null) ? "" : ("; domain="+domain))+ 
			((secure==true) ? "; secure" : "");
}


function putFileInForm(theform,thefield,val) {
	//alert(val);
	window.opener.document[theform][thefield].value += val;
}


// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// navigation

function readThread(idthread) {
	window.open("forums_read.php?idthread="+idthread,"read","height=500,width=650,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top="+(screen.height-500)/2+",left="+(screen.width-650)/2);
}

function palette(theform,thefield) {
	window.open("palette.php?theform="+theform+"&thefield="+thefield,"palette","height=400,width=200,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,top="+(screen.height-400)/2+",left="+(screen.width-200)/2);
}

function popupUpload(folder,theform,thefield) {
	window.open("upload.php?folder="+folder+"&theform="+theform+"&thefield="+thefield,"uploadfile","height=500,width=500,toolbar=yes,location=no,status=yes,menubar=no,scrollbars=no,resizable=yes,top="+(screen.height-500)/2+",left="+(screen.width-500)/2);
}
function popupChoice(folder,theform,thefield) {
	window.open("browse_folder.php?folder="+folder+"&theform="+theform+"&thefield="+thefield,"browse","height=500,width=500,toolbar=yes,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top="+(screen.height-500)/2+",left="+(screen.width-500)/2);
}


// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// fonctions formulaires

function del_confirm(theform) {
	document[theform].action.value = "del";
	if (confirm ("Veuillez confirmer votre décision") ){
		document[theform].submit();
	}
}

function autoSubmitForm(theform) {
	document[theform].submit();
}
function openPreview(theform,thefield) {
//	val = document[theform][thefield].value;
//	window.open("preview.php?message="+val,"preview","height=500,width=650,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top="+(screen.height-500)/2+",left="+(screen.width-650)/2);
	window.open("preview.php?theform="+theform+"&thefield="+thefield,"preview","height=500,width=650,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,top="+(screen.height-500)/2+",left="+(screen.width-650)/2);
}

var postmaxchars = 1500;
function validate(theform) {
// 	$champs = array("titre","auteurs","date","linkFiche");
	
	if (theform.titre_fr.value=="" || theform.rubriques.value=="" ) {
		alert("Please fill title \n and choose a category");
		return false; 
	}
	if (postmaxchars != 0) {
		if (theform.message.value.length > 1500) {
			alert("Your message is too long.\n\nPlease reduce it to 1500 letters.\nActual length is "+theform.message.value.length+" letters.");
			return false; 
		}else { 
			return true; 
		}
	}else { 
		return true; 
	}
}
function checklength(theform) {
	if (postmaxchars != 0) { message = "\nMaximum length for messages is 1500 letters."; }
	else { message = ""; }
	alert("Your message counts "+theform.message.value.length+" letters."+message);
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
// interactivite

function agrandir(thefield) {
	// var _editor_url;
	if( _editor_url != undefined){
		var h = document.getElementsByTagName('iframe')[0].style.height;
		if( h.substr(h.length-2,2) == 'px' ){
			document.getElementsByTagName('iframe')[0].style.height = parseInt (h.substr(0,h.length-2))+100 +'px';
		}
		document.getElementById('field_'+thefield).setAttribute("rows", Number (document.getElementById('field_'+thefield).getAttribute("rows"))+5 );
	}else{
		document.getElementById('field_'+thefield).setAttribute("rows", Number (document.getElementById('field_'+thefield).getAttribute("rows"))+5 );
	}
}

function reduire(thefield) {
	// var _editor_url;
	if( _editor_url != undefined){
		var h = document.getElementsByTagName('iframe')[0].style.height;
		if( h.substr(h.length-2,2) == 'px' ){
			document.getElementsByTagName('iframe')[0].style.height = parseInt (h.substr(0,h.length-2))-100 +'px';
		}
		document.getElementById('field_'+thefield).setAttribute("rows", Number (document.getElementById('field_'+thefield).getAttribute("rows"))-5 );
	}else{
		document.getElementById('field_'+thefield).setAttribute("rows", Number (document.getElementById('field_'+thefield).getAttribute("rows"))-5 );
	}
}

var weeks = '';
function focus_on_week(week){
	if(weeks==''){
		weeks = document.getElementById("cal_tbody").getElementsByTagName("tr");
		// document.getElementById(week).getElementsByTagName("div")[0].id;
		// document.getElementById( document.getElementById(week).getElementsByTagName("div")[0].id ).style.height = "100%";
		var week_height = 0;
		for(z=0; z<weeks.length; z++){
			if(weeks[z].id != week){
				document.getElementById(weeks[z].id).style.display = "none";
				if(week_height == 0){
					week_height = document.getElementById(weeks[z+1].id).offsetHeight;
				}
				/*
				*/
			}else{
				jours = document.getElementById(week).getElementsByTagName("td");
				/*
				*/
			}
		}
		document.getElementById(week).style.height = week_height * (weeks.length-1);
		for(y=0; y<jours.length; y++){
			jours[y].getElementsByTagName("div")[0].style.height = ( week_height * (weeks.length-1))+" !important";
			// jours[y].style.background = "#111 !important";
		}	
	
	}else{
		for(z=0; z<weeks.length; z++){
			document.getElementById(weeks[z].id).style.display = "inline";
		}
		weeks = '';
	}
		
}
