/*
	NOTES:
	javascript.js = codes js généraux
	
	g() = document.getElementById()
	l() = window.location.href
	temp## = indique une variable temporaire
	r = rollover
	
	1 - Codes généraux
	2 - Sous menu
	3 - Allonger page
	4 - Form
*/

	/* ========== CODES GÉNÉRAUX ================================================  */
var temp

function g(ceci)
{
	return(document.getElementById(ceci));
}

function r(ceci)
{
	if(leMenuActif!=ceci.id) {ceci.src=String(ceci.src).replace('.png','-r.png')}
	ceci.src=String(ceci.src).replace('-r-r.png','-r.png')
}

function ro(ceci)
{
	if(leMenuActif!=ceci.id) ceci.src=String(ceci.src).replace(/-r/g,'') 
}

function setOpacitySimple(el, opacity) 
{
	el = document.getElementById(el);

	el.style.opacity = opacity;
	el.style.MozOpacity = opacity;
	el.style.KhtmlOpacity = opacity;
	el.style.filter = "alpha(opacity="+(opacity * 100)+")";
}

function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
	while(1)
	{
	  curtop += obj.offsetTop;
	  if(!obj.offsetParent)
		break;
	  obj = obj.offsetParent;
	}
else if(obj.y)
	curtop += obj.y;
return curtop;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function pasvide(texte)
{
	texte=String(texte)
	if(texte==''||texte=='null'||texte=='undefined')texte='';return(texte)
}


	/* ========== SOUS-MENU ================================================  */

var leMenuActif=''
var leSMenuActif=''
var sousActif = null
var categorieActif = null  
var menuTimeout = null
var LeTimeOut = null

function smr(ceci)
{
	if(leSMenuActif!=ceci.id)
	{
		ceci.style.backgroundColor='#013668';
		ceci.style.color='white';
		document.body.style.cursor='pointer';
	}
	else
	{
		document.body.style.cursor='default';	
	}
}

function smro(ceci)
{
	if(leSMenuActif!=ceci.id)
	{
		ceci.style.backgroundColor='#F69F1A';
		ceci.style.color='#333333';
		document.body.style.cursor='';
	}
	else
	{
		document.body.style.cursor='';	
	}
}


function MenuRollOut(el) 
{
	clearInterval(intervale1);clearInterval(intervale2);clearInterval(intervale3);clearInterval(intervale4);

}

function rollOverSM(el)
{
	document.getElementById(el).style.backgroundColor='#621316'
}

function afficherSous(menu)
{
	if(menuTimeout!=null)	//si un sm est actif le cacher 
	{
		cacherSous(menuTimeout)
		clearTimeout(LeTimeOut)
	}
	
	//g('menu3').src='produits-r.png'
	
	g('s'+menu).style.display='block';
	//alert( findPosX(g(menu)) + '_'+ findPosY(g(menu)) )
		//Trouver X
	g('s'+menu).style.left=findPosX(g(menu))+'px'  //10+emplacementX+'px'
		//Trouver Y
	if (navigator.userAgent.indexOf("Firefox")==-1)
	{	
		g('s'+menu).style.top=155+'px'
	}
	else
	{
	g('s'+menu).style.top=160+'px'
	}

}

function SousMenuActif(id,menuCacher)
{
  
	LeTimeOut = setTimeout("cacherSous('"+menuCacher+"')",100)	
	var temp = menuCacher.substring(1,menuCacher.length)

	MenuRoll(temp)
} 

function IntervaleCacherSous(menu)
{
	//fermer le menu automatiquement apres 2 secondes
	menuTimeout=menu;
	LeTimeOut = setTimeout("cacherSous('"+menuTimeout+"')",400)
}

function ArretIntervaleCacherSous(menu)
{
	clearTimeout(LeTimeOut)
	//menuTimeout=null;
	LeTimeOut=null;
}


function cacherSous(menu)
{
	ro(g('menu3'));
	//document.getElementById('menu3').src='nos-divisions.jpg'
	g(menu).style.display='none';
}

	/* ========== ALLONGER PAGE ================================================  */
function allongerpage()
{
	var hauteur
	if ( Number( g('main_content').offsetHeight ) > Number(g('right_content').offsetHeight) )  hauteur=Number( g('main_content').offsetHeight ); else hauteur= Number(g('right_content').offsetHeight)
	
	g('main_content').style.height=hauteur +'px'
	g('right_content').style.height= Number(hauteur -3) +'px'

	g('logog').style.marginTop=Number(hauteur-470) +'px'
	g('logod').style.marginTop=Number(hauteur-430+5) +'px'
	
}

	
	
	/* ========== FORM ================================================  */	
	
function trim(val)	
{
if (!val) return val;

	while(val.charAt(0) == ' ') val = val.substring(1,val.length);
	while(val.charAt(length)==' ')  val = val.substring(0,val.length-1);

 return val;
}


function envoyer_reserv()
{
			//validation courriel
	var VerificationNum = trim(document.fo.c1.value);  // value of field with whitespace trimmed off
	var LettresEspaces = /^[a-zA-Z0-9\-_]{1,50}[a-zA-Z0-9\-_.]{0,50}[@][a-zA-Z0-9\-_]{1,50}[a-zA-Z0-9\-_.][a-zA-Z0-9\-_]{1,50}[.][a-zA-Z0-9]{1,50}[a-zA-Z0-9.]{1,50}$/
	if (  LettresEspaces.test(VerificationNum)) 
	{
		document.fo.c1.style.backgroundColor='white'
	}
	else
	{
		document.fo.c1.style.backgroundColor='#F69F1A'
	}
	
	if(	g('r1').checked==false && g('r2').checked==false ) g('c2').style.backgroundColor='#F69F1A' ; else g('c2').style.backgroundColor='white';
	
	if(
	   document.fo.c1.style.backgroundColor=='white' &&
	   g('c2').style.backgroundColor=='white'
	   )
	{document.fo.submit();}
	else{g('lemsg2').innerHTML="Veuillez remplir les champs ci-haut."}
}


function envoyer()
{
			//champs sont pas vide
	if(	pasvide(document.fo.c1.value) =='') document.fo.c1.style.backgroundColor='#F69F1A' ; else document.fo.c1.style.backgroundColor='white' ;
	if(	pasvide(document.fo.c2.value) =='') document.fo.c2.style.backgroundColor='#F69F1A' ; else document.fo.c2.style.backgroundColor='white' ;
	if(	g('r1').checked==false && g('r2').checked==false ) g('c3').style.backgroundColor='#F69F1A' ; else g('c3').style.backgroundColor='white'
	if(	pasvide(document.fo.c6.value) =='') document.fo.c6.style.backgroundColor='#F69F1A' ; else document.fo.c6.style.backgroundColor='white' ;
	if(	pasvide(document.fo.c7.value) =='') document.fo.c7.style.backgroundColor='#F69F1A' ; else document.fo.c7.style.backgroundColor='white' ;
	if(	pasvide(document.fo.c8.value) =='') document.fo.c8.style.backgroundColor='#F69F1A' ; else document.fo.c8.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c10.value) =='') document.fo.c10.style.backgroundColor='#F69F1A' ; else document.fo.c10.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c11.value) =='') document.fo.c11.style.backgroundColor='#F69F1A' ; else document.fo.c11.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c12.value) =='') document.fo.c12.style.backgroundColor='#F69F1A' ; else document.fo.c12.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c13.value) =='') document.fo.c13.style.backgroundColor='#F69F1A' ; else document.fo.c13.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c14.value) =='') document.fo.c14.style.backgroundColor='#F69F1A' ; else document.fo.c14.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c15.value) =='') document.fo.c15.style.backgroundColor='#F69F1A' ; else document.fo.c15.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c16.value) =='') document.fo.c16.style.backgroundColor='#F69F1A' ; else document.fo.c16.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c17.value) =='') document.fo.c17.style.backgroundColor='#F69F1A' ; else document.fo.c17.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c18.value) =='') document.fo.c18.style.backgroundColor='#F69F1A' ; else document.fo.c18.style.backgroundColor='white' ;
//	if(	pasvide(document.fo.c19.value) =='') document.fo.c19.style.backgroundColor='#F69F1A' ; else document.fo.c19.style.backgroundColor='white' ;
//	if(	g('r3').checked==false && g('r4').checked==false ) g('c21').style.backgroundColor='#F69F1A' ; else g('c21').style.backgroundColor='white';
	
									//note: ajout pour "diner"
//		if(	g('r5').checked==false && g('r6').checked==false ) g('c24').style.backgroundColor='#F69F1A' ; else g('c24').style.backgroundColor='white';


			//validation courriel
	var VerificationNum = trim(document.fo.c9.value);  // value of field with whitespace trimmed off
	var LettresEspaces = /^[a-zA-Z0-9\-_]{1,50}[a-zA-Z0-9\-_.]{0,50}[@][a-zA-Z0-9\-_]{1,50}[a-zA-Z0-9\-_.][a-zA-Z0-9\-_]{1,50}[.][a-zA-Z0-9]{1,50}[a-zA-Z0-9.]{1,50}$/
	if (  LettresEspaces.test(VerificationNum)) 
	{
		document.fo.c9.style.backgroundColor='white'
	}
	else
	{

		document.fo.c9.style.backgroundColor='#F69F1A'
		
	}
		
	if(
	   document.fo.c1.style.backgroundColor=='white' &&
	   document.fo.c2.style.backgroundColor=='white' &&
	   g('c3').style.backgroundColor=='white' &&
	   document.fo.c6.style.backgroundColor=='white' &&
	   document.fo.c7.style.backgroundColor=='white' &&
	   document.fo.c8.style.backgroundColor=='white' &&
//	   document.fo.c10.style.backgroundColor=='white' &&
//	   document.fo.c11.style.backgroundColor=='white' &&
//	   document.fo.c12.style.backgroundColor=='white' &&
//	   document.fo.c13.style.backgroundColor=='white' &&
//	   document.fo.c14.style.backgroundColor=='white' &&
//	   document.fo.c15.style.backgroundColor=='white' &&
//	   document.fo.c16.style.backgroundColor=='white' &&
//	   document.fo.c17.style.backgroundColor=='white' &&
//	   document.fo.c18.style.backgroundColor=='white' &&
//	   document.fo.c19.style.backgroundColor=='white' &&
//	   g('c21').style.backgroundColor=='white' &&

														// NOTE: ajout pour "diner"
//	   g('c24').style.backgroundColor=='white' &&

	   document.fo.c9.style.backgroundColor=='white'
	   )
	{document.fo.submit();}
	else{g('lemsg2').innerHTML="Veuillez remplir les champs ci-haut."}
}

function imprimer()
{
	var yourDOCTYPE = ""; // your doctype declaration
	var printPreview = window.open('about:blank', 'print_preview');
	var printDocument = printPreview.document;
	printDocument.open();
	printDocument.write(yourDOCTYPE+
	   "<html>"+
		   document.documentElement.innerHTML+
	   "</html>");
	printDocument.close();
}
