function OpenFileNav(box_id)
{
	var X = 500;
	var Y = 300;
	
	PosX = (screen.width/2)-(X/2);
	PosY = (screen.height/2)-(Y/2)-150;
		
	newWin = "scrollbars=yes,menubar=no,resizable=no,status=no,width="+X+",height="+Y+",screenX="+PosX+",screenY="+PosY+",top="+PosY+",left="+PosX;
									
  	myWin = window.open(path + 'class_form_files/file_nav/index.php?id=' + box_id,"",newWin);
	myWin.focus();
}

function OpenPreview(box_id)
{
	if (document.getElementsByName(box_id)[0].value != "" && document.getElementsByName(box_id)[0].value != null){
		
		var X = 700;
		var Y = 600;
		
		PosX = (screen.width/2)-(X/2);
		PosY = (screen.height/2)-(Y/2)-150;
			
		newWin = "scrollbars=yes,menubar=no,resizable=yes,status=no,width="+X+",height="+Y+",screenX="+PosX+",screenY="+PosY+",top="+PosY+",left="+PosX;
		
		myWin = window.open(path + 'class_form_files/preview.php?name=' + box_id,"",newWin);
		myWin.focus();
	} else {
		
		alert("Aucun texte n'a été rentré dans le champs");
	}
}

function OpenMax(box_id)
{

	var X = 800;
	var Y = 600;
	
	PosX = (screen.width/2)-(X/2);
	PosY = (screen.height/2)-(Y/2)-150;
		
	newWin = "scrollbars=yes,menubar=no,resizable=no,status=no,width="+X+",height="+Y+",screenX="+PosX+",screenY="+PosY+",top="+PosY+",left="+PosX;
	
	myWin = window.open(path + 'class_form_files/maximize.php?name=' + box_id,"",newWin);
	myWin.focus();
}

function ShowInfo(type, field){
	
	var info = "";
	
	switch(type){
		
		case 'B':
			info = "Mettre le texte en gras";
		break;
		
		case 'I':
			info = "Mettre le texte en italique";
		break;
		
		case 'U':
			info = "Souligner le texte";
		break;
		
		case 'Img':
			info = "Ajouter une image";
		break;
		
		case 'Mail':
			info = "Ajouter un E-Mail";
		break;
		
		case 'ListPuce':
			info = "Ajouter une liste à puces";
		break;
		
		case 'ListNumero':
			info = "Ajouter une liste numérotée";
		break;
		
		case 'Link':
			info = "Ajouter un lien";
		break;
		
		case 'PrintView':
			info = "Aperçu du texte";
		break;
		
		case 'Maximize':
			info = "Edition en plein écran";
		break;
		
		default:
			info = "&nbsp;";
		break;
	}
	
	document.getElementById(field + '_info').innerHTML = info;
}

function AddLink(field){
	
	var output = "";
	
	var url = prompt("L'url du lien", "http://");
	
	if (url != '' && url != null){
		
		var link_name = prompt("Le nom du lien", "");
		
		if (link_name != '' && link_name != null){
			
			output = "[URL=" + url + "]" + link_name + "[/URL]";
			AddTextInBox(field, output);
		}
	}
}

function AddMail(field){
	
	var output = "";
	
	var mail = prompt("Entrer l'adresse E-Mail", "");
	
	if (mail != '' && mail != null){
		
		output = "[URL=mailto:" + mail + "]" + mail + "[/URL]";
		AddTextInBox(field, output);
	}
}

function AddImg(field){
	
	var output = "";
	
	var img = prompt("Entrer le lien de l'image", "");
	
	if (img != '' && img != null){
		
		output = "[IMG]" + img + "[/IMG]";
		AddTextInBox(field, output);
	}
}

function AddList(field, type){
	
	var output = "";
	
	var list = prompt("Entrer les éléments de la liste (séparé par des points-virgules)", "");
	
	if (list != '' && list != null){
		
		var tab_list = list.split(";");
		
		if (type != ''){
			
			type = "=" + type;
		}
		
		output = "[LIST" + type + "]";
		
		for (var i = 0;i<tab_list.length;i++)
		{
		  	output += "[*]" + tab_list[i] + "[/*]";
			
			if (i + 1 != tab_list.length){
				
				output += "\n";
			}
		}
		
		output += "[/LIST]";
		
		AddTextInBox(field, output);
	}
}

function AddTextInBox(field, text){
	
	var txt = document.getElementsByName(field)[0];
	
	if (document.selection) {
		
		txt.focus();
		sel = document.selection.createRange();
		sel.text += text;
		
	} else if (txt.selectionStart || txt.selectionStart == "0") {
		
		var startPos = txt.selectionStart;
		var endPos = txt.selectionEnd;
		
		var chaine = txt.value;
		var chaine_end = chaine.substring(endPos, chaine.length);
		
		txt.value = chaine.substring(0, startPos) + text + chaine_end;
	} else {
		
		txt.value += text;
		txt.focus();
	}
}

function AddSimpleTags(field, tag){
	
	var txt = document.getElementsByName(field)[0];
	
	if (document.selection) {
		
		txt.focus();
		sel = document.selection.createRange();
		sel.text = "[" + tag + "]" + sel.text + "[/" + tag + "]";
		
	} else if (txt.selectionStart || txt.selectionStart == "0") {
		
		var startPos = txt.selectionStart;
		var endPos = txt.selectionEnd;
		
		var chaine = txt.value;
		var chaine_inter = chaine.substring(startPos, endPos);
		var chaine_end = chaine.substring(endPos, chaine.length);
		
		txt.value = chaine.substring(0, startPos) + "[" + tag + "]" + chaine_inter + "[/" + tag + "]" + chaine_end;
	} else {
		
		txt.value += "[" + tag + "][/" + tag + "]";
		txt.focus();
	}
}
