// JavaScript Document
function cocher(cas,champ,val0,val1){
	if(cas.checked){
		document.getElementById(champ).value=val1;
	}else{
		document.getElementById(champ).value=val0;
	}
}

function nouveau(com,formulaire){
	document.getElementById(formulaire).command.value=com;
	document.getElementById(formulaire).submit();
	
	
	
	
	
	}
function suprim(com,formulaire){
	if(confirm('Cet action est irréversible continuer ?')){
		
		document.getElementById(formulaire).command.value=com;
		document.getElementById(formulaire).submit();
		}
	
	}
	

var und;
function verif_mail(chaine){
	var filter=/^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;
	if (!(filter.exec(chaine)!=null)){
		return false;
	}else{
		return true;
	}

}

function verifie_mail(objet){
	
	if(!verif_mail(objet.value))window.alert(erreur_mail);
	}
	
function value_of(nom){
	//on  verifie que le champs existe
	if(document.getElementById(nom)!=und){
		//var noeud=
		alert(document.getElementById(nom).nodeName);
		
		}else if(document.getElementByName(nom)!=und){
			
		}
}
function display_block(nom,val){
	if(document.getElementById("error_"+nom)!=und){
		if(val){
			document.getElementById("error_"+nom).style.display="block";
			
		}else{
			document.getElementById("error_"+nom).style.display="none";
				
		}
		
		
	}
	
}
function confirm_champ(champs1,champs2){
	if(document.getElementById(champs1).value!=document.getElementById(champs2).value){
		
		window.alert(erreur_confirm);
		
		document.getElementById(champs1).value="";
		document.getElementById(champs2).value="";
		}
	
	
	
	}
function controle_form(nom_form){
	var verif=true;
	var le_form=document.getElementById(nom_form);
	var ancre="";
	//on reinitialise les champs
	for(var i=0;i<T_obli.length;i++){display_block(T_obli[i][0],false);}
	//on verifie les emails
	for(var i=0;i<T_mail.length;i++){
		if(document.getElementById(T_mail[i]).value!=""&&!verif_mail(document.getElementById(T_mail[i]).value)){
		
			display_block(T_mail[i],true);
			verif=false;
			if(ancre=="")ancre=T_mail[i];
		}else{
			display_block(T_mail[i],false);
			}
		
	}
	//on verifie les chomps obli
	
	
		for(var i=0;i<T_obli.length;i++){
			var val="";
			
			var type_champ=T_obli[i][1];
			var ele=document.getElementById(T_obli[i][0]);
			
			switch(type_champ){
				case "LIST":
				val=ele.options[ele.selectedIndex].value;
				if(val==0){val=""};
				break;
				
				case "RADIO":
				var ele=document.getElementsByName(T_obli[i][0]);
				var is_checked=false;
				for(var j=0;j<ele.length;j++){
					if(ele[j].checked){val="ok";break;}
					
					}
				break;
				
				default:
				val=ele.value;
				break;
			}
			if(val==""){
				verif=false;
				if(ancre=="")ancre=T_obli[i][0];
				display_block(T_obli[i][0],true);
			
				
				
			}
		
		}
	//on verifie les champs date par précaution
	//champs confirm
	for(var i=0;i<T_confirm.length;i++){
		var champs1=document.getElementById(T_confirm[i][0]);
		var champs2=document.getElementById(T_confirm[i][1]);
		if(champs1.value!=champs2.value){
			
				verif=false;
				champs1.value="";
				champs2.value="";
				display_block(T_confirm[i][0],true);
				display_block(T_confirm[i][1],true);
				if(ancre=="")ancre=T_confirm[i][0];
			}
		
		
		}
	
	//
	/*for(var i=0;i<T_date.length;i++){
		var val="";
		var ele=document.getElementById(T_date[i][0]);
		if(isdate(ele.value)){
			display_block(T_date[i][0],false);
			
			}else{
				display_block(T_date[i][0],true);
				verif=false;
				}
		
		}*/
	if(verif==false){
		window.alert(champs_obligatoires);
		//window.location="#"+ancre;
		if(ancre!=""){
			document.getElementById(ancre).focus();
			document.documentElement.scrollTop=document.documentElement.scrollTop-50;
		}
		

	}else{
		
		document.getElementById(nom_form).submit();
		
		}
	
	
	}
// JavaScript Document
var tab_close=new Array();
function test_close(){
	
	alert(tab_close['DATE_superette_0']);
	for(var i in tab_close)alert(i);
	//alert(tab_close);
	}
function value_off(champ){
		var ele;
		var commut=true;
		if(document.getElementById(champ).value==0)commut=false;
		if(document.getElementById(champ).type=="radio"){
		var les_radios=document.getElementsByName(champ);
			for(var i=0;i<=les_radios.length;i++){
				if(les_radios[i].checked){
					if(les_radios[i].value=="0"){
						commut=false;
						
					}else{
						commut=true;
						
					}
					break;
				}
			}
		}
		
		
		for (var i=1; i<arguments.length; ++i){
			tab_close[arguments[i]]=false;
			if(!commut)tab_close[arguments[i]]=true;
			if(document.getElementById(arguments[i])!=und){
				var ele=document.getElementById(arguments[i]);
				
			}else if(document.getElementsByName(arguments[i])!=und){
					var ele=document.getElementsByName(arguments[i]);
			}
			if(ele!=und&&ele.nodeName!=undefined){
				//alert(ele.nodeName.toLowerCase());
				
				switch(ele.nodeName.toLowerCase()){
					case "input":
						if(commut){
							
							ele.style.backgroundColor= "";
							switch(ele.type){
								case("hidden"):
								if(document.getElementById("__"+arguments[i])!=und){
									if(document.getElementById("__"+arguments[i]).type=="checkbox"){
										document.getElementById("__"+arguments[i]).removeAttribute("disabled");
										document.getElementById("__"+arguments[i]).parentNode.style.color= "";
										
									
									}
								
								}
								break;
								
								case("text"):
								
								ele.style.backgroundColor= "";
								ele.style.borderColor= "";
								ele.removeAttribute("readOnly");
								break;
								
								case("radio"):
								var ele2=document.getElementsByName(arguments[i]);
								for(var j=0;j<ele2.length;j++){
									
									ele2[j].removeAttribute("disabled");
									ele2[j].parentNode.style.color= "";
									
									}
								
								break;
							
							
							
							}
						}else{
							
								switch(ele.type){
								case("hidden"):
								if(document.getElementById("__"+arguments[i])!=und){
									if(document.getElementById("__"+arguments[i]).type=="checkbox"){
										document.getElementById("__"+arguments[i]).setAttribute("disabled","disabled");
										document.getElementById("__"+arguments[i]).checked=false;
										document.getElementById("__"+arguments[i]).parentNode.style.color= "#CCCCCC";
										ele.value="";
									
									}
								
								}
								break;
								
								case("text"):
								ele.value="";
								ele.style.backgroundColor= "#FFFFFF";
								ele.style.borderColor= "#DDDDDD";
								//ele.setAttribute("readonly","readonly");
								ele.setAttribute("readOnly","readOnly");
								break;
								
								case("select-one"):
								alert("ok");
								ele.selectedIndex=0;
								ele.setAttribute("disabled","disabled");
								ele.style.borderColor= "#DDDDDD";
								
								break;
								
								case("radio"):
								var ele2=document.getElementsByName(arguments[i]);
								for(var j=0;j<ele2.length;j++){
									if(ele2[j].value==""||ele2[j].value=="0"){
									ele2[j].checked=true;
									}else{
										ele2[j].checked=false;
										}
									ele2[j].setAttribute("disabled","disabled");
									ele2[j].parentNode.style.color= "#CCCCCC";
									
									}
								
								break;
								
								default:
								alert(ele.type);
								
								
								
							
							
							}
							
							
							
				
						}
						
					break;
					case("select"):
					if(commut){
						ele.style.borderColor= "";
						ele.style.backgroundColor= "";
						ele.removeAttribute("disabled");
					
						
					}else{
						ele.selectedIndex=0;
						ele.setAttribute("disabled","disabled");
						ele.style.borderColor= "#DDDDDD";
						ele.style.backgroundColor= "#FFFFFF";
						
						//alert(ele.parentNode.firstChild.tagName);
						
					}
					
					break;
					
					
					}
				
				
				
				}
					
 		
  		}
  }
 function isnum(champs){
	var valeur=champs.value;
	champs.value=valeur.replace(",",".");
	if(isNaN(champs.value)&&champs.value!=""){
		return false;
		

	}else{
		return true;
		
		}
}
function isdate(val) {
	
	var retour=true;
	if(val!=""){
		var tab_date=val.split('/');
		if ((tab_date.length != 3) || isNaN(parseInt(tab_date[0])) || isNaN(parseInt(tab_date[1])) || isNaN(parseInt(tab_date[2]))){
			retour=false;
		}else{
			var verifdate = new Date(eval(tab_date[2]),eval(tab_date[1])-1,eval(tab_date[0]));
			var annee=verifdate.getYear();
			if ((Math.abs(annee)+"").length < 4) annee = annee + 1900;
			if((verifdate.getDate() != eval(tab_date[0])) || (verifdate.getMonth() != eval(tab_date[1])-1) || (annee != eval(tab_date[2]))){
				
				retour=false;
				}
			
			}
			
		
		}
		return(retour);
}
function is_alerte(champs,type){
	var retour=true;
	var val=champs.value;
	if(type=="date"){
		
		if(!isdate(val)){
			window.alert(erreur_date);
			var retour=false;
			champs.value="";
		}
			champs.focus();
	}else if(type=="num"){
		if(!isnum(champs)){
			window.alert(erreur_num);
			var retour=false;
			champs.value="";
			}
	}else if(type=="mail"){
			if(!verif_mail(val)){
			window.alert(erreur_mail);
			var retour=false;}
		
		}
	//if(!retour){champs.focus();champs.select();}
		
		
}
function calendrier_change(nom_champ,date_d){
	document.getElementById(nom_champ).value=date_d;
	document.getElementById("calend_"+nom_champ).style.display="none";
	
	}
function calendrier(nom_champ){
	var undi;
	//alert(tab_close[nom_champ]);
	if(!tab_close[nom_champ]){
	//on detect si lechamp précedent existe
	var  pre=nom_champ.substring(0,nom_champ.lastIndexOf("_")+1)+"0";
	if(document.getElementById(pre)!=und&&document.getElementById(pre).value!=""&&document.getElementById(nom_champ).value==""){
		var the_date=document.getElementById( nom_champ.substring(0,nom_champ.lastIndexOf("_")+1)+"0" ).value;
	}else{
		var the_date=document.getElementById( nom_champ).value;
	}
				
	var flashvar='lg='+lang+'&date_d='+the_date+'&date_f=&separateur=/&champs='+nom_champ+'&test=1';
	var width=180;
	var height=195;
	document.getElementById('calend_content_'+nom_champ).innerHTML='<'+'object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+width+'" height="'+height+'" '+'><'+'param name="movie" value="http://www.holiday-cheque.com/GLOBAL_JS/calend.swf"'+'><'+'param name="quality" value="high"'+'><'+'param name="allowScriptAccess" value="always"'+'><'+'param name="flashvars" value="'+flashvar+'"'+'><'+'embed src="http://www.holiday-cheque.com/GLOBAL_JS/calend.swf" width="'+width+'" height="'+height+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"  allowscriptaccess="always" flashvars="'+flashvar+'"'+'><'+'/embed'+'><'+'/object'+'>';
							
	document.getElementById("calend_"+nom_champ).style.display="block";
	//document.getElementById("calend_"+nom_champ).style.zIndex=1010;
	
	}
	
	}
function close_calendrier(nom_champ){
	document.getElementById("calend_"+nom_champ).style.display="none";
	
	}
	
function longueur_chaine(champ,longueur){
	ele=champ.getAttribute("id");
	nb_max=longueur;
	if(und==document.getElementById("compteur_"+ele)){
		var le_texte = document.createElement("div");
		//le_texte.setAttribute("type", "text");
		le_texte.setAttribute("id","compteur_"+ele);
		//le_texte.setAttribute("readonly","readonly");
		//le_texte.setAttribute("size",20);
		le_texte.setAttribute("class","form_compteur");
	

	champ.parentNode.appendChild(le_texte);
}
 
 
	if(champ.value.length>longueur){
		champ.value=champ.value.substr(0,longueur);
		document.getElementById("compteur_"+ele).style.color="#FF0000";
	
	}else{
	document.getElementById("compteur_"+ele).style.color="";
	}
document.getElementById("compteur_"+ele).innerHTML=(longueur-champ.value.length)+" / "+longueur+" chr Max"
}