
Version = parseInt(navigator.appVersion)
NS6 = (navigator.appName.indexOf("Netscape") != 1 && parseInt(navigator.appVersion) >= 5)
NS = navigator.appName == "Netscape"
IE = navigator.appName == "Microsoft Internet Explorer"

function InitialiserFormulaire(Lang, NoOrganisation, NoMembre, NoProgramme, NoCours, NoCategorie, Focus, TableDesMatieres, Type)
	{
	eval('document.Formulaire.' + Focus + '.focus();');
	if (TableDesMatieres)
		AfficherTableDesMatieres(Lang, NoOrganisation, NoMembre, NoProgramme, NoCours, NoCategorie, Type);
	}

function AjouterFormulaire()
	{
	document.Formulaire.Action.value = 'Nouveau';
	document.Formulaire.submit();
	}

function EnregistrerFormulaire()
	{
	if (ValiderFormulaire())
		{
//		alert("Vos données ont été enregistrées correctement.");
		document.Formulaire.submit();
		}
	}

function RecommencerFormulaire(NouveauFormulaire)
	{
	if (NouveauFormulaire)
		Message = 'Voulez-vous vraiment effacer toutes les données ajoutées ou modifiées dans ce formulaire ?';
	else
		Message = 'Voulez-vous vraiment effacer définitivement toutes les données affichées dans ce formulaire ?';

	if (confirm(Message))
		document.Formulaire.reset();
	}

function SupprimerFormulaire()
	{
	if (confirm('Voulez-vous vraiment supprimer ce formulaire ?'))
		{
		document.Formulaire.Action.value = 'Supprimer';
		alert("Ce formulaire a été supprimé définitivement.");
		document.Formulaire.submit();
		}
	}

function CopierFormulaire()
	{
	document.Formulaire.Action.value = 'Copier';
	alert("Ce formulaire a été copié correctement, son nom sera précédé de « Copie de ».");
	document.Formulaire.submit();
	}

function VisualiserFormulaire(Lang, NoMembre, NoCours, NoCategorie, NoObjet, NoPage, LienPage)
	{
	if (NoPage == 0)
		{
		Lien  = '/Vision/ObjetApprentissage.asp?lang='+Lang;
		Lien += '&NoMembre=' + NoMembre + '&NoCours=' + NoCours + '&NoCategorie=' + NoCategorie + '&NoObjet=' + NoObjet;
		Left  = 0;
		FenetreVisualiser = window.open(Lien, "FenetreVisualiser", "Height=500, Width=1010, Border=0, ScrollBars=no, Status=yes");
		}
	else
		{
		Lien  = '/Vision/' + LienPage + '?';
		Lien += 'NoMembre=' + NoMembre + '&NoCours=' + NoCours + '&NoCategorie=' + NoCategorie + '&NoObjet=' + NoObjet + '&NoPage=' + NoPage;
		Left  = 215;
		FenetreVisualiser = window.open(Lien, "FenetreVisualiser", "Height=500, Width=790, Border=0, ScrollBars=yes, Status=yes");
		}

	FenetreVisualiser.moveTo(Left, 200);
	FenetreVisualiser.focus();
	}

function FermerFormulaire()
	{
	if (confirm('Voulez-vous vraiment fermer ce formulaire ?'))
		self.close();
	}

function OuvrirFenetre(Lien)
	{
	if (Lien != '' && Lien != 'http://')
		{
		Fenetre = window.open(Lien, "Fenetre", "Height=" + (screen.availHeight - 150) + ", Width=" + (screen.availWidth - 10) + ", Border=0, MenuBar=yes, Scrollbars=yes, Status=yes, Resizable=yes");
		}
	else
		alert('Il n\'y a pas  d\'adresse pour cet objet d\'apprentissage !');
	}

function AfficherTableDesMatieres(Lang, NoOrganisation, NoMembre, NoProgramme, NoCours, NoCategorie, Type)
	{
	Lien = './TableDesMatieres.asp?lang='+Lang;
	Lien += '&NoOrganisation=' + NoOrganisation + '&NoMembre=' + NoMembre + '&NoProgramme=' + NoProgramme + '&NoCours=' + NoCours;
	Lien += '&NoCategorie=' + NoCategorie + '&Type=' + Type;
	if (NS)
		parent.document.getElementById("FrameTableDesMatieres").src = Lien;
	else if (IE)
		parent.document.all["FrameTableDesMatieres"].src = Lien;
	}

/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/

function restrictinput(maxlength, e, placeholder)
	{
	if (window.event && event.srcElement.value.length >= maxlength)
		return false
	else if (e.target && e.target == eval(placeholder) && e.target.value.length >= maxlength)
		{
		var pressedkey = /[a-zA-Z0-9\.\,\/]/ // detect alphanumeric keys
		if (pressedkey.test(String.fromCharCode(e.which)))
			e.stopPropagation();
		}
	}

function countlimit(maxlength, e, placeholder, nodisplay)
	{
	var theform = eval(placeholder);
	var lengthleft = maxlength - theform.value.length;
	var placeholderobj = document.all ? document.all[placeholder] : document.getElementById(placeholder);
	if (window.event || e.target && e.target == eval(placeholder))
		{
		if (lengthleft < 0)
			theform.value = theform.value.substring(0, maxlength);
		if (lengthleft > 0 && !nodisplay)
			placeholderobj.innerHTML = lengthleft;
		else if (!nodisplay)
			placeholderobj.innerHTML = 0;
		}
	}

function displaylimit(thename, theid, thelimit, nodisplay)
	{
	var theform = theid != "" ? document.getElementById(theid) : thename;
	color = '#000000';
	if (nodisplay)
		limit_text =  '<Span Id="' + theform.toString() + '"></Span>';
	else
		limit_text =  '<Font Color=' + color + '><B><Span Id="' + theform.toString() + '">' + thelimit + '</Span>/' + thelimit + ' caractères.</B></Font>';
	document.write(limit_text);
	if (document.all)
		{
		eval(theform).onkeypress = function() { return restrictinput(thelimit, event, theform) }
		eval(theform).onkeyup = function() { countlimit(thelimit, event, theform, nodisplay) }
		}
	else if (NS6)
		{
		document.body.addEventListener('keypress', function(event) { restrictinput(thelimit, event, theform) }, true); 
		document.body.addEventListener('keyup', function(event) { countlimit(thelimit, event, theform, nodisplay) }, true); 
		}
	}

DerniereValeur = 0;

function FormaterPrixHeure(Champ, Valeur)
	{
	if ((!isNaN(Valeur) && Valeur != "") || Valeur >= 0)
		{
		Valeur += "";
		if (Valeur.indexOf(".") < (Valeur.length - 3))
			Valeur = Math.round(Valeur * Math.pow(10, 2)) / Math.pow(10, 2);
		Valeur += "";

		if (Valeur == "" || Valeur == " ")
			Valeur = "0.00";
		else if (Valeur.indexOf(".") == 0)
			Valeur = "0" + Valeur;
		else if (Valeur.indexOf(".") == -1)
			Valeur = Valeur + ".00";

		if (Valeur.indexOf(".") == Valeur.length - 1)
			Valeur = Valeur + "00";
		else if (Valeur.indexOf(".") == Valeur.length - 2)
			Valeur = Valeur + "0";

		Champ.value = Valeur;
		}
	else
		{
		alert("Champ invalide!\nFormat : 99.99");
		Champ.value = DerniereValeur;
		}
	}

function FormaterNombre(Champ, Valeur)
	{
	if ((!isNaN(Valeur) && Valeur != "") || Valeur >= 0)
		Champ.value = Math.round(Valeur);
	else
		{
		alert("Nombre invalide!");
		Champ.value = DerniereValeur;
		}
	}

var TableauMois = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"];

function FormaterDate(Champ, Valeur)
	{
	AffichageDate = new Date(Valeur);
	Champ.value = AffichageDate.getDate() + ' ' + TableauMois[AffichageDate.getMonth()] + ' ' + AffichageDate.getFullYear();
	}

function FormaterDateCourte(Champ, Valeur)
	{
	AffichageDate = new Date(Valeur);
	Month	= (parseInt(AffichageDate.getMonth()) + 1);
	if (String(Month).length == 1) Month = '0' + Month;
	Day	= AffichageDate.getDate();
	if (String(Day).length == 1) Day = '0' + Day;
	Champ.value = AffichageDate.getFullYear() + '-' + Month + '-' + Day;
	}

function isDate(d)
	{
	// Cette fonction permet de vérifier la validité d'une date au format jj/mm/aa ou jj/mm/aaaa
	// Par Romuald

//	if (d == "") // si la variable est vide on retourne faux
//		return false;

	e = new RegExp("^([0-9]{2}|[0-9]{4})\-[0-9]{1,2}\-[0-9]{1,2}$");

	if (!e.test(d)) // On teste l'expression régulière pour valider la forme de la date
		return false; // Si pas bon, retourne faux

	// On sépare la date en 3 variables pour vérification, parseInt() converti du texte en entier
	a = parseInt(d.split("-")[0], 10); // année
	m = parseInt(d.split("-")[1], 10); // mois
	j = parseInt(d.split("-")[2], 10); // jour

	// Si l'année n'est composée que de 2 chiffres on complète automatiquement
	if (a < 1000)
		{
		if (a < 89) a += 2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
		else a += 1900;
		}

	// Définition du dernier jour de février
	// Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
	if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
	else fev = 28;

	// Nombre de jours pour chaque mois
	nbJours = new Array(31, fev, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	// Enfin, retourne vrai si le jour est bien entre 1 et le bon nombre de jours, idem pour les mois, sinon retourn faux
	return ( m >= 1 && m <= 12 && j >= 1 && j <= nbJours[m-1] );
	}

function ChangerOrdre(ORDER, ORDERWAY)
	{
	document.Formulaire.ORDER.value = ORDER;
	document.Formulaire.ORDERWAY.value = ORDERWAY;
	document.Formulaire.submit();
	}

var Match = 0;

function FindInPage(SearchString)
	{
	var TextArea, Count, Found;

	if (SearchString == "")
		return false;

	// Find next occurance of the given string on the page, wrap around to the start of the page if necessary.

	if (NS)
		{
		// Look for match starting at the current point. If not found, rewind back to the first match.

		if (!window.find(SearchString))
			while(window.find(SearchString, false, true))
				Match++;
		else
			Match++;

		if (Match == 0)	// If not found in either direction, give message.
			alert("L'objet de la recherche (" + SearchString + ") n'a pu être trouvé.");
		}

	if (IE)
		{
		TextArea = window.document.body.createTextRange();

		// Find the nth match from the top of the page.

		for (Count = 0; Count <= Match && (Found = TextArea.findText(SearchString)) != false; Count++)
			{
			TextArea.moveStart("character", 1);
			TextArea.moveEnd("textedit");
			}

		if (Found)			// If found, mark it and scroll it into view.
			{
			TextArea.moveStart("character", -1);
			TextArea.findText(SearchString);
			TextArea.select();
			TextArea.scrollIntoView();
			Match++;
			}
		else					// Otherwise, start over at the top of the page and find first match.
			{
			if (Match > 0)
				{
				Match = 0;
				FindInPage(SearchString);
				}
			else				// Not found anywhere, give message.
				alert("L'objet de la recherche (" + SearchString + ") n'a pu être trouvé.");
			}
		}
	return false;
	}

function Touche(e, Item)
	{
	if (NS)
		{
		if (!NS6) { document.captureEvents(Event.KEYPRESS); }
		if (e.which == 13)
			return true;
		}
	else if (IE)
		{
		if (event.keyCode == 13)
			return true;
		}
	return false;
	}

function EffetOverTabs(img, parentFolder, lang)
{
  img.src = parentFolder+img.id+"_"+lang+"_B.gif";
}

function EffetOutTabs(img, parentFolder, lang)
{
  if (img.section != idSection){
	  img.src = parentFolder+img.id+"_"+lang+"_A.gif";
	}
}

function ShowSection(idSection, lang, Section) 
{
	
	if (typeof(Section) == 'undefined')
		location = "index.asp?lang="+lang+"&idSection="+idSection;
	else
		location = Section;
}

function setIFrameById(strId, src){
  
	if (!document.frames)  //W3C, Firefox et autres
		top.document.getElementById(strId).src = src;
	else
		top.document.frames[strId].location = src;        //IE5 et IE6
}

function ShowTab(tabID, button, imgParentFolder, lang)
{
  var elem = document.getElementById(tabID);
  var selBtn = document.getElementById(SelectedTab);

	button.src = imgParentFolder+button.id+"_"+lang+"_B.gif";

  if (SelectedTab != button.id)
  	selBtn.src = imgParentFolder+selBtn.id+"_"+lang+"_A.gif";
  
  SelectedTab = button.id;
  
  elem.className = "VisibleTabContent";

  for (var i=1; i <= 4; i++) {
    if (tabID != "tab"+i) {
      elem = document.getElementById("tab"+i);
      elem.className = "InvisibleTabContent";
    }
  }
}
