//blocage de lettre dans champs texte
no_letter=function()
{
	if(event.keyCode<45 || event.keyCode>57) event.returnValue=false;if(event.which<45 || event.which>57) return false
}
	
//format:	******************************************************************************
//creer_horaires2(num_form_horaires,"1h30 à 10h;12h10 à 20h,21h à 23h30<>1h30 à 10h;12h10 à 20h,21h à 23h30<>...")

creer_horaires2=function(id_horaires,data)
{
	code="<div id=tempo_id class='wm_horaires'></div><input type=hidden id=_"+id_horaires+" name="+id_horaires+">"
	document.write(code)
	conteneur=document.getElementById("tempo_id")
	conteneur.id=null
	conteneur.id_horaires=id_horaires
	
	conteneur.code_tranche="<div>de&nbsp;<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>h<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>&nbsp;&agrave;&nbsp;<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>h";
	conteneur.code_tranche+="<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'></div>"
	
	conteneur.MAJ_horaires=function()
	{
		code=''
		for(cpt=0;cpt<this.childNodes.length;cpt++)
		{
			if(code!=""){code+="<>"}
			code_h=""
			for(cpt2=0;cpt2<7;cpt2++)
			{
				if(code_h!=""){code_h+=";"}
				j=this.childNodes[cpt].firstChild.childNodes[cpt2].firstChild.nextSibling
				code_j=''
				for(cpt3=0;cpt3<j.childNodes.length;cpt3++)
				{
					t=j.childNodes[cpt3]
					if(code_j!=""){code_j+=","}

					
					if(parseInt(t.childNodes[1].value)>24){t.childNodes[1].value=24}
					if(parseInt(t.childNodes[3].value)>59){t.childNodes[3].value=59}
					if(parseInt(t.childNodes[5].value)>24){t.childNodes[5].value=24}
					if(parseInt(t.childNodes[7].value)>59){t.childNodes[7].value=59}

					if(t.childNodes[1].value.length==1){t.childNodes[1].value=0+t.childNodes[1].value}
					if(t.childNodes[3].value.length==1){t.childNodes[3].value=0+t.childNodes[3].value}
					if(t.childNodes[5].value.length==1){t.childNodes[5].value=0+t.childNodes[5].value}
					if(t.childNodes[7].value.length==1){t.childNodes[7].value=0+t.childNodes[7].value}
					if(t.childNodes[1].value+t.childNodes[3].value+t.childNodes[5].value+t.childNodes[7].value!="")
					{
						if(t.childNodes[1].value==""){t.childNodes[1].value="00"}
						if(t.childNodes[3].value==""){t.childNodes[3].value="00"}
						if(t.childNodes[5].value==""){t.childNodes[5].value="00"}
						if(t.childNodes[7].value==""){t.childNodes[7].value="00"}
						code_j+=t.childNodes[1].value+"h"+t.childNodes[3].value+" à "+t.childNodes[5].value+"h"+t.childNodes[7].value
					}
				}
				code_h+=code_j
			}
			code+=code_h
		}
		champ=document.getElementById(this.id_horaires)
		champ.value=code
	}

	conteneur.creer_horaire=function(data)
	{
		t_jour=new Array("Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche")
		code="<table border=0 class=wm_horaire>"
		alterne=0
		code_bt_copier=""
		for(cpt=0;cpt<7;cpt++){code+="<tr><td class=wm_horaire_jour"+alterne+">"+t_jour[cpt]+"</td><td class=wm_horaire_jour"+alterne+" id=tempo_id"+cpt+"><div>de&nbsp;<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>h<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>&nbsp;&agrave;&nbsp;<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>h<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'></div><div>de&nbsp;<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>h<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>&nbsp;&agrave;&nbsp;<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>h<input type=text maxlength=2 onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'></div></td><td><input type=button value='+' onclick='j=this.parentNode.parentNode.firstChild.nextSibling;code=j.innerHTML+this.parentNode.parentNode.parentNode.parentNode.parentNode.code_tranche;j.innerHTML=code;this.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'><input type=button value='-' onclick='j=this.parentNode.parentNode.firstChild.nextSibling;j.removeChild(j.lastChild);this.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>"+code_bt_copier+"</td></tr>";alterne=1-alterne;code_bt_copier="<input type=button value='copier' onclick='prev_j=this.parentNode.parentNode.firstChild.nextSibling.prev_j;if(prev_j){this.parentNode.parentNode.firstChild.nextSibling.innerHTML=prev_j.innerHTML;this.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()};'>"}
		code+="</table>"
		code_conteneur=this.innerHTML+code
		this.innerHTML=code_conteneur

		jours=data.split(";")
		for(cpt=6;cpt>=0;cpt--)
		{
			jour=document.getElementById("tempo_id"+cpt)
			pre=cpt-1
			prev_j=document.getElementById("tempo_id"+pre)
				
			jour.id=null
			jour.prev_j=prev_j

			if(jours[cpt] && jours[cpt]!="")
			{
				tranches=jours[cpt].split(",")
				code=""
				for(cpt2 in tranches)
				{
					if(tranches[cpt2]!="")
					{
						heure=tranches[cpt2].split(" à ")
						heure[0]=heure[0].split("h")
						heure[1]=heure[1].split("h")
						code+="<div>de&nbsp;<input type=text maxlength=2 value="+heure[0][0]+" onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>h<input type=text maxlength=2 value="+heure[0][1]+" onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>&nbsp;&agrave;&nbsp;<input type=text maxlength=2 value="+heure[1][0]+" onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'>h<input type=text maxlength=2 value="+heure[1][1]+" onKeypress='no_letter()' onblur='this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.MAJ_horaires()'></div>"
					}
				}
				jour.innerHTML=code
			}
		}
	}
	
	data=data.split("<>")
	for(cpt in data)
	{
		conteneur.creer_horaire(data[cpt])
	}
	conteneur.MAJ_horaires()
}