var ACTION_AFFICHE_CHOIX_VILLE = staticPath+'/accueil/afficherChoixVille.do';
var ACTION_VALIDE_LIBELLE_LOCALITE = staticPath+'/accueil/valideLibelleLocalite.do';
var ACTION_AFFICHER_GRANDE_CARTE = staticPath+'/cinema/AfficherGrandeCarte.do';
var ACTION_AFFICHER_GRANDE_CARTE_GUIDE = staticPath+'/guide/AfficherGrandeCarte.do';
var ACTION_AFFICHER_CARTE_PLAN_VUE = staticPath+'/cinema/AfficherPlanVueLRAction.do';

var ua		= navigator.userAgent;
var opera	= /opera [56789]|opera\/[56789]/i.test(ua);
var ie = !opera && /msie [56789]/i.test(ua);
var ie7 = ie && /msie 7/i.test(ua);
var ie6 = ie && /msie 6/i.test(ua);
var safari		= !opera && /safari\/[56789]/i.test(ua);
var moz		= !opera && !safari && /mozilla\/[56789]/i.test(ua);


// var gl
var gFormVilleId;

//valeur temporaire 
var valueIdVilleOuCp = "";
// ==============================================================
// Initialisation de la fonction de roll-over 
// sur la navigation pour IE 6
function initVedNav(){

	if(ie && !ie7){
		$("#navigation ul li").hover(
		  function () {
		    $(this).addClass("hover");
		  },
		  function () {
		    $(this).removeClass("hover");
		  }
		);
	}

}

var submitFormulaire = false;

// ==============================================================
// Initialisation de la fonction de roll-over 
// sur la navigation pour IE 6
function initVedContextualisation(){

	$("#choixVilleVED").click(
		function(){
			fermerDivAide();
			if ($("#N1_VedChoixVille").css('display') == 'block')
			{
				//la light box est déja affiché, on la supprime
				$("#N1_VedChoixVille").remove();
				$(".N2_ved_super_nav_loc > iframe").remove();
				//modifie le css pour affichage picto
				$("#choixVilleVED").removeClass("replier");
				$(".N2_ved_super_nav_loc > #ambiguiteOu").remove();
			}
			else
			{
				//on affiche la light box
				TRAITEMENT_RETOUR=afficheChoixVilleRetour;
				appelAjax(ACTION_AFFICHE_CHOIX_VILLE, "");
				if(ie && !ie7){
					// Dimensionnement "dynamique" de l'iframe pour IE 6.
					// Necessite de le declencher avec un timeout.
					window.setTimeout('$("#divContextualisation iframe").css("height", $("#divContextualisation").height() );',200);
				}
				//modifie le css pour affichage picto
				$("#choixVilleVED").addClass("replier");
			}
			return false;
		}
	);
}

// 
function afficheChoixVilleRetour(){
	// Le traitement n'est effectue que lorsque : 
	//  - La reponse a ete recue (readuState == 4)
	//  - Le format est celui attendu (Flux TEXT -> ajax.responseText est non null)
	if (ajax.readyState == '4'){
		if(ajax.responseText) {
			//si la light box est déja affiché, on la supprime
			if ($("#N1_VedChoixVille").css('display') == 'block')
			{
				//la light box est déja affiché, on la supprime
				$("#N1_VedChoixVille").remove();
				$(".N2_ved_super_nav_loc > iframe").remove();
				$(".N2_ved_super_nav_loc > #ambiguiteOu").remove();
			}
			$(".N2_ved_super_nav_loc > span").after(ajax.responseText);
			window.setTimeout("initVedContextualisationApresChargementAjax()",200);
			if(ie && !ie7){
				// Dimensionnement "dynamique" de l'iframe pour IE 6.
				// Necessite de le declencher avec un timeout.
				window.setTimeout('$("#divContextualisation iframe").css("height", $("#divContextualisation").height() );',200);
			}
		}
	}
}


// control localite
function valideLibelleLocaliteRetour(){
	// Le traitement n'est effectue que lorsque : 
	//  - La reponse a ete recue (readuState == 4)
	//  - Le format est celui attendu (Flux XML -> ajax.responseXML est non null)
	
	var bContextDisplay = ( $("#divContextualisation").css("display") == 'block' )? true : false;
	var iContextLeft = $("#divContextualisation").css("left");
	var iContextTop = $("#divContextualisation").css("top");
	var iContextRight = $("#divContextualisation").css("right");
	
	if( iContextLeft == 'auto' && bContextDisplay ){
		if( parseInt(iContextRight) > 140 ){
			// Cas du clic dans le fil d'ariane
			iContextLeft = "125px";
		}else{
			// Cas du clic sur zone dans bandeau noir superieur
			iContextLeft = "390px";
		}
	}
	
	if (ajax.readyState == '4' && ajax.responseXML) {
		// Recuperation de l'element racine
		var isValide = ajax.responseXML.getElementsByTagName("isValide");
		if (isValide && isValide[0]) {
			var value =	isValide[0].getAttribute("value");
			if(value=="true"){
				//localite est valide, submit du formulaire avec le codeLieu recupere
				var lieu = isValide[0].getElementsByTagName("lieu");
				var codeLieu = lieu[0].getAttribute("codeLieu");
				
				$("#"+gFormVilleId+" > .hlocalite").val(codeLieu);
				submitFormulaire = true;
			}else{
				//la localite n'est pas valide, affichage du message retourne dans le xml
				$("#"+gFormVilleId+" > .alerte p:first").html(isValide[0].getElementsByTagName("message")[0].getAttribute("value"));
				$("#"+gFormVilleId+" > .alerte").show();
				submitFormulaire = false;
			}
		} 
		var isAmbigu = ajax.responseXML.getElementsByTagName("isAmbigu");
		if (isAmbigu && isAmbigu[0]) {
			$("#nbLocaliteAmbigue").html(isAmbigu[0].getAttribute("nbLocalites"));
			//une ambigiute a ete levee creation de la liste d'ambiguite e afficher
			//recuperation de la liste des rubriques
			var contenuListeLieu = document.getElementById("contenuListeLieu");
			// suppression du contenu deje existant
			contenuListeLieu.innerHTML = "";
			var listeLieu = isAmbigu[0].getElementsByTagName("lieu");
			for (i=0;i<listeLieu.length;i++){
				var lieu = recupererObjetLieu(listeLieu[i]);
				var liLieu = document.createElement('li');
				contenuListeLieu.appendChild(liLieu);
				var ahref = "#null";
				var onclick ="selectionnerLocaliteAmbigue(\""+lieu.code+"\", \""+lieu.libelle+"\");";
				liLieu.appendChild(creerAhrefVed(lieu.libelle,ahref,onclick));
			}
						
			window.setTimeout('showAmbiguiteContext()',200);

			submitFormulaire = false;
		}
	}
}

function showAmbiguiteContext(){
	var bContextDisplay = ( $("#divContextualisation").css("display") == 'block' )? true : false;
	var iContextLeft = $("#divContextualisation").css("left");
	var iContextRight = $("#divContextualisation").css("right");
	var iContextTop = $("#divContextualisation").css("top");
	// IE ne calcule pas la position Left si c'est le right 
	// qui est donne dans la css...
	if( iContextLeft == 'auto' && bContextDisplay ){
		if( parseInt(iContextRight) > 140 ){
			// Cas du clic dans le fil d'ariane
			iContextLeft = "125px";
		}else{
			// Cas du clic sur zone dans bandeau noir superieur
			iContextLeft = "390px";
		}
	}
	var iAmbigLeft = (bContextDisplay) ?  parseInt(iContextLeft) : 15;
	var iAmbigTop  = (bContextDisplay)? parseInt(iContextTop)+80 : 55;
	
	$("#ambiguiteContext").css("left", iAmbigLeft );
	$("#ambiguiteContext").css("top", iAmbigTop );
	$("#ambiguiteContext").css("z-index","2002");
	
	$("#ifrAmbiguiteContext").css("left", iAmbigLeft );
	$("#ifrAmbiguiteContext").css("top", iAmbigTop );
	$("#ifrAmbiguiteContext").height( $("#ambiguiteContext").height() );
	$("#ifrAmbiguiteContext").width( $("#ambiguiteContext").width() );
	$("#ifrAmbiguiteContext").css("z-index","2001");

	$("#ambiguiteContext").show();
	$("#ifrAmbiguiteContext").show();
	// Re-initialisaton des fonctions de la fenetre d'ambiguite
	// Bouton fermer
	$("#ambiguiteContext .aFermerAmbiguite").click(
		function(){
			$("#ambiguiteContext").hide();
			$("#ifrAmbiguiteContext").hide();
		}
	);
	if (ie) {
  	//Liens de selection d'une localite
		$("#ambiguiteContext #contenuListeLieu li a").click(function(){
			eval($(this).attr("onClick"));
		});
	}
}

function selectionnerLocaliteAmbigue(idLocalite, libLocalite){
	$("#"+gFormVilleId+" > .hlocalite").val(idLocalite);
	$("#"+gFormVilleId+" > .contextVilleOuCp").val(libLocalite);
	$("#"+gFormVilleId).submit();
	$("#ambiguiteContext").hide();
	$("#ifrAmbiguiteContext").hide();
}


function selectionnerLocaliteConsultOuFavo(idLocalite, libLocalite){
	$("#"+gFormVilleId+" > .hlocalite").val(idLocalite);
	$("#"+gFormVilleId+" > .text").val(libLocalite);
	return false;
}

/**
 * Creer un noeud correspondant e un ahref avec comme attribut, le libelle du lien et son url
 */
function creerAhrefVed(libelleLien, href,onclick){
	var libelle = document.createTextNode(libelleLien);
	var ahref = document.createElement("a");
	ahref.setAttribute("href",href);
	if (ie) {
		ahref.onclick = onclick;
	}else{
		ahref.setAttribute("onClick",onclick);
	}
	ahref.appendChild(libelle);
	return ahref;
	
}


function recupererObjetLieu(noeudPere){
	var lieu = new Object();
	lieu.code = noeudPere.getAttribute("codeLieu");
	lieu.libelle = noeudPere.getAttribute("libelleLieu");
	return lieu;
}     
	
function initVedContextualisationApresChargementAjax(){
	var oContext = $("#N1_VedChoixVille");
	var oIframe = $(".N2_ved_super_nav_loc iframe");
	
	o = document.getElementById("N1_VedChoixVille");
	
	
	
	if(o.ifr==null){
		
		o.inp = o.getElementsByTagName("INPUT")[0];
		o.inp.refval = o.inp.value;
		o.inp.onfocus = function(){ this.value=(this.value==this.refval)?'':this.value;}
		o.inp.onblur = function(){ this.value=(this.value=='')?this.refval:this.value;}
	}
			
	if(o.style.display!='block'){
		o.style.visibility = 'hidden';
		o.style.display = 'block';
		o.style.visibility = 'visible';
	}
	else{
		//o.ifr.style.display = o.style.display = 'none';
	}
	oContext.show();
	
	oIframe.css("height", o.offsetHeight + "px");
	oIframe.css("width", o.offsetWidth + "px");
	oIframe.css("display",'block');
	
	var oInput = $("#contextVilleOuCp");
	
			$("#aFermer").click(
				function(){
					oContext.hide();
					$("#divContextConfirm").hide();
					$("#divContextConfirm iframe").hide();
					if(!ie && /meteo/.test($("body").attr("class")) != false ){
						//#0011607 : Bulletin video du jour : Re-affichage du embed.
						$(".N2_ved_webcam_embed_b embed").css("visibility", "visible");
					}
					return false;
				}
			);
			$("#aAide").click(
				function(){
					ouvrirPopupAideWebcam($("#aAide").attr("href"));
					return false;
				}
			);
			
			$("#aSetAsHomePage").click(
				function(){
					if (window.external && document.all) {
						document.body.style.behavior='url(#default#homepage)';
						document.body.setHomePage(staticPath+'/accueil/AccueilVed.do');
					}
					else {
						alert("Fonction non support\351e par le navigateur");
					}
					return false;
				}
			);
			$("#aFermerAmbiguite").click(
				function(){
					$("#ambiguiteContext").hide();
					return false;
				}
			);
		
			
			
			oInput.click(
				function(){
						$(this).val("");
						$(this).focus();
						$("#alerteContextVilleOuCp").hide();
				}
			);
			oInput.keydown(
				function(){
					valueIdVilleOuCp = oInput.val();
				}
			);
			
			

}

function removeVilleConsultee(idLocalite){
	TRAITEMENT_RETOUR=afficheChoixVilleRetour;
	appelAjax(ACTION_AFFICHE_CHOIX_VILLE+ "?idLocalite="+idLocalite, "");
	return false;
}

// ==============================================================
// En FIN, lancement des fonctions au chargement de la page.
function initVedDate() {
	var today = new Date();
	var iDay = today.getDay();
	var iMonth = today.getMonth();
	var iYear = today.getFullYear();
	var aDays = new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
	var aMonth = new Array("Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Ao&ucirc;t","Septembre","Octobre","Novembre","Decembre");
	$("#hdate").html( aDays[iDay]+" "+today.getDate()+" "+aMonth[iMonth]+" "+iYear+" "  );
	$("#saints").html( getSaintDuJour() );
}


// ==============================================================
// CINEMA
function initCineBandesAnnonces(){
	$("a.aVoirBA").click(
		function(e){
			// Affichage de la BA
			openBA( $(this), e );
			// Gestion des stats
			if (/evenements/.test($("body").attr("class")) != false) {
	  		sendStat($(this));
			}
			return false;
		}
	);
}
//--------------------------------------------------------------------
// Gestion de l'affichage des BANDES ANNONCES
// ouverture bande annonce
function openBA( jQThis, evt ) {

	var sFilmUrl = jQThis.attr("href");
	var iFilmId = "";
	var sPlayerClass = "";
	if(/www.allocine.fr/.test(sFilmUrl)){
		iFilmId = sFilmUrl.substring( sFilmUrl.lastIndexOf("/") + 1 );
		sPlayerClass = " allocine";	
	}else if( /www.clubvisioscene.com/.test(sFilmUrl) )  {
		iFilmId= parseInt( Math.random()* 10000 );
		sPlayerClass = " clubvisioscene";
	}

	// Fermeture (= suppression DOM) de toutes es autres BA.
	$(".cinePlayerBandeAnnonce").remove();
	
	var sHtml  = '<div id="divBa_'+iFilmId+'" class="cinePlayerBandeAnnonce'+sPlayerClass+'" style="display:none">';
			sHtml += '<a id="aFermerPlayer" title="Fermer le player">Fermer</a>';
			sHtml += '<div id="ifAllocine" scrolling="none">&nbsp;</div>';
			sHtml += '<script type="text/javascript">';
			sHtml += 'var so = new SWFObject("' + sFilmUrl + '", "ifAllocine", "442px", "370px", "9");';
			sHtml += 'so.addParam("allowFullScreen", "true");'
			sHtml += 'so.addParam("allowScriptAccess", "always");'
			sHtml += 'so.write("ifAllocine");'
			sHtml += '</script>';
			sHtml += '</div>';
	
			
	
	// Ajout du player dans le div de contenu
	$("#bodyContent").append( sHtml );
	
	// Positionnement + Affichage
	var oDiv = $("#divBa_"+iFilmId);

	var iBaHeight = parseInt(oDiv.height());
	var iBaWidth = parseInt(oDiv.width());
	
	var winWidth  = $(".N2_pg_col1").width(); //window.innerWidth;
	var winHeight = parseInt($("#bodyContent").height());
			winHeight = (winHeight > 0) ? winHeight : $(window).height();

	// Calcul de la position Top
	var iBaTop 	= ( Math.round( evt.pageY - (iBaHeight/2) )  - $("#bodyContent").offset().top );
	
	// Calcul de la position Left
	var iBaLeft = Math.round( (winWidth/2) - (iBaWidth/2) );
	
			oDiv.css('top', iBaTop );
			oDiv.css('left', iBaLeft );
			oDiv.show();	
	// Deplacement du scroll jusqu'au player
	// scrollTo( oDiv.offset().left , oDiv.offset().top ); 
	
	if (ie6) {//IE6
		var sHtml  = '<iframe id="iframeBa_'+iFilmId+'" class="cinePlayerBandeAnnonce" style="display:none" width='+oDiv.width()+'" height='+oDiv.height()+'" top='+iBaTop+'" left='+iBaLeft+'"></iframe>';
		// Ajout du iframe dans le div de contenu
		$("#bodyContent").append( sHtml);
 	}
  
	// Initialisation de la fonction de fermeture (= suppression DOM).
	$("#aFermerPlayer").click(
		function(){
			$(this).parent().remove();
		}	
	);
}


// Gestion de l'affichage des Popups d'aide sur la Light Box
var currentDivAide;
function openPopupAide(thisObj,idDiv) {
	currentDivAide = idDiv;
	var ie = !opera && /msie [56789]/i.test(ua);
	var ie6 = ie && /msie 6/i.test(ua);

	var actionAjax = thisObj;
	if (ie6) {
		TRAITEMENT_RETOUR = affichePopupAide;
		appelAjax(actionAjax,"", true); // appel synchrone
	}
	else {
		TRAITEMENT_RETOUR = null;
		appelAjax(actionAjax,"", true); // appel synchrone
		affichePopupAide();
	}
	
	return false;
}

function affichePopupAide(){
	if (ajax.readyState == '4' && ajax.responseText){		
	
		fermerDivAide();
		
		// Ajout de la div dans le contenu
		$("#"+currentDivAide).html( ajax.responseText );
		$("#"+currentDivAide).show();
		
		// Insertion de l'iframe sous-jacente
		$("#"+currentDivAide).after("<iframe id='iframeAide"+currentDivAide+"' class='iframeDivAide' frameborder='0' scrolling='no'>&nbsp;</iframe>");
		$("#iframeAide"+currentDivAide).css("height",$("#"+currentDivAide).height());
		$("#iframeAide"+currentDivAide).css("width",$("#"+currentDivAide).width());
		$("#iframeAide"+currentDivAide).show();
	}
}

function fermerDivAide(){
	if ($("iframe[id^='iframeAide']").hasClass('iframeDivAide')){
		$("div[id^='divAide']").empty();
		$("div[id^='divAide']").hide();
		$("iframe[id^='iframeAide']").remove();
	}
	return false;
}





// Gestion de l'affichage de la popup Zoom Diaporama
function afficheFenetreDiaporama(codeEtablissement,codePartenaire,thematique ){
	var ua		= navigator.userAgent;
	var opera	= /opera [56789]|opera\/[56789]/i.test(ua);
	var ie = !opera && /msie [56789]/i.test(ua);
	var ie6 = ie && /msie 6/i.test(ua);

	// Ajout de la div dans le contenu 
	$("#iframeZoom").height($("#N1_ved").height());
	$("#iframeZoom").width($("#N1_ved").width());	
	if(ie && !ie6){
		//IE7
		$("#iframeZoom").css("margin-top",-133);
	}else{
		//autres navigateurs
		$("#iframeZoom").css("margin-top",-144); 
	}

	$("#iframeZoom").css("margin-left",-15);		
	$("#iframeZoom").attr("src",staticPath+'/guide/AfficherDiaporama.do?codeEtablissement='+ codeEtablissement + '&codePartenaire=' + codePartenaire + '&thematique=' + thematique);
	
	$("#zoom").width($("#N1_ved").width());		
	$("#iframeZoom").show(); 

}

// Gestion de l'affichage de la popup Zoom Video
function afficheFenetreVideo(urlVideo){	
	var ua		= navigator.userAgent;
	var opera	= /opera [56789]|opera\/[56789]/i.test(ua);
	var ie = !opera && /msie [56789]/i.test(ua);
	var ie6 = ie && /msie 6/i.test(ua);

	// Ajout de la div dans le contenu
	$("#iframeZoom").height($("#N1_ved").height());
	$("#iframeZoom").width($("#N1_ved").width());	
	
	if(ie && !ie6){
		//IE7
		$("#iframeZoom").css("margin-top",-133); 
	}else{
		//autres navigateurs
		$("#iframeZoom").css("margin-top",-144); 
	}

	$("#iframeZoom").css("margin-left",-15);		
	$("#iframeZoom").attr("src",staticPath+'/guide/AfficherVideo.do?urlVisualisation=' + encodeURIComponent(urlVideo));

	$("#zoom").width($("#N1_ved").width());	
	$("#iframeZoom").show(); 
			
	
}


//------------------------------------------------------
function show(id) {
	var d = document.getElementById(id);
	if (d) {
		$("#"+id).show();
	}
}
//------------------------------------------------------
function hide(id) {
	var d = document.getElementById(id);
	if (d) {
		$("#"+id).hide();
	}
	
}
// Gestion du formulaire accueil Cinema NATIONAL
function validationCinemaForm(form){
	var ok = true;
    var libelle = form.libelleLocalite.value;
    var validAmbiguite=  document.getElementById("validAmbiguite").value;
    var ancienLibelle =form.ancienLibelleLocalite.value;
    if(validAmbiguite!="true" && libelle.toUpperCase()!=ancienLibelle.toUpperCase()){
        form.idLocalite.value="";
    }
    if (libelle == ''){
        show('loc_oblig');
        ok = false;
    }
    return ok;
}

// Gestion du formulaire accueil Cinema LOCAL
function voirProgSalle(code) {
	/*
	document.getElementById('RechercheSalleForm').codeEtablissement.value=code;
	document.getElementById('RechercheSalleForm').submit();
	*/
	var sLoc = String(document.location).replace(/mode=#null/, "mode=");
	if( /&action=votreCinema/.test(sLoc) == false ){
		document.location = sLoc+"&action=votreCinema";
	}else{
		document.location = sLoc;
	}
}
	
/*function effaceCodeLocalite(){
	document.getElementById('RechercheVedCinemaForm').codeLocalite.value = '';
}*/
//--------------------------------------------------------------
function effaceCodeFilm(){
	document.getElementById('RechercheVedCinemaForm').codeFilm.value = '';
}
//-------------------------------------------------------------
function validRechVedCinemaLocalForm() {
	var oForm = document.getElementById('RechercheVedCinemaForm'); 
	var ok = true;
	if(oForm.titreFilm.value == '') {
		$('#film_oblig').show();
		ok = false;
	}
	if(oForm.libelleLocalite.value == '') {
		$('#loc_oblig').show();
		ok = false;
	}

	if(ok == true){
		oForm.submit();
	}
	
	return ok;
}
// ========================================================================
// STATS...
function sendStat( oJqLink ) {

	var strSufix = ( /aShowView/.test( oJqLink.attr('class') ) != false )? "_plan" : "_ba";

	// VARS ----------------------
	var marqueurs				= ( typeof(eval('window.vgMarqueurs'+strSufix)) != 'undefined' )? eval('vgMarqueurs'+strSufix) : false;
	var estatPrimaire		= ( typeof(eval('window.vgEstatPrimaire'+strSufix)) != 'undefined' )? eval('vgEstatPrimaire'+strSufix) : false;
	var estatSecondaire	= ( typeof(eval('window.vgEstatSecondaire'+strSufix)) != 'undefined' )? eval('vgEstatSecondaire'+strSufix) : false;
	
	if( estatPrimaire != false  && estatSecondaire != false && marqueurs != false ) {

		// ESTAT ----------------------
		_estatl(estatPrimaire, estatSecondaire, marqueurs , vgServiceAbbreviation);		

		// CIWSTAT --------------------
		var idate = new Date();
		var paramCiwstat = vgUrlCiwstat + "?1||PLAN|PI|"+marqueurs+"|" + vgServiceAbbreviation + "|||||||||||||||||" + idate.getTime() +"|||||||||||";
			
		// suppression de toute image residuelle.
		$("#imgSendCiwstat").remove();	
		// Creation d'une nouvelle image pour les stats.
		var sImgHtml = '<img src="'+paramCiwstat+'" id="imgSendCiwstat" class="TagCiwDT" style="width:1px; height:1px">';
		$("body").append(sImgHtml);

	}
	// Return...	
	return false;
}

// ========================================================================
// Init des actions sur les liens Afficher/Masquer Plan/Vues aeriennes 
// sur les listes de salles.

var vgConteneurId = "";
function vedInitPlanVueAerienneActions(){
	$(".aShowView").click(
		function(){

			// Gestion des stats
			if (/evenements/.test($("body").attr("class")) != false) {
	  		sendStat($(this));
			}
			var sId = $(this).attr('id'); 
			var aParam = sId.split("_");
			var sConteneurId = "swfvue_"+aParam[1];
			
			// Initialisation en mode plan pour IE6 car erreur 
			// javascript bloquante pour IE6 generee par le GC 
			// lors du passage en mode Vue Aerienne...
			if(ie6){ GCSetPlan(); }
			
			// Si on switch entre plan et Vue aerienne.
			if( vgConteneurId == sConteneurId ){
					if( aParam[4] == 'Carto' ){
						GCSetPlan();
					}else{
						GCSetVueA();
					}
			}			
			// Initialisation de l'objet.
			else{
				// On ne peut pas avoir plusieurs plans affiches en meme temps
				vedHidePlanVueAerienne();
				
				vgConteneurId = sConteneurId;
				$("#"+sConteneurId).parent(0).show();
								
				vedVoirPlanVueAerienne( sConteneurId , aParam[2], aParam[3], aParam[4], $("#"+sConteneurId).parent(0).width(), $("#"+sConteneurId).parent(0).height());
				
				setTimeout('refreshGC()',2000);
			}
			// IMPORTANT : Evite de suivre le lien si le href est renseigne.
			return false;	
		}
	);
	
	// Init des actions sur les liens Masquer Plan/Vues aeriennes 
	// sur les listes de salles.	
	$(".aCloseShowView").click(
		function(){
			vedHidePlanVueAerienne();
			return false;
		}
	)	
}
//------------------------------------------
function refreshGC(){
 Contener.GCDone('Carto');
}
//------------------------------------------
function vedHidePlanVueAerienne(){
	swfobject.removeSWF("FlashAPI");
	$("div[id^='swfvue_']").parent(0).hide();
	$("div[id^='swfvue_'] > *").remove();
	$(".N4_btn_close_plan").hide();
	vgConteneurId = "";
}

//----------------------------------------------------------------------------
// Affichage du flash sur les ecrans de liste des salles : afficher PLAN, 
// VUE AERIENNE, FILMS ET SEANCES...
function vedVoirPlanVueAerienne( sIdConteneur, fLong, fLat, sMode, iWidth, iHeight ){
	var flashObjParams = "wmode=opaque;allowScriptAccess=always;loop=false;menu=false;quality=high;scale=noscale;salign=tl";
	var flashObjVars = "GCMAP="+sMode+";GCLOC=WGS:" + fLong +":" + fLat +":1;GCSP="+urlPJYes;

  	var iWidth = (iWidth)? parseInt(iWidth) : '587';
  
	var iHeight = (iHeight)? parseInt(iHeight) : '480';
  
	var pjFlashObj = new pjFlashObject("flash-8",
										urlContener,
										iWidth,
										iHeight,
										sIdConteneur,
										flashObjParams,
										flashObjVars);
	pjFlashObj.load();
}

//------------------------------------------
function FlashInit() {
  Contener = (navigator.appName.indexOf("Microsoft")!=-1) ? window["id"+vgConteneurId] : document["id"+vgConteneurId];
}
// ==============================================================
// PHOTOS
function initBlocsPhotosForms() {
	$("#formPhotosVotreVille select").change(
		function(){
			$("#formPhotosVotreVille").submit();
		}
	);
	
	$(".blocContent #formVueAerienne .text").click(
		function(){
			$(this).val("");
			$("#formVueAerienne > #idLocalite").val("");
			var sIdAlert = String($(this).parent("form").attr("id")).replace("form","al");
			$("#"+sIdAlert).hide();
		}
	);
	
	$(".blocContent #formVillesEn1900 .text").click(
		function(){
			$(this).val("");
			var sIdAlert = String($(this).parent("form").attr("id")).replace("form","al");
			 $("#"+sIdAlert).hide();
		}
	);
	
	$("#formVillesEn1900").submit(
		function(){
			if( trim( $(this).find(".text").val() ) == "" 
					||
					trim( $(this).find(".text").val() ) == "Ville ou code postal" 
				){
				$(this).find(".alerte").show();
				return false;
			}else{
				//alert('Go');
				return true;
			}
		}
	);
}
// ==============================================================
// EVENEMENTS
function initEvtRechRapide(){
	// Validation du formulaire.
	$("#formSearch").submit(
		function(){
			
			var sSearchVal = $("#formSearch #search").val();
			sSearchVal = trim(sSearchVal); 
			
			if(trim(sSearchVal) == "*"){
				$("#formSearch #search").val("");
				sSearchVal = "";
			}
			if( sSearchVal == "" ){
				$("#alRechRapideEvt").show();
				return false;
			}
		}
	);
	// Masquage de l'alerte au focus sur le champ.
	$("#formSearch #search").focus(
		function(){
				$("#alRechRapideEvt").hide();
		}
	);
}
//------------------------------------------
// Initialisation du bloc de filtre des evenements.
function initEvtFiltreEvenements(){
	$("#divFiltrerEvts ul li.filtre a").hover(
		function(){
			$(this).parent().find("span").addClass('over');
		},
		function () {
		  $(this).parent().find("span").removeClass("over");
		}
	);
}

function initSeDeplacerReserverHotelDatePicker(){ 
	var today = new Date();
	var iMonth = today.getMonth();
	var iYear = today.getFullYear();
	var iDate = today.getDate();
	
	 $("#linkedDatesIn").datepicker({	      
	      beforeShow: readLinkedIn,
	      onSelect: updateLinkedIn,
	      showOn: "both",
	      minDate: ( new Date() ),
    	  maxDate: ( new Date(iYear+1, iMonth , iDate ) ),
	      buttonImage: staticPath+'/images/v4/calendar.gif', 
	      buttonImageOnly: true }); 
	 $("#b_checkin_month").change(checkLinkedDaysIn);
	 
	 $("#linkedDatesOut").datepicker({	      
	      beforeShow: readLinkedOut,
	      onSelect: updateLinkedOut,
	      showOn: "both",
	      minDate: ( new Date() ),
    	  maxDate: ( new Date(iYear+1, iMonth , iDate ) ),
	      buttonImage: staticPath+'/images/v4/calendar.gif', 
	      buttonImageOnly: true });
	 $("#b_checkout_month").change(checkLinkedDaysOut);
	 
    return {}; 
	
}
function readLinkedIn() { 
   	var month;
	if ($('#b_checkin_month').val().length == '6'){
		month =  $('#b_checkin_month').val().substring(5, 6);
	}else{
		month = $('#b_checkin_month').val().charAt(5);
	}
	
	var year = $('#b_checkin_month').val().substring(0, 4);
	
    $('#linkedDatesIn').val($('#b_checkin_day').val() + '/' + month + '/' + year); 
    $('#linkedDatesIn').show();
    return {}; 
}
function readLinkedOut() { 
	var month;
	if ($('#b_checkout_month').val().length == '6'){
		month =  $('#b_checkout_month').val().substring(5, 6);
	}else{
		month = $('#b_checkout_month').val().charAt(5);
	}
	
	var year = $('#b_checkout_month').val().substring(0, 4);
	
    $('#linkedDatesOut').val($('#b_checkout_day').val() + '/' + month + '/' + year); 
    $('#linkedDatesOut').show();
    return {}; 
} 
 
// Update three select controls to match a date picker selection 
function updateLinkedIn(date) {    
    var day = date.substring(0, 2);
    if (day.charAt(0) == '0'){
    	$('#b_checkin_day').val(day.charAt(1));	
    }else{
    	$('#b_checkin_day').val(day);
    }
    
    var month = date.substring(3, 5);
    if (month.charAt(0) == '0'){
    	 $('#b_checkin_month').val(date.substring(6, 10) + '-' + month.charAt(1));
    }else{
    	 $('#b_checkin_month').val(date.substring(6, 10) + '-' + month);
    }
}
function updateLinkedOut(date) {    
    var day = date.substring(0, 2);
    if (day.charAt(0) == '0'){
    	$('#b_checkout_day').val(day.charAt(1));	
    }else{
    	$('#b_checkout_day').val(day);
    }
    
    var month = date.substring(3, 5);
    if (month.charAt(0) == '0'){
    	 $('#b_checkout_month').val(date.substring(6, 10) + '-' + month.charAt(1));
    }else{
    	 $('#b_checkout_month').val(date.substring(6, 10) + '-' + month);
    }
}
 
// Prevent selection of invalid dates through the select controls 
function checkLinkedDaysIn() {
	var mois;
	if ($('#b_checkin_month').val().length == '6'){
		mois = $('#b_checkin_month').val().charAt(5);
	}else{
		mois = $('#b_checkin_month').val().substring(5,7);
	}
	
	var annee = $('#b_checkin_month').val().substring(0,4);
   	var daysInMonth = 32 - new Date(annee,mois - 1, 32).getDate(); 
    
    $('#b_checkin_day option').attr('disabled', ''); 
    $('#b_checkin_day option:gt(' + (daysInMonth - 1) +')').attr('disabled', 'disabled'); 
    if ($('#b_checkin_day').val() > daysInMonth) { 
        $('#b_checkin_day').val(daysInMonth); 
    } 
}
function checkLinkedDaysOut() {
	var mois;
	if ($('#b_checkout_month').val().length == '6'){
		mois = $('#b_checkout_month').val().charAt(5);
	}else{
		mois = $('#b_checkout_month').val().substring(5,7);
	}
	
	var annee = $('#b_checkout_month').val().substring(0,4);
   	var daysInMonth = 32 - new Date(annee,mois - 1, 32).getDate(); 
    
    $('#b_checkout_day option').attr('disabled', ''); 
    $('#b_checkout_day option:gt(' + (daysInMonth - 1) +')').attr('disabled', 'disabled'); 
    if ($('#b_checkout_day').val() > daysInMonth) { 
        $('#b_checkout_day').val(daysInMonth); 
    }
}

//---------------------------------------------
function initEvtOuQuandDatePicker(){
	$.datepicker.setDefaults(
		{
			showOn: 'both',
			mandatory : true, 
			buttonImage: staticPathVersion+'/images/v4/calendar.gif', 
			buttonImageOnly: true
		}
	);
	$(".dateRange").datepicker({beforeShow: customRange});
	
	// Initialisation des champs date
	
	// Aujourd'hui
	var oDate = new Date();
	var iDate = oDate.getDate();
			iDate = ( iDate < 10 )? "0"+iDate : iDate;
	var iMonth = (oDate.getMonth() + 1);
			iMonth = (iMonth < 10 ) ? "0"+iMonth : iMonth; 
	var iYear = oDate.getFullYear();
	var iMsecs = oDate.getTime(); 
	
	if(document.getElementById("selectRechEvtQuand") != null) 
	{
		var semainier = document.getElementById("selectRechEvtQuand").value;	
		if((document.getElementById("txtRechEvtDu").value == "") && (semainier == "0"))
		{
			$("#txtRechEvtDu").val( iDate+"/"+iMonth+"/"+iYear );
		}	
		$("#txtRechEvtDu").datepicker("setDate", new Date( iYear, oDate.getMonth() , iDate ) );
		
		// Semaine prochaine
		var oNwDate = new Date();
				oNwDate.setTime( iMsecs + (24 * 60 * 60 * 1000 * 7) );// + 7 jours.
		var iNwDate = oNwDate.getDate();
				iNwDate = ( iNwDate < 10 )? "0"+iNwDate : iNwDate;
		var iNwMonth = (oNwDate.getMonth() + 1);
				iNwMonth = (iNwMonth < 10 ) ? "0"+iNwMonth : iNwMonth; 
		var iNwYear = oNwDate.getFullYear();
		
		if((document.getElementById("txtRechEvtAu").value == "") && (semainier == "0"))
		{
			$("#txtRechEvtAu").val( iNwDate+"/"+iNwMonth+"/"+iNwYear );
		}	
		$("#txtRechEvtAu").datepicker("setDate", new Date( iNwYear, oNwDate.getMonth() , iNwDate ) );	
	} 
	
	// Ne pas autoriser le focus sur les champs.
	$(".dateRange").focus(
		function(){
			$(this).blur();
		}
	);
	// Re-initialisation des dates si le select est choisi.
	$("#selectRechEvtQuand").change(
		function(){
		
			if($("#selectRechEvtQuand option:first").attr("selected")==true){
				$("#txtRechEvtDu").val( iDate+"/"+iMonth+"/"+iYear );
				$("#txtRechEvtDu").datepicker("setDate", new Date( iYear, oDate.getMonth() , iDate ) );
				$("#txtRechEvtAu").val( iNwDate+"/"+iNwMonth+"/"+iNwYear );
				$("#txtRechEvtAu").datepicker("setDate", new Date( iNwYear, oNwDate.getMonth() , iNwDate ) );
			}else{
				$(".dateRange").val("");
			}
		}
		
	)
	
	// Re-initialisation du select si une date est choisie
	$(".dateRange").change(
		function(){
			$("#selectRechEvtQuand option:first").attr( "selected","selected" );
			if((document.getElementById("txtRechEvtAu").value == ""))
			{
				$("#txtRechEvtAu").val( iNwDate+"/"+iNwMonth+"/"+iNwYear );
				$("#txtRechEvtAu").datepicker("setDate", new Date( iNwYear, oNwDate.getMonth() , iNwDate ) );
			}
			if((document.getElementById("txtRechEvtDu").value == ""))
			{
				$("#txtRechEvtDu").val( iDate+"/"+iMonth+"/"+iYear );
				$("#txtRechEvtDu").datepicker("setDate", new Date( iYear, oDate.getMonth() , iDate ) );
			}	
		}
	);
	
	$("#txtRechEvtOu").keydown(
		function(){
			valueIdVilleOuCp = $("#txtRechEvtOu").val();
		}
	);
	$("#txtRechEvtOu").keyup(
		function(){
			if(valueIdVilleOuCp!=trim($("#txtRechEvtOu").val())){
				document.getElementById("formOuQuand").idLocalite.value="";
			}
		}
	);
}
//-----------------------------------------------------
// Customize two date pickers to work as a date range 
function customRange(input) { 

	var oDate = new Date();
	var iDate = oDate.getDate();
	var iMonth = oDate.getMonth();
	var iYear = oDate.getFullYear();
  return {
		change: (input.id == 'txtRechEvtAu' && $('#txtRechEvtDu').datepicker('getDate') == null) ? $('#txtRechEvtDu').datepicker('setDate', new Date( iYear, iMonth , iDate ) ) : null ,
		minDate: ( input.id == 'txtRechEvtAu' ? $('#txtRechEvtDu').datepicker('getDate') : new Date( iYear, iMonth , iDate ) ),
    maxDate: ( input.id == 'txtRechEvtDu' ? $('#txtRechEvtAu').datepicker('getDate') : null )
	};
} 

//----------------------------------------------------
function initEvtOuQuandForm(){
	$("#ambiguiteEvenements").show();
}
//-----------------------------------------------------
function submitRecherchePJForm(valQuoi) {
	$("#quoiquiPJForm").val(valQuoi);
	$("#RecherchePagesJaunesForm").submit();
}

//-----------------------------------------------------
// Form choix ville
//-----------------------------------------------------


// submit formulaire ville
function submitFormVille() {
	oCodeLieu = $("#"+gFormVilleId+" > .hlocalite ");
	oInput = $("#contextVilleOuCp");	
	
	oInput.val( ( oInput.val().toUpperCase() == "VILLE OU CODE POSTAL" ) ? "" : oInput.val() );
	// Saisie vide  
	if( oInput.val() == "" ){
		$("#"+gFormVilleId+" > .alerte p:first").html("Merci d'indiquer une localite");
		$("#"+gFormVilleId+" > .alerte").show();
		return false;
	}else{
		//appel ajax pour verifier la validite du libelle de localite et affciher le cas echeant 
		//la liste des localites correspondantes 
		var bCheck = true;
		$("#"+gFormVilleId).find("input[@type$='checkbox']").each( 
			function() {	
				bCheck &= this.checked;
			}
		);	
						
		var actionAjax = ACTION_VALIDE_LIBELLE_LOCALITE+"?textfieldLocalite="+oInput.val()+"&idfieldLocalite="+oCodeLieu.val()+"&checkboxmemory="+bCheck;
		
		if (ie6) {
			TRAITEMENT_RETOUR=valideLibelleLocaliteRetour;
			appelAjax(actionAjax,"", true); // appel synchrone
		}
		else {
			TRAITEMENT_RETOUR = null;
			appelAjax(actionAjax,"", true); // appel synchrone
			valideLibelleLocaliteRetour();
		}
		
		return submitFormulaire;
	}					
}


// formulaire du module ville"
function initFormModuleVille() {

	var oInput2 = $("#ville_cp");

	oInput2.click(
	function(){
	 	if( oInput2.val() == "Ville ou code postal" ){
	 		$(this).val("");
	 		$(this).focus();
	 	}
	 	$("#formChoixVille .alerte").hide();
	 }
	 );
	 oInput2.change(
	 	function(){
	 		$("#codeLocalite").val("");
	 	}
	 );
	
}

function initPrintDetailEvenement() {
	$("a.printDetail").click(
		function(){
			var params = "toolbar=no,status=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=660,height=600";
			window.open( $(this).attr("href") ,'printEvt',params);
			return false;			
		}
	);
}

function initPopUpEvenementEnvoyerMail() {
	$("#mailEvt").click(
		function(){
			var params = "toolbar=no,status=no,menubar=no,location=no,scrollbars=no,resizable=no,width=595,height=460";
			window.open( $(this).attr("href") ,'mailEvt',params);
			return false;
		}
	);
}


function initPopUpPrintDetailEvenement() {
	$("#aPrintWithPlanVue").click(
		function(){
			$(this).hide();
			$("#divEvtGC").show();
			$("#divEvtGC .liEvtPlan a").trigger('click');
			$("#divEvtGC .aCloseShowView").click(
				function(){
					$("#divEvtGC").hide();
					$("#aPrintWithPlanVue").show();
				}
			);
		}
	);
}

// ==============================================================
// PETITES ANNONCES
function initPetitesAnnoncesForm(){
	$("#formqui").submit(
		function(){
			var bOut = true;
			
			$(".boite").hide();
			$(".alerte").hide();

			if( trim( $("#ouPA").val() ) == "" ){
				$("#divAlerteOu").show();
				bOut = false;
			}
			if (bOut) {
				ouvrirFenetreAJ(this);
				bOut = false; // soumission par ajax
			}
			return bOut;
		}
	)
	$("#formqui input").click(
		function(){
			var sTxtId = $(this).attr("id");
			if( sTxtId == 'quoiPA' ){
				$("#divAlerteQuoi").hide();
			}
			if( sTxtId == 'ouPA' ){
				$("#divAlerteOu").hide();
			}
		}
	)
	// Gestion de l'affichage des boites d'aide.
	$("#formqui .N4_form_aide").click(
		function(){
			var sBoiteId = $(this).attr("id");
					sBoiteId = sBoiteId.replace("aAide","boiteAide");
			$(".boite").hide();
			window.setTimeout('$("#'+sBoiteId+'").show();', 0);
			return false;
		}
	)

}

// En FIN, lancement des fonctions au chargement de la page.
$(document).ready(function(){

	initVedDate();
	initVedNav();
	initVedContextualisation();

	initFormModuleVille();
	initPrintDetailEvenement();
	// Bandes annonces
	initCineBandesAnnonces();
	// Plans / Vues aeriennes
	vedInitPlanVueAerienneActions();
	
	//Meteo
	if (/meteo/.test($("body").attr("class")) != false) {
		if(!ie){
			//#0011607 : Bulletin video du jour : Masquage du embed contenant la video 
			// pour les navigateurs non IE, car pas de prise en compte du parmetre "windowlessVideo"
			$("#aSelLocalite , #aSelLocaliteTop").click(
				function(){
					$(".N2_ved_webcam_embed_b embed").css("visibility", "hidden");
				}
			);
		}
	}
	//photo 
	if (/photo/.test($("body").attr("class")) != false) {
		initBlocsPhotosForms();
  }
  
	//Se Deplacer
	if( /se_deplacer/.test( $("body").attr("class") ) != false ){
		initSeDeplacerReserverHotelDatePicker();
	}
	
	// Evenements
	if( /evenements/.test( $("body").attr("class") ) != false ){
		initEvtRechRapide();
		initEvtFiltreEvenements();
		initEvtOuQuandForm();
		if( "undefined" != typeof($.datepicker) ){
			initEvtOuQuandDatePicker();
		}
		initPopUpPrintDetailEvenement();
		initPopUpEvenementEnvoyerMail();
		
	    var ancre = document.getElementById("downAmbiguite");
	    if(ancre){
	        document.location.href="#down";
	    }
	}

	// Petites annonces
	if (/petites_annonces/.test($("body").attr("class")) != false) {
  		initPetitesAnnoncesForm();
  	}
  
	
});
// ============================================================
/**
 **	AFFICHAGE CARTE PLAN/VUE DANS LE CINEMA EN LISTE REPONSE
 **/

var currentIndexCarte;
function afficherPlanVueCinemaLR(idBloc,idInscription,indexCarte,action,thisObj){
	//Lien inactif si pas de href
	if ($(thisObj).attr("href") != "#null"){
		return false;
	}
		
	currentIndexCarte = indexCarte;
	
	//on supprime toutes les cartes
	closaAllPlanVueCinemaLR();
	
	//on réinitialise les liens
	$("#aPlan"+indexCarte).attr("href","#null");
	$("#aPlan"+indexCarte).removeClass("inactif");
	$("#aVue"+indexCarte).attr("href","#null");
	$("#aVue"+indexCarte).removeClass("inactif");
	
	$(thisObj).removeAttr("href");
	$(thisObj).addClass("inactif");
	
	//on cache le bloc filmSeance
	closeBlocFilmSeanceCinemaLR(currentIndexCarte);
	
	//on affiche la petite carte (mode raster)
	afficherPetiteCarteCinema();
	
	currentIndexCarte = indexCarte;
	
	var actionAjax = ACTION_AFFICHER_CARTE_PLAN_VUE + "?idBloc="+idBloc.replace(/\+/g,'%2B') +"&idInscription="+idInscription+"&typeAction=afficherBloc&actionAnnonceur="+action;
	if (ie6) {
		//TRAITEMENT_RETOUR est défini dans le fichier ajax.js (static commun)
		TRAITEMENT_RETOUR = insererPlanVueCinemaLR;
		appelAjax(actionAjax,"", true); // appel synchrone
	}
	else {
		TRAITEMENT_RETOUR = null;
		appelAjax(actionAjax,"", true); // appel synchrone
		insererPlanVueCinemaLR();
	}
	return false;
}

function insererPlanVueCinemaLR(){
	if (ajax.readyState == '4' && ajax.responseText){
		evalScriptAndHTML(ajax.responseText,'swfvue_'+currentIndexCarte);		
		$("#swfvue_"+currentIndexCarte ).show();
		$("#N4_btn_close_plan_"+currentIndexCarte ).show();		
	}
}

//ferme la carte plan/vue en liste reponse cinéma correspondant à l'index
function closePlanVueCinemaLR(indexCarte){
	$("#aPlan"+indexCarte).attr("href","#null");
	$("#aPlan"+indexCarte).removeClass("inactif");
	$("#aVue"+indexCarte).attr("href","#null");
	$("#aVue"+indexCarte).removeClass("inactif");
	
	swfobject.removeSWF("FlashAPI");
	$("#swfvue_"+indexCarte ).empty();
	$("#swfvue_"+indexCarte ).hide();
	$("#N4_btn_close_plan_"+indexCarte ).hide();
	return false;
}

//ferme toutes les cartes plan/vue en liste reponse cinéma
function closaAllPlanVueCinemaLR(){
	$("a[id^='aPlan']").attr("href","#null");
	$("a[id^='aPlan']").removeClass("inactif");
	$("a[id^='aVue']").attr("href","#null");
	$("a[id^='aVue']").removeClass("inactif");
	
	swfobject.removeSWF("FlashAPI");
	$("div[id^='swfvue_']").empty();
	$("div[id^='swfvue_']").hide();
	$("div[id^='N4_btn_close_plan_']").hide();
}

//affiche le bloc film et seance en liste reponse cinema
function afficheFilmSeanceCinemaLR(indexCarte){
	//on supprime toutes les cartes en liste reponse
	closaAllPlanVueCinemaLR();
	
	//on affiche le bloc filmSeance
	$("#filmSeance_"+indexCarte ).show();
	$("#aSeance"+indexCarte).removeAttr("href");
	$("#aSeance"+indexCarte).addClass("inactif");
	
	return false;
}

//ferme le bloc film et seance en lmiste rponse cinema
function closeBlocFilmSeanceCinemaLR(indexCarte){
	$("#filmSeance_"+indexCarte ).hide();
	$("#aSeance"+indexCarte).attr("href","#null");
	$("#aSeance"+indexCarte).removeClass("inactif");
}




/**
 **	AFFICHAGE CARTE DANS LE CINEMA
 **/
 
function afficherGrandeCarteCinema(idLocalite,idFilm,afficherBloc,cleAlpha,numPage)
{	
	//on cache la petite carte
	$("#N5_bloc_cine_carte_240_h").hide();
	$("#N5_bloc_cine_carte_240_m").hide();
	
	//on supprime toutes les autres cartes
	closaAllPlanVueCinemaLR();
	
	//on affiche le bloc voir les séances (cas d'une liste reponse programmation)
	if (afficherBloc == true) {
		$("div[id^='filmSeance_']").show();
	}
	
	//on affiche la grande carte
	var actionAjax = ACTION_AFFICHER_GRANDE_CARTE + "?idLocalite="+idLocalite+"&idFilm="+idFilm+"&cleAlphaTournante="+cleAlpha+"&numPage="+numPage+"&urlCorner="+urlCorner;
	if (ie6) {
		//TRAITEMENT_RETOUR est défini dans le fichier ajax.js (static commun)
		TRAITEMENT_RETOUR = insererGrandeCarteCinema;
		appelAjax(actionAjax,"", true); // appel synchrone
	}
	else {
		TRAITEMENT_RETOUR = null;
		appelAjax(actionAjax,"", true); // appel synchrone
		insererGrandeCarteCinema();
	}
	
}

function insererGrandeCarteCinema(){
	if (ajax.readyState == '4' && ajax.responseText){
		evalScriptAndHTML(ajax.responseText,'idBlocGrandeCarte');		
	}
}

function afficherPetiteCarteCinema(){
	$("#idBlocGrandeCarte > *").remove();	
	$("#N5_bloc_cine_carte_240_h").show();
	$("#N5_bloc_cine_carte_240_m").show();
}


/**
 **	AFFICHAGE CARTE DANS LE GUIDE
 **/

function afficherGrandeCarteGuide(idLocalite,nom,ou,aCoteDe,thematique,page,filtres,tri,cleAlpha)
{
	//on cache la pettie carte
	$(".N4_bloc_300_petite_carte_h").hide();
	$(".N4_bloc_300_petite_carte_b").hide();
	if ($("#grandeCarte").html() != ''){
		$("#grandeCarte").show();
		$("#guide_pub_autopromo").addClass("bas");
		$("#N3_col_right_ba2").addClass("grandeCarte");
	}
	else{
	
		//on insère la grande carte
		var actionAjax = ACTION_AFFICHER_GRANDE_CARTE_GUIDE +"?idLocalite="+idLocalite+"&nom="+nom+"&ou="+ou+"&acotede="+aCoteDe+"&thematique="+thematique+"&page="+page+"&filtres="+filtres+"&tri="+tri+"&cleAlpha="+cleAlpha;
		if (ie6) {
			TRAITEMENT_RETOUR = insererGrandeCarteGuide;
			appelAjax(actionAjax,"", true); // appel synchrone
		}
		else {
			TRAITEMENT_RETOUR = null;
			appelAjax(actionAjax,"", true); // appel synchrone
			insererGrandeCarteGuide();
		}
	}
	return false;
}

function insererGrandeCarteGuide()
{
	if (ajax.readyState == '4' && ajax.responseText){
		evalScriptAndHTML(ajax.responseText,'grandeCarte');
		$("#grandeCarte").show();
		$("#guide_pub_autopromo").addClass("bas");
		$("#N3_col_right_ba2").addClass("grandeCarte");
	}
}

function afficherPetiteCarteGuide()
{
	$("#grandeCarte").hide();
	$(".N4_bloc_300_petite_carte_h").show();
	$(".N4_bloc_300_petite_carte_b").show();
	$("#guide_pub_autopromo").removeClass("bas");
	$("#N3_col_right_ba2").removeClass("grandeCarte");
}


var vgInlineScripts = new Array();
/**
 * Traite la reponse HTML retournée par Ajax, l'ajoute à la div d'id idDivContenant et effectue un eval 
 * pour chaque balise script présente avec le HTML.    
 **/
function evalScriptAndHTML(reponseAjax, idDivContenant){
	var divContenant = document.getElementById(idDivContenant);
    // on supprime les anciens scripts
	window.vgInlineScripts.length = 0;
    // ajout de la reponse à la div
    divContenant.innerHTML=reponseAjax;
    // recuperation des scripts
    var allScript = divContenant.getElementsByTagName("script");
    if (allScript.length > 0) {
        for (i = 0; i < allScript.length; i++) {
            // pour chaque import de fichiers js, création du dom correspondant, pour l'ajout 
            // dans le head de la page. remplace non présent
            if (allScript[i].src != "") {
                var s = document.createElement("script");
                s.type = "text/javascript";
                s.src = allScript[i].src;
                if ($("head>script[src='"+allScript[i].src+"']").length != 0) {
                	$("head>script[src='"+allScript[i].src+"']").replaceWith(s);
                } else {
                	document.getElementsByTagName("head")[0].appendChild(s);
                } 
            }
            // on met dans un tableau chaque script, pour eval ultérieur
            if (allScript[i].text != "") {
                window.vgInlineScripts.push(allScript[i].text);
            }
            if (i == allScript.length - 1) {
                // à la fin du traitement de tous les scripts :
                // on attend 1 sec que les eventuels imports js sont terminés
                // puis on effectue un eval de chaque script.
                window.setTimeout( function(){ timedGlobalEval( window.vgInlineScripts) }, 1000 );
            }
         }
    }
}

/**
 * Parcourt une liste de script et effectue un eval.
 */
function timedGlobalEval(aScripts) {
	for (var i = 0; i < aScripts.length; i++  ) {
		globaleval(aScripts[i]);
	}
}

/**
 * Effectue un eval du script passé en paramètre en fonction des traitements
 * de différents navigateurs.
 */ 
function globaleval(script) {
	if(window.execScript) {
		window.execScript(script);
		return null;
	} else if (navigator.userAgent.indexOf("KHTML") != -1) {
		var s = document.createElement("script");
		s.type = "text/javascript";
		s.innerHTML = script;
		document.getElementsByTagName("head")[0].appendChild(s);
	} else {
		return window.eval(script);
	}
}

