// anime les vignettes en bas de la page d'accueil
function animate(num) {
	if(num < 8) {
		var img1 = document.getElementById("imgAnim"+num);
		var op1 = parseFloat(img1.style.opacity);
		op1 = op1 + 0.02;
		img1.style.opacity = op1;
		img1.style.filter = "alpha(opacity=" + (op1 * 100) + ")";
		if(op1 > 0.3 && num < 7) {
			var img2 = document.getElementById("imgAnim"+(num+1));
			var op2 = parseFloat(img2.style.opacity);
			op2 = op2 + 0.02;
			img2.style.opacity = op2;
			img2.style.filter = "alpha(opacity=" + (op2 * 100) + ")";
		}
		if(op1 > 0.6 && num < 6) {
			var img3 = document.getElementById("imgAnim"+(num+2));
			var op3 = parseFloat(img3.style.opacity);
			op3 = op3 + 0.02;
			img3.style.opacity = op3;
			img3.style.filter = "alpha(opacity=" + (op3 * 100) + ")";
		}
		if(op1 > 0.9 && num < 5) {
			var img4 = document.getElementById("imgAnim"+(num+3));
			var op4 = parseFloat(img4.style.opacity);
			op4 = op4 + 0.02;
			img4.style.opacity = op4;
			img4.style.filter = "alpha(opacity=" + (op4 * 100) + ")";
		}
		if(op1 >= 1)
			timer = setTimeout("animate("+(num+1)+")", "15");
		else
			timer = setTimeout("animate("+num+")", "15");
	}
}
// soumet le formulaire caché de changement de langue
function changeLanguage(lang) {
	document.language.lang.value = lang;
	document.language.submit();
}
function submitFamilyChoiceForm(id, form) {
	form.family.value = id;
	form.submit();
}
function horizontalPosition(id, left) {
	var div = document.getElementById(id);
	var l = document.body.clientWidth;
	if(l > 900)
		div.style.left = (Math.ceil((l - 900) / 2) + left) + "px";
	else
		div.style.left = left + "px";
}
function foHorizontalPosition() {
	horizontalPosition('banner-title', 240);
	horizontalPosition('admin-link', 3);
	horizontalPosition('connectAdminDialog', 325);
	horizontalPosition('errorDialog', 325);
	horizontalPosition('btn-fr', 127);
	horizontalPosition('btn-en', 155);
	horizontalPosition('btn-de', 183);
	horizontalPosition('btn-ru', 211);
	horizontalPosition('no_langs', 126);
}
function changeHomeNews(id) {
	document.homeNews.news.value = id;
	document.homeNews.submit();
}
function openDialog(id, input) {
	var d = document.getElementById(id);
	d.style.display = "";
	if(input != "")
		input.focus();
}
function closeDialog(id) {
	var d = document.getElementById(id);
	d.style.display = "none";
}
function boHorizontalPosition() {
	horizontalPosition('banner-title', 240);
	horizontalPosition('lbl-admin', 600);
	horizontalPosition('admin-link', 3);
	horizontalPosition('admin-menu', -1);
	horizontalPosition('errorDialog', 325);
	horizontalPosition('btn-fr', 127);
	horizontalPosition('btn-en', 155);
	horizontalPosition('btn-de', 183);
	horizontalPosition('btn-ru', 211);
	horizontalPosition('no_langs', 126);
	horizontalPosition('updatePageTitleSubmit', 760);
	horizontalPosition('updatePasswordDialog', 350);
}
function verticalPosition(e, id, move) {
	var div = document.getElementById(id);
	if(navigator.appName == "Netscape") {
		div.style.top = (e.pageY - move) + "px";
	}
	else {
		div.style.top = (e.y + document.documentElement.scrollTop - move) + "px";
	}
}
function initPositionColorSizeRange(e, divId) {
	var div = document.getElementById(divId);
	if(navigator.appName == "Netscape") {
		div.style.top = (e.pageY - 20) + "px";
		div.style.left = (e.pageX - 20) + "px";
	}
	else {
		t = e.y + document.documentElement.scrollTop - 20;
		l = e.x + document.documentElement.scrollLeft - 20;
		div.style.top = t + "px";
		div.style.left = l + "px";
	}
}
function downloadDxf(id) {
	document.downloadDxf.id.value = id;
	document.downloadDxf.submit();
}

function showColorRange(formID) {
	document.getElementById('colorTarget').value = formID;
	document.getElementById('sizeRange').style.display = "none";
	document.getElementById('colorRange').style.display = "";
}

function keepColorRange() {
	document.getElementById('colorRange').style.display = "";
}

function hideColorRange() {
	document.getElementById('colorRange').style.display = "none";
}

function showSizeRange(formID) {
	document.getElementById('sizeTarget').value = formID;
	document.getElementById('colorRange').style.display = "none";
	document.getElementById('sizeRange').style.display = "";
}

function keepSizeRange() {
	document.getElementById('sizeRange').style.display = "";
}

function hideSizeRange() {
	document.getElementById('sizeRange').style.display = "none";
}

function insertColorTag(repdeb, repfin) {
	var target = document.getElementById('colorTarget').value;
	var input = document.getElementById(target).text;
	insertTag(input, repdeb, repfin);
}

function insertSizeTag(repdeb, repfin) {
	var target = document.getElementById('sizeTarget').value;
	var input = document.getElementById(target).text;
	insertTag(input, repdeb, repfin);
}

/* Insertion de BBcodes */
/* Source : http://actuel.fr.selfhtml.org/articles/javascript/bbcode/index.htm */
function insertTag(input, repdeb, repfin) {
	//var input = document.forms['formulaire'].elements['saisie'];
	input.focus();
	/* pour l'Explorer Internet */
	if(typeof document.selection != 'undefined') {
		/* Insertion du code de formatage */
		var range = document.selection.createRange();
		var insText = range.text;
		if(repfin == "[/url]" && insText == "")
			repdeb = repdeb + "lien";
		range.text = repdeb + insText + repfin;
		/* Ajustement de la position du curseur */
		range = document.selection.createRange();
		if (insText.length == 0)
			range.move('character', -repfin.length);
		else
			range.moveStart('character', repdeb.length + insText.length + repfin.length);
		range.select();
	}
	/* pour navigateurs plus récents basés sur Gecko*/
	else if(typeof input.selectionStart != 'undefined') {
		/* Insertion du code de formatage */
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		if(repfin == "[/url]" && insText == "")
			repdeb = repdeb + "lien";
		input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);
		/* Ajustement de la position du curseur */
		var pos;
		if (insText.length == 0)
			pos = start + repdeb.length;
		else
			pos = start + repdeb.length + insText.length + repfin.length;
		input.selectionStart = pos;
		input.selectionEnd = pos;
	}
	/* pour les autres navigateurs */
	else {
		/* requête de la position d'insertion */
		var pos;
		var re = new RegExp('^[0-9]{0,3}$');
		while(!re.test(pos)) {
			pos = prompt("Insertion à la position (0.." + input.value.length + "):", "0");
		}
		if(pos > input.value.length)
			pos = input.value.length;
		/* Insertion du code de formatage */
		var insText = prompt("Veuillez entrer le texte à formater:");
		if(repfin == "[/url]" && insText == "")
			repdeb = repdeb + "lien";
		input.value = input.value.substr(0, pos) + repdeb + insText + repfin + input.value.substr(pos);
	}
}

function displaySiteInfos(id) {
	var pp = document.getElementById('pp'+id);
	var txt = document.getElementById('txt'+id);
	var o_id = document.getElementById('current').value;
	if(o_id != "") {
		var o_pp = document.getElementById('pp'+o_id);
		var o_txt = document.getElementById('txt'+o_id);
		o_pp.style.display = "none";
		o_txt.style.display = "none";
	}
	else {
		var bg = document.getElementById('pp_bg_img').value;
		document.getElementById('pp_bg').style.backgroundImage = "url(" + bg + ")";
	}
	document.getElementById('current').value = id;
	pp.style.display = "";
	txt.style.display = "";
	foHorizontalPosition();
	horizontalPosition('caption', 130);
}
function popup(famID, txt) {
	var popuptext = window.open('popup-text.php?id=' + famID + '&txt=' + txt, 'popuptext', 'width=700,height=700,toolbar=0,menubar=0,location=0,scrollbars=1,resizable=0,directories=0,top=200,left=500');
	popuptext.focus();
}
function openUpdateNameDialog(id, value) {
	document.updateName.id.value = id;
	document.updateName.text.value = value;
	openDialog('updateNameDialog', document.updateName.text);
}
function openUpdateTechnicalDataDialog(id) {
	document.updateTechnicalData.id.value = id;
	document.updateTechnicalData.text.value = document.getElementById('t'+id).value;
	openDialog('updateTechnicalDataDialog', document.updateTechnicalData.text);
}
function openUpdateRecommandationsDialog(id) {
	document.updateRecommandations.id.value = id;
	document.updateRecommandations.text.value = document.getElementById('r'+id).value;
	openDialog('updateRecommandationsDialog', document.updateRecommandations.text);
}
function goUpFamily(id) {
	document.go_up_down.action.value = "riseFamily";
	document.go_up_down.id.value = id;
	document.go_up_down.submit();
}
function goDownFamily(id) {
	document.go_up_down.action.value = "lowerFamily";
	document.go_up_down.id.value = id;
	document.go_up_down.submit();
}
function viewImage(img) {
	document.getElementById('preview').src="../72dpi/" + img;
	openDialog('div_preview', '');
}
function goUpType(id) {
	document.postActions.action.value = "riseType";
	document.postActions.id.value = id;
	document.postActions.submit();
}
function goDownType(id) {
	document.postActions.action.value = "lowerType";
	document.postActions.id.value = id;
	document.postActions.submit();
}
function enableDiameterCrit(id) {
	document.postActions.action.value = "enableDiameterCrit";
	document.postActions.id.value = id;
	document.postActions.submit();
}
function disableDiameterCrit(id) {
	document.postActions.action.value = "disableDiameterCrit";
	document.postActions.id.value = id;
	document.postActions.submit();
}
function enableStrokeCrit(id) {
	document.postActions.action.value = "enableStrokeCrit";
	document.postActions.id.value = id;
	document.postActions.submit();
}
function disableStrokeCrit(id) {
	document.postActions.action.value = "disableStrokeCrit";
	document.postActions.id.value = id;
	document.postActions.submit();
}
function addType(parent, position) {
	document.addType.parent.value = parent;
	document.addType.position.value = position;
	if(parent != "0" && position == "1")
		document.getElementById('msgAddType').style.display = "";
	else
		document.getElementById('msgAddType').style.display = "none";
	openDialog('addTypeDialog', document.addType.name);
}
function addTechdraw(id) {
	document.addTechdraw.id.value = id;
	openDialog('addTechdrawDialog', document.addTechdraw.tech_draw_ld);
}
function add3dmodel(id) {
	document.add3dmodel.id.value = id;
	openDialog('add3dmodelDialog', document.add3dmodel.model_ld);
}
function addAbacus(id) {
	document.addAbacus.id.value = id;
	openDialog('addAbacusDialog', document.addAbacus.abacus_ld);
}
function addBonus(id) {
	document.addBonus.id.value = id;
	openDialog('addBonusDialog', document.addBonus.abacus_ld);
}
function updateTechdraw(id) {
	document.updateTechdraw.id.value = id;
	openDialog('updateTechdrawDialog', document.updateTechdraw.tech_draw_ld);
}
function update3dmodel(id) {
	document.update3dmodel.id.value = id;
	openDialog('update3dmodelDialog', document.update3dmodel.model_ld);
}
function updateAbacus(id) {
	document.updateAbacus.id.value = id;
	openDialog('updateAbacusDialog', document.updateAbacus.abacus_ld);
}
function updateBonus(id) {
	document.updateBonus.id.value = id;
	openDialog('updateBonusDialog', document.updateBonus.abacus_ld);
}
function updateHdTechdraw(id) {
	document.updateHdTechdraw.id.value = id;
	openDialog('updateHdTechdrawDialog', document.updateHdTechdraw.tech_draw_svg);
}
function updateHd3dmodel(id) {
	document.updateHd3dmodel.id.value = id;
	openDialog('updateHd3dmodelDialog', document.updateHd3dmodel.model_hd);
}
function updateHdAbacus(id) {
	document.updateHdAbacus.id.value = id;
	openDialog('updateHdAbacusDialog', document.updateHdAbacus.abacus_hd);
}
function updateHdBonus(id) {
	document.updateHdBonus.id.value = id;
	openDialog('updateHdBonusDialog', document.updateHdBonus.abacus_hd);
}
function deleteTechdraw(id) {
	document.deleteTechdraw.id.value = id;
	openDialog('deleteTechdrawDialog', '');
}
function delete3dmodel(id) {
	document.delete3dmodel.id.value = id;
	openDialog('delete3dmodelDialog', '');
}
function deleteAbacus(id) {
	document.deleteAbacus.id.value = id;
	openDialog('deleteAbacusDialog', '');
}
function deleteBonus(id) {
	document.deleteBonus.id.value = id;
	openDialog('deleteBonusDialog', '');
}
function openUpdateCommentDialog(id) {
	document.updateComment.id.value = id;
	document.updateComment.text.value = document.getElementById('com'+id).value;
	openDialog('updateCommentDialog', document.updateComment.text);
}
function deleteType(id) {
	document.deleteType.id.value = id;
	openDialog('deleteTypeDialog', '');
}
function checkAnswer() {
	if(document.getElementById('ans_yes').checked)
		document.deleteType.submit();
	else
		closeDialog('deleteTypeDialog');
}
function submitTypeChoiceForm(id) {
	document.type_choice.type.value = id;
	document.type_choice.submit();
}
function addDxf(id) {
	document.addDxf.id.value = id;
	openDialog('addDxfDialog');
}
function updateDxf(id, old) {
	document.updateDxf.id.value = id;
	if(old == "")	document.getElementById('old_dxf').innerHTML = "Current : <b><font color='red'>No file</font></b>";
	else document.getElementById('old_dxf').innerHTML = "Current : <b>" + old + "</b>";
	openDialog('updateDxfDialog');
}
function deleteDxf(id) {
	document.deleteDxf.id.value = id;
	openDialog('deleteDxfDialog');
}
function moveRef(id) {
	document.moveRef.id.value = id;
	openDialog('moveRefDialog', '');
}
function deleteRef(id) {
	document.deleteRef.id.value = id;
	openDialog('deleteRefDialog', '');
}
function deleteDocumentation(id) {
	document.deleteDocumentation.id.value = id;
	openDialog('deleteDocDialog', '');
}
function riseDocumentation(id) {
	document.actionForm.action.value = "riseDocumentation";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function lowerDocumentation(id) {
	document.actionForm.action.value = "lowerDocumentation";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function displayArticle(id) {
	document.actionForm.action.value = "displayArticle";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function hideArticle(id) {
	document.actionForm.action.value = "hideArticle";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function riseArticle(id) {
	document.actionForm.action.value = "riseArticle";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function lowerArticle(id) {
	document.actionForm.action.value = "lowerArticle";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function deleteArticle(id) {
	document.deleteArticle.id.value = id;
	openDialog('deleteArtDialog', '');
}
function updateKeyNum(id) {
	document.updateKeyNum.id.value = id;
	document.updateKeyNum.title.value = document.getElementById('title_' + id).value;
	document.updateKeyNum.text.value = document.getElementById('text_' + id).value;
	openDialog('updateKeyNumDialog', document.updateKeyNum.title);
}
function riseKeyNum(id) {
	document.actionForm.action.value = "riseKeyNum";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function lowerKeyNum(id) {
	document.actionForm.action.value = "lowerKeyNum";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function deleteKeyNum(id) {
	document.deleteKeyNum.id.value = id;
	openDialog('deleteKeyNumDialog', '');
}
function displayNews(id) {
	document.actionForm.action.value = "displayNews";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function hideNews(id) {
	document.actionForm.action.value = "hideNews";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function archiveNews(id) {
	document.actionForm.action.value = "archiveNews";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function unarchiveNews(id) {
	document.actionForm.action.value = "unarchiveNews";
	document.actionForm.id.value = id;
	document.actionForm.submit();
}
function deleteNews(id) {
	document.deleteNews.id.value = id;
	openDialog('deleteNewsDialog', '');
}
function generatePDF(id, histo) {
	document.generatePDF.type.value = id;
	if(histo == '0')
		document.getElementById('enableHisto').style.display = 'none';
	else
		document.getElementById('enableHisto').style.display = '';
	openDialog('generatePdfDialog', '');
}
function generatePDFtxt(id) {
	document.generatePDF.family.value = id;
	openDialog('generatePdfDialog', '');
}
function fontSizeUp() {
	var form = document.generatePDF;
	var size = form.font.value.replace(" pt", "");
	size = parseInt(size * 10)/10;
	if(size < 9)
		form.font.value = (size + 0.5) + " pt";
}
function fontSizeDown() {
	var form = document.generatePDF;
	var size = form.font.value.replace(" pt", "");
	size = parseInt(size * 10)/10;
	if(size > 6)
		form.font.value = (size - 0.5) + " pt";
}