	
	function $(id){
		try{
			return document.getElementById(id);
		}catch(err){
			return null;
		}
	}
	
	function objConnexion(){
		//on prepare un attribut pour les arguments passé par 
		//la fonction appelante
		this.argument = null;
		
		//on definie la fonction de traitement de la réponse
		this.callBack = function() {
			//Debug(this.obj.readyState)
			if (this.obj.readyState==4){
				if( this.obj.status == 200 ) 
				{
					if( this.argument )
					{
						var element = document.getElementById( this.argument[1] );
						element.innerHTML = this.obj.responseText;
					}				
				}else{
					//alert('Problème de connexion : verifiez votre connexion au web\n erreur : '+this.obj.status+'\n'+this.obj.responseText);
				 }	
			}
		}
		
		if(window.XMLHttpRequest) // Firefox 
			this.obj = new XMLHttpRequest(); 
		else if(window.ActiveXObject) // Internet Explorer 
			this.obj = new ActiveXObject("Microsoft.XMLHTTP"); 
		else { 
		} 
			
		return this;
	}
	
	function connexion_asc(url,contexte) {
		var methode = "GET";
		var asynchrone = true;
		var httpRequest = new objConnexion();
		
		httpRequest.argument = arguments
		
		if ( httpRequest ) {
		try{
			var _this = httpRequest;
				//Appel de la fonction de callback quand l'objet XMLHTTPRequest change de status
				httpRequest.obj.onreadystatechange = function() {
					//alert(_this);
					_this.callBack();
				}
			httpRequest.obj.open(methode, url, asynchrone);
			httpRequest.obj.send(null);
				
		}catch(oe){
		}
		}
	}
	
	function valideprofil(qui)
	{
		document.form_recherche.le_combo.value=qui;
		document.form_recherche.submit();
	}
	
	function resetmoteur()
	{
		remote.location.href='moteur.inc.php?reset=1';
	}
	
	function resetall()
	{
		remote.location.href='moteur.inc.php?reset=2';
	}
	
	function ChangePage(pas)
	{
		top.connexion_asc('resultats.inc.php?pas='+pas,'resultat');
	}


	/***************************************************************/
	
	function regenCarto( bool )
	{
		if( bool )
			top.cartoRecharge( 'carto/carto.php' );
		else
			top.cartoRecharge( '_' );
	}
    
    function resetCarto()
	{
		top.cartoRecharge( '_' );
	}
	
	function changeValue( id , value , valid )
	{
		var element = document.getElementById( id );
		
		if( element )
		{
			var elementOptions = element.getElementsByTagName( "option" );
			
			for( var i = 0 ; i < elementOptions.length ; i++ )
			{
				if( elementOptions[i].selected )
				{
					elementOptions[i].selected = false;
				}
				else
				{
					if( elementOptions[i].value == value )
					{
						elementOptions[i].selected = true;
					}
					else
					{
						elementOptions[i].selected = false;
					}
				}
			}
			
			if( id == "destination" )
			{
				changeValue( "commune" , -1 , false );
			}
			
			if( valid )
			{
				valideprofil( id );
			}
		}
	}
	
	function viewCommune( insee )
	{
		//var iframeCarto = document.getElementById( "iframeCarto" );
		//iframeCarto.contentWindow.document.getElementById( "carto" ).SetVariable( "insee" , insee );
	}
