//--------------------------------------------------------------------------------------------------------------
	
var xmlhttp_dep;
var controle_list_dst=null;

function loadXMLDoc_Dep(url)
{
xmlhttp_dep=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp_dep=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp_dep=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
if (xmlhttp_dep!=null)
  {
  xmlhttp_dep.onreadystatechange=state_Change_Dep;
  xmlhttp_dep.open("GET",url,true);
  xmlhttp_dep.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

//---------------------------------------------------------------------------

function state_Change_Dep()
{
  //document.getElementById('T1').innerHTML=xmlhttp.readyState;
  if (xmlhttp_dep.readyState==4)
  {// 4 = "loaded"
    if (xmlhttp_dep.status==200)
    {
    	// 200 = "OK"
    	//document.getElementById('T1').innerHTML=xmlhttp.responseText;
			//window.opener.location.reload();
			//window.setTimeout('window.close()',10);		
			//document.getElementById('T1').innerHTML=xmlhttp.responseText;
			var TabCommune=getContenu('unecommune',xmlhttp_dep);
			
			/*
			idx = document.getElementById('iddep').style;
			idx.visibility="visible";
			
			idx = document.getElementById('idcom').style;
			idx.visibility="visible";*/
			
			if (controle_list_dst)
			{
				for (i=0;i<controle_list_dst.options.length;i++)
	   		{
	   			controle_list_dst.options[i]=null;
	   		}
	   		controle_list_dst.options.length=0;
	   	}
			
			var option = new Option('Toutes',0);				
			controle_list_dst.options[controle_list_dst.options.length]=option;	
			
			for (var i=0;i<TabCommune.length;i++)
			{
				var option = new Option(TabCommune[i].nom+' '+TabCommune[i].codepostal,TabCommune[i].id);
				//eval("document.formcv.commune.options[document.formcv.commune.options.length]=option");			
				controle_list_dst.options[controle_list_dst.options.length]=option;			
			}
    }
	else
    {
     	alert("Problem retrieving data:" + xmlhttp.statusText);
    }
  }
  
  //alert("fini");
}	

 	

//---------------------------------------------------------------------------

function une_commune(nom,id,codepostal)
{
this.nom=nom;
this.id=id;
this.codepostal=codepostal;
}

//---------------------------------------------------------------------------

function getContenu(champ,req)
{			var items = req.responseXML.getElementsByTagName(champ);
	    // loop through <nom> elements, and add each nested
	    // <title> element to Topics select element
	    
	    var tabcommune=new Array();
	    var valeur;
	    var valeurid;
	    
	    var icommune=0;
	    
	    for (var i = 0; i < items.length; i++) 
	    {
	    	var result=items[i];
	      if (result) 
	      {
	      	
	      	
	      	if (result.getElementsByTagName('NomComplet')[0].firstChild 
	      			&& result.getElementsByTagName('IdCodePostal')[0].firstChild
	      			&& result.getElementsByTagName('CodePostal')[0].firstChild )
	      	
	      	{
	      		
	      		
		      	var valeur = unescape(result.getElementsByTagName('NomComplet')[0].firstChild.nodeValue);
		      	var valeurid = result.getElementsByTagName('IdCodePostal')[0].firstChild.nodeValue;
		      	var codepostal = result.getElementsByTagName('CodePostal')[0].firstChild.nodeValue;
		      	
		      	valeur=valeur.replace(/\+/g,' ');
		      	
		      	tabcommune[icommune++]=new une_commune(valeur,parseInt(valeurid),codepostal);  					
		      }
	      	
  				
				}
	    }							    
	    return tabcommune;
}

//---------------------------------------------------------------------------
 	
function change_dep(ctrl_dep,ctrl_dest)
{
	if (ctrl_dep)
	{
		controle_list_dst=ctrl_dest;
		//alert("ok1");
		var URL='tourisme/getcommune.php?NumDep='+ctrl_dep.options[ctrl_dep.selectedIndex].value;
		//alert(URL);
		loadXMLDoc_Dep(URL);		
		
				
	}	
}

