//------------------------------------------------
function IsMin(strVal, strZone, iSize)
{
  if(strVal.length < iSize)
  {
    strMsg += strZone + " : La zone doit contenir au moins " + iSize + " caractères\r\n";
    return true;
  }
  return false;
}
//------------------------------------------------
function IsFloat(fVal, strZone)
{
	if(fVal == null || fVal.length == 0)
	{
		strMsg += strZone + " : La zone doit contenir une valeur numérique\r\n";
		return false;
	}
	var str = fVal.toString();
	var Decimal = false;

	for(var i = 0; i < str.length; i++)
	{
		var c = str.charAt(i);
		if (c == "." && !Decimal)
		{
			Decimal = true;
			continue;	
		}
 		if(c < "0" || c > "9")
		{
			strMsg += strZone + " : La zone contient des caractères alphabétiques\r\n";
			return false;	
		}
	}
	return true;
}
//------------------------------------------------
function IsMax(strVal, strZone, iSize)
{
  if(strVal.length > iSize)
  {
    strMsg += strZone + " : La zone doit contenir au plus " + iSize + " caractères\r\n";
    return true;
  }
  return false;
}
//------------------------------------------------
function IsNull(strVal)
{
	if(strVal == null ||strVal.length == 0)
		return true;
	else
		return false;
}
//------------------------------------------------
function IsEmpty(strVal, strZone)
{
	if(strVal == null ||strVal.length == 0)
	{
		strMsg += strZone + " : La zone est obligatoire\r\n";
		return true;
	}
	return false;
}
//------------------------------------------------
function IsHour(strVal, strZone)
{
	if(strVal == null || strVal.length == 0)
		return false;

	var	Delim = strVal.indexOf(":");
	var	iValHH = 0;
	var	iValNN = 0;
	
	if (strVal.length != 5)
	{
		strMsg += strZone + " : La zone contient une heure erronnée (Format HH:MM)\r\n";
		return false;
	}

	if(Delim == -1)
	{
		strMsg += strZone + " : La zone contient une heure erronnée (Format HH:MM)\r\n";
		return false;
	}
	iValHH 	= parseInt(strVal.substring(0, 2), 10);
	iValNN 	= parseInt(strVal.substring(3, 5), 10);

	if(isNaN(iValHH) || isNaN(iValNN))
	{
		strMsg += strZone + " : La zone contient une heure erronnée (Format HH:MM)\r\n";
		return false;
	}
	if(iValHH < 0 || iValHH > 24)
	{
		strMsg += strZone + " : La zone contient une plage d'heure invalide\r\n";
		return false;
	}
	if(iValNN < 0 || iValNN > 59)
	{
		strMsg += strZone + " :  La zone contient une plage d'heure invalide\r\n";
		return false;
	}
	return true;
}
//------------------------------------------------
function IsDate(strVal, strZone)
{
 if(strVal == null || strVal.length == 0)
	return false;

 var Delim = strVal.indexOf("/");
 var Delim1= strVal.lastIndexOf("/");
 var iValDD = 0;
 var iValMM = 0;
 var iValYYYY = 0;
 
 if (strVal.length < 10)
 {
  strMsg += strZone + " : La zone contient une date erronnée (Format JJ/MM/AAAA)\r\n";
  return false;
 }

 if(Delim != -1 && Delim1 == Delim)
 {
  strMsg += strZone + " : La zone contient des séparateurs invalides (Format JJ/MM/AAAA)\r\n";
  return false;
 }
 iValDD = strVal.substring(0, Delim);
 iValMM  = strVal.substring(Delim + 1, Delim1);
 iValYYYY  = strVal.substring(Delim1 + 1, strVal.length);
 Months = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
 Leap  = false;

 if (isNaN(iValDD) || isNaN(iValMM) || isNaN(iValYYYY))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 if((iValYYYY % 4 == 0) && ((iValYYYY % 100 != 0) || (iValYYYY %400 == 0)))
  Leap = true;
 if((iValDD < 1) || (iValDD > 31) || (iValMM < 1) || (iValMM > 12) || (iValYYYY < 0))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 if((iValDD > Months[iValMM-1]) && !((iValMM == 2) && (iValDD > 28)))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 if(!(Leap) && (iValMM == 2) && (iValDD > 28))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 if((Leap)  && (iValMM == 2) && (iValDD > 29))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n"
  return false;
 }

  return true;
}
//------------------------------------------------
function IsNumber(lVal, strZone)
{
	if(lVal == null || lVal.length == 0)
	{
		strMsg += strZone + " : La zone doit contenir une valeur numérique\r\n";
		return false;
	}

	var str = lVal.toString();

	for(var i = 0; i < str.length; i++)
	{
		var c = str.charAt(i);
		if(c < "0" || c > "9")
		{
			strMsg += strZone + " : La zone contient des caractères alphabétiques\r\n";
			return false;	
		}
	}
	return true;
}
//------------------------------------------------
function GetDay(strVal)
{
	return parseInt(strVal.substring(0, 2), 10);
}
//------------------------------------------------
function GetMonth(strVal)
{
	return 	parseInt(strVal.substring(3, 5), 10);
}
//------------------------------------------------
function GetYear(strVal)
{
	return parseInt(strVal.substring(6, strVal.length), 10);
}

function IsEmail(emailStr, strZone)
{
	var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/ 
	
	if(emailStr == null || emailStr.length == 0) {
		strMsg += strZone + " : L'adresse email est obligatoire\r\n";
		return false;
	}
	else
  	  if (reg.exec(emailStr) == null){
		strMsg += strZone + " : L'adresse email n'est pas valide\r\n";
		return false;
	 }
			
	return true;
}
