function isAlpha(pStr)
{
	vsStr = pStr.toUpperCase();
	for(i=0; i<vsStr.length; i++)
		if(vsStr.charAt(i)!= ' ' && vsStr.charAt(i)!= '-' && (vsStr.charAt(i) < 'A' || vsStr.charAt(i) > 'Z') && (vsStr.charAt(i) < 'Ç' || vsStr.charAt(i) > 'Ü'))
			return false;
	
	return true;
}


function isCodePostalFrancais(psCP)
{
	if(psCP.length != 5)
		return false;
	for(i=0; i<psCP.length; i++)
		if(psCP.charAt(i) < '0' || psCP.charAt(i) > '9')
			return false;
	
	return true;
}


// isEmail()
// fonction qui verifie qu'une adresse eMail est valide
// parametre : la chaine de caracteres contenant l'adresse eMail

function isEmail(ps_src)
	{
		var vt_txt = new Array(2);	// tableau qui va contenir les chaines avant et apres l'arobase
		var vi_arobase;				// va contenir l'index de l'arobase dans la chaine
		var vc_tmp;					// caractere temporaire
		
		vi_arobase = ps_src.indexOf("@");
		if (vi_arobase > 0 &&							// l'arobase ne doit pas etre en premier...
			vi_arobase != (ps_src.length - 1) &&		// ... ni en dernier...
			vi_arobase == ps_src.lastIndexOf("@") &&	// ... et il ne peut en rester qu'un
			ps_src.indexOf("..") < 0)					// il ne peut y avoir ".."
		{
			vt_txt[0] = ps_src.substring(0,vi_arobase);					// prend la chaine avant l'arobase <=> nom
			vt_txt[1] = ps_src.substring(vi_arobase + 1,ps_src.length);	// prend la chaine apres l'arobase <=> adresse
			if ((vt_txt[0].indexOf(".") != 0) &&							// pas de point en debut de chaine
				(vt_txt[1].indexOf(".") > 0) &&								// idem
				(vt_txt[0].lastIndexOf(".") < (vt_txt[0].length - 1)) &&	// ni en fin de chaine
				(vt_txt[1].lastIndexOf(".") < (vt_txt[1].length - 2)))		// pas un des 2 derniers caracteres
			{
				for (var vi_nbr = 0;vi_nbr < 2;vi_nbr++)		// boucle sur les deux chaines
				for (var vi_char_nbr = 0;vi_char_nbr < vt_txt[vi_nbr].length;vi_char_nbr++)
				{
					vc_tmp = vt_txt[vi_nbr].charAt(vi_char_nbr);// si le caractere recupere
					if ((vc_tmp < '0' || vc_tmp > '9') &&		// n'est pas un chiffre
						(vc_tmp < 'a' || vc_tmp > 'z') &&		// n'est pas une minuscule
						(vc_tmp < 'A' || vc_tmp > 'Z') &&		// n'est pas une majuscule
						vc_tmp != '.' && vc_tmp != '_' &&		// ni un autre caractere
						vc_tmp != '-')							// autorise...
							return false;						// alors l'adresse est invalide
				}
				return true;
			}
		}
		return false;
	}


// focusOnFirst()
// fonction qui repositionne le focus sur le premier element du premier formulaire de la page
// pas de parametre

function focusOnFirst()
	{
		document.forms[0].elements[0].focus();
		document.forms[0].elements[0].select();
	}

//isPrice(psPrix)
//fonction qui renvoie un booleen à vrai si la variable est un prix : 
//des nombres, éventuellement un point OU une virgule.

function isPrice(psPrix)
	{
		var vc_tmp;					// caractere temporaire
		var vs_prix;				// copie de la chaine
		var vb_point;				// booleen de résence d'un point
		var vb_virgule;				// booleen de présence d'une virgule
					
		vb_point=false;
		vb_virgule=false;
					
		vs_prix=psPrix.toString();
					
		for (var vi_char_nbr = 0;vi_char_nbr < vs_prix.length;vi_char_nbr++)
		{
			vc_tmp = vs_prix.charAt(vi_char_nbr);// si le caractere recupere
			if ((vc_tmp < '0' || vc_tmp > '9') &&		// n'est pas un chiffre
				vc_tmp != '.' && vc_tmp != ',')			// ni un autre caractere autorise...
				return false;							// alors le prix est invalide.
			if (vc_tmp == '.') 
				if (vb_point == true || vb_virgule == true)		// Si le caractere recupere
					return false;							// est un deuxième point
				else
					vb_point=true;
			if (vc_tmp == ',')
				if (vb_point == true || vb_virgule == true)		// Si le caractere recupere 
					return false;							// est une deuxième virgule
				else
					vb_virgule=true;
		}
		return true;
	}	




// permet de supprimer tous les espaces d'une chaine

		function StringTrim(psString) 
			{
			var viSize=psString.length;
			var vstemp='';
			for (i=0; i<viSize; i++)
				{ 
					if(psString.charAt(i) != " ") vstemp = vstemp + psString.charAt(i);
				}
			return vstemp;
			}
			
		function LTrim(psString) 
		{			
			var i = 0;
			var viSize=psString.length;	
			while (psString.charCodeAt(i) == 32)
			{	
				if (i == viSize)
					break;			
				i = i + 1				
			}
			vstemp = psString.slice(i)
			return vstemp;
		}		
			
		function RTrim(psString) 
		{									
			var i = psString.length;
			i = i - 1;
			
			while (psString.charCodeAt(i) == 32)
			{					
				if (i == -1)
					break;											
				i = i - 1				
			}			
			vstemp = psString.slice(0, i+1)
			return vstemp;
		}

		function Trim(psString)			
		{
			var vsTemp = psString;
			vsTemp = LTrim(RTrim(vsTemp));
			return vsTemp;
		}
					
 
// Verifie la validité d'un champs obligatoires
//  ds le cas de l'mail (psOption ="mail") il teste la valeur 
// grace à la fonction IsMail 

		function VerifieChamps(psObjet, psLibele, psOption) 
			{
			var vsValue = psObjet.value;


								// Test du mail
								if ( psOption == "mail*")
									{
										if (!isEmail (vsValue)) 
										{
											alert ("Le Champ '"+ psLibele +"' n'est pas correct.");
											psObjet.focus();
											return false
										} 
										return true
									}

								if ( psOption == "mail")
									{
										if (!isEmail (vsValue) && StringTrim(vsValue)!='') 
										{
											alert ("Le Champ '"+ psLibele +"' n'est pas correct.");
											psObjet.focus();
											return false
										} 
										return true
									}


								// Test de la Date
								if ( psOption == "date*")
									{
										if ((vsValue.length == 10)||(vsValue.length == 8))
											{
											if((vsValue.substring(2,3)=="/")&(vsValue.substring(5,6)=="/"))
												{
												if (isValid ( vsValue.substring(0,2) , vsValue.substring(3,5) , vsValue.substring(7,9) )) 
													{	
														return true
													} 
												}
											}
											alert ("Le Champ '"+ psLibele +"' n'est pas correct.");
											psObjet.focus();
											return false
									}

								// Test de la Date
								if ( psOption == "date")
									{
										if (Trim(vsValue) == '') return true;
										
										if ((vsValue.length == 10)||(vsValue.length == 8))
											{
											if((vsValue.substring(2,3)=="/")&(vsValue.substring(5,6)=="/"))
												{
												if (isValid ( vsValue.substring(0,2) , vsValue.substring(3,5) , vsValue.substring(7,9) )) 
													{	
														return true
													} 
												}
											}
											alert ("Le Champ '"+ psLibele +"' n'est pas correct.");
											psObjet.focus();
											return false
									}


									
										if ( psOption == "pseudo")
									{
										vbValide = true;
										if (psObjet.value.length <2 || psObjet.value.charAt(0) == ' ')
											vbValide = false;
											vsPseudo = psObjet.value.toLowerCase();
										i = 0;
										
										vsCorrect = new String(" _-.,\'àáâãäåæèéêëìíîïòóôõöøœùúûüýÿç¢ñ");
										while(i <psObjet.value.length && vbValide)
										{
											c= vsPseudo.charAt(i);
											if(!((c >= 'a' && c<='z') || (c >= '0' && c <= '9') || vsCorrect.indexOf(c) != -1 ))
												vbValide = false;
											
											i++;
										}
											
										if (!vbValide) 
										{
											alert ("Votre "+ psLibele +" n'est pas correct.\nIl doit faire au moins 2 caractères,\nil ne doit pas commencer par un espace,\nIl ne peut contenir que des lettres, des chiffres et les caractères suivants :\nespace, souligné, tiret, point, virgule et apostrophe.");
											psObjet.focus();
											return false;
										} 
										return true;
								}
									
									if ( psOption == "pwd")
									{
										vbValide = true;
										if (psObjet.value.length <5)
											vbValide = false;
											
										i = 0;
										vsCorrect = new String("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
										while(i < psObjet.value.length && vbValide)
										{
											if(vsCorrect.indexOf(psObjet.value.charAt(i)) == -1)
												vbValide = false;
												
											i++;
										}
											
										if (!vbValide) 
										{
											alert ("Votre "+ psLibele +" n'est pas correct.\nIl doit faire au moins 5 caractères,\net seuls les lettres et les chiffres sont autorisés.");
											psObjet.focus();
											return false;
										} 
										return true;
								}

							 // Test normal Champ non nul
							if  (StringTrim(vsValue)=='')
								{
									alert ("Le Champ '"+ psLibele +"' n'est pas correct.");
									psObjet.focus();
									return false
								}
							return true
			}
			
			
			
			


// Monte la valeur sélectionnée d'un select d'un crant

		function SelectUp(pSelect)
		{
		var i, optTemp, servTemp;
		//on ne passe pas par le premier car il est déjà au plus haut
		for(i=1; i< pSelect.options.length; i++)
			if(pSelect.options[i].selected)
			{
				optTemp =pSelect.options[i-1];
				pSelect.options[i-1] = new Option(pSelect.options[i].text, pSelect.options[i].value, false, pSelect.options[i].selected);
				pSelect.options[i] = optTemp;
			}
		}


// Descend la valeur sélectionnée  d'un select d'un crant

		function SelectDown(pSelect)
		{	
			var i, optTemp, servTemp;
			//on ne passe pas par le dernier car il est déjà au plus bas
			for(i=pSelect.options.length - 1; i>= 0 ; i--)
				if(pSelect.options[i].selected)
				{
					optTemp = pSelect.options[i+1];
					pSelect.options[i+1] = new Option(pSelect.options[i].text, pSelect.options[i].value, false, pSelect.options[i].selected);
					pSelect.options[i] = optTemp;
				}
		}		


// Sélectionne toutes les lignes d'un select

		function SelectAllSelect(pSelect) 
		{
			for(var i=0;i<pSelect.options.length;i++)
				pSelect.options[i].selected=true;
		}

// Sélectionne toutes les lignes de tous les selects d'un formulaire

		function SelectAllSelectForm (psForm)
		{
			var viLen, vsForm;
			vsForm = eval('document.' + psForm);
			viLen = vsForm.elements.length;
			for (i = 0; i < viLen; i++)
			{
				if(vsForm.elements[i].nodeName == 'SELECT')
					{SelectAllSelect(eval('document.' + psForm + '.' + document.frm.elements[i].name));}
			}
		}	

// DéSélectionne toutes les lignes d'un select

		function SelectAllUnSelect(pSelect) 
		{
			for(var i=0;i<pSelect.options.length;i++)
				pSelect.options[i].selected=false;
		}

// Renvoi le nombre d'élement sélectionné dans un select

		function GetNumberSelected(pSelect)
		{
		var vi_Nbselect=0;
			for(i=pSelect.options.length - 1; i>= 0 ; i--)
			{ 
					// Calcul du nombre de ligne sélectionné
				if(pSelect.options[i].selected)vi_Nbselect++;
			}
		return vi_Nbselect;
		}


// Renvoi true si la value passée est dans le select
		function ValueIsInSelect(pSelect, pValue)
		{
			for(i=pSelect.options.length - 1; i>= 0 ; i--)
			{ 
				if (pSelect.options[i].value == pValue) return true;
			}
		return false;
		}




// Renvoi la valeur du dernier élement sélectionné
// renvoi "null" si aucune valeur n'est sélectionnée

		function GetLastSelected(pSelect)
		{
		var vResult="null";
			for(i=pSelect.options.length - 1; i>= 0 ; i--)
			{ 
					// Calcul du nombre de ligne sélectionné
				if(pSelect.options[i].selected) vResult=pSelect.options[i].value;
			}
		return vResult;
		}
			

// Supprime les options du select pour lesquels 
// la valeur est psValue 

		function SupprimerValueSelect(pSelect,psValue)
		{
		if (pSelect.options[0].value!='') 
			{
			j=0;
			while(j<pSelect.options.length)
				{
				if(pSelect.options[j].value == psValue )
					{
						pSelect.options[j]=null;
					}
				else j++;
				}
			}
		}
		

// Supprime les options sélectionnées du select
//  sans aquitemment

		function SupprimerSelectNoAquit(pSelect)
		{
		if (pSelect.options[0].value!='') 
			{
			j=0;
			while(j<pSelect.options.length)
				{
				if(pSelect.options[j].selected)
					{
						pSelect.options[j]=null;
					}
				else j++;
				}
			}
		}
		

// Copie les sélection du select From vers le select To
// + supprime les selection de From si Bit SuppFrom = 1

		function CopieSelectToSelect(pSelectFrom, pSelectTo, pbSuppFrom )
		{
		var i,newMot, viTemp;

		if (pSelectFrom.length) 
			{
				for(i=0 ; i < pSelectFrom.options.length ; i++)
				{
					if(pSelectFrom.options[i].selected)
					{
						newMot = new Option(pSelectFrom.options[i].text,pSelectFrom.options[i].value,false,false);
						pSelectTo.options[pSelectTo.length] = newMot;
					}
				}
				if (pbSuppFrom==1) SupprimerSelectNoAquit(pSelectFrom);
			}
		}


// Ajoute une option au select
// avec les params : valeur et texte de l'option

		function AddToSelect(pSelectTo, pValue, pText )
		{
		var newMot;
			
		newMot = new Option(pText,pValue,false,false);
		pSelectTo.options[pSelectTo.length] = newMot;
					
		}



		function SetValueFisrtSelectAndDesactivOption(pSelect, pValue)
			{	
				for(var i=0;i<pSelect.options.length;i++)
					{
						if(pSelect.options[i].selected)
							{
							pSelect.options[i].selected= true;
							pSelect.options[i].value = pValue;
							return true
							}	
					}
			}

		function SelectSetOptionByValue(pSelect, pValue)
			{	
				for(var i=0;i<pSelect.options.length;i++)
					{
						if( pSelect.options[i].value == pValue )
							{
								pSelect.options[i].selected= true;
							}	
					}
			}




		function GetOptionFirstSelectedValueIndex(pSelect,piIndex)
			{	
			var vsTempValue
			var vTabValue = new Array();			
			var viSizeTab
			
			for(var i=0;i<pSelect.options.length; i++)
				{
					if(pSelect.options[i].selected)
					{
					vsTempValue = pSelect.options[i].value;
					vTabValue = vsTempValue.split(";");
					viSizeTab = vTabValue.length;
						
					if (piIndex > viSizeTab) 
						return "";
					else
							return vTabValue[piIndex-1];
					}
				}
			}
		


		function GetOptionIndexForValueIndex(pSelect ,piOptionIndex ,piValueIndex)
			{	
			var vsTempValue
			var vTabValue = new Array();			
			var viSizeTab
			
			if (piOptionIndex < pSelect.options.length)
				{
					vsTempValue = pSelect.options[piOptionIndex].value;
					vTabValue = vsTempValue.split(";");
					viSizeTab = vTabValue.length;
						
					if (piValueIndex > viSizeTab) 
						return "";
					else
							return vTabValue[piValueIndex-1];
				}	
			}
			






















			
		
	// Formate une chaine de caractère en suppriment les espaces , 
	// sépare les couple de chiffres par des espaces.			
	
	function FormatTel (psTel)
	{
		var vsTemp,vsTemp2, viLen, viLen2, i, vsCarac;
		vsTemp = ""; 
	  vsTemp2 = ""; 
	  viLen = psTel.length; 
		for (i=0; i <= viLen ; i++) 
			{
				vsCarac = psTel.charAt(i); 
				//alert(vsCarac);
			 if(! isNaN(vsCarac) && vsCarac != " " )	vsTemp = vsTemp + vsCarac;
			}
		viLen2 = vsTemp.length; 
		for (i=0; i <= viLen2 ; i++) 
			{
				vsCarac = vsTemp.charAt(viLen2 - i); 
				if (i % 2 == 0 &&((viLen2-i)>1) )  vsCarac= vsCarac + ' ';
				//alert(vsCarac);
			 	vsTemp2 = vsTemp2 + vsCarac;
			}
		//alert(vsTemp2);
		viLen2 = vsTemp2.length; 
		vsTemp= "";
		for (i=0; i <= viLen2 ; i++) 
			{
				vsCarac = vsTemp2.charAt(viLen2 - i); 
				vsTemp = vsTemp + vsCarac;
			}
		return  vsTemp; 
	}
		
			
  
  // FONCTIONS GENERIQUES DE CALCUL DE DATES
  function isValid(dd, mm, yyyy) {
    if (dd < 1 || dd > 31 || mm < 1 || mm > 12) return false
    if (mm == 2) {
      if (dd == 30 || dd == 31) return false
      if (dd == 29) return ((yyyy % 4 == 0 && yyyy % 100 != 0) || yyyy % 400 == 0)
    }
    else if (dd == 31)
      return !( mm == 4 || mm == 6 || mm == 9 || mm == 11 )
    return true
  }

  //input is date in form mmddyyyy; output is julian day number & fraction
  function toJul(dd, mm, yyyy) {
    if ( mm==1 || mm==2 ) {
      yyyyp = yyyy - 1;
      mmp = mm + 12;
    } else {
      yyyyp=yyyy;
      mmp=mm;
    }

    yyyymmdd=(yyyy*10000)+(mm*100)+dd;
    if(yyyymmdd >=15821015 ) {
      a = Math.floor(yyyyp/100);
      b = 2 - a + Math.floor(a/4); }
    else b=0;

    t2 = 365.25 * yyyyp;
    if(yyyyp<0)
      t2 = t2 - 0.75;

    c = Math.floor(t2);
    t1 = 30.6001 * (mmp + 1);
    d = Math.floor(t1);
    return b+c+d+dd+1720994.5;
  }
			
			
			
			