/*
 *
 */

// Fonction TestChampVide('chaine de caractere') => Test si le champ est vide
function validForms(tabErreurs) {
	var bSubmit = false;
	if (tabErreurs.length > 0) {
		var strAlert = '';
		for (var i=0; i<tabErreurs.length; i++) {
			if (i > 0) {
				strAlert += '\n\r';
			}
			strAlert += tabErreurs[i];
		}
		alert(strAlert);
		bSubmit = false;
	} else {
		bSubmit = true;
	}
	return bSubmit;
}

// Initialise les champ lors du 'onfocus' ou du 'onblur'
function initField( objField, fieldValue) {
	if (objField.value == fieldValue) {
		objField.value = '';
	} else if (objField.value == '') {
		objField.value = fieldValue;
	}
}

// Fonction TestChampVide('chaine de caractere') => Test si le champ est vide
function IsEmpty(oChamp) {
	var bRetour = true;
	if (oChamp.value != '') bRetour = false;
	return bRetour;
}

// Fonction
function IsChecked(oChamp) {
	var bRetour = false;
	if (oChamp.checked) bRetour = true;
	return bRetour;
}

// Fonction
function IsSelected(oChamp) {
	var bRetour = false;
	if (oChamp[oChamp.selectedIndex].value != '') bRetour = true;
	return bRetour;
}

// Fonction
function IsInteger(oChamp) { 
	var int = parseInt(oChamp.value); 
	if (isNaN(int)) {
		return false; 
	}
	return ((oChamp.value == int) && (oChamp.value.toString() == int.toString())); 
} 

// Fonction
function IsEmail (oChamp) {
	var bRetour = false;
	var RegExp = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/;
	if (RegExp.exec(oChamp.value) != null) bRetour = true;
	return bRetour;
}

// Fonction
function IsDate (oChampJ, oChampM, oChampA) {
	d = oChampJ.value + '/' + oChampM.value + '/' + oChampA.value;
	if (d == '') return false;
	e = new RegExp('^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$');
	if (!e.test(d)) return false;
	j = parseInt(d.split('/')[0], 10);
	m = parseInt(d.split('/')[1], 10);
	a = parseInt(d.split('/')[2], 10);
	if (a < 1000) {
		if (a < 89)	a+=2000;
		else a+=1900;
	}
	if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
	else fev = 28;
	nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
	return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
}
