// Fichier javascript général pour tout le site sur les formulaires uniquement
// --------------------------------------------------------------
// Formulaires 
// --------------------------------------------------------------
function VerifEmail(monform) {
      if (!/^[\.\w-]+@[\.\w-]+\.\w{2,4}$/g.test(monform.stremail.value)) {
        alert ("Please type a valid email address.");
        monform.stremail.focus();
        return false;
      }
      return true;
}

function VerifURL(monform) {
      if (monform.substring(0,6)!="http://") {
               return false;
      }
      return true;
}

function VerifSaisEmail(champsemail) {  // Version 2
      
	  if (!/^[\.\w-]+@[\.\w-]+\.\w{2,4}$/g.test(champsemail.value)) {
        if (document.all) {
        	return false;
        } else {
        	return true;
        }
      } else {
        return true;
      }
}

/*********************************************************************
Method:   String.trim
Purpose:  Removing leading and trailing spaces
Inputs:   none
Returns:  string
*********************************************************************/
String.prototype.trim=function () {
	return this.replace(/^\s+|\s+$/g,"");
}

/*********************************************************************
Function: isDate
Purpose:  Check that value is a date of the correct format
Inputs:   oElement - form element
		  sFormat  - string format
Returns:  boolean
*********************************************************************/
function isDate(inDate) {
	var aDaysInMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var strDatestyle ; //date style
	
	sDate=inDate.trim();
	sFormat=kDateformat;
	
	if (sFormat.substr(0, 1)=="D")	
		strDatestyle = "EU";  //European date style
	else
		strDatestyle = "US"; //United States date style
	
	// Fetch the date separator from the user's input
	var sSepDate=sDate.charAt(sDate.search(/\D/));
	// Fetch the date separator from the format
	var sSepFormat=sFormat.charAt(sFormat.search(/[^MDY]/i));
	// Compare separators
	if (sSepDate!=sSepFormat)
		return false;
	
	// Fetch the three pieces of the date from the user's input and the format
	var aValueMDY=sDate.split(sSepDate,3);
	var aFormatMDY=sFormat.split(sSepFormat,3);
	
	// Assign day, month, year based on format
	var iMonth,iDay,iYear;
	if (strDatestyle == "US") {
		iMonth = aValueMDY[0];
		iDay   = aValueMDY[1];
		iYear  = aValueMDY[2];
	} else {
		iMonth = aValueMDY[1];
		iDay   = aValueMDY[0];
		iYear  = aValueMDY[2];
		}
	
	// Validate that all pieces of the date are numbers
	if (  !isInteger( iMonth )
		||!isInteger( iDay   )
		||!isInteger( iYear  ) )
		return false;
	
	// Require 4 digit year
	if(iYear.length!=4)
		return false;
	
	// Check for leap year
	var iDaysInMonth=(iMonth!=2)?aDaysInMonth[iMonth-1]:
		((iYear%4==0 && iYear%100!=0 || iYear % 400==0)?29:28);
	
	return (iDay!=null && iMonth!=null && iYear!=null
			&& iMonth<13 && iMonth>0 && iDay>0 && iDay<=iDaysInMonth);
}

/********************************************
Function: isInteger
Purpose:  Check that parameter is a number
Returns:  boolean
********************************************/
function isInteger(s) {
	if (s==null)
		s=this.element.value.trim();

	var valeur = s.replace(",", "")
	valeur = valeur.replace(".", "")

	return (s.toString() && /(^-?\d\d*$)/.test(valeur));
}