// JavaScript Document
var x=1,y=1; 
function enableTooltips(id){  
   var links,i,h,f;  
   if(!document.getElementById || !document.getElementsByTagName) return;  
   AddCss();  
   h=document.createElement("div");  
   h.id="btc";  
   h.setAttribute("id","btc");
   h.style.position="absolute"; 
	 h.style.zIndex="100";
	 document.getElementsByTagName("body")[0].appendChild(h);  
	 document.getElementById("btc").style.display="";
	 
	 f = document.createElement("iframe");	
	 f.id="btc_frame";
	 f.setAttribute("id","btc_frame");
	 f.setAttribute("scrolling","no");
	 f.setAttribute("frameborder","0");
	 f.style.position="absolute";
	 f.style.zIndex="90";	
	 f.style.border="0";	
 	 document.getElementsByTagName("body")[0].appendChild(f); 
	 document.getElementById("btc_frame").style.display="none";
	 setOpacity2(f);
   
  if(id==null) links=document.getElementsByTagName("select");  
  else links=document.getElementById(id).getElementsByTagName("select");  
  for(i=0;i<links.length;i++){  
 	Prepare(links[i]);  
  }
	if(id==null) links=document.getElementsByTagName("input");  
  else links=document.getElementById(id).getElementsByTagName("input");  
  for(i=0;i<links.length;i++){  
  Prepare(links[i]);  
  }
	if(id==null) links=document.getElementsByTagName("textarea");  
  else links=document.getElementById(id).getElementsByTagName("textarea");  
  for(i=0;i<links.length;i++){  
  Prepare(links[i]);  
  }
	/*if(id==null) links=document.getElementsByTagName("option");  
  else links=document.getElementById(id).getElementsByTagName("option");  
  for(i=0;i<links.length;i++){  
  Prepare(links[i]);  
  }*/
}  
function Prepare(el){  
 	var tooltip,tooltip2,e,t,b,s,l,iframe,id_tmp,tmp_champ; 
 	id_tmp=el.getAttribute("name");
	tmp_champ=el;
	if (document.getElementById(id_tmp+"_info"))
	{
		t=document.getElementById(id_tmp+"_info").getAttribute("title");
	}
	else
		t=el.getAttribute("title");
	if (document.getElementById(id_tmp+"_error"))
	{
		e=document.getElementById(id_tmp+"_error").getAttribute("title");
	}
	else
		e=el.getAttribute("title");
  	if(t==null || t.length==0) 
	{
		t="name:";  
	}
	else
	{
		el.removeAttribute("title");
		tooltip=CreateEl("div","tooltip");	
		s=CreateEl("div","top");
		s.id="btc_txt";
		s.setAttribute("id","btc_txt");
		s.appendChild(document.createTextNode(t));  
		tooltip.appendChild(s);  
		b=CreateEl("b","bottom");
		b.id="btc_img";  
		b.setAttribute("id","btc_img");
		b.appendChild(document.createTextNode(""));
		tooltip.appendChild(b);  
		setOpacity(tooltip);	
		el.tooltip=tooltip;  
		
		tooltip2=CreateEl("div","tooltip");
		s=CreateEl("div","top");
		s.id="btc_txt";
		s.setAttribute("id","btc_txt");
		s.appendChild(document.createTextNode(e));
		tooltip2.appendChild(s);
		b=CreateEl("b","bottom");
		b.id="btc_img";
		b.setAttribute("id","btc_img");
		b.appendChild(document.createTextNode(""));
		tooltip2.appendChild(b);
		setOpacity(tooltip2);
		el.tooltip2=tooltip2;
		
		
		el.onfocus=function(){
			if(el.getAttribute("alt")=="erreur")
				document.getElementById("btc").appendChild(this.tooltip2);
			else
				document.getElementById("btc").appendChild(this.tooltip);
			document.getElementById("btc_frame").style.display="block";
			if ((el.name=="journaiss" && el.value=='JJ') || (el.name=="moisnaiss" && el.value=='MM' )||( el.name=="anneenaiss" && el.value=='AAAA') || (el.name=="nom" && el.value=='Nom')|| (el.name=="prenom" && el.value=='Prénom') || (el.name=="journaiss_mini" && el.value=='JJ') || (el.name=="moisnaiss_mini" && el.value=='MM' )||( el.name=="anneenaiss_mini" && el.value=='AAAA'))
			{
				el.value='';
				el.focus();
			}
			Locate(tmp_champ);	
		};
		el.onblur=function(){
			hideTooltip();
			if(el.getAttribute("alt")=="erreur")
			{
				var el1 = $(el).up('form');
				if (el1.name=="forminscripcontact_mini")
					reverif_form_mini(el);
				else if (el1.name=="forminscripcontact_inclu")
					reverif_form_inclu(el);
				else
					reverif_form(el);
			}
		};
		el.onkeyup=function(){
			 if (el.name=="journaiss" || el.name=="moisnaiss" || el.name=="journaiss_inclu" || el.name=="moisnaiss_inclu" || el.name=="journaiss_mini" || el.name=="moisnaiss_mini")
				{
					var max = 2;
					var taille = el.value.length
					if (taille >= max)
					{
						 if (el.id=="journaiss" )	
						 {
							 if ( document.getElementById("moisnaiss").value =='MM' )
							 {
								  document.getElementById("moisnaiss").value="";
								  document.getElementById("moisnaiss").focus();
							  }
							 
						 }
						 else if(el.id=="journaiss_inclu")
						 {
							 if ( document.getElementById("moisnaiss_inclu").value =='MM' )
							 {
								  document.getElementById("moisnaiss_inclu").value="";
								  document.getElementById("moisnaiss_inclu").focus();
							 }
						 }
						 else if(el.id=="journaiss_mini")
						 {
							 if ( document.getElementById("moisnaiss_mini").value =='MM' )
							 {
								  document.getElementById("moisnaiss_mini").value="";
								  document.getElementById("moisnaiss_mini").focus();
							 }
						 }
						 else if (el.id=="moisnaiss")	
						 {
							 if ( document.getElementById("anneenaiss").value=='AAAA')
							 {
								document.getElementById("anneenaiss").value="";
								document.getElementById("anneenaiss").focus();
							 }
							
						 }
						 else if (el.id=="moisnaiss_inclu")	
						 {
							if ( document.getElementById("anneenaiss_inclu").value=='AAAA')
							{
								document.getElementById("anneenaiss_inclu").value="";
								document.getElementById("anneenaiss_inclu").focus();
							}
						 }
						 else if (el.id=="moisnaiss_mini")	
						 {
						 	if ( document.getElementById("anneenaiss_mini").value=='AAAA')
							{
								document.getElementById("anneenaiss_mini").value="";
								document.getElementById("anneenaiss_mini").focus();
							}
						 }
					}
			   }
		};
	}
}  
function showTooltip(e){  
  document.getElementById("btc").appendChild(this.tooltip);	
	document.getElementById("btc_frame").style.display="block";
	Locate(e);	
}  
function hideTooltip(e){  
  var d=document.getElementById("btc");  
  if(d.childNodes.length>0) d.removeChild(d.firstChild);
	document.getElementById("btc_frame").style.display="none";
}  
function setOpacity(el){  
  el.style.filter="alpha(opacity:99)";  
  el.style.KHTMLOpacity="0.99";  
  el.style.MozOpacity="0.99";  
  el.style.opacity="0.99";  
}
function setOpacity2(el){  
  el.style.filter="alpha(opacity:1)";  
  el.style.KHTMLOpacity="0.01";  
  el.style.MozOpacity="0.01";  
  el.style.opacity="0.01";  
}
function CreateEl(t,c){  
  var x=document.createElement(t);  
  		x.className=c;  
   		x.style.display="block";  	 
  return(x);  
}  
function AddCss(){  
  var l=CreateEl("link");  
  l.setAttribute("type","text/css");  
  l.setAttribute("rel","stylesheet");  
  l.setAttribute("href","bt1.css");  
  l.setAttribute("media","screen");  
  document.getElementsByTagName("head")[0].appendChild(l);  
}  
function AddCss2(i){  
  var l=CreateEl("link");  
  l.setAttribute("type","text/css");  
  l.setAttribute("rel","stylesheet");  
  l.setAttribute("href","bt"+i+".css");  
  l.setAttribute("media","screen");  
  document.getElementsByTagName("head")[0].appendChild(l);  
}  
function Locate(el){
	/*var top_champ = "";
	var left_champ = "";
	left_champ = el.offsetLeft;
	tmp_elt=el;
	top_champ = el.offsetTop;
	var img = document.getElementById("btc_img");
	var txt = document.getElementById("btc_txt");
	while ((el = el.offsetParent )!=null) {
		top_champ += el.offsetTop;
		left_champ += el.offsetLeft;
	}
	d = document.getElementById("btc");
	if(left_champ>650)
	{
		top_champ = top_champ + 5;
		left_champ = left_champ - 205;
	}
	else
	{
		top_champ = top_champ + 8;
		if(tmp_elt.type=="radio")
			left_champ = left_champ +13; 
		else
			left_champ = left_champ + 140;
		img.style.background="url(bt2.gif) no-repeat bottom";
		txt.style.background="url(bt2.gif) no-repeat top";
		
	}
	//left_champ = left_champ - 205;
	document.getElementById("btc_frame").style.width=d.offsetWidth+"px";  
	document.getElementById("btc_frame").style.height=d.offsetHeight+"px";
	document.getElementById("btc_frame").style.display="block";
	d.style.display="block";
	document.getElementById("btc_frame").style.top=(top_champ-d.offsetHeight)+"px";  
	d.style.top=(top_champ-d.offsetHeight)+"px";
	document.getElementById("btc_frame").style.left=left_champ+"px";
	d.style.left=left_champ+"px";*/
	
	
	var top_champ = "";
	var left_champ = "";
	left_champ = el.offsetLeft;
	tmp_elt=el;
	top_champ = el.offsetTop;
	var img = document.getElementById("btc_img");
	var txt = document.getElementById("btc_txt");
	while ((el = el.offsetParent )!=null) {
		top_champ += el.offsetTop;
		left_champ += el.offsetLeft;
	}
	d = document.getElementById("btc");
	if(left_champ>700)
	{
		top_champ = top_champ + d.offsetHeight + 10;
		left_champ = left_champ - 202;
		txt.style.background="url(bt3.gif) no-repeat top";
		img.style.background="url(bt3.gif) no-repeat bottom";
		txt.style.paddingTop="30px";
		img.style.paddingTop="10px";
	}
	else
	{
		if(tmp_elt.type=="radio")
		{
			  
			top_champ = top_champ + 5;
			left_champ = left_champ +20; 
		}
		else if(tmp_elt.name=="nom" || tmp_elt.name=="prenom")
		{	  
			top_champ = top_champ - 2;
			left_champ = left_champ +70;
		}
		else if (tmp_elt.name=="journaiss" || tmp_elt.name=="moisnaiss" || tmp_elt.name=="journaiss_inclu" || tmp_elt.name=="moisnaiss_inclu" || tmp_elt.name=="journaiss_mini" || tmp_elt.name=="moisnaiss_mini")
		{	  
			top_champ = top_champ -2;
			left_champ = left_champ +20;
		}
		else if(tmp_elt.name=="anneenaiss" || tmp_elt.name=="anneenaiss_inclu" || tmp_elt.name=="anneenaiss_mini")
	
		{	  
			top_champ = top_champ -2;
			left_champ = left_champ +35;
		}
		else
		{
			top_champ = top_champ + 10;
			left_champ = left_champ + 150;
		}
		txt.style.background="url(bt2.gif) no-repeat top";
		img.style.background="url(bt2.gif) no-repeat bottom";
	}
	document.getElementById("btc_frame").style.width=d.offsetWidth+"px";  
	document.getElementById("btc_frame").style.height=d.offsetHeight+"px";
	document.getElementById("btc_frame").style.display="block";
	d.style.display="block";
	document.getElementById("btc_frame").style.top=(top_champ-d.offsetHeight)+"px";  
	d.style.top=(top_champ-d.offsetHeight)+"px";
	document.getElementById("btc_frame").style.left=left_champ+"px";
	d.style.left=left_champ+"px";

}  
