
var errfound=false;
var k_intOk=0;
var k_intLngInvalide=1;
var k_intSaisieOblg=2;
var k_intCarNonAutorise=3;
var k_intStructureEmailInvalide=4;
var k_intNumInvalide=5;
var k_intValNonNum=6;
var k_intStructureDateInvalide=7;
var k_intDateInvalide=8;
var k_intSelectionOblg=9;
var k_intQuestion=10;
var k_intDateType=12;
var k_intChampSeq=13;
var k_intChampPasSlash=14;
var k_intNonCoche=15;
var k_intValNonFloat=16

var k_strlng_Fr="Fr";
var k_strlng_En="En";

function AffErr (CodeLangue,CodeErreur) {
	var g_strMesgErr;
	switch (CodeLangue) {
		case "Fr" :
			switch (CodeErreur) {
				case 1 :
					g_strMesgErr="La longueur de champ est invalide";
					break;
				case 2 :
					g_strMesgErr="La saisie de ce champ est obligatoire";
					break;
				case 3 :
					g_strMesgErr="Caractère(s) non autorisé(s)";
					break;
				case 4 :
					g_strMesgErr="Structure invalide (ex : j.dupondt@domain.fr)";
					break;
				case 5 :
					g_strMesgErr="Numéro invalide";
					break;
				case 6 :
					g_strMesgErr="Valeur non numérique";
					break;
				case 7 :
					g_strMesgErr="Structure invalide (ex : 01/01/1998)";
					break;
				case 8 :
					g_strMesgErr="Date invalide";
					break;
				case 9 :
					g_strMesgErr="Sélectionnez un élément dans la liste";
					break;			
				case 10 :
					g_strMesgErr="En êtes-vous sûr ?"
					break;							
				case 11 :
					g_strMesgErr="La date de debut ne peut être supérieure à la date de fin";
					break;
				case 12 :
					g_strMesgErr="Le filtre ne s'applique que sur un type de date";
					break;							
				case 13 :
					g_strMesgErr="Les champs doivent être saisis de manière séquentielle";
					break;
				case 14 : 
					g_strMesgErr="Le caractère '\\' est interdit";
					break;
				case 15 : 
					g_strMesgErr="Tous les boutons radios ne sont pas sélectionnés";
					break;					
				default :
					g_strMesgErr="Erreur Générale";
					break;
				case 16 :				
					g_strMesgErr="Valeur non numérique (mettre une virgule pour les nombres décimaux ex : 12,34)";
					break;

				}
			break;
		default :
			switch (CodeErreur) {
				case 1 :
					g_strMesgErr="Invalid length";
					break;
				case 2 :
					g_strMesgErr="data entry required";
					break;					
				case 3 :
					g_strMesgErr="characters forbidden";
					break;
				case 4 :
					g_strMesgErr="Invalid email structure (ex : j.dupont@domain.fr)";
					break;
				case 5 :
					g_strMesgErr="Invalid number";
					break;
				case 6 :
					g_strMesgErr="Numeric only";
					break;
				case 7 :
					g_strMesgErr="Invalid date structure (ex : 01/01/1998)";
					break;
				case 8 :
					g_strMesgErr="Invalide date";
					break;
				case 9 :
					g_strMesgErr="Select an element in the list";
					break;						
				case 10 :
					g_strMesgErr="Are you sure ?"
					break;
				case 11 :
					g_strMesgErr="The date of debut can not be superior to the date of the end";
					break;	
				case 12 :
					g_strMesgErr="The filter applies only to a type of date";
					break;							
				case 13 :
					g_strMesgErr="Fields must be seized in a sequential way";
					break;
				case 14 : 
					g_strMesgErr="Character ' \\ ' is forbidden";
					break;
				default :
					g_strMesgErr="General error";
					break;
				case 15 : 
					g_strMesgErr="All radio buttons are not selected";
					break;
				case 16 :				
					g_strMesgErr="Valeur non numérique (mettre une virgule pour les nombres décimaux ex : 12,34)";
					break;

			}
			break;
	}
	return g_strMesgErr;
}
function ValidLength(a_strChaine, a_intLongueurSouhaitee) {
	if (a_strChaine.length != a_intLongueurSouhaitee)
		return k_intLngInvalide;
	
	return k_intOk;
}
function ValidLengthMinMax(a_strChaine, a_intLongueurMin, a_intLongueurMax) {
	if ((a_strChaine.length<a_intLongueurMin) || (a_strChaine.length>a_intLongueurMax))
		return k_intLngInvalide;
	return k_intOk;
}
function ValidLengthDiff(a_strChaine, a_intLongueurOne, a_intLongueurTwo) {
	if ((a_strChaine.length!=a_intLongueurOne) && (a_strChaine.length!=a_intLongueurTwo))
		return k_intLngInvalide;
	return k_intOk;
}
function ValidLenghtForBoth(a_strChaineOne,a_strChaineTwo)
{
	if ( (a_strChaineOne.length==0)&&(a_strChaineTwo==0) )
		return k_intSaisieOblg;
	
	if ((a_strChaineOne.length > 0)&&(a_strChaineTwo > 0))
		return k_intFiltreType;	
	return k_intOk;
}
function Valid(a_strChaine)
{
	if (a_strChaine.length==0)
		return k_intSaisieOblg;
	return k_intOk;
}
function ValidSelection (a_strListe)
{
	if (a_strListe.selectedIndex<=0)
		return k_intSelectionOblg;
	return k_intOk;
}
function ValidSelectionItem(a_strItemSelected,a_strItem)
{
	if ( a_strItemSelected[a_strItemSelected.selectedIndex].value==a_strItem)
		return k_intOk;
	return k_intNo;
}
function ValidSelectObligatoire (a_strListe)
{
	if (a_strListe.value=="False")
		return k_intSelectionImpossible;
	return k_intOk;
}
function ValidMinSelection (a_strListe)
{
	if (a_strListe.length<1)
		return k_intUnAttributMin;
	return k_intOk;
}
function ValidNum(a_strChaine) 
{
	if (a_strChaine.length>0) {
		for (var c=0;c<a_strChaine.length;c++) 
			if ((a_strChaine.charAt(c)<'0') || (a_strChaine.charAt(c)>'9'))
				return k_intValNonNum;
	}
	else
		return k_intSaisieOblg;
		
	return k_intOk;
}

function ValidFloatNum(a_strChaine) 
{
	if (a_strChaine.length>0) {
		for (var c=0;c<a_strChaine.length;c++) 
			if ( (a_strChaine.charAt(c)<'0' ||
a_strChaine.charAt(c)>'9') && a_strChaine.charAt(c) != ',' )
				return k_intValNonFloat;
	}
	else
		return k_intSaisieOblg;
		
	return k_intOk;
}

function Error (a_element,a_strMessage,Check)
{
	if (errfound) return;
	window.alert (a_strMessage);
	if (Check==1) {
		a_element.select ();
		a_element.focus();
	}
	errfound=true;
}


function IsDate (a_strDate,a_strCodelangue) 
{
	var jour=0;
	var mois=0;
	var annee=0;
	var Dsiecle=0;
	var Fsiecle=0;
	var result=0;
	var arrondit=0;
	var DateCourante=new Date();
	var JourCourant=DateCourante.getDate();
	var MoisCourant=1+DateCourante.getMonth();
	var AnneeCourante=1900 + DateCourante.getYear();	
	for (var i = 0; (i<a_strDate.length); i++)
		if ( ((a_strDate.charAt(i)<"0") || (a_strDate.charAt(i)>"9")) && a_strDate.charAt(i)!="/")
			return k_intStructureDateInvalide;
	if ( (ValidLength(a_strDate,10)!=k_intOk) || (a_strDate.charAt(2)!='/') || (a_strDate.charAt(5)!='/'))
		return k_intStructureDateInvalide;

	switch (a_strCodelangue) {
		case "Fr" :
			jour=parseInt(a_strDate.substring(0,2),10);
			mois=parseInt(a_strDate.substring(3,5),10);
			break;
		default :
			mois=parseInt(a_strDate.substring(0,2),10);
			jour=parseInt(a_strDate.substring(3,5),10);
			break;
	}
	annee=parseInt(a_strDate.substring(6,10),10);
	if ( (jour<1) || (jour>31) || (mois<1) || (mois>12) )
		return k_intDateInvalide;
	if ( ( (mois==4) || (mois==6) || (mois==9) || (mois==11)) && (jour==31) )
		return k_intDateInvalide;
	if ( (mois==2) && (jour>29) )
		return k_intDateInvalide;
	if ( (mois==2) && (jour==29) ) {
		Dsiecle=parseInt(a_strDate.substring(6,8));
		Fsiecle=parseInt(a_strDate.substring(8,10));		
		if (Fsiecle==0)
			result=(Dsiecle/4);
		else
			result=(annee/4);
		arrondit = Math.round(result);
		if ( ((result-arrondit)!=0) && ((result-arrondit)!=1))
			return k_intDateInvalide;
	}
	return k_intOk;
}

function ValidEmail (a_strEmail) {
	var FindCar;
	var PtrStrOrigine;
	var g_intPositionAt=0;
	var g_intPositionLastAt=0;
	var g_intPositionLastPoint=0;
	var g_strCarAutorise="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@.-_";
	if (a_strEmail.length < 5 )
		return k_intLngInvalide;
	for (FindCar=0, ptrStrOrigine = 0; (ptrStrOrigine < a_strEmail.length) && (FindCar!=-1) ;ptrStrOrigine++)
		FindCar=g_strCarAutorise.indexOf(a_strEmail.charAt(ptrStrOrigine));
	if (FindCar==-1)
		return k_intCarNonAutorise;
	g_intPositionAt = a_strEmail.indexOf("@");
	g_intPositionLastAt = a_strEmail.lastIndexOf("@");
	if ( (g_intPositionAt==-1) || (g_intPositionLastAt!=g_intPositionAt) || (g_intPositionAt<2) )
		return k_intStructureEmailInvalide;

	g_intPositionLastPoint = a_strEmail.lastIndexOf(".");
	if ( (g_intPositionLastPoint==-1) || ((a_strEmail.length - g_intPositionLastPoint)>4))
		return k_intStructureEmailInvalide;

	if (g_intPositionLastPoint<g_intPositionAt+2)
		return k_intStructureEmailInvalide;
	
	return k_intOk;
}


function display_day(strLangue,strType)
{
	var date=new Date();
	var monthName;
	var dayName;
	var arDate;
	if (strLangue==k_strlng_Fr)
	{
		dayName=new Array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
		switch (strType)
		{
			case 'full' :
				monthName= new Array('Janvier', 'Février', 'Mars', 'Avril', 'Mai','Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
				document.write(dayName[date.getDay()] + " " + date.getDate() + " " + monthName[date.getMonth()] + " " + date.getFullYear());
				break;
			case 'medium' :
				document.write(dayName[date.getDay()] + " " + date.getDate() + "/" + (date.getMonth()+1) + "/" + date.getFullYear());
				break;
		}
	}
	else
	{
	    dayName=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
		switch (strType)
		{
			case 'full' :
				monthName= new Array('January', 'February', 'March', 'April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December');
				arDate = new Array("0th","1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st");
				document.write(dayName[date.getDay()] + ", " + monthName[date.getMonth()] + " " + arDate[date.getDate()] + ", " + date.getFullYear());
				break;
			case 'medium' :
				document.write(dayName[date.getDay()] + " " + (date.getMonth()+1) + "/" +  date.getDate() + "/" + date.getFullYear());
				break;
		}

	}
}

function servicepopup(strUrl,strId)
{
	newwin=window.open(strUrl,strId,"toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes,directories=no,width=750,height=500");
}		 

function popup(strUrl,strId)
{
	newwin=window.open(strUrl,strId,"toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,directories=no,width=650,height=400");
}		 

function popupWithSize(strUrl,strId, width, height)
{
	newwin=window.open(strUrl,strId,"toolbar=no,menubar=no,location=no,status=no,scrollbars=yes,resizable=yes,directories=no,width=" + width + ",height=" + height );
}

<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->

