/*Gestion des elements source evenement sous netscape */
var flag = (window.Event)? true : false;

if (flag)
{ 
  document.captureEvents(Event.CLICK);
}

/*Fin gestion des elements source evenement sous netscape*/

var ns6=document.getElementById&&!document.all
var ie=document.all

// Affiche dans une nouvelle fenêtre le contenu de l'objet passé en paramètre
function showProps(object,objectName)
{
      var fen = window.open();
      fen.document.open("text/html");

      fen.document.write("<H1>Contenu de l'objet " + objectName + "</H1>");
      fen.document.write("<TABLE>");

      for(var i in object)
      {
        fen.document.write("<TR><TD><TT>" + objectName + "." + i + " </TT>" +
                               "<TD><TT>== " + object[i] + "</TT>");
      }

      fen.document.write("</TABLE>");
      fen.document.close();
}

function show(Obj2Show)
{
	if ( Obj2Show )
	{
		if ( document.all || document.getElementById ) 
		{
			isns4 = false;
		}
		else
		{ 
			isns4 = true;
		}
		if ( isns4 ) 
		{	
			//Obj2Show.visibility = 'show';
			//Obj2Show.style.display = 'block'
			Obj2Show.style.display = ''
		}
		else 
		{
			//Obj2Show.style.visibility = 'visible';
			//Obj2Show.style.display = 'block'
			Obj2Show.style.display = ''
		}
	}
}

function showBis(Obj2Show)
{
	if ( Obj2Show )
	{
		if ( document.all || document.getElementById ) 
		{
			isns4 = false;
		}
		else 
		{
			isns4 = true;
		}
		if ( isns4 ) 
		{
			Obj2Show.visibility = 'show';
			//Obj2Show.style.display = ''
		}
		else 
		{
			Obj2Show.style.visibility = 'visible';
			//Obj2Show.style.display = ''
		}
	}
}

function hide(Obj2Hide)
{
	if ( Obj2Hide )
	{
		if ( document.all || document.getElementById )
		{
			isns4 = false;
		}
		else
		{
			isns4 = true;
		}

		if ( isns4 ) 
		{
			//Obj2Hide.visibility = 'hide';
			Obj2Hide.style.display = 'none'
		}
		else 
		{
			//Obj2Hide.style.visibility = 'hidden';
			Obj2Hide.style.display = 'none'
		}
	}
}

function hideBis(Obj2Hide)
{
	if ( Obj2Hide )
	{
		if ( document.all || document.getElementById )
		{
			isns4 = false;
		}
		else
		{
			isns4 = true;
		}

		if ( isns4 ) 
		{
			Obj2Hide.visibility = 'hide';
			//Obj2Hide.style.display = 'none'
		}
		else 
		{
			Obj2Hide.style.visibility = 'hidden';
			//Obj2Hide.style.display = 'none'
		}
	}
}

function isNumeric(chaine)
{
	response=true;
	
	for(i=0;i<chaine.length;i++)
	{
		if (chaine.charAt(i)!=parseInt(chaine.charAt(i)))
		{
			response=false;
		}
	}	
	return response;
}

function trim(inputString)
{
	 // Removes leading and trailing spaces from the passed string. Also removes
	 // consecutive spaces and replaces it with one space. If something besides
	 // a string is passed in (null, custom object, etc.) then return the input.
	 if (typeof inputString != "string")
	 {
	 	return inputString;
	 }
	 var retValue = inputString;
	 var ch = retValue.substring(0, 1);
	 while (ch == " ")
	 { 
	   	// Check for spaces at the beginning of the string
	      	retValue = retValue.substring(1, retValue.length);
	      	ch = retValue.substring(0, 1);
	 }
	 ch = retValue.substring(retValue.length-1, retValue.length);
	 while (ch == " ")
	 { 
	 	// Check for spaces at the end of the string
	    	retValue = retValue.substring(0, retValue.length-1);
	    	ch = retValue.substring(retValue.length-1, retValue.length);
	 }
	 while (retValue.indexOf("  ") != -1)
	 { 
	   	// Note that there are two spaces in the string - look for multiple spaces within the string
	      	retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	 }
	 return retValue; 
	 // Return the trimmed string back to the user
} 

function dateJour()
{
	var d, s = ""
 	d = new Date();       
 	s += d.getHours() + ":";
 	s += d.getMinutes() + " ";                    
 	s += d.getDate() + "/";
 	s += (d.getMonth() + 1) + "/";         
 	s += d.getYear();  					
 	return s;
}

function CheckDate(d)
{
      // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
      // Le séparateur est défini dans la variable separateur
      var amin=1901; // année mini
      var amax=2050; // année maxi
      var separateur="/"; // separateur entre jour/mois/annee
      var j=(d.substring(0,2));
      var m=(d.substring(3,5));
      var a=(d.substring(6));
      var ok=1;
      if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) )
      {
         //alert("Le jour n'est pas correct."); 
         ok=0;
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) )
      {
         //alert("Le mois n'est pas correct."); 
         ok=0;
      }
      if ( ((isNaN(a))||(a<amin)||(a>amax)) && (ok==1) )
      {
         //alert("L'année n'est pas correcte."); 
         ok=0;
      }
      if ( ((d.substring(2,3)!=separateur)||(d.substring(5,6)!=separateur)) && (ok==1) )
      {
         //alert("Les séparateurs doivent être des "+separateur); 
         ok=0;
      }
      if (ok==1)
      {
      		var d2=new Date(a,m-1,j);
	        j2=d2.getDate();
	        m2=d2.getMonth()+1;
	        a2=d2.getYear();
	        if (a2<=100)
	        {
	        	a2=1900+a2
	        }
         	//Attention aux valeurs renvoyées par Nescafé avec getYear
         	if ((flag) && (a2<=1900)) {a2=1900+a2}
         	if ( (j!=j2)||(m!=m2)||(a!=a2) )
         	{
            	//alert(a2);	
            	//alert("La date "+d+" n'existe pas !");
            	ok=0;
       		}
      }
      return ok;
}

// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers)
{ // Netscape
	document.captureEvents(Event.MOUSEMOVE);
    	document.onmousemove = captureMousePosition;
} 
else if (document.all)
{ // Internet Explorer
	document.onmousemove = captureMousePosition;
} 
else if (document.getElementById) 
{ // Netcsape 6
    document.onmousemove = captureMousePosition;
}

// Global variables
xMousePos = 0; 		// Horizontal position of the mouse on the screen
yMousePos = 0; 		// Vertical position of the mouse on the screen
xMousePosMax = 0; 	// Width of the page
yMousePosMax = 0; 	// Height of the page
divBloque=''

function captureMousePosition(e)
{
    if (document.layers)
    {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
    else if (document.all)
    {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById)
    {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function verifierChamp(objet,nomChamp,type,obligatoire,longueurMini,longueurMaxi,objet2)
{
	//référence objet html dont le contenu est à vérifier
	//nomChamp: nom du champ pour message erreur
	//type: type de champ (texte,numerique,mail,date)
	//obligatoire: champs vide autorisé ou pas 'oui','non'
	//longueurMini: nombre de caractère minimum pour type texte,valeur minimale pour type numerique,dateMini pour type date (non réalisé)
	//longueurMaxi: nombre de caractère maximum pour type texte,valeur maximale pour type numerique,dateMaxi pour type date (non réalisé)
	//objet2: non utilisé encore, envue verif valeur dans liste et mot de passe de confirmation identiques

	//nb: pour vérification longueur et intervalle renseigner les deux paramètres ci-dessus

	//la fonction de vérification des libellés multilangue doit utiliser cette fonction à terme
	//alert(objet + ',' + type + ',' + nomChamp);
	switch (type)
	{
		case 'texte':
			{
			if (trim(objet.value)=='')
			{
				if (obligatoire=='non')
				{
					return true;
				}
				else
				{
					alert(nomChamp + ' est obligatoire.');
					//objet.focus();
					//objet.select();
					return false;
				};
			}
			else
			{
				if ((longueurMini!='') && (longueurMaxi!=''))
				{
					if ((objet.value.length<longueurMini) || (objet.value.length>longueurMaxi))
					{
						alert(nomChamp + ' doit être composé de ' + longueurMini + ' à ' + longueurMaxi + ' caractères.');
						return false;
					}
				}
				else
				{
					return true;
				};
			};
			break;
			};
		case 'numerique':
			{
			if (trim(objet.value)=='')
			{
				if (obligatoire=='non')
				{
					return true;
				}
				else
				{
					alert(nomChamp + ' est obligatoire.');
					return false;
				};
			}
			else
			{
				if (isNumeric(objet.value))
				{
					if ((longueurMini!='') && (longueurMaxi!=''))
					{
						if ((objet.value<longueurMini) || (objet.value>longueurMaxi))
						{
							alert(nomChamp + ' doit être compris entre ' + longueurMini + ' et ' + longueurMaxi + '.');
							return false;
						}
					}
					else
					{
						return true;
					};
				}
				else
				{
					alert(nomChamp + ' ne doit comporter que des chiffres.');
					return false;
				};
			};
			break;
			};
		case 'mail':
			{
			if (trim(objet.value)=='')
			{
				if (obligatoire=='non')
				{
					return true;
				}
				else
				{
					alert(nomChamp + ' est obligatoire.');
					return false;
				};
			}
			else
			{
					if (objet.value.indexOf(" ")>=0 )                    
			          	{
						 alert('Le format de ' + nomChamp + ' est incorrect.');
			   	                 return false;
					}
					else
					{ 
						if ((objet.value.indexOf("@") != -1) && (objet.value.indexOf("@") < objet.value.lastIndexOf(".")))
				        	{
							return true;
						}
						else
						{
							alert('Le format de ' + nomChamp + ' est incorrect.');
							return false;
						};
					};
			};
			break;
			};
		case 'date':
			{
			if (trim(objet.value)=='')
			{
				if (obligatoire=='non')
				{
					return true;
				}
				else
				{
					alert(nomChamp + ' est obligatoire.');
					return false;
				};
			}
			else
			{
				//Tester si est une date correcte
				if (CheckDate(objet.value))
				{
					return true;
				}
				else
				{
					alert(nomChamp + ' n\'est pas une date correcte.');
					return false;
				};
				//Pour le moment on ne controle pas date mini et maxi...
				//si oui adapter fonction CheckDate plutot
				/*if ((longueurMini!='') && (longueurMaxi!=''))
				{
					//Comparer les dates
					if ((objet.value.length<longueurMini) || (objet.value.length>longueurMaxi))
					{
						alert(nomChamp + ' doit être compris entre ' + longueurMini + ' et ' + longueurMaxi + '.');
						return false;
					}
				}
				else
				{
					return true;
				};*/
			};
			break;
			};
		default:
			{
			alert('Erreur fonction verifierChamp, type de champ non géré');
			break;
			};
	};
	
	return true;
}

function debugPrint(strChaine)
{
	document.getElementById("debug").innerHTML = document.getElementById("debug").innerHTML + strChaine + "<br></br>"
}

function favoris() {
       if ( navigator.appName != 'Microsoft Internet Explorer' ){
           window.sidebar.addPanel("FinalesRugby.com - Toutes les finales du championnat depuis 1892!","http://www.finalesrugby.com/","");
       }
       else {
           window.external.AddFavorite("http://www.finalesrugby.com/","FinalesRugby.com - Toutes les finales du championnat depuis 1892!");
       }
}

function checkEmail(emailAddr) {
	// Cette fonction vérifie la bon format d'une adresse e-mail.
	// Comme :
	// user@domain.com ou user.perso@domain.com
	
	var i;
	
	// Recherche de @
	i = emailAddr.indexOf("@");
	if (i == -1) {
		return false;
	}
	
	// Séparation du nom de l'utilisateur et du nom de domaine.
	var username = emailAddr.substring(0, i);
	var domain = emailAddr.substring(i + 1, emailAddr.length)

	// Recherche des espaces au début du nom de l'utilisateur.
	i = 0;
	while ((username.substring(i, i + 1) == " ") && (i < username.length)) {
		i++;
	}
	// Les enlève s'il en trouve.
	if (i > 0) {
		username = username.substring(i, username.length);
	}

	// Recherche d'espaces à la fin du nom de domaine.
	i = domain.length - 1;
	while ((domain.substring(i, i + 1) == " ") && (i >= 0)) {
		i--;
	}
	// Les enlève s'il en trouve.
	if (i < (domain.length - 1)) {
		domain = domain.substring(0, i + 1);
	}

	// Vérifie que le nom de l'utilisateur et du domaine ne soit pas vide.
	if ((username == "") || (domain == "")) {
		return false;
	}
	
	// Vérifie s'il n'y a pas de caractères interdits dans le nom de l'utilisateur.
	var ch;
	for (i = 0; i < username.length; i++) {
		ch = (username.substring(i, i + 1)).toLowerCase();
		if (!(((ch >= "a") && (ch <= "z")) || 
			((ch >= "0") && (ch <= "9")) ||
			(ch == "_") || (ch == "-") || (ch == "."))) {
				return false;
		}
	}
	
	// Vérifie s'il n'y a pas de caractères interdits dans le nom de domaine
	for (i = 0; i < domain.length; i++) {
		ch = (domain.substring(i, i + 1)).toLowerCase();
		if (!(((ch >= "a") && (ch <= "z")) || 
			((ch >= "0") && (ch <= "9")) ||
			(ch == "_") || (ch == "-") || (ch == "."))) {
				return false;
		}
	}

// Ajouter ci-dessous de nouveaux noms de domaine.
// Voir tous les noms de domaine sur http://www.toulouse-renaissance.net/c_outils/c-nom-domaine.htm
//
var aSuffix = new Array("com","net","int","aero","biz","museum","name","info","coop","pro","eu","edu","org","gov","mil","bj","dz","de","ad","be","ca","bf","bi","cm","cf","cg","cd","ci","dj","fr","ga","gp","gf","lu","mg","ml","ma","mq","mr","mc","nc","pf","re","pm","sn","ch","td","tf","tn");
	var bFoundSuffix = false;
	i = 0;
	while (i < aSuffix.length) {
		if (("." + aSuffix[i]) == domain.substring(domain.length - aSuffix[i].length - 1, domain.length)) {
			return true;
		}
		i++;
	}
	// Si le nom de domaine est inconnu  : return false
	return false;
	
}
