//**********************************************************************
//*	ETEAM : August 2002			       *
//*			   Form Validation client scripts	       *
//**********************************************************************
//
// Global vars definition
//
VarAlpha='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
VarDigit='0123456789';
VarWhite=' \t\r\f\n';
VarMaskNames=new Array('digit','alphabetic','non-blank','space');

// Error messages definitions
MsgLTMinSize='Attention: %1 doit contenir au moins %2 caracteres.';
MsgNotInCharset="Attention: Le caractere %2 n'est pas autorise dans le champ %1.";
MsgReqdFldEmpty='Attention, %1 doit etre renseigne.';
MsgNotEmailFormat='Il semble que %1 ne soit pas une adresse mail valide.';

//***************************************************************************************************
//* Function FmtMsg									            *
//* Description :									            *
//* Function to substitute args (as strings) for positional markers %1, %2 etc. in source string    *
//*												    *
//* Args: InString - format specification; e.g. "Error %1 in Object %2" or "Object %2 has Error %1" *
//*		Args 2-n - substitution parameters						    *
//***************************************************************************************************
//
function FmtMsg (MsgStr, Args)
{
	var i, c, Start;
	var OutStr = "";			
	for (i=0; i < MsgStr.length; i++)  
	{
		c = MsgStr.charAt (i);
		if ((c == '%') && (i < (MsgStr.length-1)))
		{
			i++;   c = MsgStr.charAt(i);
			if ((c == '%') || (VarDigit.indexOf(c, 0) == -1))
				OutStr += '%';
			else
			{	
				Start = i++;
				while (i < MsgStr.length)
				{	// Scan until we hit a nondigit
					c = MsgStr.charAt(i);
					if (VarDigit.indexOf(c, 0) == -1)
					{
						i--;	break;
					}
					i++;
				}
				Start = parseInt(MsgStr.substring(Start, i+1));
				if (Start < FmtMsg.arguments.length)
				{
					OutStr += FmtMsg.arguments[Start];
				}
				// otherwise leave it empty
			}
		}
		else
			OutStr += c;
	}
	return OutStr;
}
//***************************************************************************************************
//* Function TextCharset								    *
//* Description :									            *
//* Test field to ensure all chars in specified charset; also tests fields for min len.             *
//*												    *
//* Args: formName, formField to be tested, min length, 
//*	  maskStr : =   # : field must be in numerical format			                    *
//* 	            or  W : white space forbidden in field					    *
//*		    or  A : field must be in alphabetic format					    *
//*	  otherStr : list of digits and or alphabetics cars authorized in this field 		    *
//*                              								    *
//***************************************************************************************************
//
function TextCharset (formName, formField, minL, maskStr, otherStr, formLabel)
{
	var s = formName.elements[formField.name].value;
	var i,c;

	if (s.length == 0)
	{
		c = TextCharset.caller.toString();
		if ((c.indexOf('onblur') != -1) || (c.indexOf('onBlur') != -1) || (c.indexOf('ONBLUR') != -1))
			return true;
		else if ((navigator.appName == 'Netscape')
			&& ((c.indexOf('onchange') != -1) || (c.indexOf('onChange') != -1) || (c.indexOf('ONCHANGE') != -1)))
			return true;
	}

	if ((minL != '') && (s.length < minL))
	{
		alert (FmtMsg(MsgLTMinSize, formLabel, minL)); 
		formName.elements[formField.name].focus(); return false;
	}
	if ((maskStr != '') || (otherStr != ''))
	{
		for (i = 0; i < s.length; i++)
		{	// Iterate through str, testing each char - as part of set if so; else as itself
			c = s.charAt(i);
			if (VarDigit.indexOf(c) != -1) c = '#';
			else if (VarWhite.indexOf(c) != -1) c = 'W';
			else if (VarAlpha.indexOf(c) != -1) c = 'A';
			// Else use char itself. Test both as pseudo and as itself - user may
			//   list a single alphabetic (A, B) or digit (7) character in the "otherStr"
			if (((maskStr == '') || (maskStr.indexOf(c) == -1)) && 
				((otherStr == '') || (otherStr.indexOf(s.charAt(i)) == -1)))
			{
				alert (FmtMsg(MsgNotInCharset, formLabel, s.charAt(i)));
				formName.elements[formField.name].focus(); return false;
			}
		}
	}
	return true;
}
//***************************************************************************************************
//* Function ReqdFlds								            *
//* Description :									            *
//* Function to test a form for empty 'required' fields and notify the user if any are found        *
//*												    *
//* Args: formName, formField to test, label of tested formfield for error message	            *
//***************************************************************************************************
//
function ReqdFlds (formName, formField, formLabel)
{
	if (formField.type == "text" ||
		formField.type == "password" ||
		formField.type == "textarea")
	{
		var i,j;
		var failed = false;
		var s = formName.elements[formField.name].value;

		if (s == '') failed = true;
		else
		{
			for(j=0;(j < s.length) && (s.charAt(j)==' '); j++);
			if (j == s.length) failed = true;
		}
		if (failed)
		{
			alert (FmtMsg(MsgReqdFldEmpty, formLabel));
			formField.focus();
			return false;
		}
	}
	else if (formField.type == "select-one" ||
			 formField.type == "select-multiple")
	{
		if (formField.selectedIndex == -1)
		{
			alert(FmtMsg(MsgReqdFldEmpty, formLabel));
			formField.focus();
			return false;
		}
	}

	return true;
}
//***************************************************************************************************
//* Function CheckEmail								            *
//* Description :									            *
//* Function to test if the format of a field is in a good email format	                            *
//*												    *
//* Args: formName, formField to test, label of tested formfield for error message	            *
//***************************************************************************************************
// 
function CheckEmail(formName, formField, formLabel) 
{
    var  s = formName.elements[formField.name].value;
    if (s>""){
    // test using regular expression
	    if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(s)))
	    {
			alert(FmtMsg(MsgNotEmailFormat, formLabel));
			formField.focus();
			return false;
	    }
    }
    return true;
}

var speed_sel_espece; 

function initialize_sel_espece(){ 
	
	if (window.scroll_speed_espece!=0){ 
		
		speed_sel_espece=window.scroll_speed_espece ;
		scrollwindow_sel_espece() ;
	} 
} 
  
function scrollwindow_sel_espece(){ 
	if (document.getElementById('cadre')) {
		document.getElementById('cadre').scrollTop -= speed_sel_espece;
	}
} 