function loadXMLDoc(dname) 
{
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
  catch(e) {alert(e.message)}
  }
try 
  {
  xmlDoc.async=false;
  xmlDoc.load(dname);
  return(xmlDoc);
  }
catch(e) {alert(e.message)}
return(null);
}

function cargarXml(){				
		
		//alert('1');
		tam=domDoc.getElementsByTagName("INMUEBLE").length;
		//alert(domDoc.getElementsByTagName("INMUEBLE").length);
		var j=0;
		ini=tam-(tam_pag*pag);
		fin=tam-(tam_pag*(pag+1));
		nPag=Math.ceil((tam-6)/tam_pag);
		//alert("Pagina: "+pag+" pag ini:"+ini+" fin:"+fin+" ntpags:"+nPag);
		//for(i=ini-1;i>=fin&&i>=0;i--){
		for(i=ini-1;i>=fin&&i>6;i--){
		//for(i=tam-1;i>6;i--){
			nodoActual=domDoc.getElementsByTagName("INMUEBLE").item(i);
			//alert(j);
			var x=document.getElementById('inmuebles').insertRow(j)
  			var y0=x.insertCell(0);
 			var y1=x.insertCell(1);
 			var y2=x.insertCell(2);
			y0.vAlign="top";
			y2.vAlign="top";
			y0.width="130px";
			y0.innerHTML="<strong style='color:#00204E;' >Ref. PG"+nodoActual.getElementsByTagName("N_REF")[0].childNodes[0].nodeValue+"</strong>";
						
			y1.innerHTML="<div class='Estilo10' style='overflow:hidden;height:20px;'>"+nodoActual.getElementsByTagName("TITULO")[0].childNodes[0].nodeValue+"</div>";
			
			y2.width="100px"
			y2.innerHTML="<div align='right' class='Estilo11'>"+nodoActual.getElementsByTagName("PRECIO")[0].childNodes[0].nodeValue+" &euro;</div>";
			j++;
 			var x=document.getElementById('inmuebles').insertRow(j);
 			var y10=x.insertCell(0);
			y10.colSpan=2;
 			var y11=x.insertCell(1);
			//alert(nodoActual.getElementsByTagName("N_REF")[0].childNodes[0].nodeValue);
			
			y10.innerHTML="<span class='Estilo8'>"+nodoActual.getElementsByTagName("RESENYA")[0].childNodes[0].nodeValue+"</span>";
 			y11.vAlign="top";
			y11.align="center";
			y11.innerHTML="<div align='right'><a href='detalleOportunidades.html?"+i+"&"+pag+"'><strong>[+ info]</strong></a></div>";
			j++;
			var x=document.getElementById('inmuebles').insertRow(j);
			var z=x.insertCell(0);
			z.colSpan=3;
			z.innerHTML="<hr/>";
			j++;
 		}//alert(document.getElementById('inmuebles').innerHTML);
		document.getElementById('inmuebles').style.tableLayout="fixed";
		CrearPaginador();
	} 
	
	function cargarXmlDetalle(){

		try{
			if(location.href.split("?")[1]!=null){		
				//alert(document.getElementById('inmuebles'));
				nRef=nodoActual.getElementsByTagName("N_REF")[0].childNodes[0].nodeValue;
				document.getElementById('referencia').innerHTML=nodoActual.getElementsByTagName("N_REF")[0]==null||nodoActual.getElementsByTagName("N_REF")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("N_REF")[0].childNodes[0].nodeValue;
				document.getElementById('precio').innerHTML=nodoActual.getElementsByTagName("PRECIO")[0]==null||nodoActual.getElementsByTagName("PRECIO")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("PRECIO")[0].childNodes[0].nodeValue+" &euro;";
				document.getElementById('nDormitorio').innerHTML=nodoActual.getElementsByTagName("N_DORMITORIO")[0]==null||nodoActual.getElementsByTagName("N_DORMITORIO")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("N_DORMITORIO")[0].childNodes[0].nodeValue;
				document.getElementById('superficie').innerHTML=nodoActual.getElementsByTagName("SUPERFICIE")[0]==null||nodoActual.getElementsByTagName("SUPERFICIE")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("SUPERFICIE")[0].childNodes[0].nodeValue+" m<font class='font9'><sup>2</sup></font>";
				document.getElementById('ubicacion').innerHTML=nodoActual.getElementsByTagName("SITUACION")[0]==null||nodoActual.getElementsByTagName("SITUACION")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("SITUACION")[0].childNodes[0].nodeValue;
				document.getElementById('comentario').innerHTML=nodoActual.getElementsByTagName("COMENTARIO")[0]==null||nodoActual.getElementsByTagName("COMENTARIO")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("COMENTARIO")[0].childNodes[0].nodeValue;
				document.getElementById('instalaciones').innerHTML=nodoActual.getElementsByTagName("INSTALACIONES")[0]==null||nodoActual.getElementsByTagName("INSTALACIONES")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("INSTALACIONES")[0].childNodes[0].nodeValue;
				document.getElementById('equipamientos').innerHTML=nodoActual.getElementsByTagName("EQUIPAMIENTOS")[0]==null||nodoActual.getElementsByTagName("EQUIPAMIENTOS")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("EQUIPAMIENTOS")[0].childNodes[0].nodeValue;
				document.getElementById('zonasComunes').innerHTML=nodoActual.getElementsByTagName("ZONAS_COMUNES")[0]==null||nodoActual.getElementsByTagName("ZONAS_COMUNES")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("ZONAS_COMUNES")[0].childNodes[0].nodeValue;
				document.getElementById('entorno').innerHTML=nodoActual.getElementsByTagName("ENTORNO")[0]==null||nodoActual.getElementsByTagName("ENTORNO")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("ENTORNO")[0].childNodes[0].nodeValue;
				document.getElementById('observaciones').innerHTML=nodoActual.getElementsByTagName("OBSERVACIONES")[0]==null||nodoActual.getElementsByTagName("OBSERVACIONES")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("OBSERVACIONES")[0].childNodes[0].nodeValue;
				document.getElementById('garaje').innerHTML=nodoActual.getElementsByTagName("GARAJE")[0]==null||nodoActual.getElementsByTagName("GARAJE")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("GARAJE")[0].childNodes[0].nodeValue;
				document.getElementById('trastero').innerHTML=nodoActual.getElementsByTagName("TRASTERO")[0]==null||nodoActual.getElementsByTagName("TRASTERO")[0].childNodes[0]==null?"&nbsp;":nodoActual.getElementsByTagName("TRASTERO")[0].childNodes[0].nodeValue;
				//imagenes
				//alert("toy1");
				//alert(nodoActual.getElementsByTagName("IMAGENES")[0].getAttribute("num"));
				if(nodoActual.getElementsByTagName("IMAGENES")[0].getAttribute("num")!=null&&nodoActual.getElementsByTagName("IMAGENES")[0].getAttribute("num")!=""){
						var hayImagen= new Image;
						numImagenes=nodoActual.getElementsByTagName("IMAGENES")[0].getAttribute("num");
						if (numImagenes>0) document.getElementById('carruselImagenes').innerHTML="";
						for(i=0;i<numImagenes;i++){
							document.getElementById('carruselImagenes').innerHTML+="<img id=\"img"+i+"\" src=\"oportunidades/pg"+nRef+"/pg"+nRef+"-"+i+".JPG\" vspace=\"15\" onMouseOver=\"cambiarFotoOportunidades("+i+")\" onMouseOut=\"cambiarOportunidadesFoto()\"><br>"
						}
//						document.images.img1.src="oportunidades/pg"+nRef+"/pg"+nRef+"-0.JPG";
//						if(nodoActual.getElementsByTagName("IMAGENES")[0].getAttribute("num")<1)
//							document.images.img1.style.visibility="hidden";
//						document.images.img2.src="oportunidades/pg"+nRef+"/pg"+nRef+"-1.JPG";
//						if(nodoActual.getElementsByTagName("IMAGENES")[0].getAttribute("num")<2)
//							document.images.img2.style.visibility="hidden";
//						document.images.img3.src="oportunidades/pg"+nRef+"/pg"+nRef+"-2.JPG";
//						if(nodoActual.getElementsByTagName("IMAGENES")[0].getAttribute("num")<3)
//							document.images.img3.style.visibility="hidden";
//						document.images.img4.src="oportunidades/pg"+nRef+"/pg"+nRef+"-3.JPG";
//						if(nodoActual.getElementsByTagName("IMAGENES")[0].getAttribute("num")<4)
//							document.images.img4.style.visibility="hidden";
					}
					tam=nodoActual.getElementsByTagName("ESTANCIA").length;//alert(tam);
					for(i=0;i<tam;i++){
						//nodoActual=domDoc.getElementsByTagName("ESTANCIA").item(i);	
						var x=document.getElementById('datosEspecificos').insertRow(2+i);
			  		var y0=x.insertCell(0);
			 			var y1=x.insertCell(1);
			 			y0.innerHTML="<strong>"+nodoActual.getElementsByTagName("ESTANCIA")[i].getAttribute("nombre");+"</strong>"
			 			y1.innerHTML="<div align='right'>"+nodoActual.getElementsByTagName("ESTANCIA")[i].childNodes[0].nodeValue+" m<font class='font9'><sup>2</sup></font></div>";
			 			y0.style.borderBottom="1px solid #87D300";
			 			y0.style.height="20px";
			 			y1.style.borderBottom="1px solid #87D300";
					}
			}
  	}catch(e) {
		}
		cargado=true;
	} 
	
	function borrar(){
		for(i=0;i<tam_pag&&document.getElementById('inmuebles').rows.length>3;i++){
			document.getElementById('inmuebles').deleteRow(3);
			document.getElementById('inmuebles').deleteRow(2);
			document.getElementById('inmuebles').deleteRow(1);
		}
		document.getElementById('inmuebles').deleteRow(0);
		document.getElementById('inmuebles').deleteRow(0);
		document.getElementById('inmuebles').deleteRow(0);
	}
	
	function avanzar(){
		if(fin>0){
			borrar();
			pag++;
			cargarXml();
		}
	}
	
	function retroceder(){
		if (pag>0){
			borrar();
			pag--;
			cargarXml();
		}
	}
	
	function irA(pagSel,event){
			if (pagSel>0){
				pag=pagSel-1;
				borrar();
				cargarXml();
			}
	}
	function CrearPaginador(){
		document.getElementById('paginador').innerHTML="<a href=\"javascript:retroceder()\"><< Anterior</a>";
		for(i=1;i<=nPag;i++){
				if((i-1)==pag){
					document.getElementById('paginador').innerHTML+="<span class='active'\">"+i+"</span>"
				}else{
					document.getElementById('paginador').innerHTML+="<a href=\"#\" onclick=\"javascript:irA("+i+")\">"+i+"</a>";
				}
			}
		document.getElementById('paginador').innerHTML+="<a href=\"javascript:avanzar()\">Siguiente >></a>";
	}
	
	function getParam(){
		if(document.URL.split("#")[1]!=null){
			document.URL.split("#")[1];
		}
	}
	
	function moverArriba(idDiv,nPx){
		document.getElementById(idDiv).scrollTop+=nPx;
	}
	
	function moverAbajo(idDiv,nPx){
		document.getElementById(idDiv).scrollTop-=nPx;
		
	}

	function moverDcha(idDiv,nPx){
		
	}

	function moverIzqa(idDiv,nPx){
		
	}
	
	function startCarrusel(direccion,idImg,velocidad){
		if(direccion=="arriba"){
				document.getElementById(idImg).src="imgs/triangulosuperior14azul.gif";
		}else if(direccion=="abajo"){
				document.getElementById(idImg).src="imgs/trianguloinferior14azul.gif";
		}
		flagMover=setInterval("moverCarrusel('"+direccion+"')",1);
	}
	
	function moverCarrusel(direccion){
		div='carruselImagenes';
		cantidadMovimiento=4;
		totmov=0;
			if(direccion=="arriba"){
				totmov+=cantidadMovimiento
				if(totmov==document.getElementById(div).offsetHeight) stopCarrusel();
				moverArriba(div,cantidadMovimiento)
			}else if(direccion=="abajo"){
				totmov=document.getElementById(div).offsetHeight-cantidadMovimiento
				if(totmov<=0) stopCarrusel();
				moverAbajo(div,cantidadMovimiento)
			}else if(direccion=="derecha"){
				moverDcha(div,cantidadMovimiento)
			}else if(direccion=="izquierda"){
				moverIzqa(div,cantidadMovimiento)
			}
	}
	
	function stopCarrusel(){
		//flagMover=false;
		clearInterval(flagMover);
	}
	function restaurarImgs(){
			document.images.trianguloSuperiorA.src="imgs/triangulosuperior14verde.gif";
			document.images.trianguloInferiorA.src="imgs/trianguloinferior14verde.gif";
			document.images.trianguloSuperiorB.src="imgs/triangulosuperior14verde.gif";
			document.images.trianguloInferiorB.src="imgs/trianguloinferior14verde.gif";
	}

	