﻿// Fichier JScript

	//<![CDATA[
			var Desc;
			var map;
			var geocoder;
			var y = 0;
			var x = 0;
		
			var Adresse ="";
			
			function addAddressToMap(response) 
			{
				if (!response || response.Status.code != 200) {
				//document.write (';null;null<br>');
			  } else {
				//Le point a été localisé

				place = response.Placemark[0];
				point = new GLatLng(place.Point.coordinates[1],	place.Point.coordinates[0]);
				marker = new GMarker(point);
				map.addOverlay(marker);
				
				marker.openInfoWindowHtml(Desc);
				//alert('123');
				/* Lorsque le marqueur est cliqué, on ouvre l'info-bulle */
				GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(text);});	
			  }
			}


	
	
			function recupPos() {
				//alert("Dans recupPos");
				map = new GMap2(document.getElementById("carte_magasin"));
				map.setCenter(new GLatLng(y,x), 15);
				geocoder = new GClientGeocoder();
				geocoder.getLocations(Adresse, addAddressToMap);
				

			}
			

			
			/*recupPos;
			GUnload;*/
		
		function displayMag(id) {
			
			var http_request ;    
			//alert('ici');
			if (window.XMLHttpRequest) { // Mozilla, Safari, ...
				http_request = new XMLHttpRequest();
			}	else if (window.ActiveXObject) { // IE
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			if (!http_request) {
				alert(getTraduction("recrutement_erreur_navig"));
				return false; 
			}	else {     
				http_request.onreadystatechange = function() { showMag(http_request); }
				Url = "/popup_magasin.asp?m=" + id;
				http_request.open('GET', Url, true);
				if (window.XMLHttpRequest)  { // Mozilla, Safari, ...
					http_request.send(null); 
				} else if (window.ActiveXObject) { // IE
					http_request.send(null); 
				}
			}
	}
	
	function diplayMag(id) {
			
			var http_request ;    
			//alert('ici');
			if (window.XMLHttpRequest) { // Mozilla, Safari, ...
				http_request = new XMLHttpRequest();
			}	else if (window.ActiveXObject) { // IE
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			if (!http_request) {
				alert(getTraduction("recrutement_erreur_navig"));
				return false; 
			}	else {     
				http_request.onreadystatechange = function() { showMag(http_request); }
				Url = "/popup_magasin.asp?m=" + id;
				http_request.open('GET', Url, true);
				if (window.XMLHttpRequest)  { // Mozilla, Safari, ...
					http_request.send(null); 
				} else if (window.ActiveXObject) { // IE
					http_request.send(null); 
				}
			}
	}
			
			
			function closeDiv() {
				document.getElementById('select-ville').style.display = "block";
				document.getElementById('select-region').style.display = "block";
				document.getElementById('mag').style.display='none'; 
			}
			
			
			function showMag(http_request) {
				//alert('state:'+http_request.status);
				if (http_request.readyState == 4) {
					if (http_request.status == 200) {
						response = http_request.responseText;
						if ( response == "err" ) {
							alert(getTraduction("magasins_erreur")); 
						}else {
							
							magasin = response.split("|");
							
							Adresse = magasin[2] + ", " + magasin[5] + " " + magasin[6] + getTraduction("magasins_fr");
							x = magasin[8].replace(",",".");
							y = magasin[9].replace(",",".");
							Desc = magasin[10];
							
							html = "";
							html = html + "<div id=\"popup-magasin\"><img src=\"http://tao-img.naxento.fr/img/"+returnLang()+"/popup_mag_haut.gif\" />";
							html = html + "<div id=\"detail_magasin\">";
							html = html + "<div id=\"tit_magasin\">";
            				html = html + "<div id=\"btn_fermerpopup\">";
							html = html + "<a href=\"javascript:void(0);\" onClick=\"closeDiv();\">";
							html = html + "<img src=\"http://tao-img.naxento.fr/img/"+returnLang()+"/fermer_popup.gif\"><br></a></div>";
            				html = html + "<b><font color=\"#d91539\">" + magasin[0] + "</font>&nbsp;" +  magasin[1] + "</b>";
            				html = html + "</div>";
           					html = html + "<div id=\"coordonnees_magasin\">";
							
							html = html + "<div class=\"intitule_coord_mag\">"+getTraduction("magasins_adresse")+"</div>";
								
                			html = html + "<div class=\"intitule_contenu_mag\" style=\"margin-top:-16px;\">";
                    		html = html +  "<br />" + magasin[2] + "<br />";
							
							//alert(magasin[11]);
							
							if (magasin[3] != "")
								html = html + magasin[3] + "<br />"
							if (magasin[4] != "")
								html = html + magasin[4] + "<br />"
                    		html = html + magasin[5] + "&nbsp;" + magasin[6] + "<br />";
                    		html = html + getTraduction("magasins_tel") + magasin[7];
                			html = html + "</div>";
                			
							html = html + "<!--div class=\"intitule_coord_mag\">"+getTraduction("magasins_manager")+"</div>";
							
                			html = html + "<div class=\"intitule_contenu_mag\"></div-->";
							
							html = html + "<div class=\"intitule_coord_mag\">"+getTraduction("magasins_horaires")+"</div>";
								
                			html = html + "<div class=\"intitule_contenu_mag\">";
                    		html = html + magasin[11].replace("@@puce@@","<img src=\"http://tao-img.naxento.fr/img/"+returnLang()+"/puce.gif\" />");
               				html = html + "</div>";
            				html = html + "</div>";
            				html = html + "<div id=\"carte_magasin\" style=\"width:340px;height:340px\">";
							
							html = html + getTraduction("magasins_geo");
        					
							html = html + "</div></div><img src=\"http://tao-img.naxento.fr/img/"+returnLang()+"/popup_mag_bas.gif\" /></div>";


							document.getElementById('select-ville').style.display = "none";
							document.getElementById('select-region').style.display = "none";
							document.getElementById('mag').innerHTML = html;
							
							document.getElementById('mag').style.display = 'block';
							
							

							if (magasin[8] != "") {
								recupPos();
								/*GUnload();*/
							}
								
								
								
							//ICI, on fait l'appel de la fonction NAXETRIS. On reactulise l'image.
							//try {
								if (NAXETRIS_VGO==1) 
								{
								//document.getElementById('naxetris').src = "ici" ;
								document.getElementById('naxetris').src = 'http://www.naxetris.com/data/default.asp?SRC=VICTORIA&RUB=' + escape('MAG') + '&PAG=' + escape(x+'_'+y) + '&CLI=25&REF=' + FormatURL(getReferrer()) + '&DAT=' + getDate() + '&URL=' + FormatURL(escape(document.location)) + '&LIB=' + escape(magasin[0] + ' ' +  magasin[1]) + '&TYP=012';
								}
							//}
							//catch {}
							
							
							
						}
				
					}
				}
			}
			
			
			
			
			
			
		function send_form() {
				//alert("123");
				if (document.getElementById("select-region").value!="" || document.getElementById("select-ville").value!="") {
					//document.getElementById("form_region").submit();
					var http_request ;        

					if (window.XMLHttpRequest) { // Mozilla, Safari, ...
						http_request = new XMLHttpRequest(); } 
		            else if (window.ActiveXObject) { // IE
                		http_request = new ActiveXObject("Microsoft.XMLHTTP"); }

            		if (!http_request) {
				//alert(getTraduction("recrutement_erreur_navig"));
                		return false; }
            		else {           
						http_request.onreadystatechange = function() { displayResults(http_request); }
						Url = "/ajax/magasins-resultats.asp?r=" + document.getElementById('select-region').value + "&v=" + document.getElementById('select-ville').value;
						//alert(Url);
						http_request.open('GET', Url, true);
						if (window.XMLHttpRequest)  { // Mozilla, Safari, ...
							http_request.send(null); } 
					
						else if (window.ActiveXObject) { // IE
							http_request.send(null); }
            		}
				}
				else
				{
						alert(getTraduction("magasins_choisir"));
				}
			}
			
			function displayResults(http_request) {
				//alert('state:'+http_request.status);
				if (http_request.readyState == 4) {
					if (http_request.status == 200) {
					//alert("200");
						response = http_request.responseText;
						if ( response == "err" ) {
							alert(getTraduction("magasins_erreur")); }
						else {
							// OK !
							var magasins = response.split("~");						
							var i;
							//alert("Nombre d'options : " + document.getElementById("select-ville").length);
							
							var html;
							var j;
							var k;

							html = "<div id=\"tit_liste_mag\" style=\"display:block;\"><b>"+getTraduction("magasins_resultat")+"</b><br><br></div>";
							
							for(i=0;i<magasins.length;i++) {
								// Magasin par magasin
								var mag = magasins[i].split("|");

									//alert('Magasin #' + j);
									html = html + "<font color=\"#da1539\"><b>" + mag[1] + "</b></font> - <b>" + mag[2];
									html = html + "</b><div id=\"adresse_mag\">" + mag[3] + "<br />";
									//for(k=4;k<mag.length - 2; k++) {
										//html = html + mag[k] + "<br />"
									//}
									html = html + mag[mag.length - 2] + " " + mag[mag.length - 1];
									html = html + "<a href=\"#\" onClick=\"diplayMag(";
									html = html + mag[0] + ");\">";
									html = html + "<img src=\"http://tao-img.naxento.fr/img/"+returnLang()+"/btn_ensavoirplus.gif\" align=\"right\" class=\"align_btn\"/></a></div>";

							}
							//;
							document.getElementById('liste_mag').innerHTML = html;
						}
				
					}
				}
			}
			
			
			function refreshVilles() {
				//if (document.getElementById('select-region').value != "") {
									
					var http_request ;   
					
					

					if (window.XMLHttpRequest) { // Mozilla, Safari, ...
						http_request = new XMLHttpRequest(); } 
		            else if (window.ActiveXObject) { // IE
                		http_request = new ActiveXObject("Microsoft.XMLHTTP");
									}

            		if (!http_request) {
							alert(getTraduction("magasins_erreur")); 
						
                		return false; }
            		else {     
					
				
						http_request.onreadystatechange = function() { displayVille(http_request); }
						Url = "/ajax/magasins-ville.asp?r=" + document.getElementById('select-region').value;
					
						http_request.open('GET', Url, true);
						if (window.XMLHttpRequest)  { // Mozilla, Safari, ...
							http_request.send(null); } 
					
						else if (window.ActiveXObject) { // IE
							http_request.send(null); }
            		}
				//}
				//else {
					//alert('0');
				//}			
			}
			
			function displayVille(http_request) {
				//alert('state:'+http_request.status);
				if (http_request.readyState == 4) {
					if (http_request.status == 200) {
					//alert("200");
						response = http_request.responseText;
						if ( response == "err" ) {
							alert(getTraduction("magasins_erreur")); 
						}
						else 
						{
							// OK !
							var villes = response.split("|");						
							var i;
							//alert("Nombre d'options : " + document.getElementById("select-ville").length);
							
							for(i=0;i<document.getElementById("select-ville").length;i++){
								//alert("Passage : " + i);
								document.getElementById("select-ville").options[i] = null;
								i--;
							}
					
					// Et on ajoute la reponse...		
					nouvel_element = new Option(getTraduction("magasins_ville"),"",false,true);
 					document.getElementById("select-ville").options[document.getElementById("select-ville").length] = nouvel_element;
					
					for(i=0;i<villes.length;i++){
						//alert(villes[i]);
						nouvel_element = new Option(villes[i],villes[i],false,true);
 						document.getElementById("select-ville").options[document.getElementById("select-ville").length] = nouvel_element;
					}
							
						}
				
					}
				}
				document.getElementById('select-ville').selectedIndex = 0;
				//window.onunload = GUnload;
			}
			
			function refreshMagasins() {
				
				if ($("#select-region").val()!="" || $("#select-ville").val()!="") {
					//document.getElementById("form_region").submit();
					var http_request ;        

					if (window.XMLHttpRequest) { // Mozilla, Safari, ...
						http_request = new XMLHttpRequest(); } 
		            else if (window.ActiveXObject) { // IE
                		http_request = new ActiveXObject("Microsoft.XMLHTTP"); }

            		if (!http_request) {
				//alert(getTraduction("recrutement_erreur_navig"));
                		return false; }
            		else {           
						http_request.onreadystatechange = function() { displayResultsMagasins(http_request); }
						Url = "/ajax/magasins-resultats.asp?r=" + $('#select-region').val() + "&v=" + $('#select-ville').val();
						
						//alert(Url);
						http_request.open('GET', Url, true);
						if (window.XMLHttpRequest)  { // Mozilla, Safari, ...
							http_request.send(null); } 
					
						else if (window.ActiveXObject) { // IE
							http_request.send(null); }
            		}
				}
				else
				{
						alert(getTraduction("magasins_choisir"));
				}
			}
			
			function displayResultsMagasins(http_request) {
				//alert('state:'+http_request.status);
				if (http_request.readyState == 4) {
					if (http_request.status == 200) {
					//alert("200");
						response = http_request.responseText;
						if ( response == "err" ) {
							alert(getTraduction("magasins_erreur")); }
						else {
							// OK !
							var magasins = response.split("~");						
							var i;
							var regexpE = new RegExp('&#233;') ;
							var regexpO = new RegExp('&#244;') ;
							
							
								for(i=0;i<document.getElementById("select-magasin").length;i++){
								//alert("Passage : " + i);
								document.getElementById("select-magasin").options[i] = null;
								i--;
								}
					
							// Et on ajoute la reponse...		
							nouvel_element = new Option(getTraduction("magasins_magasin"),"",false,true);
							document.getElementById("select-magasin").options[document.getElementById("select-magasin").length] = nouvel_element;
							
							for(i=0;i<magasins.length;i++){
								
								//Magasin par magasin
								var mag = magasins[i].split("|");
								nouvel_element = new Option(mag[1]+" - " +mag[2].replace(regexpO,'ô').replace(regexpE,'é'), mag[0] ,false,true);
								document.getElementById("select-magasin").options[document.getElementById("select-magasin").length] = nouvel_element;
							}
						}
				
					}
				}
				window.onunload = GUnload;
			}
		
			
			
		
			