// JavaScript Document
var blnDone = false;

function init() {
   // quit if this function has already been called
   if (blnDone) return;

   // flag this function so we don't do the same thing twice
   blnDone = true;
	    
   // Gestion du formulaire d'accès client
   var objFormAcces = document.getElementById("frmAcces");
   
   if (objFormAcces) {
		
	   objFormAcces.onsubmit = function () {

			if (validateFormAcces(this)) {
				return true;
			}
			else {
				return false;	
			};	
		}
		
   } 
   
   // Afficher le Flash en accueil
   if (document.getElementById("headermovie")) {
		displayHeaderFlash("fr");   
   }
   
   // Afficher le Flash en accueil
   if (document.getElementById("headermovieen")) {
		displayHeaderFlash("en");   
   }
   
   var objFormContact = document.getElementById("frmContact");
   
   if (objFormContact) {
		objFormContact.onsubmit = function () {
			if (validateFormContact(this)) {
				return true;
			}
			else {
				return false;
			}
		}
   }
   
   if (typeof jQuery != "undefined") { 
	   $(".definition em").hover(function() {
			$(this).next("span").stop(true, true).animate({opacity: "show", top: "20"}, "slow");
		}, function() {
			$(this).next("span").animate({opacity: "hide", top: "20"}, "fast");
		});
	   
	   if ($("#photo-section").length > 0) {
		$('#photo-section a').lightBox();
	   }
	   
	   if ($("#slideshow").length > 0) {
		   var intMax = $("#slideshowmax").val()-1;
		   
		   if (intMax > 0) {
		   //This keeps track of the slideshow's current location
			var current_panel = 1;
			//Controlling the duration of animation by variable will simplify changes
			var animation_duration = 8000;
			
			
			
			$.timer(12000, function (timer) {
				//Determine the current location, and transition to next panel
				switch(current_panel){
					case 1:
						$("#slideshow").stop().animate({left: "-388px", top: "0px"}, "");
						if (current_panel == intMax) {
							current_panel = 4;
						}
						else {
							current_panel = 2;
						}
						
					break;
					case 2:
						$("#slideshow").stop().animate({left: "-776px", top: "0px"}, "");
						if (current_panel == intMax) {
							current_panel = 4;
						}
						else {
							current_panel = 3;
						}
					break;
					case 3:
						$("#slideshow").stop().animate({left: "-1164px", top: "0px"}, "");
						current_panel = 4;
					break;
					case 4:
						$("#slideshow").stop().animate({left: "0px", top: "0px"}, "");
						current_panel = 1;
					break;	
					timer.reset(12000);
				}
			});
		   }
		   }
   }
   
};


/* Ce bout de code est ajout? afin d'appeler init seulement lorsque le DOM est charg? compl?tement */
/* for Mozilla */
if (document.addEventListener) {
   document.addEventListener("DOMContentLoaded", init, null);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
   document.write("<script defer src=ie_onload.js><"+"/script>");
/*@end @*/

/* for other browsers */
window.onload = init;

function displayHeaderFlash(strLangue) {
	var flashvars = false;
	var params = {
	wmode:"transparent"
	};
	var attributes = false;
	
	var strMovie;
	
	if (strLangue == "fr") {
		swfobject.embedSWF("flash/PolytechFR.swf", "headermovie", "460", "166", "9.0.0", "flash/swfobject/expressInstall.swf", flashvars, params, attributes);
	} else {
		swfobject.embedSWF("flash/PolytechEN.swf", "headermovieen", "460", "166", "9.0.0", "flash/swfobject/expressInstall.swf", flashvars, params, attributes);
	}
	
	
}

function displayCitySelection() {
		var objSelectBureau = document.getElementById("selBureau");
		
		if (objSelectBureau) {
				objSelectBureau.style.display = "block";
		}
}

function changeCity(objSelection) {
	var strCity = objSelection.value;
	var strVille = objSelection.options[objSelection.selectedIndex].text;
	var objFrameWeather = document.getElementById("frmWeather");
	
	if (objFrameWeather) {
		var strUrl = "affichage-meteo.asp?code=" + strCity + "&ville=" + strVille;
		objFrameWeather.className = strCity;
		objFrameWeather.src = strUrl;
		//objFrameWeather.reload();
	}
	
	objSelection.style.display = "none";

}

function displayExpertise(objListe) {
		
	var objListeDescription = document.getElementsByTagName("ul");
		
	for (i=0; i < objListeDescription.length; i++) {
			if (objListeDescription[i].className == "liste-description") {
					var objItemExpertise = objListeDescription[i].getElementsByTagName("ul");
					
					for (y=0; y < objItemExpertise.length; y++) {
						objItemExpertise[y].style.display = "none";
					}
			}
	}	
	
	var objItemDisplay = objListe.getElementsByTagName("ul");
	
	for (z = 0; z < objItemDisplay.length; z++) {
		objItemDisplay[z].style.display = "block";
	}
		
}

function validateFormAcces(frmSearch) {
	
	var blnValide = true;
	var strLabel = "";

	var strCodeUser = document.getElementById("txtCodeUsager").value;
	var strPwd = document.getElementById("txtMotPasse").value;
	
	if (strCodeUser == "") {
		alert("Vous devez préciser votre code usager.");
		blnValide = false;
	}
	else if (strPwd == "") {
		alert("Vous devez précisez votre mot de passe.");
		blnValide = false;
	}
	
	return blnValide;
}

function validateFormContact(frmJoindre) {
	var blnValide = true;

	if (document.getElementById("txtCourriel").value == "" || document.getElementById("txtSujet").value == "" || document.getElementById("txaMessage").value == "" || document.getElementById("selBureauDetail") == "0") {
		alert("Tous les champs du formulaire sont obligatoires");
		return false;
	}
	
	return blnValide;
}

function afficheRegion(selIntervention) {
	var objLabelRegion = document.getElementById("labRegion");
	var objSelRegion = document.getElementById("selRegion");
	
	if (selIntervention == "sur-place") {
		objLabelRegion.style.display = "block";
		objSelRegion.style.display = "block";
	}
	else {
		objLabelRegion.style.display = "none";
		objSelRegion.style.display = "none";
	}
}

