function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Non č stato possibile impostare un gestore di eventi");
  }
}
toursTID=null;
addEvent(window,'load',initSels,false);
function initSels(){
	if (document.getElementById('fcontinenti-fe')){
	if (typeof  continenti!="undefined"){
		var pathXml="/qg/dMapAjax.do?cnte="+continenti;
		var get_nazioni=new net.ContentLoader(pathXml,updateList,null,"GET",null,null);
		checkSelTours();
		}

	if (document.getElementById('fcontinenti-fe')){
		s1=document.getElementById('fcontinenti-fe');
		s1.onchange=setMngLists;
	}
 }
}

function checkSelTours(){
	if (document.getElementById('fnazioni-fe')){
		window.clearTimeout(toursTID);
		initSelTours();
		return;
		}
	else{
		toursTID=window.setTimeout('checkSelTours()',200);
		}
	}

function initSelTours(){
if (typeof  nazioni!="undefined"&&id_destinazione!=''){
		if (zone=='tour'){
			var pathXml="/qg/dMapToursAjax.do?cc="+nazioni;
			var get_tours=new net.ContentLoader(pathXml,updateList,null,"GET",null,null);
			}
		else {
			var pathXml="/qg/dMapToursAjax.do?cc="+nazioni+"&zone=location";
			var get_tours=new net.ContentLoader(pathXml,updateList,null,"GET",null,null);
			 }
		}
}

function setMngLists(){
	//alert('this.id '+this.id)
	if (this==document.getElementById('fnazioni-fe')){
		if (document.getElementById('ftours-fe')){
			container.removeChild(p3)
			}
		var pathXml="/qg/dMapToursAjax.do?cc="+this.value;
		var get_tours=new net.ContentLoader(pathXml,updateList,null,"GET",null,null);
		}
	else if (this==document.getElementById('fcontinenti-fe')){
		if (document.getElementById('fnazioni-fe')){
			container.removeChild(p2)
			}
		if (document.getElementById('ftours-fe')){
			container.removeChild(p3)
			}
		var pathXml="/qg/dMapAjax.do?cnte="+this.value;
		var get_tours=new net.ContentLoader(pathXml,updateList,null,"GET",null,null);
		}
}



	function updateList(){
	container=document.getElementById('fsel-to-destinazione');
	var root = this.req.responseXML.documentElement;
	var type = root.getAttribute('type');
	//alert('type selezione '+type)
	var items = root.getElementsByTagName("elemento");
	var option = null;
	if (type=='nazioni'){

	//crea una option vuota con indicazione scelta nazione
	p2=document.createElement("p");
		container.appendChild(p2);
	var s2=document.createElement("select");
		p2.appendChild(s2);
	s2.setAttribute('id','fnazioni-fe');
	if (id_destinazione!=''){
	s2.onchange=setMngLists;
	}
	else {
		s2.onchange=goToPage;
		}
	var optionDefault=document.createElement("option");
			optionDefault.setAttribute('value','');
			//optionDefault.appendChild;
			optionDefault.appendChild(document.createTextNode('Seleziona una nazione'));
			s2.appendChild(optionDefault);
		for(var i=0; i<items.length;i++) {
			var option=document.createElement("option");
			s2.appendChild(option);
			valId=items[i].getAttribute('id');
			option.setAttribute('value',valId);
			valUrl=items[i].getAttribute('url');
			option.setAttribute('id',valUrl);
			option.appendChild(document.createTextNode(items[i].firstChild.nodeValue));
			if (typeof nazioni!="undefined"&&nazioni==valId){
				option.selected="selected";
				}
		}
		var img2=document.createElement('img');
		img2.src="/qg/img/interne/seldest_separatore.gif";
		p2.appendChild(img2);
	}
	else if (type=='tours'||type=='locations'){
			p3=document.createElement("p");
				container.appendChild(p3);
			var s3=document.createElement("select");
				p3.appendChild(s3);
			s3.setAttribute('id','ftours-fe');
            s3.setAttribute('name','idFK');
			s3.onchange=goToPage;
			var optionDefault=document.createElement("option");
					optionDefault.setAttribute('value','');
					optionDefault.appendChild;
					if (type=='tours'){
					optionDefault.appendChild(document.createTextNode('Seleziona un tour'));
					}
					else if(type=='locations'){
						optionDefault.appendChild(document.createTextNode('Seleziona una cittā'));
					}
					s3.appendChild(optionDefault);
				for(var i=0; i<items.length; i++) {
					var option=document.createElement("option");
					s3.appendChild(option);
					valId=items[i].getAttribute('id');
					option.setAttribute('value',valId);
					valUrl=items[i].getAttribute('url');
					option.setAttribute('id',valUrl);
					option.appendChild(document.createTextNode(items[i].firstChild.nodeValue));
					if (typeof id_destinazione!="undefined"&&id_destinazione==valId){
						option.selected="selected";
						}
				}


		}

	}
function goToPage(){
	location.href=this.options[this.selectedIndex].id
	}