d = document;
fontsize = 14;
lineheight = 14;
idEnvoi = 0;

if(window.XMLHttpRequest) // Firefox 
	xhr = new XMLHttpRequest(); 
else if(window.ActiveXObject) // Internet Explorer 
	xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
else { // XMLHttpRequest non supporté par le navigateur 
	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	//return; 
}

function texte_fonte(arg){
	fontsize += arg;
	lineheight = fontsize;
	d.getElementById('site').style.lineHeight = lineheight+"px";
	d.getElementById('site').style.fontSize = fontsize+"px";
}

function validation(form){

	err = false;
	verifMail = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,3}$/
	var reg=new RegExp("(_)", "g");
	
	chpCheck = d.getElementById('chpCheck').value;
	listechp = chpCheck.split(',');
	
	chpTitle = d.getElementById('chpTitle').value;
	listechpTitle = chpTitle.split(',');

	for(i=0;i<listechp.length;i++){
		if(d.getElementById(listechp[i]).value == '' && d.getElementById(listechp[i]).type != "hidden" && d.getElementById(listechp[i]).type != "checkbox"){
			//monchamp = listechpTitle[i].replace(reg, ' ');
			monchamp = listechpTitle[i];
			alert("Veuilez renseigner le champ '"+monchamp+"'");
			d.getElementById(listechp[i]).focus();
			i=listechp.length;
			err = true;
		}else if(listechp[i] == "email" && verifMail.exec(d.getElementById(listechp[i]).value) == null){
			alert("l'adresse email est invalide");
			i=listechp.length;
			err = true;
		}else if(listechp[i] == "emailFrom" && verifMail.exec(d.getElementById(listechp[i]).value) == null){
			alert("l'adresse email est invalide");
			i=listechp.length;
			err = true;
		}else if(listechp[i] == "emailDest" && verifMail.exec(d.getElementById(listechp[i]).value) == null){
			alert("l'adresse email est invalide");
			i=listechp.length;
			err = true;		
		}else if(listechp[i] == "accept"){
			if(d.getElementById(listechp[i]).checked == false){
				alert("Vous devez accepter les conditions..");
				i=listechp.length;
				err = true;
			}
		}
	}
	
	if(err == false){
		if(form == "f_ami"){
			//document.forms[form].action = 'mail2friend.php';
			envoiMailAmi();
		}else{
			document.forms[form].formname.value = form;
			document.forms[form].action = 'enregistrement.php';
		}
	}
	
	return !err;

}

function gotoPage(page){
	document.location.href = page;
}

function editPage(id){
	document.location.href = "?id="+id;
}

function recordDroit(id){
	var path = d.getElementById('path').value;
	if(d.getElementById(id).checked == true)
	var val = 1;
	else
	var val = 0;
	var act = id.substring(0,1);
	var id = id.substring(2);
	//alert(act+'/'+id);

	var filename = path+"inc/ajax.php";
	data = null;	
	data = "script=recordDroit&act="+act+"&id="+id+"&val="+val;
	xhr.open("POST", filename, true);	
	xhr.onreadystatechange  = function(){ 
		 if(xhr.readyState  == 4){
			  if(xhr.status  == 200) {
				 if(xhr.responseText){
				 	response = xhr.responseText;
				 	//alert(response);
				 }
			  }
		 }
	};
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}

function printPDF(id){
	window.open("printPDF.php?id="+id,"impression PDF","");
}

function editSynopsis(id){
	window.open("editSynopsis.php?id="+id,"Edition","");
}

function corbeille(id){
	var path = d.getElementById('path').value;
	var filename = path+"inc/ajax.php";
	data = null;	
	data = "script=corbeille&id="+id;
	xhr.open("POST", filename, true);	
	xhr.onreadystatechange  = function(){ 
		 if(xhr.readyState  == 4){
			  if(xhr.status  == 200) {
				 if(xhr.responseText){
				 	response = xhr.responseText;
				 	//alert(response);
				 	d.getElementById("nt_"+id).className = "notation_titre2";
				 }
			  }
		 }
	};
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}


function printPDF2(id){
	window.open("printPDF2.php?id="+id,"impression PDF","");
}

function editSynopsis2(id){
	window.open("editSynopsis2.php?id="+id,"Edition","");
}

function corbeille2(id){
	var path = d.getElementById('path').value;
	var filename = path+"inc/ajax.php";
	data = null;	
	data = "script=corbeille2&id="+id;
	xhr.open("POST", filename, true);	
	xhr.onreadystatechange  = function(){ 
		 if(xhr.readyState  == 4){
			  if(xhr.status  == 200) {
				 if(xhr.responseText){
				 	response = xhr.responseText;
				 	//alert(response);
				 	d.getElementById("nt_"+id).className = "notation_titre2";
				 }
			  }
		 }
	};
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}


function displayBlock(id){
	var bloc = d.getElementById('edition_'+id);
	var listBloc = d.getElementById('listBloc').value;
	listBloc = listBloc.split(',');
	
	if(bloc.style.display == 'block')
		bloc.style.display = 'none';
	else{
		// on referme les autres blocs
		for(i=0;i < listBloc.length;i++)
		d.getElementById('edition_'+listBloc[i]).style.display = 'none';
		
		bloc.style.display = 'block';
	}
}

function calcul(s){
	var s1 = d.getElementById('selectCritere_1_'+s).value;
	var s2 = d.getElementById('selectCritere_2_'+s).value;
	var s3 = d.getElementById('selectCritere_3_'+s).value;
	var s4 = d.getElementById('selectCritere_4_'+s).value;
	var s5 = d.getElementById('selectCritere_5_'+s).value;
	var s6 = d.getElementById('selectCritere_6_'+s).value;
	d.getElementById('totalNotation_'+s).value = parseInt(s1) + parseInt(s2) + parseInt(s3) + parseInt(s4) + parseInt(s5) + parseInt(s6);
	d.getElementById('moyenneNotation_'+s).value = arrondi((parseInt(s1) + parseInt(s2) + parseInt(s3) + parseInt(s4) + parseInt(s5) + parseInt(s6)) / 6); 
}

function arrondi(nombre){
	virgule=Math.pow(10,2);
	valeur_arrondi=(Math.round(nombre*virgule))/virgule;
	return (valeur_arrondi);
}

function validate(id){
	var path = d.getElementById('path').value;
	var c1 = d.getElementById('selectCritere_1_'+id).value;
	var c2 = d.getElementById('selectCritere_2_'+id).value;
	var c3 = d.getElementById('selectCritere_3_'+id).value;
	var c4 = d.getElementById('selectCritere_4_'+id).value;
	var c5 = d.getElementById('selectCritere_5_'+id).value;
	var c6 = d.getElementById('selectCritere_6_'+id).value;
	var total = d.getElementById('totalNotation_'+id).value;
	var moyenne = d.getElementById('moyenneNotation_'+id).value;
	var commentaires = d.getElementById('commentaires_'+id).value;
	var valid = 1;
	
	if(total == 0)
	valid = confirm("Etes-vous certain de vouloir valider ce script avec une note globale à 0 ?");
	
	if(valid == 1){
	
	var filename = path+"inc/ajax.php";
	data = null;	
	data = "script=recordNotation&id="+id+"&c1="+c1+"&c2="+c2+"&c3="+c3+"&c4="+c4+"&c5="+c5+"&c6="+c6+"&total="+total+"&moyenne="+moyenne+"&commentaires="+commentaires;
	xhr.open("POST", filename, true);	
	xhr.onreadystatechange  = function(){ 
		 if(xhr.readyState  == 4){
			  if(xhr.status  == 200) {
				 if(xhr.responseText){
				 	response = xhr.responseText;
				 	if(response == 1){
				 	d.getElementById('edition_'+id).style.display = 'none';
				 	d.getElementById('nt_'+id).className = "notation_titre2";
				 	//Effect.Fade('notation_'+id);
				 	}
				 }
			  }
		 }
	};
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
	
	}
}

function validate2(id){
	var path = d.getElementById('path').value;
	var c1 = d.getElementById('selectCritere_1_'+id).value;
	var c2 = d.getElementById('selectCritere_2_'+id).value;
	var c3 = d.getElementById('selectCritere_3_'+id).value;
	var c4 = d.getElementById('selectCritere_4_'+id).value;
	var c5 = d.getElementById('selectCritere_5_'+id).value;
	var c6 = d.getElementById('selectCritere_6_'+id).value;
	var total = d.getElementById('totalNotation_'+id).value;
	var moyenne = d.getElementById('moyenneNotation_'+id).value;
	var commentaires = d.getElementById('commentaires_'+id).value;
	var valid = 1;
	
	if(total == 0)
	valid = confirm("Etes-vous certain de vouloir valider ce script avec une note globale à 0 ?");
	
	if(valid == 1){
	
	var filename = path+"inc/ajax.php";
	data = null;	
	data = "script=recordNotation2&id="+id+"&c1="+c1+"&c2="+c2+"&c3="+c3+"&c4="+c4+"&c5="+c5+"&c6="+c6+"&total="+total+"&moyenne="+moyenne+"&commentaires="+commentaires;
	xhr.open("POST", filename, true);	
	xhr.onreadystatechange  = function(){ 
		 if(xhr.readyState  == 4){
			  if(xhr.status  == 200) {
				 if(xhr.responseText){
				 	response = xhr.responseText;
				 	if(response == 1){
				 	d.getElementById('edition_'+id).style.display = 'none';
				 	d.getElementById('nt_'+id).className = "notation_titre2";
				 	//Effect.Fade('notation_'+id);
				 	}
				 }
			  }
		 }
	};
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
	
	}
}

function recordJure(id){
	var path = d.getElementById('path').value;
	var prenom = d.getElementById('prenom_'+id).value;
	var nom = d.getElementById('nom_'+id).value;
	var email = d.getElementById('email_'+id).value;
	var login = d.getElementById('login_'+id).value;
	var pass = d.getElementById('password_'+id).value;
	
	d.getElementById('bt_'+id).innerHTML = "<img src='"+path+"images/ajax-loader.gif'>";
	
	var filename = path+"inc/ajax.php";
	data = null;	
	data = "script=recordJure&id="+id+"&prenom="+prenom+"&nom="+nom+"&email="+email+"&login="+login+"&pass="+pass;
	xhr.open("POST", filename, true);	
	xhr.onreadystatechange  = function(){ 
		 if(xhr.readyState  == 4){
			  if(xhr.status  == 200) {
				 if(xhr.responseText){
				 	response = xhr.responseText;
				 	//d.getElementById('test').value = response;
				 	if(response == 1){
				 	d.getElementById('bt_'+id).innerHTML = '<input type="button" value="enregistrer" onClick="recordJure('+id+')">';				 	
				 	}
				 }
			  }
		 }
	};
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}

function recordJure2(id){
	var path = d.getElementById('path').value;
	var prenom = d.getElementById('prenom_'+id).value;
	var nom = d.getElementById('nom_'+id).value;
	var email = d.getElementById('email_'+id).value;
	var login = d.getElementById('login_'+id).value;
	var pass = d.getElementById('password_'+id).value;
	
	d.getElementById('bt_'+id).innerHTML = "<img src='"+path+"images/ajax-loader.gif'>";
	
	var filename = path+"inc/ajax.php";
	data = null;	
	data = "script=recordJure2&id="+id+"&prenom="+prenom+"&nom="+nom+"&email="+email+"&login="+login+"&pass="+pass;
	xhr.open("POST", filename, true);	
	xhr.onreadystatechange  = function(){ 
		 if(xhr.readyState  == 4){
			  if(xhr.status  == 200) {
				 if(xhr.responseText){
				 	response = xhr.responseText;
				 	//d.getElementById('test').value = response;
				 	if(response == 1){
				 	d.getElementById('bt_'+id).innerHTML = '<input type="button" value="enregistrer" onClick="recordJure2('+id+')">';				 	
				 	}
				 }
			  }
		 }
	};
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}

function enabledMe(id){
	for(i=1;i<=8;i++){
	d.getElementById("dateCRON_"+i).style.background = "#FFF";
	d.getElementById("heureCRON_"+i).style.background = "#FFF";
	d.getElementById("manuel_"+i).style.background = "#FFF";
	}
	d.getElementById("dateCRON_"+id).style.background = "#CCC";
	d.getElementById("heureCRON_"+id).style.background = "#CCC";
	d.getElementById("manuel_"+id).style.background = "#CCC";
	idEnvoi = id;
}

function miseAjourEnvoi(){
	var path = d.getElementById('path').value;
	var dateCRON = d.getElementById("dateCRON_"+idEnvoi).value;
	var heureCRON = d.getElementById("heureCRON_"+idEnvoi).value;
	var manuel = d.getElementById("manuel_"+idEnvoi).value;
	
	var filename = path+"inc/ajax.php";
	data = null;	
	data = "script=recordEnvoi&id="+idEnvoi+"&dateCRON="+dateCRON+"&heureCRON="+heureCRON+"&manuel="+manuel;
	xhr.open("POST", filename, true);	
	xhr.onreadystatechange  = function(){ 
		 if(xhr.readyState  == 4){
			  if(xhr.status  == 200) {
				 if(xhr.responseText){
				 	response = xhr.responseText;
				 	if(response == 1){
				 	d.getElementById("manuel_"+idEnvoi).style.background = "#FFF";
				 	d.getElementById("dateCRON_"+idEnvoi).style.background = "#FFF";
				 	d.getElementById("heureCRON_"+idEnvoi).style.background = "#FFF";
				 	}
				 }
			  }
		 }
	};
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);
}

function envoiMailAmi(){
	var path = d.getElementById('path').value;
	var emailFrom = d.getElementById('emailFrom').value;
	var emailDest = d.getElementById('emailDest').value;
	var msg = d.getElementById('comments').value;
	
	var filename = path+"inc/ajax.php";
	data = null;	
	data = "script=envoiMail&emailFrom="+emailFrom+"&emailDest="+emailDest+"&msg="+msg;
	xhr.open("POST", filename, true);	
	xhr.onreadystatechange  = function(){ 
		 if(xhr.readyState  == 4){
			  if(xhr.status  == 200) {
				 if(xhr.responseText){
				 	response = xhr.responseText;
				 	var msgRetour = "";
				 	if(response == 1){
				 		msgRetour = "Le message a bien été envoyé.";
				 		//THIS.fadeBox('myBox');
				 	}else
				 		msgRetour = "Problème d'envoi";
				 	
				 	msgRetour+= "<br><br><br><input type='button' value='fermer' onclick='Modalbox.hide()'>"
				 	d.getElementById('content').innerHTML = msgRetour;
				 }
			  }
		 }
	};
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send(data);	
}

function openWin(win,arg){
	if(arg == 1){
		d.getElementById('win'+win).style.display = "block";
		
	}else{
		
		d.getElementById('win'+win).style.display = "none";

	}
}

function openWin2(win,arg){
	if(arg == 1){
		d.getElementById('winVideo'+win).style.display = "block";
		
	}else{
		
		d.getElementById('winVideo'+win).style.display = "none";

	}
}