var _addresseRVPC = "ajax/RVPC.php"; // recuperation de la ville par le code postal

var _xmlHttpRVPC = null;
function recup_ville_par_cp() // recupere la ville par le cp ou si non trouvée, par departement
{
	if(_xmlHttpRVPC&&_xmlHttpRVPC.readyState!=0){
    	_xmlHttpRVPC.abort()
 	}
	_xmlHttpRVPC=getXMLHTTP();
  if(_xmlHttpRVPC){
    //appel à l'url distante		
    _xmlHttpRVPC.open("GET",_addresseRVPC+"?cp="+document.getElementById('inscription_cp').value,true);
    _xmlHttpRVPC.onreadystatechange=function() {
        if(_xmlHttpRVPC.readyState==4&&_xmlHttpRVPC.responseXML) {
        var result = traiteXmlSuggestions(_xmlHttpRVPC.responseXML)        	      		
                document.getElementById('td_ville').innerHTML = result[0];						
		      }

	};
    // envoi de la requete
    _xmlHttpRVPC.send(null)
    
  }
  
  	
}

//Debloquage du compte utilisateur

var _adresseDebloquage = "ajax/debloque.php";
var _xmlHttpDeBloque = null;
function debloquage() 
{
/*	if(_xmlHttpDeBloque&&_xmlHttpDeBloque.readyState!=0){
    	_xmlHttpDeBloque.abort()
 	}
	_xmlHttpDeBloque=getXMLHTTP();
  if(_xmlHttpDeBloque){
    //appel à l'url distante		
    _xmlHttpDeBloque.open("GET",_adresseDebloquage,true);
    _xmlHttpDeBloque.onreadystatechange=function() {
        if(_xmlHttpDeBloque.readyState==4&&_xmlHttpDeBloque.responseXML) {
        var result = traiteXmlSuggestions(_xmlHttpDeBloque.responseXML)        	      		
               					
		      }

	};
    // envoi de la requete
    _xmlHttpDeBloque.send(null)
    
  }*/
  
  	
}


function SelectMagActuel(id_mag)
{
	if(winPlaceMagasin)
	{
		winPlaceMagasin.hide();
	}
	if(id_mag == "-")
	{
		id_magasin_actuel = '';
		num_magasin_actuel = '';
		enseigne_magasin_actuel = '';
		adresse_magasin_actuel = '';
		cp_magasin_actuel = '';
		ville_magasin_actuel = ''; 
		x_magasin_actuel = '';
		y_magasin_actuel = '';  
		document.getElementById('titre_application').innerHTML = "Gestion France enti&egrave;re ";
		map.zoomToExtent(new OpenLayers.Bounds('-5.140089','41.32716','9.56251','51.08723').transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")));           
	}
	else
	{
		Ext.MessageBox.show({
			msg: 'Changement de magasin, veuillez patienter...',
			progressText: 'Sauvegarde...',
			width:300,
			wait:true,
			waitConfig: {interval:200},
			icon:'ext-mb-download'
		});	
		
		var _xmlHttpSelMagAct = null;
		
		if(_xmlHttpSelMagAct&&_xmlHttpSelMagAct.readyState!=0)
		{
			_xmlHttpSelMagAct.abort()
		}
		_xmlHttpSelMagAct=getXMLHTTP();
		if(_xmlHttpSelMagAct)
		{
			//appel à l'url distante		
			_xmlHttpSelMagAct.open("GET","ajax/SelMagAct.php?id="+id_mag,true);
			_xmlHttpSelMagAct.onreadystatechange=function()
			{
				if(_xmlHttpSelMagAct.readyState==4&&_xmlHttpSelMagAct.responseXML)
				{
					var result = traiteXmlSuggestions(_xmlHttpSelMagAct.responseXML)
					id_magasin_actuel = result[0];
					num_magasin_actuel = result[1];
					enseigne_magasin_actuel = result[2];
					adresse_magasin_actuel = result[3];
					cp_magasin_actuel = result[4];
					ville_magasin_actuel = result[5];
					id_zdc_actuel = result[6];
					infotool.vendorParams.ID_Z = id_zdc_actuel;
					document.getElementById('titre_application').innerHTML = "Gestion magasin : "+enseigne_magasin_actuel+" ("+num_magasin_actuel+")";
					if(result[7] == 'ok')
					{

						
						if(id_zdc_actuel != '')
						{
							xmin_zdc_actuel = result[8];
							ymin_zdc_actuel = result[9];			
							xmax_zdc_actuel = result[10];
							ymax_zdc_actuel = result[11];	
							if(document.getElementById('checkboxVisiblePerso1'))
							{										
								document.getElementById('checkboxVisiblePerso1').disabled = false;
								document.getElementById('checkboxVisiblePerso1').checked = true;
								
							}
							map.zoomToExtent(new OpenLayers.Bounds(xmin_zdc_actuel,ymin_zdc_actuel,xmax_zdc_actuel,ymax_zdc_actuel).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")));  
						}
						else
						{
							x_magasin_actuel = result[8];
							y_magasin_actuel = result[9];
							map.setCenter(new OpenLayers.LonLat(x_magasin_actuel,y_magasin_actuel).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")),12);
							if(document.getElementById('checkboxVisiblePerso1'))
							{										
								document.getElementById('checkboxVisiblePerso1').checked = false;
								document.getElementById('checkboxVisiblePerso1').disabled = true;
							}
						}

						layersRefresh('reload','normalLayer');
						layersRefresh('reload','themaLayer','limiteThema');
					}
					else
					{                        
						x_magasin_actuel = '';
						y_magasin_actuel = '';      
						document.getElementById('adresse_magasin_temp_span').innerHTML = adresse_magasin_actuel+" "+cp_magasin_actuel+" "+ville_magasin_actuel;
						affichePlaceMagasin();
						winPlaceMagasin.show();
						PlaceMagasin();
						AfficherAdresse(adresse_magasin_actuel+" "+cp_magasin_actuel+" "+ville_magasin_actuel);	
						Outils_Pan.activate();
					}
												
					ComboSelectMag.setValue(enseigne_magasin_actuel+" ("+num_magasin_actuel+")");
					ComboSelectMagZDCDist.setValue(enseigne_magasin_actuel+" ("+num_magasin_actuel+")");
					id_magasin_zdc = id_magasin_actuel;
					document.getElementById('fenetreProfilZoneTableau').innerHTML = '';
					document.getElementById('fenetreProfilZoneGraph').innerHTML = '';
					
					tree.getRootNode().expand(false);
					tree.getRootNode().expand(true);							
					store_concurents.reload();
					store_zone.reload();
					store_magasin.reload();
					layersRefresh('reload','normalLayer');
					layersRefresh('reload','themaLayer','limiteThema');
					
					Ext.MessageBox.hide();
				}
			};
			// envoi de la requete
			_xmlHttpSelMagAct.send(null)
		}		
	}
}
		
//Raffraichissement du recapitulatif magasin
var _adresserecapMag = "ajax/recapMag.php";
var _xmlHttprecapMag = null;
function RefreshRecapMag() 
{
	/*if(_xmlHttprecapMag&&_xmlHttprecapMag.readyState!=0){
    	_xmlHttprecapMag.abort()
 	}
	_xmlHttprecapMag=getXMLHTTP();
  if(_xmlHttprecapMag){
    //appel à l'url distante		
    _xmlHttprecapMag.open("GET",_adresserecapMag,true);
    _xmlHttprecapMag.onreadystatechange=function() {
        if(_xmlHttprecapMag.readyState==4&&_xmlHttprecapMag.responseXML) {
        var result = traiteXmlSuggestions(_xmlHttprecapMag.responseXML)        	      		
               		document.getElementById('recap_mag').innerHTML = result[0];			
		      }

	};
    // envoi de la requete
    _xmlHttprecapMag.send(null)
    
  }*/
  
  	
}
