function logout(niv){
	if (confirm('Quitter votre session?')) {
		if (niv=='acc') window.location.href = './logout.php';
		if (niv=='ed') window.location.href = '../logout.php';
	}
	return false;
}
function aide(page) {
	var top=(screen.height-750)/2;
	var left=(screen.width-600);
	var laide = window.open(page,"aide","top="+top+",left="+left+",width=600,height=750,'menubar=no,scrollbars=yes,statusbar=no,resizable=no'");
	laide.focus();
}
function justificatifs(val){
	elt= document.getElementById('cabinet');
	if (val=='c') {
		elt.style.display = 'block';
	}
	else {
		elt.style.display = 'none';
	}
	return true;
}
function confirmVersement(){
	if (confirm("Attention, vous vous apprêtez à valider un versement partiel.\n\nLes montants restants dûs doivent impérativement être versés à un autre organisme collecteur agréé au titre de la taxe d'apprentissage.\n\n Confirmez vous ce versement partiel ?")){
		document.getElementById('form1').submit();
		return true;
	}
	else{
		return false;
	}
}
function enableInput(){
	var mesinputs = document.getElementsByTagName("input" );
	for (var i=0; i<mesinputs.length; i++) {
		if (mesinputs[i].disabled==true) {
			mesinputs[i].disabled=false;
		}
	}
}
function inscr(val,elt){
	elem= document.getElementById(elt);
	if (val=='o') {
		elem.style.display = 'block';
	}
	else {
		elem.style.display = 'none';
		if (elt=='elt2') {
			elem3= document.getElementById('elt3');
			elem3.style.display = 'none';
			elem3= document.getElementById('qImp');
			elem3.checked = 'checked';
			elem3= document.getElementById('qApp');
			elem3.checked = 'checked';
		}else{
			elem3= document.getElementById('qApp');
			elem3.checked = 'checked';
		}
		elem3= document.getElementById('qSal');
		elem3.checked = 'checked';
	}
	return true;
}
function proratisation(){
	if (confirm('En cas de dépassement de plafond, seule la déduction après plafonnement sera prise en compte.\n\nconfirmez vous cette validation?')){
		enableInput();
		return true;
	} else {
		return false;
	}
}
function actuJM(){
	var s4g = document.getElementById('s4g').value;
	var s4h = document.getElementById('s4h').value;
	var s4i  = document.getElementById('s4i').value;
	//alert(s4g);alert(s4h);alert(s4i);
	// calcul total et arrondi decimal
	s4g = s4g*100/100;
	s4h = s4h*100/100;
	s4i = s4i*100/100;
	var total = eval(s4g+s4h+s4i);
	total = Math.round(total*100) / 100;
	// alert(total);
	// actualisation total
	document.getElementById('total').innerHTML = total+'&nbsp;¤';
	// recup plafond
	plafond = document.getElementById('plafond').value;
	// si depassement de plafond
	if (total>plafond){
		// depassement = rouge
		document.getElementById('plafondAff').style.color = 'red';
		document.getElementById('total').style.color = 'red';
		document.getElementById('totalPro').style.color = 'green';
		// prorata -> meme pourcentage
		tauxB = (s4h*100)/total;
		tauxC = (s4i*100)/total;
		proB = (tauxB*plafond)/100; proB = Math.round(proB*100) / 100;
		proC = (tauxC*plafond)/100; proC = Math.round(proC*100) / 100;
		proA = plafond - proB - proC; proA = Math.round(proA*100) / 100;

	}else{
		// non depassement = noir
		document.getElementById('plafondAff').style.color = '#000000';
		document.getElementById('total').style.color = '#000000';
		document.getElementById('totalPro').style.color = '#000000';
		// copie des valeurs car non depassement dans champs
		proB = document.getElementById('s4h').value;
		proC = document.getElementById('s4i').value;
		proA = document.getElementById('s4g').value;
	}
	// dans les champs hidden
 	document.getElementById('proA').value = proA;
	document.getElementById('proB').value = proB;
	document.getElementById('proC').value = proC;
	// affichage cellules tableau
	document.getElementById('proA_cell').innerHTML = proA+' ¤';
	document.getElementById('proB_cell').innerHTML = proB+' ¤';
	document.getElementById('proC_cell').innerHTML = proC+' ¤';
	// total prorata
	proA = proA*100/100;
	proB = proB*100/100;
	proC = proC*100/100;
	totalPro = eval(proA+proB+proC);
	totalPro = Math.round(totalPro*100) / 100;
	document.getElementById('totalPro').innerHTML = totalPro+'&nbsp;¤';
	// 	calcul et affichage hors quota();
	var hqa = document.getElementById('hqa').value;
	var hqb = document.getElementById('hqb').value;
	var hqc = document.getElementById('hqc').value;
	hqa = (hqa*100)/100; hqb = (hqb*100)/100; hqc = (hqc*100)/100;
	var A = hqa - proA;
	var B = hqb - proB;
	var C = hqc - proC;
	A = Math.round(A*100) / 100; B = Math.round(B*100) / 100; C = Math.round(C*100) / 100;
	//alert(A);alert(B);alert(C);
	document.getElementById('cellA').innerHTML = A+' ¤';
	document.getElementById('cellB').innerHTML = B+' ¤';
	document.getElementById('cellC').innerHTML = C+' ¤';
	//alert(total);
}
function convertJM(cible){
	switch (cible) {
		case 's4g': // 19
			val   = document.getElementById('s4gJ').value;
			val = val.replace( ',' , '.' );
			document.getElementById('s4gJ').value = val;
			val2 = val*19;
			document.getElementById('s4g').value = Math.round(val2*100) / 100;
			break;
		case 's4gJ':
			val   = document.getElementById('s4g').value;
			val = val.replace( ',' , '.' );
			document.getElementById('s4g').value = val;
			val2 = val/19;
			document.getElementById('s4gJ').value = Math.round(val2*100) / 100;
			break;
		case 's4h': // 31
			val   = document.getElementById('s4hJ').value;
			val = val.replace( ',' , '.' );
			document.getElementById('s4hJ').value = val;
			val2 = val*31;
			document.getElementById('s4h').value = Math.round(val2*100) / 100;
			break;
		case 's4hJ':
			val   = document.getElementById('s4h').value;
			val = val.replace( ',' , '.' );
			document.getElementById('s4h').value = val;
			val2 = val/31;
			document.getElementById('s4hJ').value = Math.round(val2*100) / 100;
			break;
		case 's4i': // 40
			val   = document.getElementById('s4iJ').value;
			val = val.replace( ',' , '.' );
			document.getElementById('s4iJ').value = val;
			val2 = val*40;
			document.getElementById('s4i').value = Math.round(val2*100) / 100;
			break;
		case 's4iJ':
			val   = document.getElementById('s4i').value;
			val = val.replace( ',' , '.' );
			document.getElementById('s4i').value = val;
			val2 = val/40; //val2.replace( ',' , '.' );
			document.getElementById('s4iJ').value = Math.round(val2*100) / 100;
			break;
		default:
			break;
	}
	actuJM();
}
function deverrouiller(){
	var ad = window.location;
	window.location = 'verrouiller.php?dev=y&ad='+ad;
}
function continueDecl(){
	window.location.href = 'apprentis.php?continDecl=1';
	/*
	if (confirm("Continuer?\nVous retrouverez les informations saisies lors de votre prochaine connexion.")){
		window.location.href = 'apprentis.php?continDecl=1';
		return true;
	}
	else{
		return false;
	}
	*/
}
function delCfaApp(id){
	if (confirm(' Attention\n\n les apprentis enregistrés dans ce CFA vont également être supprimés.\n\n Continuer ?')){
		add ='apprentis.php?del=1&id='+id;
		//alert(add);
		window.location.href = add;
	}
}
function modifApp(){
	if (confirm('Les apprentis déjà saisis vont être réinitialisé.\n\n Continuer?')){
		add ='effectifs.php';
		//alert(add);
		window.location.href = add;
	}
}