// JavaScript Document

function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function mostrarLinksDestino() {

	cboContinente=document.getElementById('continente');
	cboPais=document.getElementById('pais');
	cboEstado=document.getElementById('estado');
	cboCiudad=document.getElementById('ciudad');

	var destinationHolder=document.getElementById('destinoHolder');
	if (valorCombo(cboContinente)!='') {
		if (destinationHolder)
			destinationHolder.style.display='';
	}
	else {
		if (destinationHolder)
			destinationHolder.style.display='none';
		document.getElementById('waitForCompletion').style.display='none';
		return;
	}

	continente=textoCombo(cboContinente);
	pais=textoCombo(cboPais);
	provincia=textoCombo(cboEstado);
	ciudad=textoCombo(cboCiudad);

	id_continente=valorCombo(cboContinente);
	id_pais=valorCombo(cboPais);
	id_provincia=valorCombo(cboEstado);
	id_ciudad=valorCombo(cboCiudad);

	var links='<a href="javascript:showAddress(\''+addslashes(continente)+'\',1)">'+continente+'</a>';
	if (id_pais!='') 
		links+='&nbsp;&raquo;&nbsp;<a href="javascript:showAddress(\''+addslashes(pais)+', '+addslashes(continente)+'\',4)">'+pais+'</a>';
	if (id_provincia!='') 
		links+='&nbsp;&raquo;&nbsp;<a href="javascript:showAddress(\''+addslashes(provincia)+', '+addslashes(pais)+', '+addslashes(continente)+'\',7)">'+provincia+'</a>';
	if (id_ciudad!='') 
		links+='&nbsp;&raquo;&nbsp;<a href="javascript:showAddress(\''+addslashes(ciudad)+', '+addslashes(provincia)+', '+addslashes(pais)+', '+addslashes(continente)+'\',11)">'+ciudad+'</a>';
		
	if (destinationHolder)
		document.getElementById('linksHolder').innerHTML=links;
	
	document.getElementById('planisferio').style.display='none';
	document.getElementById('googleMaps').style.display='';
	
	var address='';
	var zoomLevel=1;
	if (id_ciudad!='') {
		address=ciudad;
		zoomLevel=10;
	}
	if (id_provincia!='') {
		if (address!='')
			address+=', ';
		address+=provincia;
		if (id_ciudad=='')
			zoomLevel=7;
	}
	if (id_pais!='') {
		if (address!='')
			address+=', ';
		address+=pais;
		if (id_provincia=='' && id_ciudad=='')
			zoomLevel=4;
	}
	if (address!='')
		address+=', ';
	address+=continente;
	showAddress(address,zoomLevel);
}

function poblarPaises(xmlDoc) {
	var paises=xmlReq.responseXML.getElementsByTagName('pais');
	for (i=0; i<paises.length; i++) {
		pais=paises[i];
		idPais=pais.getElementsByTagName('id')[0].firstChild.data;
		nombrePais=pais.getElementsByTagName('nombre')[0].firstChild.data;
		agregarOpcion('pais',idPais,nombrePais);
	}
	document.getElementById('waitForCompletion').style.display='none';
}

function poblarProvincias(xmlDoc) {
	var provincias=xmlReq.responseXML.getElementsByTagName('provincia');
	for (i=0; i<provincias.length; i++) {
		provincia=provincias[i];
		id=provincia.getElementsByTagName('id')[0].firstChild.data;
		nombre=provincia.getElementsByTagName('nombre')[0].firstChild.data;
		agregarOpcion('estado',id,nombre);
	}
	document.getElementById('waitForCompletion').style.display='none';
}

function poblarCiudades(xmlDoc) {
	var ciudades=xmlReq.responseXML.getElementsByTagName('ciudad');
	for (i=0; i<ciudades.length; i++) {
		ciudad=ciudades[i];
		id=ciudad.getElementsByTagName('id')[0].firstChild.data;
		nombre=ciudad.getElementsByTagName('nombre')[0].firstChild.data;
		agregarOpcion('ciudad',id,nombre);
	}
	document.getElementById('waitForCompletion').style.display='none';
}

function cargaDatosContinente() {
	document.getElementById('waitForCompletion').style.display='';
	cboContinente=document.getElementById('continente');
	cboPais=document.getElementById('pais');
	cboEstado=document.getElementById('estado');
	cboCiudad=document.getElementById('ciudad');
	
	limpiarCombo(cboPais);
	limpiarCombo(cboEstado);
	limpiarCombo(cboCiudad);
	var i_continente_id=valorCombo(cboContinente);
	mostrarLinksDestino();
	if (i_continente_id=='') {
		return;
	}
//	alert('http;//www.pasajerofrecuente.com/ajax/get_xml.php?metodo=paises&id='+i_continente_id);
	loadData('/ajax/get_xml.php?metodo=paises&id='+i_continente_id,poblarPaises);
}

function cargaDatosPais() {
	document.getElementById('waitForCompletion').style.display='';
	cboContinente=document.getElementById('continente');
	cboPais=document.getElementById('pais');
	cboEstado=document.getElementById('estado');
	cboCiudad=document.getElementById('ciudad');
	
	limpiarCombo(cboEstado);
	limpiarCombo(cboCiudad);
	var i_pais_id=valorCombo(cboPais);
	mostrarLinksDestino();
//	alert('http;//www.pasajerofrecuente.com/ajax/get_xml.php?metodo=paises&id='+i_continente_id);
	if (i_pais_id=='') {
		return;
	}
	loadData('/ajax/get_xml.php?metodo=provincias&id='+i_pais_id,poblarProvincias);
}

function cargaDatosProvincia() {
	document.getElementById('waitForCompletion').style.display='';
	cboContinente=document.getElementById('continente');
	cboPais=document.getElementById('pais');
	cboEstado=document.getElementById('estado');
	cboCiudad=document.getElementById('ciudad');
	
	limpiarCombo(cboCiudad);
	mostrarLinksDestino();
	var i_provincia_id=valorCombo(cboEstado);
	if (i_provincia_id=='') {
		return;
	}
//	alert('http;//www.pasajerofrecuente.com/ajax/get_xml.php?metodo=paises&id='+i_continente_id);
	loadData('/ajax/get_xml.php?metodo=ciudades&id='+i_provincia_id,poblarCiudades);
}

