function addHover(elm) {
	elm.style.behavior = " ";
	if (document.all && window.print && /MSIE [56]/.test(navigator.userAgent)) {
		 elm.style.behavior = " ";
		 elm.onmouseenter = function() {
			this.className+= ' hover';
		 }
		elm.onmouseleave = function() {
			this.className = this.className.replace(/\bover\b/,"" );
		 }
	}
}
function displayPub()
{
	// On cache celui d'avant
	var bindex = index - 1;
	
	// 
	if (index == 0)
	{
		bindex = Elements.length -1;
	}
		
	var be = Elements[bindex];
	
	be.setStyle({ display: 'none'});
	
	// On affiche le courant
	var e = Elements[index];
	
	// Alert(e.identify());
	e.setStyle({ display: 'block'});
	
	// Si c'est le dernier on réinitialise
	if ( Elements.last() == e )
	{
		// Alert('last');
		index = 0;	
	}
	else
	{
		index++;	
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function Increment(obj) {
  if (isNaN(parseInt(obj.value)))
    obj.value = 1;
  else
    obj.value = parseInt(obj.value)+1;
}

function Decrement(obj) {
  if (isNaN(parseInt(obj.value)) || parseInt(obj.value)-1 < 0)
    obj.value = 0;
  else
    obj.value = parseInt(obj.value)-1;
}

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&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// fonction de validation de formulaire amélioré V5.0
function MM_validateForm()
{
	//v5.0
  var i,p,q,nm,test,num,min,max,errors = '',args=MM_validateForm.arguments;
  alert('test'+args+'');
  for (i=0; i<(args.length-2); i+=3)
 	{
  	test=args[i+2]; val=MM_findObj(args[i]);

    if (val)
   	{
    	affich=args[i+1];
    	nm=val.name;
    	if ((val=val.value)!="")
   		{
      	if (test.indexOf('isEmail')!=-1)
     		{
      		p=val.indexOf('@');
        	if (p<1 || p==(val.length-1)) errors+= '- '+affich+' (doit contenir une adresse e-mail valide).\n';
     		}
      	else if (test!= 'R')
     		{
        	if (isNaN(val)) errors+= '- '+affich+' doit contenir un nombre.\n';
        	if (test.indexOf('inRange') != -1)
       		{
        		p=test.indexOf(':');
          	min=test.substring(8,p); max=test.substring(p+1);
          	if (val<min || max<val) errors+= '- '+affich+' doit contenir un nombre compris entre '+min+' et '+max+'.\n';
					}
				}
			}
    else if (test.charAt(0) == 'R') errors += '- '+affich+'.\n';
    }
  }
    
	  var Compt = 0;
		var Deb = errors.indexOf('\n');
		while (Deb != -1)
		{
		  Compt++;
		  Deb = errors.indexOf('\n',++Deb);
		}
   	if (errors)
   	{
   		if (Compt>1)
   		{
   			alert('Les champs suivants sont obligatoires :\n'+errors);
   		}
   		else
   		{
   		  alert('Le champ suivant est obligatoire :\n'+errors);  		
   		}   	
   	}
  	document.MM_returnValue = (errors == '');
}

// fonction de validation de formulaire amélioré multi-langage V1.0
function MM_validateFormMultiLang()
{
  var i,p,q,nm,test,num,min,max,errors = '',args=MM_validateFormMultiLang.arguments;
  
  for (i=6; i<(args.length-2); i+=3)
 	{
  	test=args[i+2]; val=MM_findObj(args[i]);

    if (val)
   	{
    	affich=args[i+1];
    	nm=val.name;

		//Pour DEBUG
		//errors+='* val='+args[i]+' \n';
		//errors+='* nm='+nm+' \n';
		//errors+='* test='+test+' \n';
		//errors+='* affich='+affich+' \n';	

		if ((val=val.value)!="")
   		{
      	if (test.indexOf('isEmail')!=-1)
     		{
      		p=val.indexOf('@');
        	if (p<1 || p==(val.length-1)) errors+= '- '+affich+' '+args[0]+'.\n';
     		}
      	else if (test!= 'R')
     		{
        	if (isNaN(val)) errors+= '- '+affich+' '+args[1]+'.\n';
        	if (test.indexOf('inRange') != -1)
       		{
        		p=test.indexOf(':');
          	min=test.substring(8,p); max=test.substring(p+1);
          	if (val<min || max<val) errors+= '- '+affich+' '+args[2]+' '+min+' '+args[3]+'et '+max+'.\n';
					}
				}
			}
    else if (test.charAt(0) == 'R') errors += '- '+affich+'.\n';
    }
  }
    
	  var Compt = 0;
		var Deb = errors.indexOf('\n');
		while (Deb != -1)
		{
		  Compt++;
		  Deb = errors.indexOf('\n',++Deb);
		}
   	if (errors)
   	{
   		if (Compt>1)
   		{
   			alert(''+args[4]+' :\n'+errors);
   		}
   		else
   		{
   		  alert(''+args[5]+' :\n'+errors);  		
   		}   	
   	}
  	document.MM_returnValue = (errors == '');
}

function validateDisclaimer(obj)
{
	if ( obj.checked )
	{
		return true;
	}
	else
	{
		return false;
	}
}

function switchDivDisplay(id, value, mode)
{
	if ( div = document.getElementById(id) )
	{
		if ( !mode )
		{
			mode = 'block';	
		}
		
		if ( value )
		{
			div.style.display = mode;
		}
		else
		{
			div.style.display = 'none';
		}
	}	
}

function CheckPassword(error1, error2, text_field,text_field2,length)
{ 
	var mp1 = MM_findObj(text_field).value;
	var mp2 = MM_findObj(text_field2).value;
	
	if( mp1 || mp2 )
	{
		if ( mp1 == mp2 )
		{
			if ( mp1.length < length )
			{
				alert(error1);
				document.MM_returnValue = false;
			}
		}
		else
		{
			alert(error2);
			document.MM_returnValue = false;
		}
	}
}

function CheckLengthField(error1,text_field,length)
{ 
	var field1 = MM_findObj(text_field).value;
	
	if ( field1.length < length )
	{
		alert(error1);
		document.MM_returnValue = false;
	}
}

function CheckCheckbox(error1,checkbox_field)
{
	document.MM_returnValue = true;
	
	var field1 = MM_findObj(checkbox_field).checked;
	
	if (!field1)
	{
		alert(error1);
		document.MM_returnValue = false;
	}
}

function evalPwd(pw)
{
    var counter= 0;
    var minlength = 5;
 
    if (pw.length >= minlength) counter = counter + 1;
    if (pw.match(/[A-Z\?\?\?]/)) counter = counter + 1;
    if (pw.match(/[a-z\?\?\?]/)) counter = counter + 1;
    if (pw.match(/[0-9]/)) counter = counter + 1;
    if (pw.match(/[\.\,\?\!\%\*\_\#\:\;\~\&$\?\?\@\/\=\+\-\(\)\[\]\|\<\>]/)) counter = counter + 2;
 
    if (counter == 6)
    {
	 document.getElementById("weak").className = "green";
	 document.getElementById("medium").className = "green";
	 document.getElementById("strong").className = "green";
    }
    else if (counter > 2)
    {
	 document.getElementById("weak").className = "yellow";
	 document.getElementById("medium").className = "yellow";
	 document.getElementById("strong").className = "nrm";
    }
    else
    {
	 document.getElementById("weak").className = "red";
	 document.getElementById("medium").className = "nrm";
	 document.getElementById("strong").className = "nrm";
    }
}

function confirmMsg(msg, url)
{
	if ( confirm(msg) )
	{
		document.location = url;	
	}
}

function collateChecked(formid, blockid, id, name)
{
	var container = document.getElementById(formid);
	
	var source = document.getElementById(blockid);
	
	if ( container && source )
	{
		container.innerHTML = '';
		
		var items = source.getElementsByTagName('input');
	
		for ( var i = 0 ; i < items.length ; i++ )
		{
			if ( items[i].id == id && items[i].checked )
			{
				container.innerHTML += '<input type="hidden" name="' + name + '[]" value="' + items[i].value + '" />';
			}
		}
	}	
}
