// Archipel $Id: ile_fiches.js 376 2011-12-11 20:05:58Z pascal $ - $Author: pascal $ - $Revision: 376 $

//Affichage du formulaire pour l'annulation
function request_spe(_id_niveau){
	send_request('post','ajax/fiches_ajax.php','_act=affichespe&_id_niveau='+_id_niveau);
}

function request_fiches(_id_chapitre){
	send_request('post','ajax/fiches_ajax.php','_act=affichefiches&_id_chapitre='+_id_chapitre);
}


function format(f){
	if(editAreas['contribinput']["displayed"]==true){
		//Mode EditArea
		editAreaLoader.insertTags("contribinput", "[" + f + "]", "[/" + f + "]");
	}else{
		//Mode normal
		//Mode normal
		var field  = document.forms['ficheform1']._contenu; 
		var scroll = field.scrollTop;
		field.focus();
	        
		if (window.ActiveXObject) { //IE
			var textRange = document.selection.createRange();            
			var currentSelection = textRange.text;
	
			textRange.text = "[" + f + "]" + currentSelection + "[/" + ico + "]";
			textRange.moveStart("character", -("[/" + ico + "]").length - currentSelection.length);
			textRange.moveEnd("character", -("[/" + ico + "]").length);
			textRange.select();     
		} else {
			var startSelection   = field.value.substring(0, field.selectionStart);
			var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
			var endSelection     = field.value.substring(field.selectionEnd);
	                
			field.value = startSelection + "[" + f + "]" + currentSelection + "[/" + f + "]" + endSelection;
			field.focus();
			field.setSelectionRange(startSelection.length + ("["+f+"]").length, startSelection.length + ("["+f+"]").length + currentSelection.length);
		} 
		field.scrollTop = scroll;
	}
	cacheVal();
	return;
}

function symbole(ico){
	if(editAreas['contribinput']["displayed"]==true){
		//Mode EditArea
		editAreaLoader.insertTags("contribinput", ico, "");
	}else{
		//Mode normal
		var field  = document.forms['ficheform1']._contenu; 
	  var scroll = field.scrollTop;
	  field.focus();
	  
	  if (window.ActiveXObject) { //IE
			var textRange = document.selection.createRange();            
			var currentSelection = textRange.text;
	                
			textRange.text = currentSelection + ico;
			textRange.moveStart("character", -ico.length - currentSelection.length);
	    textRange.moveEnd("character", 0);            
	    textRange.select(); 
	        
		} else {
			var startSelection   = field.value.substring(0, field.selectionStart);
			var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
			var endSelection     = field.value.substring(field.selectionEnd);
	                
			field.value = startSelection + currentSelection + ico + endSelection;
			field.focus();
			field.setSelectionRange(startSelection.length + currentSelection.length + ico.length, startSelection.length + currentSelection.length + ico.length);
		} 
	
		field.scrollTop = scroll;
	}
	cacheVal();
	return;
}

function parent_img(ico){
	if(window.parent.document.getElementById("editareaareactive").value==1){
		//Mode EditArea
		//alert('tapez '+ico+' dans la zone de saisie pour utiliser cette image');
		window.parent.editAreaLoader.insertTags("contribinput", ico, "");
	}else{
		//Mode normal
		var field  = window.parent.document.forms['ficheform1']._contenu; 
	  var scroll = field.scrollTop;
	  field.focus();
	  
	  if (window.ActiveXObject) { //IE
			var textRange = document.selection.createRange();            
			var currentSelection = textRange.text;
	                
			textRange.text = currentSelection + ico;
			textRange.moveStart("character", -ico.length - currentSelection.length);
	    textRange.moveEnd("character", 0);            
	    textRange.select(); 
	        
		} else {
			var startSelection   = field.value.substring(0, field.selectionStart);
			var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
			var endSelection     = field.value.substring(field.selectionEnd);
	                
			field.value = startSelection + currentSelection + ico + endSelection;
			field.focus();
			field.setSelectionRange(startSelection.length + currentSelection.length + ico.length, startSelection.length + currentSelection.length + ico.length);
		} 
	
		field.scrollTop = scroll;
	}
	
	window.parent.document.getElementById('contribinput').focus();
}

function zone_plus(){
	document.ficheform1._contenu.rows=document.ficheform1._contenu.rows+2;
	return false;
}

function zone_moins(){
	document.ficheform1._contenu.rows=document.ficheform1._contenu.rows-2;
	return false;
}

function zone_img_plus(){
	var taille=document.getElementById("frameListeimg").style.height;
	taille=taille.substring(0,taille.length-2);
	taille=parseInt(taille)+50;
	taille=taille+'px';
	document.getElementById("frameListeimg").style.height=taille;
	return false;
}

function zone_img_moins(){
	var taille=document.getElementById("frameListeimg").style.height;
	taille=taille.substring(0,taille.length-2);
	taille=parseInt(taille)-50;
	if(taille < 50){
		taille=50;
	}
	taille=taille+'px';
	document.getElementById("frameListeimg").style.height=taille;
	return false;
}

function insert_table(){
	
	var formulaire = new Formulaire("ficheform1");
	
	formulaire.regle("_nb_l","requis","Vous devez entrer un nombre de lignes");
	formulaire.regle("_nb_c","requis","Vous devez entrer un nombre de colonnes");
	formulaire.regle("_nb_l","regex","format du nombre de lignes incorrect","entier");
	formulaire.regle("_nb_c","regex","format du nombre de colonnes incorrect","entier");
		
	if (formulaire.valider()){
		symbole("\n"+'[table]');
		for(i=1;i<=document.forms['ficheform1']._nb_l.value;i++){
			symbole("\n  "+'[tr]');
			for(j=1;j<=document.forms['ficheform1']._nb_c.value;j++){
				symbole("\n    "+'[td][/td]');
			}
			symbole("\n  "+'[/tr]');
		}
		symbole("\n"+'[/table]');
	}
		
}


function insert_table_qcm3(){
	symbole("\n"+'[centre]<table class="nobords" width="80%">');
	symbole("\n"+'<tr><td width="33%">[num]a)[/num] </td><td width="34%">[num]b)[/num] </td><td width="33%">[num]c)[/num] </td></tr>');
	symbole("\n"+'</table>[/centre]'+"\n");	
}
function insert_table_qcm4(){
	symbole("\n"+'[centre]<table class="nobords" width="80%">');
	symbole("\n"+'<tr><td width="25%">[num]a)[/num] </td><td width="25%">[num]b)[/num] </td><td width="25%">[num]c)[/num] </td><td width="25%">[num]d)[/num] </td></tr>');
	symbole("\n"+'</table>[/centre]'+"\n");	
}
function insert_table_width(w){
	symbole(' width="'+w+'%"');
}
function insert_table_premcol(){
	symbole('<tr align="center"><td align="left" bgcolor="[bgcol]">');
}

function action_edite(_id,_contenu){
	send_request('post','ajax/fiches_ajax.php','_act=action_edite&_id='+_id+'&_contenu='+_contenu);
}

function cacheValCall(_id){
	cacheVal();
}

function displayValCall(_id){
	new Effect.Appear('ficheform2');
	new Effect.Appear('ficheform3');
}


function activeToggle(_id){
	document.getElementById("editareaareactive").value=1;
	Element.hide('plusmoins');
}
function desactiveToggle(_id){
	document.getElementById("editareaareactive").value=0;
	new Effect.Appear('plusmoins');
}

function choix_filiere(_filiere){
	send_request('post','ajax/fiches_ajax.php','_act=choixfiliere&_filiere='+_filiere);
}
