<!-- 
// -----------------------------------------------------------
// 											http://www.antares-sa.fr 
// -----------------------------------------------------------
// Fichier      :  fct_hidetools.js
// Description  :  librairie de fonctions utilisees par fct_tools.js
// Date         :  juillet 2002
// -----------------------------------------------------------
// Prototypes	:
// -----------------------------------------------------------
//	Les fonctions ci-dessous sont utilises par fct_tools.js
// inutile de les appeler, on le fait pour vous !
//		function 	checkField		controle de type --> fonction de selection appelee par check
// 	
// 	Les fonctions suivantes sont appelées par la fonction check de fct_tools.js
//		function 	ctrlTypInt		controle de type integer (objet passée en parametre)
//		function 	ctrlTypFloat	controle de type decimal
//		function 	ctrlTypHexa		controle de type hexadecimal
//		function 	ctrlTypChar		controle de type caractere
//		functions  	ctrlTypDate	et checkDate controle de type date (gere les formats jj/mm/aaaa, jj/mm/aa, jjmmaaaa et jjmmaa)
//		function 	ctrlTypHeure	contrôle de l'heure (gere les formats hh:mmm et hhmm)
//		function		getNumberDayOfWeek calcul le jour de la semaine (0 = Dimanche --> 6 = Samedi)
// -----------------------------------------------------------
// Utilisation	:
//		aucune, voir fct_tools.js
// -----------------------------------------------------------
// Librairies requises : 
//		cst_tool.js
//		fct_browsercheck.js
// -----------------------------------------------------------

// --------------------------------------------------


// -----------------------------------------------------------
//	Les fonctions ci-dessous sont utilisess par les precedentes
// inutile de les appeler, elles le font pour vous !

// --------------------------------------------------
// controle de type --> fonction de selection
function checkField(obj,Format) {
	var exact = false;
	if (obj.value.length > 0) {
		if (Format == "NUM")
			exact = ctrlTypInt(obj);
		if (Format == "ALNUM")
			exact = ctrlTypChar(obj);
		if (Format == "DEC")
			exact = ctrlTypFloat(obj);
		if (Format == "HEXA")
			exact = ctrlTypHexa(obj);
		if (Format == "DATE")
			exact = ctrlTypDate(obj);
		if (Format == "HOUR")
			exact = ctrlTypHeure(obj);
	}
	return exact;
} // function checkField

// ------------------------------------------------------------------------------
//  Controle de type integer
function ctrlTypInt(obj) {
	var It = true;
	var c;
	for (var x = 0; x < obj.value.length; x++)
		if (It) {
			c =  obj.value.charAt(x);
			It = ( NumChars.indexOf(c) != -1);
		}
	return It;
} // function ctrlTypInt

// ------------------------------------------------------------------------------
//  Controle de type Décimal
function ctrlTypFloat (champs){
//  Traitement du point et de la virgule
//  virgule interpétée comme separateur de decimale
//  point est remplace par une virgule
	var It = true;
	var c;
	var virgule = false;
 	var substituechamp = "";
    var endstring = 0;
    c = champs.value.charAt(0);
    It = It && (  (NumChars.indexOf(c) != -1) || (c == "+") || (c=="-") );
	for (var x = 0; x < champs.value.length; x++) {
  		if (It) {
			c = champs.value.charAt(x);
			if ( (c==".") || (c == ",") ) {
	         if (virgule) It = false;
				else {
					It = true;
					virgule = true;
	      	}
	      }
	      else It =  (NumChars.indexOf(c) != -1);
   	}
	}
	if (It == false) {
		if (is.ie) {
			champs.style.backgroundColor = bgColFormatErr;
		}
		champs.focus();
		champs.value = "";
	}
	else {
		// Modificaton de la couleur de fond
		if (is.ie) {
			champs.style.backgroundColor = bgColFormatErr;
		}
		dotToComa(champs);
	}
	return It;
}

// ------------------------------------------------------------------------------
//  Controle de type hexadecimal
function ctrlTypHexa(obj) {
	var It = true;
	var c;
	for (var x = 0; x < obj.value.length; x++)
		if (It) {
			c = obj.value.charAt(x);
			It = (  (HexaChars.indexOf(c) != -1) || (NumChars.indexOf(c) != -1) );
		}
	return It;
}

// ------------------------------------------------------------------------------
//  Controle de type caractere
function ctrlTypChar (obj) {
	var It = true;
	var c;
	for (var x = 0; x < obj.value.length; x++)
		if (It) {
			c = obj.value.charAt(x);
			It = (  (AlphaChars.indexOf(c) != -1) || (NumChars.indexOf(c) != -1) );
		}
	return It;
}

// --------------------------------------------------
// Controle de type date
function ctrlTypDate (champs ) {
//	modif des controles sur les dates a afficher 
// 	format Français par défaut jj/mm/aaaa
// 	saisies également acceptées : jj/mm/aa, jjmmaa et jjmmaaaa 
	var i;
	var dateString = "";
	var temp = new Array; // on définit un tabl temp pour construire la chaine date
	if ( champs.value == "" ) {return false;}
	temp  = champs.value.split("/"); // tests si le format est correct initialement
	for(i=0;i<temp.length;i++) {
		dateString += fullTrim(temp[i]);
	}
	if ((dateString.length == 6)&&(isNumeric(dateString))) {
		if (parseInt(dateString.substring(4,6)) < 80) {
			dateString = dateString.substring(0,4)+"20"+dateString.substring(4,6);
		}
		else {
			dateString = dateString.substring(0,4)+"19"+dateString.substring(4,6);
		}
	}
	if ((dateString.length != 8)||(!isNumeric(dateString))) {
		return false;
	}
	dateString = dateString.substring(0,2)+"/"+dateString.substring(2,4)+"/"+dateString.substring(4,8);
	if (!checkDate(dateString,"FR")) {
		return false;
	}
	champs.value = dateString;
	return true
} // function ctrltypdat

// --------------------------------------------------
// Controle de type date (appelee par ctrlTypDate)
function checkDate(DateData,DateFormat) {
	correct = true;
	if ( (DateData.length < 11) && (DateData.length > 7) ) {
		if (DateFormat == "FR") {
			j = DateData.substring(0,2);
			m = DateData.substring(3,5);
		}
		else {
			j = DateData.substring(3,5);
			m = DateData.substring(0,2);
		}
		a = DateData.substring(6,DateData.length);
		bi = ((parseInt(a) % 4) == 0);
		if (  ( (m == "01") || (m == "03") || (m == "05") || (m == "07") || (m == "08") || (m == "10") || (m == "12") ) && ( (Math.round(j) >= 1) && (Math.round(j) <= 31) ) ) {
			correct = true;
		}
		else {
			if (  ( (m == "04") || (m == "06") || (m == "09") || (m == "11") ) && ( (Math.round(j) >= 1) && (Math.round(j) <= 30) ) ) {
				correct = true;
			}
			else {
				if (bi)  {
					correct = (  ( (Math.round(j) >= 1) && (Math.round(j) <= 29) ) && (m == "02") );
				}
				else {
					correct = ( ( (Math.round(j) >= 1) && (Math.round(j) <= 28) ) && (m == "02")  );
				}
			}
		}
	}
	else {
		correct = false;
	}
	return correct;
} // function checkDate

// --------------------------------------------------
//contrôle de l'heure hh:mmm (gere le format hhmm)
function ctrlTypHeure(champs) {
	var c;
	var hour;
	var min;
	var It = true;
	var htemp = champs.value.replace(/\:/gi,"");

	for (var x = 0; x < htemp.length; x++)
		if (It) {
			c = htemp.charAt(x);
			It = ( NumChars.indexOf(c) != -1);
		}
		if (It) {
			It = ( htemp.length == 4);
			if (It) {
				hour   = htemp.substring(0,2);
				min = htemp.substring(2);
			   It = ((parseInt(hour)<24)&&(parseInt(min)<60))
			}
		}
	if (It) champs.value = hour + ':' + min;
	return It;
} // function ctrlTypHeure


// --------------------------------------------------
// calcul le jour de la semaine (0 = Dimanche --> 6 = Samedi)
function getNumberDayOfWeek(j,m,a)
{var f=0;
 var g=0;
 if (m<=2) 
    {g=a-1;f=m+13
    } 
    else 
    {g=a;f=m+1
    };
 return Math.floor(365.25*g)+Math.floor(30.6001*f)+j-621049;
};

//-->
