//=== VARIABLES GLOBALES ===
var reWhiteSpace = /^\s+$/;
var reDigit = /^\d$/;
var reInteger = /^\d+$/;
var reSignedInteger = /^(\+|\-)?\d+$/;
var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
var reSignedFloat = /^(((\+|\-)?\d+(\.\d*)?)|((\+|\-)?(\d*\.)?\d+))$/;
var reLetter = /^[a-zA-Z]$/;
var reAlphabetic = /^[a-zA-Z]+$/;
var reLetterOrDigit = /^([a-zA-Z]|\d)$/;
var reAlphanumeric = /^[a-zA-Z0-9]+$/;
var reEmail = /^([\w-]+\.)*[\w-]+\@([\w-]+\.)+[a-zA-Z]{2,3}$/;
var reZipCode = /^\d{5}$/;
var reDep = /^((\d\d)|(2A)|(2B)|(97[1-6]))$/;
var reDate = /^(\d{2}\/){2}\d{4}$/;
var reUrl = /^http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}$/;

//=== CHAINES NULLES OU BLANCHES ===
function isEmpty(sIn){return ((sIn == null) || (sIn.length == 0));}

function isWhiteSpace(sIn){return (isEmpty(sIn) || reWhiteSpace.test(sIn));}

//=== NOMBRES ENTIERS ===
function isDigit(sIn){return reDigit.test(sIn);}

function isInteger(sIn){return reInteger.test(sIn);}

function isSignedInteger(sIn){return reSignedInteger.test(sIn);}

function isIntegerInRange(sIn, i_Min, i_Max){
    var iNum, iMin, iMax;
    var bOkMin, bOkMax;

    bOkMin = true;
    bOkMax = true;
    if(isSignedInteger(sIn)){
        iNum = parseInt(sIn, 10);
        if(i_Min!=""){
            iMin = parseInt(i_Min, 10);
            bOkMin = (iNum>=iMin);
            }
        if(i_Max!=""){
            iMax = parseInt(i_Max, 10);
            bOkMax = (iNum<=iMax)
            }
        return (bOkMin && bOkMax);
        }
    else{return false;}
    }

//=== NOMBRES REELS ===
function isFloat(sIn){return reFloat.test(sIn);}

function isSignedFloat(sIn){return reSignedFloat.test(sIn);}

function isFloatInRange(sIn, f_Min, f_Max){
    var fNum, fMin, fMax;
    var bOkMin, bOkMax;

    bOkMin = true;
    bOkMax = true;
    if(isSignedFloat(sIn)){
        fNum = parseFloat(sIn);
        if(f_Min!=""){
            fMin = parseFloat(f_Min);
            bOkMin = (fNum>=fMin);
            }
        if(f_Max!=""){
            fMax = parseFloat(f_Max);
            bOkMax = (fNum<=fMax)
            }
        return (bOkMin && bOkMax);
        }
    else{return false;}
    }

function isFloatFormatted(sIn, iTotal, iFrac){
    if(isSignedFloat(sIn)){}
    else{return false;}
    }

//=== CHAINES ALPHABETIQUES ===
function isLetter(sIn){return reLetter.test(sIn);}

function isAlpha(sIn){return reAlphabetic.test(sIn);}

//=== CHAINES ALPHANUMERIQUES  ===
function isLetterOrDigit(sIn){return reLetterOrDigit.test(sIn);}

function isAlphaNum(sIn){return reAlphanumeric.test(sIn);}

//=== CODES POSTAUX ET DEPARTEMENTS ===
function isZipCode(sIn){return ((reZipCode.test(sIn)) && (sIn.substring(0,2)!="00"));}

function isDepartement(sIn){
    if (reDep.test(sIn)){
        if(isInteger(sIn) && (sIn.length==2) && !(isIntegerInRange(sIn,1,95))){return false;}
        else{return true;}
        }
    else{return false}
    }

//=== E-MAIL ===
function isEmail(sIn){return reEmail.test(sIn);}

//=== NUMEROS DE TELEPHONE ===
function isPhoneNumber(sIn, sDelim){
    var rePhoneNumber;

    rePhoneNumber = new RegExp("^(\\d\\d"+ sDelim + "){4}(\\d\\d)$");
    return rePhoneNumber.test(sIn);
    }

//=== DATES  ===
function isDay(sIn){return isIntegerInRange(sIn, 1, 31);}

function isMonth(sIn){return isIntegerInRange(sIn, 1, 12);}

function isYear(sIn){return (isInteger(sIn) && ((sIn.length==2) || (sIn.length==4)))}

function isDate(sIn){
    var bOK;
    var i, iDay, iMonth, iYear;

    if(reDate.test(sIn)){
        bOK = true;
        // test élémentaires
        iDay    = sIn.substring(0,2);
        iMonth  = sIn.substring(3,5);
        iYear   = sIn.substring(6,10);
        if(!isDay(iDay)) bOK = false;
        if(!isMonth(iMonth)) bOK = false;
        if(!isYear(iYear)) bOK = false;

        // Les mois 30 jours
        if(iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11){if(iDay==31) bOK=false;}

        // Le mois de fevrier et son 29eme jour !
        if (iMonth==2){
            if(iDay>29) bOK=false;
            if(iDay==29){
                if( (iYear%4)==0 && ((iYear%100)!=0 || (iYear%400)==0) ) {bOK = true;}
                else{bOK = false;}
                }
            }
        return bOK;
        }
    else{return false;}
    }

function isDateInRange(sIn, d_Min, d_Max){
    var iIn, iMin, iMax;
    var bOkMin, bOkMax;

    bOkMin = true;
    bOkMax = true;
    if(isDate(sIn)){
        iIn = Date.parse(sIn);
        if(d_Min!=""){
            iMin = Date.parse(d_Min);
            bOkMin = (iIn>=iMin);
            }
        if(d_Max!=""){
            iMax = Date.parse(d_Max);
            bOkMax = (iIn<=iMax)
            }
        return (bOkMin && bOkMax);
        }
    else{return false;}
    }

//=== HEURES-MINUTES-SECONDES ===
function isHourMinute(sIn, sDelim){
    var reHourMinute;
    var iHour, iMinute;

    reHourMinute = new RegExp("^\\d\\d"+ sDelim + "\\d\\d$");
    if(reHourMinute.test(sIn)){
        iHour = sIn.substring(0,2);
        iMinute = sIn.substring(3,5);
        return(isIntegerInRange(iHour,0,23) && isIntegerInRange(iMinute,0,59));
        }
    else{return false;}
    }

function isHourMinuteSecond(sIn, sDelim){
    var reHourMinuteSecond;
    var iHour, iMinute, iSecond;

    reHourMinuteSecond = new RegExp("^\\d\\d"+ sDelim + "\\d\\d" + sDelim + "\\d\\d$");
    if(reHourMinuteSecond.test(sIn)){
        iHour = sIn.substring(0,2);
        iMinute = sIn.substring(3,5);
        iSecond = sIn.substring(6,8);
        return(isIntegerInRange(iHour,0,24) && isIntegerInRange(iMinute,0,59)&& isIntegerInRange(iSecond,0,59));
        }
    else{return false;}
    }

function isUrl(sIn){return reUrl.test(sIn);}

function popup(texte) {
	
  contenu="<TABLE border=0 cellspacing=0 cellpadding="+objpopup.NbPixel+"><TR bgcolor='"+objpopup.ColContour+"'><TD><TABLE border=0 cellpadding=2 cellspacing=0 bgcolor='"+objpopup.ColFond+"'><TR><TD><FONT size='-1' face='arial' color='"+objpopup.ColTexte+"'>"+texte+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";
  var finalPosX=posX-xOffset;
  if (finalPosX<0) finalPosX=0;
  if (document.layers) {
    document.layers["bulle"].document.write(contenu);
    document.layers["bulle"].document.close();
    document.layers["bulle"].top=posY+yOffset;
    document.layers["bulle"].left=finalPosX;
    document.layers["bulle"].visibility="show";}
  if (document.all) {
    //var f=window.event;
    //doc=document.body.scrollTop;
    bulle.innerHTML=contenu;
    document.all["bulle"].style.top=posY+yOffset;
    document.all["bulle"].style.left=finalPosX;//f.x-xOffset;
    document.all["bulle"].style.visibility="visible";
  }
  //modif CL 09/2001 - NS6 : celui-ci ne supporte plus document.layers mais document.getElementById
  else if (document.getElementById) {
    document.getElementById("bulle").innerHTML=contenu;
    document.getElementById("bulle").style.top=posY+yOffset;
    document.getElementById("bulle").style.left=finalPosX;
    document.getElementById("bulle").style.visibility="visible";
  }
}
function getMousePos(e) {
  if (document.all) {
  posX=event.x+document.body.scrollLeft; //modifs CL 09/2001 - IE : regrouper l'évènement
  posY=event.y+document.body.scrollTop;
  }
  else {
  posX=e.pageX; //modifs CL 09/2001 - NS6 : celui-ci ne supporte pas e.x et e.y
  posY=e.pageY; 
  }
}
function killpopup() {
	if (document.layers) {document.layers["bulle"].visibility="hide";}
	if (document.all) {document.all["bulle"].style.visibility="hidden";}
	else if (document.getElementById){document.getElementById("bulle").style.visibility="hidden";}
}

function initpopup(ColTexte,ColFond,ColContour,NbPixel) {
	objpopup.ColTexte=ColTexte;objpopup.ColFond=ColFond;objpopup.ColContour=ColContour;objpopup.NbPixel=NbPixel;
	if (document.layers) {
		window.captureEvents(Event.MOUSEMOVE);window.onMouseMove=getMousePos;
		document.write("<LAYER name='bulle' top=0 left=0 visibility='hide'></LAYER>");
	}
	if (document.all) {
		document.write("<DIV id='bulle' style='position:absolute;top:0;left:0;visibility:hidden'></DIV>");
		document.onmousemove=getMousePos;
	}
	//compatibilité NS6 document.layers non supporté : document.getElementById
	else if (document.getElementById) {
	        document.onmousemove=getMousePos;
	        document.write("<DIV id='bulle' style='position:absolute;top:0;left:0;visibility:hidden'></DIV>");
	}

}


function verif_form(form_name)
{
	form = eval("document."+form_name);
	
	backColor ="ddddff";
  	// Cette fonction affiche toutes les saisies du formulaire
 
	valid_form="";
  
	// La deuxième boucle parcourt les champs de formulaire
	for(var j = form.elements.length-1 ; j >= 0; j--)
	{
        if (form.elements[j].value=="" && form.elements[j].type!="hidden" && form.elements[j].oblig=='true')
       	{
   		   	valid_form="Un ou plusieurs champs obligatoires n'a pas &eacute;t&eacute; renseign&eacute;s, ou un format de champs n'a pas &eacute;t&eacute; respect&eacute;";
			set_error_form(form,j);
   		}
       	else if ((form.elements[j].type=="radio") && (form.elements[j].oblig=='true'))
       	{
       		isValid = false
       		groupeRadio = eval(form.elements[j].name)
			for( k=0; k<groupeRadio.length; ++k)
			{
				if( groupeRadio[k].checked)
					isValid = true;
			}
			if (!isValid)
			{
				for( k=0; k<groupeRadio.length; ++k)
				{
					valid_form="Un ou plusieurs champs obligatoires n'a pas &eacute;t&eacute; renseign&eacute;s, ou un format de champs n'a pas &eacute;t&eacute; respect&eacute;";
					groupeRadio[k].style.backgroundColor=backColor;
				}
   			}
   		}
   		else 
		{
			if (form.elements[j].value!="" && form.elements[j].format=="integer")
			{
				if (!isInteger(form.elements[j].value))
				{
		   		   	valid_form="Un ou plusieurs champs obligatoires n'a pas &eacute;t&eacute; renseign&eacute;s, ou un format de champs n'a pas &eacute;t&eacute; respect&eacute;";
					set_error_form(form,j);
				}
				else
					form.elements[j].style.backgroundColor="ffffff";
			}
			
			else if (form.elements[j].value!="" && form.elements[j].format=="email")
			{
				if (!isEmail(document.forms[i].elements[j].value))
				{
		   		   	valid_form="Un ou plusieurs champs obligatoires n'a pas &eacute;t&eacute; renseign&eacute;s, ou un format de champs n'a pas &eacute;t&eacute; respect&eacute;";
					set_error_form(form,j);
				}
				else
					form.elements[j].style.backgroundColor="ffffff";
			}

			else if (form.elements[j].value!="" && form.elements[j].format=="date")
			{
				if (!isDate(form.elements[j].value))
				{
		   		   	valid_form="Un ou plusieurs champs obligatoires n'a pas &eacute;t&eacute; renseign&eacute;s, ou un format de champs n'a pas &eacute;t&eacute; respect&eacute;";
					set_error_form(form,j);
				}
				else
					form.elements[j].style.backgroundColor="ffffff";
			}	
			else
			{
				if (form.elements[j].type!='radio' && form.elements[j].type!='checkbox')
				{
					form.elements[j].style.backgroundColor="ffffff";
				}
			}
	   	}				
	}
    if (valid_form!="")
    {
	    alert(valid_form);
	    return false;
    }
    else
	{
		return true;
	}		
}

function set_error_form(form, id_element)
{
	valid_form="Un ou plusieurs champs obligatoires n'a pas &eacute;t&eacute; renseign&eacute;s, ou un format de champs n'a pas &eacute;t&eacute; respect&eacute;";
	if (form.elements[id_element].type!='radio' && form.elements[id_element].type!='checkbox')
	{
		form.elements[id_element].style.backgroundColor=backColor;
	}
		
	form.elements[id_element].focus()
}

function focus_form(i)
{
  
	// La deuxième boucle parcourt les champs de formulaire
	if (document.forms[i]!=undefined)
	{
		for(var j = 0 ; j<document.forms[i].elements.length; j++)
		{
	
	        if (document.forms[i].elements[j].type!="hidden")
	        {
	        	document.forms[i].elements[j].focus();			
	        	break;
	        }
		}
	}
}

function focus_element(i,j)
{
  
	// La deuxième boucle parcourt les champs de formulaire
   	document.forms[i].elements[j].focus();			
}

function isDateSup(date1,date2)
{

	timeDate1 = Date.parse(date_iso_to_fr(date1));
	timeDate2 = Date.parse(date_iso_to_fr(date2));
	
	if (timeDate1>timeDate2)
		return true;
	else
		return false;
}

function date_iso_to_fr(date_us)
{
	tab_date = date_us.split("/");
	iYear    = tab_date[2];
	iMonth  = tab_date[1];
	iDay   = tab_date[0];
	
	return (iMonth+"/"+iDay+"/"+iYear);
}

function confirm_box(url,str)
{
	ans=window.confirm(str);
  if(ans){
    window.location.replace(url);
  }
			
}

function popup(page,largeur,hauteur) 
{
	options="menubar=no,scrollbars=yes,statusbar=no,resizable=no,toolbar=no,location=no,status=no";
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,'mail',"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
function modalDialog(page,largeur,hauteur) 
{
	options="menubar=no,scrollbars=yes,statusbar=no,resizable=no,toolbar=no,location=no,status=no";
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	
    var myObject = new Object();
    myObject.item1 = window
	window.showModalDialog("../iframe.asp?url=" + page + "&w=" + largeur + "&h=" + hauteur,myObject,"dialogHeight: " + hauteur + "px; dialogWidth: "+ largeur + "px; scroll:no");
}
function disable(element)
{
	element.disabled = true
}
function enable(element)
{
	element.disabled = false
}


