function CheckHeure(HeureIn) {

    // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
	var HeureLoc = HeureIn;
    var HeureData = HeureLoc.value;

//    pos_first_slash = DateData.indexOf("/");
 //   pos_last_slash  = DateData.lastIndexOf("/");

	if (HeureLoc.value.length==-1)
		{
			return(true);
		}
	if (HeureLoc.value.length==0)
		{
			return(true);
		}

	var pos_first_slash = HeureData.indexOf(":");

	if (pos_first_slash==-1) 
	{
		if (HeureLoc.value.length!=4)
			{
			alert("L'heure saisie semble incorrecte. Merci de vérifier.");
	//        jour.focus();
			return(false);
		}
		else
		{
			var hh = HeureData.substring(0, 2);
			var mn = HeureData.substring(2, 4);
		}
	}
	else
	{

	    var hh = HeureData.substring(0,pos_first_slash);

		if (HeureLoc.value.length==pos_first_slash+1)
		
			{
				var Mn="99";
			 }
		else
			{
			    var mn = HeureData.substring( (pos_first_slash +1), pos_last_slash);
			}
	}

	if (((isNaN(hh))||(hh<0)||(hh>23)) ) {
        alert("L'heure saisie semble incorrecte. Merci de vérifier.");
//        jour.focus();
        return(false);
    }

    if ( ((isNaN(mn))||(mn<0)||(mn>59)) ) {
        alert("L'heure saisie semble incorrecte. Merci de vérifier.");
  //      mois.focus();
        return(false);
    }
	
	if (hh<9) 
	{
		hh="0"+eval(hh);
	}
	
	if (mn<9) 
	{
		mn="0"+eval(mn);
	}
	
	HeureOut=hh + ":" + mn;
	//alert(HeureOut);
	
    return(HeureOut);
    
}

function FormatYear(annee)
	{
	var aujourd_hui = new Date;
	var annee4 = aujourd_hui.getFullYear();
	var annee2=FormatNumberZeros(annee4,2);
		if (eval(annee) < 100)
			{
				if (eval(annee) > eval(annee2) )
					{
						return ("19"+FormatNumberZeros(annee,2));
					}
				else
					{
						return ("20"+FormatNumberZeros(annee,2));
					}
			}
		else
			{
				return (annee);
			}
		
	}
	
function ValidationChamp(ChampIn,MsgErreur)
{
	var Champ = ChampIn;
	if (Champ.value.length == 0)
		{
			if (MsgErreur != "")
				{
					alert(MsgErreur);
				}
			return false;
		}
	return true;
}

function ValidationCBO(ChampIn,MsgErreur)
{
	var Champ = ChampIn;

	if (Champ.value.length == 0)
		{
			if (MsgErreur != "")
				{
					alert(MsgErreur);
				}
			return false;
		}
	if (Champ.value == '@@@-vide')
		{
			if (MsgErreur != "")
				{
					alert(MsgErreur);
				}
			return false;
		}
	return true;
}

function ValidationChampNum(Champ,MsgErreur)
{
theObservateur=Champ.value;

if (theObservateur > 0 && theObservateur < 2000)
	{
	return true;
	}else{
		if (MsgErreur != "")
			{
			alert(MsgErreur);
			}
		return false;
		}
return true;
}
 

function CheckDate(DateIn) {
    // Cette fonction vérifie le format JJ/MM/AAAA saisi et la validité de la date.
    var amin=1970; // année mini
	var aujourd_hui = new Date;
	var amax = aujourd_hui.getFullYear() +1;
	var DateLoc = DateIn;
    var DateData = DateLoc.value;
    pos_first_slash = DateData.indexOf("/");
    pos_last_slash  = DateData.lastIndexOf("/");
   
   	switch (pos_first_slash)
	{
		case -1:
			switch (DateLoc.value.lenght=6)
				{
					case 6:
						var j = DateData.substring(0,2);
						var m = DateData.substring(2,4);
						var a = DateData.substring(4);
						a=FormatYear(FormatNumberZeros(a,2));
						break;
					case 8:
						var j = DateData.substring(0,2);
						var m = DateData.substring(2,4);
						var a = DateData.substring(4);
						break;
					default:
						alert("La date saisie semble incorrecte. Merci de vérifier.");
						return(false);
						break;
				}
				break;
		default:
			var j = DateData.substring(0,pos_first_slash);
			var m = DateData.substring( (pos_first_slash +1), pos_last_slash);
			var a = DateData.substring( (pos_last_slash +1 ) , DateData.length);
			
			j=FormatNumberZeros(j,2);
			m=FormatNumberZeros(m,2);
			a=FormatYear(a);
			break;
	}

	if (((isNaN(j))||(j<1)||(j>31)) ) {
        alert("La date saisie semble incorrecte. Merci de vérifier.");
//        jour.focus();
        return(false);
    }

    if ( ((isNaN(m))||(m<1)||(m>12)) ) {
        alert("La date saisie semble incorrecte. Merci de vérifier.");
  //      mois.focus();
        return(false);
    }
    //    alert("coucou2");
    if ( ((isNaN(a))||(a<amin)||(a>amax)) ) {
        alert("La date saisie semble incorrecte (hors limites "+amin+"-"+amax+"). Merci de vérifier.");
      //  annee.focus();
        return(false);
    }
        //alert("coucou3");
    ok=1;

    if (ok==1) {
        var d2=new Date(a,m-1,j);
        j2=d2.getDate();
        m2=d2.getMonth()+1;
        a2=d2.getFullYear();
        
        if (a2<=100) {a2=1900+a2; alert(a);}
        
        if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
            alert("La date saisie semble incorrecte. Merci de vérifier.");
            return(false);
            verif=1;
        }
        else {
            verif=0;
        }
    }
    
    if (verif==1) {
        return(false);
    }
    else {
        return(j+"/"+m+"/"+a);
    }
}



function FormatNumberZeros(num, Longueur)
	{
		var Work=""
		var i=1;
		for (i=0;i<Longueur;i++)
			{
				Work=Work+"0";
			}
		Work=Work+num;
		return (Work.substring(Work.length-Longueur,Work.length));
	}
	
function FormatNumber(num, decimalNum, bolLeadingZero, bolParens)
   /* IN - num:            the number to be formatted
           decimalNum:     the number of decimals after the digit
           bolLeadingZero: true / false to use leading zero
           bolParens:      true / false to use parenthesis for - num

      RETVAL - formatted number
   */
   {
       var tmpNum = num;

       // Return the right number of decimal places
       tmpNum *= Math.pow(10,decimalNum);
       tmpNum = Math.floor(tmpNum);
       tmpNum /= Math.pow(10,decimalNum);

       var tmpStr = new String(tmpNum);

       // See if we need to hack off a leading zero or not
       if (!bolLeadingZero && num < 1 && num > -1 && num !=0)
           if (num > 0)
               tmpStr = tmpStr.substring(1,tmpStr.length);
           else
               // Take out the minus sign out (start at 2)
               tmpStr = "-" + tmpStr.substring(2,tmpStr.length);                        


       // See if we need to put parenthesis around the number
       if (bolParens && num < 0)
           tmpStr = "(" + tmpStr.substring(1,tmpStr.length) + ")";


       return tmpStr;
   }
function ValidationEmail (emailStr,MsgErreur) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
		if (MsgErreur != "")
			{
			alert(MsgErreur);
			}
		
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
		if (MsgErreur != "")
			{
			alert(MsgErreur);
			}

return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
		if (MsgErreur != "")
			{
			alert(MsgErreur);
			}

return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

		if (MsgErreur != "")
			{
			alert(MsgErreur);
			}

return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
		if (MsgErreur != "")
			{
			alert(MsgErreur);
			}

return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
		if (MsgErreur != "")
			{
			alert(MsgErreur);
			}

return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
		if (MsgErreur != "")
			{
			alert(MsgErreur);
			}

return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
		if (MsgErreur != "")
			{
			alert(MsgErreur);
			}

return false;
}

// If we've gotten this far, everything's valid!
return true;
}
/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


