function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}




_arrMsgError = new Array();
_arrMsgError['champVide'] = "Vous devez remplir tous les champs.";
_arrMsgError['invalideNumeric'] = "le format est incorrect.\nVous devez rentrer obligatoirement que des chiffres.";
_arrMsgError['invalideEmail'] = "L'e-mail n'est pas un format strandard d'un e-mail.";



//--------------------------------------------------------------------------
// 
function fct_verifForm(argFormName, argActionType, argWidth, argHeight)
{
	var objForm = document.forms[argFormName];
	var blnErreur = false;
	var strMsg = _arrMsgError['champVide'];
	var strName = '';
	var strValue = '';

	for(i = 0; i < objForm.length; i++)
	{
		strName = strName + objForm.elements[i].name + ' - ' + objForm.elements[i].type + '\n';
	}

	//alert(strName);

	for(i = 0; i < objForm.length; i++)
	{
		strName = objForm.elements[i].name;
		_elementType = '';

		if(strName != null)
		{
			//alert(strName);
			_arrSplit = strName.split("_");

			if(_arrSplit[0] == 'chk')
			{
				strTest = objForm.elements[i].value;
				_arrSplit.shift();
				strName = _arrSplit.join("_");
				//alert(strName);

				objInput = objForm.elements[strName];
				
				if(objInput != undefined && objForm.elements[i].disabled == false)
				{
					strValue = objInput.value;
					//alert('strValue : ' + strValue);

					_elementType = objInput.type;
					//alert('_elementType : ' + _elementType);

					if(_elementType == 'radio')
					{
						strValue = '';
						for(j = 0; j < objInput.length; j++)
						{
							if(objInput[j].checked == true)
							{
								//alert(strName + ' - ' + _elementType);
								strValue = objInput[j].value;
							}
						}
					}

					if(_elementType == 'checkbox')
					{
						strValue = '';
						if(objInput.checked == true)
						{
							strValue = objInput.value;
						}
					}

					strMsgTest = isTest(strValue, strTest, argFormName);

					//alert(strMsgTest);

					if(strMsgTest != '')
					{
						strMsg = strMsgTest;

						if(_elementType == 'hidden' || _elementType == undefined || _elementType == 'radio' || _elementType == 'checkbox')
						{
							//objForm.elements[strName][0].focus();
						}
						else
						{
							objInput.focus();
						}

						blnErreur = true;
						break;
					}
				}
			}
		}
	}

	if(blnErreur)
	{
		if(strMsg != '')
		{
			alert(strMsg);
		}

		switch(argActionType)
		{
			case 'post' :

				return false;

				break;

			case 'popupclick' :

				return false;

				break;

			default :

				break;
		}
	}
	else
	{
		for(i = 0; i < objForm.length; i++)
		{
			strName = objForm.elements[i].name;
			arrSplit = strName.split("_");

			//objForm.elements[i].disabled = false;
			if(strName.substr(0, 4) == 'chk_')
			{
				objForm.elements[i].disabled = true;
				//document.getElementByName(strName).style.display = 'none';
			}
		}


		switch(argActionType)
		{
			case 'post' :

				return true;

				break;

			case 'click' :

				objForm.submit();

				break;

			case 'popupclick' :

				fctOpenWindow('../_templates/blanc.html', argWidth, argHeight, false, 'win');

				return true;

				break;

			default :

				//return true;

				break;
		}
	}
}
//--------------------------------------------------------------------------




//--------------------------------------------------------------------------
// 
function isTest(argValue, argTest, argFormName)
{
	var i;
	var _objForm = document.forms[argFormName];
	var _blnTest = false;
	var _msg = '';
	var _nonObligatoire = false;
	var _type = null;
	var _arrSplit1 = null;
	var _arrSplit2 = null;
	var _arrData = new Array();

	if(argTest != '')
	{
		_arrSplit1 = argTest.split("&");
		//alert(_arrSplit1.length);

		for(i = 0; i < _arrSplit1.length; i++)
		{
			_arrSplit2 = _arrSplit1[i].split("=");

			if(_arrSplit2.length == 2)
			{
				_arrData[_arrSplit2[0]] = _arrSplit2[1];
			}
		}


		if(argValue != '')
		{
			//alert(_arrData['type'] + ' ' + _arrData['message'] + ' ' + _arrData['messagetest']);

			switch(_arrData['type'])
			{
				case 'formatage' :
				
					if(_arrData['expression'] != undefined)
					{
						var reg = new RegExp('^(' + _arrData['expression'] + ')$', 'gi');
						if((reg.exec(argValue) != null) == false)
						{
							if(_arrData['messageCheck'] != undefined)
							{
								_msg = _arrData['messageCheck'];
							}
						}
					}

					break;

				case 'email' :

					if(!isEmail(argValue))
					{
						_msg = _arrMsgError['invalideEmail'];

						if(_arrData['messageCheck'] != undefined)
						{
							_msg = _arrData['messageCheck'];
						}
					}

					break;

				case 'numeric' :

					if(!isNumeric(argValue))
					{
						_msg = _arrMsgError['invalideNumeric'];

						if(_arrData['messageCheck'] != undefined)
						{
							_msg = _arrData['messageCheck'];
						}
					}

					break;

				case 'chiffresAndLettres' :

					var reg = new RegExp('^([a-z0-9]+)$', 'gi');
					if((reg.exec(argValue) != null) == false)
					{
						strMsg = "le format est incorrect.\nVous devez rentrer obligatoirement que des chiffres ou des lettres.";	
					}
					break;

				case 'limitechiffre' :

					intLimite = 1;
					var resultat = _test.match(/(limite#)([^§]*)(\s)/);
					intLimite = resultat[2];

					var reg = new RegExp('^[0-9]{' + intLimite + '}$', 'gi');
					if((reg.exec(argValue) != null) == false)
					{
						strMsg = "le format de ce numéro est incorrect.\nVous devez rentrer obligatoirement " + intLimite + " chiffres.";
					}
					break;

				case 'password' :

					var resultat = _test.match(/(comparaison#)([^§]*)(\s)/);
					_input = resultat[2];

					if(document.forms[argFormName].elements[_input].value != argValue)
					{
						strMsg = "la confirmation de mot de passe est incorrect.";
					}

					break;

				case 'chaineVideInterdite' :

					break;

				default :

					break;

			}
		}
		else
		{
			_msg = _arrMsgError['invalideNumeric'];

			if(_arrData['message'] != undefined)
			{
				_msg = _arrData['message'];
			}
		}
	}

	return _msg;
}
//--------------------------------------------------------------------------




//--------------------------------------------------------------------------
// 
 function isNull(argValue) 
 {
      return typeof argValue == 'object' && !argValue;
 }
//--------------------------------------------------------------------------




//--------------------------------------------------------------------------
// 
function isEmail(argValue)
{
	var _reg = new RegExp('^[a-z0-9._-]+@[a-z0-9\-\.]+[.][a-z]{2,4}$', 'gi');
	var _blnCheck = true;

	if((_reg.exec(argValue) != null) == false)
	{
		_blnCheck = false;
	}

	return _blnCheck;
}
//--------------------------------------------------------------------------




//--------------------------------------------------------------------------
// 
function isNumeric(argValue)
{
	var i;
	var _validChars = "0123456789.-";
	var _char;
	var _blnCheck = true;

	if(argValue.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < argValue.length && _blnCheck == true; i++)
	{
		_char = argValue.charAt(i);

		if (_validChars.indexOf(_char) == -1)
		{
			_blnCheck = false;
		}
	}

	return _blnCheck;
}


