var glogalTM;

function init_js(){
	
	rollOvers();
	loadMasks();
	
	// fonctions pour IE seulement ...
	if(window.attachEvent){
		startList();
		overBtn();
		highLights();
	}
}


function startList(){
	if(document.getElementById("nav")){
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

function rollOvers(){
	if (!document.getElementById) return
	
	var imgOriginSrc;
	var MouseOverHappened;
	var oldtop;
	var imgTemp = new Array();
	var imgarr = document.getElementsByTagName('img');
	
	for (var i = 0; i < imgarr.length; i++) {
		//Attribut hsrc pour Rollovers
		if (imgarr[i].getAttribute('hsrc')) {
			imgTemp[i] = new Image();
			imgTemp[i].src = imgarr[i].getAttribute('hsrc');
			imgarr[i].onmouseover = function() {
				imgOriginSrc = this.getAttribute('src');			
				this.setAttribute('src',this.getAttribute('hsrc'));
				MouseOverHappened=true;
			}
			imgarr[i].onmouseout = function() {
				if(MouseOverHappened)
					this.setAttribute('src',imgOriginSrc);
			}
		}
	
		//Attribut csrc pour action de click comme boutons
		if (imgarr[i].getAttribute('csrc')) {
			imgTemp[i] = new Image();
			imgTemp[i].src = imgarr[i].getAttribute('csrc');
			imgarr[i].onmousedown = function() {
				imgOriginSrc = this.getAttribute('src');			
				this.setAttribute('src',this.getAttribute('csrc'));
				MouseOverHappened=true;
			}
			imgarr[i].onmouseup = function() {
				if(MouseOverHappened)
					this.setAttribute('src',imgOriginSrc);
			}
		}
	}
}

function loadMasks(){
	var tags = new Array('input','textarea','span');
	for (var k = 0; k < tags.length; k++) {
		var inparr = document.getElementsByTagName(tags[k]);
		for (var i = 0; i < inparr.length; i++) {
			if(inparr[i].getAttribute('mask')){
				var div,childs,nfos;
				var image = new Array("qmark.gif","emark.gif")
				nfos = inparr[i].getAttribute('mask').split(";");
				
				if(nfos[0]!=-1){
					div = inparr[i].parentNode;
					div.className = div.className+" nfoLbl";
					div.innerHTML = '<div class="nopad">'+div.innerHTML+'</div><div style="padding-left: 5px;"><img src="/gestion/images/'+image[nfos[0]]+'" width="16" height="16" /><span style="display: none;">'+nfos[1]+'</span></div>';
					
					//Applique le mouseover sur l'image
					div.childNodes[1].childNodes[0].onmouseover = function() {
						pardiv = this.parentNode;
						span = pardiv.getElementsByTagName("span");
					
						span[0].style.display='';
						span[0].style.top=(this.offsetTop-span[0].offsetHeight+20)+'px';
						span[0].style.left=(this.offsetLeft-span[0].offsetWidth+20)+'px';
	
						span[0].onmouseout = function() {span[0].style.display='none';}
						MouseOverHappened=true;
					}
					
					//Applique le mouseout sur l'image
					div.childNodes[1].childNodes[0].onmouseout = function() {
						if(MouseOverHappened){
							pardiv = this.parentNode;
							span = pardiv.getElementsByTagName("span");
				
							span[0].style.display='none';
							span[0].onmouseover = function() {span[0].style.display='';}
						}
					}
				}
			}
		}
	}
}

function overBtn(){
	var sfBtns = document.getElementsByTagName("INPUT");
	for (var i=0; i<sfBtns.length; i++) {
		if(sfBtns[i].className=="btn"){
			//sfBtns[i].style.width="0";
			sfBtns[i].onmouseover=function() {
				this.className="btno";
			}
			sfBtns[i].onmouseout=function() {
				this.className="btn";
			}
		}
	}
}

function highLights(){
	var tags = new Array("tr","div");
	for (var k=0; k<tags.length; k++){
		var sfElems = document.getElementsByTagName(tags[k]);
		for (var i=0; i<sfElems.length; i++) {
			if(sfElems[i].className.indexOf("highlight")!=-1){
				sfElems[i].onmouseover=function() {
					this.className=this.className.replace(/ highlight/," highlighto");
				}
				sfElems[i].onmouseout=function() {
					this.className=this.className.replace(/ highlighto/," highlight");
				}
			}
		}
	}
}

function chgsrc(id,img){
	clearTimeout(glogalTM);
	setTimeout('document.getElementById("'+id+'").style.backgroundImage="url(images/bg-loading.gif)";',1);
	glogalTM = setTimeout('document.getElementById("'+id+'").style.backgroundImage="url(images/realisations/4-'+img+'.jpg)";',1000);
}

//Manual Scroller- © Dynamic Drive 2001
//For full source code, visit http://www.dynamicdrive.com
//Modified by Pierre-Michel Morais-Godin for ADN Communication 2006
//Please visit http://www.adncomm.com
function movedown(crossobj,contentheight,speed,scroller){
	if(!contentheight) getcontent_height(crossobj);
	maxHeight = scroller.offsetHeight;
	if (window.moveupvar) clearTimeout(moveupvar);
	if (parseInt(crossobj.style.top)>=(contentheight*(-1)+maxHeight)) crossobj.style.top=parseInt(crossobj.style.top)-speed+"px";
	movedownvar=setTimeout("movedown(crossobj,contentheight,speed,scroller)",20);
}

function moveup(crossobj,speed){
	if(!contentheight) getcontent_height(crossobj);
	if (window.movedownvar) clearTimeout(movedownvar);
	if (parseInt(crossobj.style.top)<=-speed) crossobj.style.top=parseInt(crossobj.style.top)+speed+"px";
	moveupvar=setTimeout("moveup(crossobj,speed)",20);
}

function stopscroll(){
	if (window.moveupvar) clearTimeout(moveupvar);
	if (window.movedownvar) clearTimeout(movedownvar);
}

function movetop(crossobj){
	stopscroll()
	crossobj.style.top=0+"px";
}

function getcontent_height(crossobj){
	contentheight=crossobj.offsetHeight;
}
//End Manual Scroller- © Dynamic Drive 2001

function IsEmpty(champ,Message)
{
	if (champ.value == "")
	{
		alert(Message);
		champ.focus();
		return(true);
	}
	return(false);
}

function validFormDemande(){
	if (IsEmpty(document.formulaire.nom,"Veuillez entrer votre nom")) return(false);
	if (IsEmpty(document.formulaire.email,"Veuillez entrer votre adresse de courriel")) return(false);
	if (IsEmpty(document.formulaire.tel,"Veuillez entrer votre numéro de téléphone")) return(false);
	if (IsEmpty(document.formulaire.message,"Veuillez entrer votre message")) return(false);
	return(true);
}

// DÉBUT fonctions DW
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// --- FIN fonctions DW