var hauteurcontenu;
var xactuel;
var yactuel;
var nouvelletaille;
var isIE
var ecart;



function recomposeMail(obj, region, nom, domaine)
{
	obj.href = 'mailto:' + nom + '@' + domaine + '.' + region;
	obj.onclick = (function() {});
}

function init()
{
//	document.getElementById("zonedetection").style.height=parseInt(document.getElementById("souscadre").offsetHeight)-parseInt(document.getElementById("menu").offsetHeight)+"px";//
//	window.status="sous cadre:" + parseInt(document.getElementById("souscadre").offsetHeight)+" menu :" + parseInt(document.getElementById("menu").offsetHeight);
	document.getElementById("query").blur();
	
	if(navigator.appVersion.indexOf("MSIE 6")!=-1)
	{
		if(parseInt(document.getElementById("souscadre").offsetHeight)<=600)
			document.getElementById("souscadre").style.height="599px";
		
	}
	
	redimensionnerZoneDetection();
	
	if(parseInt(document.getElementById("souscadre").offsetHeight)<=600)
	{
		
		
		if(document.getElementById("retourhaut"))
			document.getElementById("retourhaut").style.display="none";
		
	}
	
		
}

function getInfos()
{
	ecran_largeur=screen.availWidth;
	page_pos=document.getElementById("page").offsetLeft;
	window.status="largeur ecran:"+ecran_largeur+" pos page:"+page_pos;
}


function fenetre_redimensionnement()
{
	//window.status="redimensionner:"+document.getElementById("main").offsetLeft;
}

function infobulle_afficher(_x,_y)
{
	
	document.getElementById("infobulle").style.top=_y+15+"px";
	var infobulle=document.getElementById("infobulle");
	var infobulle_largeur=parseInt(infobulle.offsetWidth);
	var infobulle_hauteur=parseInt(infobulle.offsetHeight);
	var page_x=parseInt(document.getElementById("page").offsetLeft);
	//window.status="x:"+_x+" y:"+_y+ "pageoff:"+page_x;
	var newX=_x-page_x-30;
	if(_x-130<page_x)
		newX=100;
	
	document.getElementById("infobulle").style.left=newX+"px";
}
function infobulle_activer()
{
	document.getElementById("zonedetection").style.cursor="pointer";
	document.getElementById("infobulle").style.display="block";	
}


function infobulle_eteindre()
{
	document.getElementById("zonedetection").style.cursor="default";
	document.getElementById("infobulle").style.display="none";
}



function redimensionnerZoneDetection()
{
	var htdepart=document.getElementById("zonedetection").offsetHeight;
	hauteurcontenu=parseInt(document.getElementById("souscadre").offsetHeight)-parseInt(document.getElementById("menu").offsetHeight);
	document.getElementById("zonedetection").style.height=parseInt(document.getElementById("souscadre").offsetHeight)-parseInt(document.getElementById("menu").offsetHeight)-1+"px";
	nouvelletaille=parseInt(document.getElementById("souscadre").offsetHeight)-parseInt(document.getElementById("menu").offsetHeight);
	ecart=parseInt(document.getElementById("zonedetection").style.height)-htdepart;
	
//	window.status="nouvelle taille:" +nouvelletaille;
}

function croixon(truc)
{
	truc.className="croix_on";	
}

function croixoff(truc)
{
	truc.className="croix";	
}


function montrer(item)
{
	if ($.browser.msie) 
	{	
		
		lid=item.substr(item.lastIndexOf("_")+1);
		if(item.indexOf("rev")!=-1)
			activerrevue();
		else
			activeritem();
	}
	else
		$("#"+item).click();	
}

function effacerFormulaire()
{
	var frm=document.getElementById("frmcontact");	
	var tinput=frm.getElementsByTagName("input");
	for(var x=0;x<tinput.length;x++)
	{
		if(tinput[x].type=="text")
		{
			tinput[x].value="";		
		}
	}
	
	frm.getElementsByTagName("textarea")[0].value="";
}

function validerrecherche()
{
	
	if(document.getElementById("query").value.length>0 && document.getElementById("query").value!="Votre recherche")
		document.getElementById("frmrecherche").submit();
	
}

function decaler()
{
	window.scrollBy(0,-250);		
}

function validerformulaire(iform)
{	
	strMessageValidation="Le message a &eacute;t&eacute; envoy&eacute;";
	messageErreurFormulaire="";
	document.getElementById("messageerreur").style.display="none";
	iform=document.getElementById(iform);

	var tix=new Array();
	var nberreurs=0;
	tix=iform.getElementsByTagName("input");
		
	for(var x=0;x<tix.length;x++)
	{
		if((tix[x].type=="text" || tix[x].type=="password")  && tix[x].className.indexOf("obligatoire")!=-1)
		{
			while(tix[x].value.substr(0,1).indexOf(" ")!=-1)
				{
					tix[x].value=tix[x].value.substr(1);
				}
			if(tix[x].value.length<2)
			{
				tix[x].style.backgroundColor="#b30000";
				tix[x].style.color="#ffffff";
				nberreurs++;
			}
			else
			{
				//on verifie les espaces
				tix[x].style.backgroundColor="#ffffff";
				tix[x].style.color="#333333";
				if(tix[x].className.indexOf("courriel")!=-1)
					nberreurs=nberreurs+verifierCourriel(tix[x]);
			}
		}	
		if(messageErreurFormulaire.length>0)
		{
			document.getElementById("messageerreur").style.display="block";
			document.getElementById("messageerreur").innerHTML=messageErreurFormulaire;
		}
	}
	/*
	 GESTION DES SELECT
	 */
	tix=iform.getElementsByTagName("select");
	for(var x=0;x<tix.length;x++)
	{
		if(tix[x].className.indexOf("obligatoire")!=-1)
		{
			if(tix[x].value<1)
			{
				tix[x].style.backgroundColor="#b30000";
				tix[x].style.color="#ffffff";
				nberreurs++;
			}
			else
			{				
				tix[x].style.backgroundColor="#ffffff";
				tix[x].style.color="#333333";
				
			}
		}	
		if(messageErreurFormulaire.length>0)
		{
			document.getElementById("messageerreur").style.display="block";
			document.getElementById("messageerreur").innerHTML=messageErreurFormulaire;
		}
	}
	/*
	 GESTION DES TEXTAREA
	 */
	tix=iform.getElementsByTagName("textarea");
	for(var x=0;x<tix.length;x++)
	{
		if(tix[x].className.indexOf("obligatoire")!=-1)
		{
			if(tix[x].value.length<1)
			{
				tix[x].style.backgroundColor="#b30000";
				tix[x].style.color="#ffffff";
				nberreurs++;
			}
			else
			{				
				tix[x].style.backgroundColor="#ffffff";
				tix[x].style.color="#333333";
				
			}
		}	
		if(messageErreurFormulaire.length>0)
		{
			document.getElementById("messageerreur").style.display="block";
			document.getElementById("messageerreur").innerHTML=messageErreurFormulaire;
		}
	}
	if(nberreurs==0)
	{
		document.getElementById("messageerreur").style.display="none";
		
		if(strMessageValidation.length>0)
		{
			document.getElementById("messageerreur").style.display="block";
			document.getElementById("messageerreur").innerHTML=strMessageValidation;
		}
		//gestioncac(iform);
		//alert("le formulaire est valide... la methode submit() peut s'executer ");
		iform.submit();
		
		iform.reset();
	}
	else
		return false;
}


function verifierCourriel(nodeInput)
{
	
	if(nodeInput.value.indexOf("@")!=-1)
	{
		
		if(nodeInput.value.lastIndexOf(".")==-1)
		{
			nodeInput.style.backgroundColor="#b30000";
			nodeInput.style.color="#ffffff";
			messageErreurFormulaire+=strError_manqueExtension;
			return 1;			
		}
		else
		{
			nodeInput.style.backgroundColor="#ffffff";
			nodeInput.style.color="#333333";
			return 0;
		}			
	}	
	else {
		nodeInput.style.backgroundColor="#b30000";
		nodeInput.style.color="#ffffff";
		messageErreurFormulaire+=strError_manqueArobase;
		return 1;		
	}
}
