function objetoAjax(){
 var xmlhttp=false;
  try{
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e){
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }catch(E){
    xmlhttp = false;
   }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
   xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}
//////////////////////////// FUNCIONES LINKIMAGENESGRANDES

function superCarussel(id){
	// Inicia scroll
	jQuery(function(){
		jQuery('#superCar'+id).mbScrollable({
		width:992,
		height:103,
		controls:"#controlsSuperCar"+id,
		scrollTimer:5000,
		nextCallback: 
			function() {
				carregaDadesCarrouselHome('carga_'+id,'next');
				superCarusselHover(id);				
			},
		prevCallback: 
			function() {
				carregaDadesCarrouselHome('carga_'+id,'prev');
				superCarusselHover(id);			
			}
		});
	});
	// Textos
	superCarusselHover(id);
}

function superCarusselHover(id){
	jQuery('#superCar'+id+' li a').hover(function(){
		jQuery('.info_superCar',this).animate({
			bottom:'0'
	  },350, function() {
	  });
	}, function(){
		jQuery('.info_superCar',this).animate({
			bottom:'-68'
	  },150, function() {
	  });
	});
}
////////////////////////////////////////

function Pagina(canal,nropagina){
 divContenido = document.getElementById('contenido');
 ajax=objetoAjax();
 ajax.open("GET", "http://www.transportebcn.es/todasimagenesajax.php?canal="+canal+"&pag="+nropagina);
 divContenido.innerHTML= '<img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif">';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}
/* 
* FUNCIONES DEL GLOSARIO
*/
function PalabraGlosario(idpalabra){
 divContenido = document.getElementById('contenidodefinicion');
 ajax=objetoAjax();
 ajax.open("GET", "http://www.transportebcn.es/glosario.php?tipo=3&palabra="+idpalabra);
 divContenido.innerHTML= '<img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif">';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}

function PalabrasGlosario(letra){
 divContenido = document.getElementById('contenido');
 ajax=objetoAjax();
 ajax.open("GET", "http://www.transportebcn.es/glosario.php?tipo=2&letra="+letra);
 divContenido.innerHTML= '<img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif">';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}

/*
* FUNCIONES DE LAS PREGUNTAS FRECUENTES
*/
function PreguntasTema(idpregunta){
 divContenido = document.getElementById('contenido');
 ajax=objetoAjax();
 ajax.open("GET", "http://www.transportebcn.es/preguntas_frecuentes.php?tipo=2&pregunta="+idpregunta);
 divContenido.innerHTML= '<img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif">';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}

function RespuestaPregunta(idpregunta){
 divContenido = document.getElementById('contenidorespuesta');
 ajax=objetoAjax();
 ajax.open("GET", "http://www.transportebcn.es/preguntas_frecuentes.php?tipo=3&pregunta="+idpregunta);
 divContenido.innerHTML= '<img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif">';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}


/*
* LISTA DE ESTACIONES
*/

function LetraEstacion(canal,letra){
	divContenido = document.getElementById('contenido');
 	ajax=objetoAjax();
	ajax.open("GET", "http://www.transportebcn.es/estacionesajax.php?canal="+canal+"&letra="+letra);
 divContenido.innerHTML= '<div align="center"><img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif"></div>';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}



function PaginaReportajes(canal,idpagina){
	divContenido = document.getElementById('contenido');
 	ajax=objetoAjax();
	ajax.open("GET", "http://www.transportebcn.es/reportajes.php?canal="+canal+"&pagina="+idpagina);
 divContenido.innerHTML= '<div align="center"><img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif"></div>';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}


function MesAnoArchivoNoticias(canal,mes,ano){
	divContenido = document.getElementById('contenido');
 	ajax=objetoAjax();
	ajax.open("GET", "http://www.transportebcn.es/archivonoticias.php?tipo=2&canal="+canal+"&mes="+mes+"&ano="+ano);
	divContenido.innerHTML= '<div align="center"><img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif"></div>';
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		divContenido.innerHTML = ajax.responseText
		}
	 }
 ajax.send(null)
}

function MesAnoArchivoOpiniones(canal,mes,ano){
	divContenido = document.getElementById('contenido');
 	ajax=objetoAjax();
	ajax.open("GET", "http://www.transportebcn.es/archivoopinionesajax.php?canal="+canal+"&mes="+mes+"&ano="+ano);
	divContenido.innerHTML= '<div align="center"><img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif"></div>';
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		divContenido.innerHTML = ajax.responseText
		}
	 }
 ajax.send(null)
}

function InfoEstacion(canal,idestacion,tipo,pagina){
	/*
	* TIPO: 1: Informacion
			2: Fotografias
			3: Noticias
			4: Mapa
	*/
	divContenido = document.getElementById('contenido');
 	ajax=objetoAjax();
	ajax.open("GET", "http://www.transportebcn.es/estacion.php?canal="+canal+"&tipo="+tipo+"&estacion="+idestacion+"&pagina="+pagina);
 divContenido.innerHTML= '<div style="text-align:center;" class="tablainfo"><b>CARGANDO DATOS DE LA ESTACI&Oacute;N</b><br /><img src="http://www.transportebcn.es/images/varios/trenloading.gif"></div>';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}

function InfoLinea(canal,idlinea,tipo,pagina){
	/*
	* TIPO: 1: Informacion
			2: Fotografias
			3: Noticias
			4: Mapa
	*/
	divContenido = document.getElementById('contenido');
 	ajax=objetoAjax();
	ajax.open("GET", "http://www.transportebcn.es/linea.php?canal="+canal+"&tipo="+tipo+"&linea="+idlinea+"&pagina="+pagina);
 divContenido.innerHTML= '<div align="center" class="tablatextoestacion"><b>CARGANDO DATOS DE LA LINEA</b><br /><img src="http://www.transportebcn.es/images/varios/trenloading.gif"></div>';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}

function InfoTren(canal,tren,tipo,pagina){
	/*
	* TIPO: 1: Informacion
			2: Fotografias
			3: Noticias
			4: Mapa
	*/
	divContenido = document.getElementById('contenido');
 	ajax=objetoAjax();
	ajax.open("GET", "http://www.transportebcn.es/tren.php?canal="+canal+"&tipo="+tipo+"&tren="+tren+"&pagina="+pagina);
 divContenido.innerHTML= '<div align="center" class="tablatextoestacion"><b>CARGANDO DATOS DEL TREN</b><br /><img src="http://www.transportebcn.es/images/varios/trenloading.gif"></div>';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}


function InfoReportaje(canal,idreportaje,tipo,pagina){
	/*
	* TIPO: 1: Informacion
			2: Fotografias
			3: Noticias
	*/
	divContenido = document.getElementById('contenido');
 	ajax=objetoAjax();
	ajax.open("GET", "http://www.transportebcn.es/reportaje.php?canal="+canal+"&tipo="+tipo+"&reportaje="+idreportaje+"&pagina="+pagina);
 divContenido.innerHTML= '<div align="center"><b>CARGANDO DATOS DEL REPORTAJE</b><br /><img src="http://www.transportebcn.es/images/varios/trenloading.gif"></div>';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}



function cargarResultados(){
   divResultado = document.getElementById('resultadosencuesta');
   codenc=document.frmencuesta.idencuesta.value;
   nroopc=document.frmencuesta.nroopciones.value;
   lug=document.frmencuesta.lugar.value;
   i=1;
   while(i<=nroopc){
      opcion=document.getElementById('opcion'+i).checked;
      if (opcion==true){
         alt=i;
      }
      i++;
   }
   ajax=objetoAjax();
   ajax.open("POST", "http://www.transportebcn.es/resultadosajax.php",true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
         divResultado.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("idencuesta="+codenc+"&alternativa="+alt+"&lugar="+lug)
}


function cargarSatisfaccionPregunta(){
   divResultado = document.getElementById('satisfaccionpregunta');
   idp=document.frmsatisfaccion.idpregunta.value;
   opcion1=document.getElementById('opcion1').checked;
      if (opcion1==true){
         opc='S';
      }
	  else opc='N';
   ajax=objetoAjax();
   ajax.open("POST", "http://www.transportebcn.es/preguntas_frecuentes.php?tipo=4",true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
         divResultado.innerHTML = ajax.responseText
      }
   }
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("tipo=4&idpregunta="+idp+"&opc="+opc);
}

function ResultadoZonas(){
	divResultado = document.getElementById('zonas');
	eini=document.frmzonas.estini.value;
	efin=document.frmzonas.estfin.value;
	id=document.frmzonas.id.value;
	divResultado.innerHTML= '<div align="center"><img src="http://www.transportebcn.es/images/varios/indicator.gif"></div>';
	eurlfinal="http://www.transportebcn.es/zonas.php?estacionini="+eini+"&estacionfin="+efin+"&id="+id;
	
	ajax=objetoAjax();
    ajax.open("POST", eurlfinal  ,true);
	ajax.onreadystatechange=function() {
  		if (ajax.readyState==4) {
   		divResultado.innerHTML = ajax.responseText;
  		}
 	}
   ajax.send(null);
}

function CargaFormularioRutaSimpleAv(form){
	divContenido = document.getElementById('formularioruta');
 	ajax=objetoAjax();
	ajax.open("GET", "http://www.transportebcn.es/buscaruta.php?form="+form+"&type=1");
 divContenido.innerHTML= '<div style="text-align:center; border:1px solid #000000;" class="tablatextoestacion"><b>CARGANDO FORMULARIO DE BUSQUEDA DE RUTAS</b><br /><img src="http://www.transportebcn.es/images/varios/indicator.gif"></div>';
 ajax.onreadystatechange=function() {
  if (ajax.readyState==4) {
   divContenido.innerHTML = ajax.responseText
  }
 }
 ajax.send(null)
}


function ResultadoBuscaRuta(){
	divResultado = document.getElementById('resultadoruta');
	eini=document.frmruta.pi.value;
	efin=document.frmruta.pf.value;
	busc=document.frmruta.buscador.value;
	
	if (busc=='A'){
		evita1=document.frmruta.evita1.value;
		evita2=document.frmruta.evita2.value;
		evita3=document.frmruta.evita3.value;
		evitaest1=document.frmruta.evitaest1.value;
		evitaest2=document.frmruta.evitaest2.value;	
		if (document.frmruta.nooficial[1].checked) noof='N';
		else noof='S';
		
		eurlfinal="http://www.transportebcn.es/buscaruta.php?estacionini="+eini+"&estacionfin="+efin+"&busc="+busc+"&evita1="+evita1+"&evita2="+evita2+"&evita3="+evita3+"&evitaest1="+evitaest1+"&evitaest2="+evitaest2+"&noof="+noof+"&type=2";
		//alert(eurlfinal);
	}
	else{
		eurlfinal="http://www.transportebcn.es/buscaruta.php?estacionini="+eini+"&estacionfin="+efin+"&busc="+busc+"&type=2";	
	}
	/*alert(eini+"-"+efin);*/
	divResultado.innerHTML= '<div align="center"><b>Cargando Ruta</b><br />Esta busqueda puede tardar unos 30 seg.<br /><img src="http://www.transportebcn.es/images/varios/loadingAnimation0.gif"></div>';
	
	ajax=objetoAjax();
    ajax.open("POST", eurlfinal  ,true);
	ajax.onreadystatechange=function() {
  		if (ajax.readyState==4) {
   		divResultado.innerHTML = ajax.responseText;
  		}
 	}
   ajax.send(null);
}
