//////////////////////////////////////////////////////////
// Type de champs : Téléphone
// Description: 1. Force la saisie d'un caractère numérique
//		2. Formate automatiquement au Format français XX.XX.XX.XX.XX 		 	
// Sur evenement: OnKeyPress
// Paramètres d'entrée:
// Valeur retournée : Faux si la touche préssée n'est pas un entier
//////////////////////////////////////////////////////////
/*function ETOverifTel(obj) {
if (event.keyCode < 48 || event.keyCode > 57)
	event.returnValue = false;
else ETOverifTel2(obj);
}*/

function ETOverifTel(obj) {
if (event.keyCode < 48 || event.keyCode > 57)
	event.returnValue = false;
else event.returnValue = true;
}

function ETOverifTel2(obj) {
var sep = "."
var strDateArray
var strTemp
var strToAdd
	if (event.keyCode == 8) return true;
	strTemp = obj.value;
	if (strTemp.indexOf(sep) != -1) {
		strDateArray = strTemp.split(sep);
		if (strDateArray.length > 1) {
			strTemp = "";
			for (i=0;i<strDateArray.length-1;i++) {
				if (strDateArray[i].length == 0) strToAdd = "00";
				else if (strDateArray[i].length == 1) strToAdd =  "0" + strDateArray[i];
				else strToAdd = strDateArray[i];
				if (strTemp.length < obj.maxLength) strTemp = strTemp + strToAdd;
				if ((strTemp.length > 0) && (strToAdd.length > 0) && (strTemp.length < obj.maxLength)) strTemp = strTemp + sep				
			}
			strTemp = strTemp + strDateArray[i];
			obj.value = strTemp;
			if ((strDateArray[strDateArray.length-1].length == 2) && (obj.value.length < obj.maxLength)) obj.value = obj.value + sep;
		}
	}
	else {
		if (strTemp.length == 2) obj.value = obj.value + sep;
	}
	return true;
}


//////////////////////////////////////////////////////////
// Type de champs : tous champs de formalaire
// Description:  Controle si un champ est vide
// Paramètres d'entrée: obj ==> objet représentant le champ du formalaire
//			msg ==> message d'erreur 
// Valeur retournée : 	Vrai si le champs est vide
//			Faux si le champs n'est pas vide
//////////////////////////////////////////////////////////
function ETOIsEmpty(obj,msg)
{
if ((obj.value == "") || (obj.length==0))
	{
		alert(msg);
		obj.focus();
		return true;
	}
return false;
}


//////////////////////////////////////////////////////////
// Type de champs : Champs texte (type numérique)
// Description:  Force la saisie d'un caractère numérique 	
// Sur evenement: OnKeyPress
// Paramètres d'entrée:
// Valeur retournée : Faux si la touche préssée n'est pas un entier
//////////////////////////////////////////////////////////
function ETOPressKeyIsNumeric()
{
if (event.keyCode < 48 || event.keyCode > 57)
	event.returnValue = false;
else return true;
}


//////////////////////////////////////////////////////////
// Type de champs : CheckBox
// Description:  Controle si une CheckBox est cliquée 	
// Paramètres d'entrée: obj ==> objet de type checkbox
// Valeur retournée : 	Vrai si la chekbox est cliquée
//			Faux si la chekbox n'est pas cliquée
//////////////////////////////////////////////////////////
function ETOCheckBoxIsChecked(obj)
{
	if (obj.checked) return true;
	return false;
}

//////////////////////////////////////////////////////////
// Type de champs : CheckBox
// Description:  Controle si au moins une des 2 CheckBox est cliquées 	
// Paramètres d'entrée: obj ==> objet de type checkbox
// Valeur retournée : 	Vrai si une chekbox cliquée
//			Faux si aucune des deux chekbox est cliquée
//////////////////////////////////////////////////////////
function ETO2CheckBoxNoChecked(obj1,obj2,msg)
{
	if (obj1.checked || obj2.checked)
		return false;
	else
	{	
		alert(msg);
		return true;
	}	
}



//////////////////////////////////////////////////////////
// Type de champs : Champs texte (type e-mail)
// Description: 1. Vérifie la syntaxe d'un e-mail
// Paramètres d'entrée: obj ==> objet represemtant un champ de type texte
// Valeur retournée : 	Faux si la syntaxe n'est pas correcte
// 			Vrai si la syntaxe est correcte
//////////////////////////////////////////////////////////
function ETOVerifSyntaxEmail(obj,msg)
{
var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	if (!re.test(obj.value)) 
	{
	alert(msg);
	obj.focus()
	return false;
	}
return true;
}


//////////////////////////////////////////////////////////
// Type de champs : Date
// Description: 1. Force la saisie d'un caractère numérique
//		2. Formate automatiquement au Format français XX/XX/XXXX		 	
// Sur evenement: OnKeyPress
// Paramètres d'entrée:
// Valeur retournée : Faux si la touche préssée n'est pas un entier
//////////////////////////////////////////////////////////
function ETOverifDate(obj) {
if (event.keyCode < 45 || event.keyCode > 57)
	event.returnValue = false;
else ETOverifDate2(obj);
}

function ETOverifDate2(obj) {
var sep = "/"
var strDateArray
var strTemp
var strToAdd
       if (event.keyCode == 8) return true;
       strTemp = obj.value;
       if (strTemp.indexOf(sep) != -1) {
              strDateArray = strTemp.split(sep);
              if (strDateArray.length > 1) {
                    strTemp = "";
                    for (i=0;i<strDateArray.length-1;i++) {
                           if (strDateArray[i].length == 0) strToAdd = "00";
                           else if (strDateArray[i].length == 1) strToAdd =  "0" + strDateArray[i];
                           else strToAdd = strDateArray[i];
                           if (strTemp.length < obj.maxLength) strTemp = strTemp + strToAdd;
                           if ((i<2) && (strTemp.length > 0) && (strToAdd.length > 0) && (strTemp.length < obj.maxLength)) strTemp = strTemp + sep                     
                    }
                    strTemp = strTemp + strDateArray[i];
                    obj.value = strTemp;
                    if ((strDateArray.length<3)&&(strDateArray[strDateArray.length-1].length == 2) && (obj.value.length < obj.maxLength)) obj.value = obj.value + sep;
              }
       }
       else {
              if (strTemp.length == 2) obj.value = obj.value + sep;
              else
                    if (strTemp.length>2 && strTemp.length<5)
                           obj.value = obj.value.substr(0,2) + sep + obj.value.substr(2);
                    else if (strTemp.length>4) obj.value = obj.value.substr(0,2) + sep + obj.value.substr(2,2) + sep + obj.value.substr(4);
       }
}

function ETOMiseEnMajuscule(obj){
	if ((event.keyCode >= 97 && event.keyCode <= 122)){
		event.keyCode = event.keyCode - 32;
	}
	
}

function ETOverifDate3(obj) {
var sep = "/"
var strDateArray
var strTemp
var strToAdd
       if (event.keyCode == 8) return true;
       strTemp = obj.value;
       if (strTemp.indexOf(sep) != -1) {
              strDateArray = strTemp.split(sep);
              if (strDateArray.length > 1) {
                    strTemp = "";
                    for (i=0;i<strDateArray.length-1;i++) {
                           if (strDateArray[i].length == 0) strToAdd = "00";
                           else if (strDateArray[i].length == 1) strToAdd =  "0" + strDateArray[i];
                           else strToAdd = strDateArray[i];
                           if (strTemp.length < obj.maxLength) strTemp = strTemp + strToAdd;
                           if ((i<2) && (strTemp.length > 0) && (strToAdd.length > 0) && (strTemp.length < obj.maxLength)) strTemp = strTemp + sep                     
                    }
                    strTemp = strTemp + strDateArray[i];
                    obj.value = strTemp;
                    if ((strDateArray.length<3)&&(strDateArray[strDateArray.length-1].length == 2) && (obj.value.length < obj.maxLength)) obj.value = obj.value + sep;
              }
       }
       else {
              if (strTemp.length == 2) {
              	if (parseInt(strTemp) <= 31) 
              		obj.value = obj.value + sep;
              	else {alert('saisie incorrecte du jour'); event.returnValue = false;}
              	}
              else
                    if (strTemp.length>2 && strTemp.length<5)
                           obj.value = obj.value.substr(0,2) + sep + obj.value.substr(2);
                    else if (strTemp.length>4) obj.value = obj.value.substr(0,2) + sep + obj.value.substr(2,2) + sep + obj.value.substr(4);
       }
}

/*Vérification de la date : n'autorise pas les dates supérieures à la date du jour*/

function chkdate(objName) {

var strDate;
var d;
var strDateDuJour;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var sIntDay;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
var ListeMois=new Array(12);
	strMonthArray[0] = "01";strMonthArray[1] = "02";strMonthArray[2] = "03";strMonthArray[3] = "04";
	strMonthArray[4] = "05";strMonthArray[5] = "06";strMonthArray[6] = "07";strMonthArray[7] = "08";
	strMonthArray[8] = "09";strMonthArray[9] = "10";strMonthArray[10] = "11";strMonthArray[11] = "12";
	strDate = datefield.value;
	if (strDate.length < 1) return true;
	else if (strDate.length < 6) {
		alert("Format JJ/MM/AAAA obligatoire");
		objName.focus();
		err = 4;
		return false;	
	}	
	
	
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
				if ((isNaN(strDay) || isNaN(strMonth) || isNaN(strYear))) return false;
			}
			booFound = true;
		}
	}
	
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if (strYear.length == 1) {
		strYear = "0" + strYear;
	}
	if (strYear.length == 2) {
		d = new Date();
		strDateDuJour = String(d.getFullYear());
		strDateDuJour = strDateDuJour.substr(2,2);
		if (strYear <= strDateDuJour ) strYear = '20' + strYear;else strYear = '19' + strYear;
	}
	if (strYear.length == 3) {
		strYear = '0' + strYear;
	}	
	
	d = new Date();
	intYear = parseInt(strYear, 10);	

	Dat=new Date(strYear, strMonth - 1, strDay) ;   	

	if (Dat>d) {
		alert("Date supérieure à la date du jour");
		objName.focus();
		err = 4;
		return false;	
	}
	
	
	diff = d-Dat    //difference en millisecondes
	mtg = new String(diff/86400000)    //calculate days and convert to string
	point=mtg.indexOf(".")    //find the decimal point
	days=mtg.substring(0,point)    //get just the whole days
		
	if (days > 366) {
		alert("Date trop ancienne (plus d un an)");
		objName.focus();
		err = 4;
		return false;	
	}
	
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}

	
	if (isNaN(intYear)) {
		alert("L annee est incorrecte");
		objName.focus();
		err = 4;
		return false;
	}
	

	
	if (intMonth>12 || intMonth<1) {
		alert("Le mois est incorrect");
		objName.focus();
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		alert("Le jour est incorrect");
		objName.focus();
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		alert("Le jour est incorrect");
		objName.focus();
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			alert("Le jour est incorrect");
			objName.focus();
			return false;
		}
		
		if (Math.floor(intYear/4) == (intYear/4)) {
			if (intday > 29) {
				err = 9;
				alert("Le jour est incorrect");
				objName.focus();
				return false;
			}
		}
		else {
			if (intday > 28) {
				err = 10;
				alert("Le jour est incorrect");
				objName.focus();
				return false;
			}
		}
		
	}
	
	
	
	if (intday < 10) sIntDay = "0" + intday;else sIntDay = intday;
	datefield.value = sIntDay + "/" + strMonthArray[intMonth-1] + "/" + strYear;

	return true;
}

/*Vérification de la date : autorise les dates supérieures à la date du jour*/
function chkdate2(objName) {

var strDate;
var d;
var strDateDuJour;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var sIntDay;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
var ListeMois=new Array(12);
	strMonthArray[0] = "01";strMonthArray[1] = "02";strMonthArray[2] = "03";strMonthArray[3] = "04";
	strMonthArray[4] = "05";strMonthArray[5] = "06";strMonthArray[6] = "07";strMonthArray[7] = "08";
	strMonthArray[8] = "09";strMonthArray[9] = "10";strMonthArray[10] = "11";strMonthArray[11] = "12";
	strDate = datefield.value;
	if (strDate.length < 1) return true;
	else if (strDate.length < 6) {
		alert("Format JJ/MM/AAAA obligatoire!");
		objName.focus();
		err = 4;
		return false;	
	}	
	
	
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
				if ((isNaN(strDay) || isNaN(strMonth) || isNaN(strYear))) return false;
			}
			booFound = true;
		}
	}
	
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if (strYear.length == 1) {
		strYear = "0" + strYear;
	}
	if (strYear.length == 2) {
		d = new Date();
		strDateDuJour = String(d.getFullYear());
		strDateDuJour = strDateDuJour.substr(2,2);
		if (strYear <= strDateDuJour ) strYear = '20' + strYear;else strYear = '19' + strYear;
	}
	if (strYear.length == 3) {
		strYear = '0' + strYear
	}	
	
	d = new Date();
	intYear = parseInt(strYear, 10);	
	Dat=new Date(strYear, strMonth - 1, strDay) ;   	

	/*Dat=new Date(parseInt(strYear), parseInt(strMonth) - 1 , parseInt(strDay) , 00, 00, 00)    	

	if (Dat>d) {
		alert("Date supérieure à la date du jour");
		objName.focus();
		err = 4;
		return false;	
	}*/
	
	diff = d-Dat    //difference en millisecondes
	mtg = new String(diff/86400000)    //calculate days and convert to string
	point=mtg.indexOf(".")    //find the decimal point
	days=mtg.substring(0,point)    //get just the whole days
		
	if (days > 730) {
		alert("Date trop ancienne (plus de deux ans)");
		objName.focus();
		err = 4;
		return false;	
	}
	
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
		}
	}

	
	if (isNaN(intYear)) {
		alert("L annee est incorrecte");
		objName.focus();
		err = 4;
		return false;
	}
	

	
	if (intMonth>12 || intMonth<1) {
		alert("Le mois est incorrect");
		objName.focus();
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		alert("Le jour est incorrect");
		objName.focus();
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		alert("Le jour est incorrect");
		objName.focus();
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			alert("Le jour est incorrect");
			objName.focus();
			return false;
		}
		
		if (Math.floor(intYear/4) == (intYear/4)) {
			if (intday > 29) {
				err = 9;
				alert("Le jour est incorrect");
				objName.focus();
				return false;
			}
		}
		else {
			if (intday > 28) {
				err = 10;
				alert("Le jour est incorrect");
				objName.focus();
				return false;
			}
		}
		
	}
	
	
	
	if (intday < 10) sIntDay = "0" + intday;else sIntDay = intday;
	datefield.value = sIntDay + "/" + strMonthArray[intMonth-1] + "/" + strYear;

	return true;
}


//////////////////////////////////////////////////////////
// Description: 1. Ouvre pop-up de confimation une fois qu'un traitement est terminé
//		2. Redirige vers une page 
// Paramètres d'entrée: pURL ==> URL de redirection
//			pURL2==> URL de la pop-up d econfirmation
//			pWIDTH==> Largeur de la pop-up
//			pHEIGHT==> Hauteur de la pop-up 
//////////////////////////////////////////////////////////
function openPopUp(pURL,pWIDTH,pHEIGHT)
{
window.open(pURL,'Ppup','width=' + pWIDTH + ',height=' + pHEIGHT + ',toolbar=no,menubar=no,scrollbars=no,resizable=no,status=no,directories=no,top=250,left=250');
}