// JavaScript Document

function cambiarTitulo(texto)
{
	var original = document.title;
	var posicion = 0;
	
	for(var i=0; i<original.length; i++)
	{
		if(original.charAt(i)=='-')
		{
			posicion=i;	
		}
	}
	
	document.title = original.substring(0,posicion)+" - "+texto; 
}

// FUNCIONES PARA OCULTAR LOS COMBOS Y QUE NO QUEDEN POR ENCIMA DEL FLASH
	function hideSelect() {
		if (document.all) {
			for (var i = 0; i < document.getElementsByTagName("SELECT").length; i++)
				document.getElementsByTagName("SELECT")[i].style.visibility = 'hidden';
		}
	}
	
	function unhideSelect() {
		if (document.all) {
			for (var i = 0; i < document.getElementsByTagName("SELECT").length; i++)
				document.getElementsByTagName("SELECT")[i].style.visibility = 'visible';
		}
	}

// FUNCION PARA MANDAR EL FORMULARIO DEL BUSCADOR ARIADNA
	function mandarFormulario(combo, valor, provincia, localidad) {
		document.frmBuscador.localidad.value = 0;
		document.frmBuscador.barrio.value = 0;
		document.frmBuscador.pagina.value = 1;
		if (combo==0) {
			document.frmBuscador.provincia.value = valor;
			document.location = "/vhpromociones/buscador/" + valor + "/0/0/1.jsp";
		} else if (combo==1) {
			document.frmBuscador.provincia.value = provincia;
			document.frmBuscador.localidad.value = valor;
			document.location = "/vhpromociones/buscador/" + provincia + "/" + valor + "/0/1.jsp";
		} else if (combo==2) {
			document.frmBuscador.provincia.value = provincia;
			document.frmBuscador.localidad.value = localidad;
			document.frmBuscador.barrio.value = valor;
			document.location = "/vhpromociones/buscador/" + provincia + "/" + localidad + "/" + valor + "/1.jsp";
		}
	}
	
// FUNCION PARA MARCAR LA PESTAÑA EN LA QUE SE ENCUENTRA EL USUARIO	
	function marcarPestanaPromocion(grPestanas, idPestana) {
		ind=(document.all)?0:1;
		if (grPestanas=="current") {
			obj = document.getElementById("header");
		} else if (grPestanas=="currentInfo") {
			obj = document.getElementById("infoPes");
			if (idPestana==0) {
				document.getElementById("contenidoExteriores").style.display = "block";
				document.getElementById("contenidoInteriores").style.display = "none";
				capaImgMov(0, 1, 'capaImgExt');
			} else if (idPestana==2) {
				document.getElementById("contenidoInteriores").style.display = "block";
				document.getElementById("contenidoExteriores").style.display = "none";
				capaImgMov(0, 1, 'capaImgInt');
			}
		}
		
		if (idPestana==-1)
			obj.childNodes[ind].childNodes[ind].id = "deshab";
		else {	
			if (document.getElementById(grPestanas))
				document.getElementById(grPestanas).id = "";
			idPestana=(document.all)?idPestana:(idPestana*2)+1;
			obj.childNodes[ind].childNodes[idPestana].id = grPestanas;
		}
	}
	
// MOUSEOVER DE LOS ICONOS DE NAVEGACION Y ONCLICK (PARA QUE SE QUEDE MARCADO EL ICONO
	var contAnt = "";		//en estas variables evaluo si el usuario se encuentra en una pestaña representada por uno de los iconos
	function onMouseOverIco(nombreImagen, obj) {
		if (document.getElementById("capaInfIcono").parentNode.id!='') {
			contAnt = document.getElementById("capaInfIcono").innerHTML;
		}
		obj.src = "/vhpromociones/recursos/img/iconos/" + nombreImagen + "_over.gif";
		document.getElementById("capaInfIcono").innerHTML = obj.name;
	}
	
	function onMouseOutIco(nombreImagen, obj) {
		if (document.getElementById("capaInfIcono").parentNode.id!=obj.id + "0") {
			obj.src = "/vhpromociones/recursos/img/iconos/" + nombreImagen + ".gif";
		}
		document.getElementById("capaInfIcono").innerHTML = contAnt;
	}
	
	function onMouseOverIcoFlash(texto) {
		if (document.getElementById("capaInfIcono").parentNode.id!='') {
			contAnt = document.getElementById("capaInfIcono").innerHTML;
		}
		
		document.getElementById("capaInfIcono").innerHTML = texto;
	}
	
	function onMouseOutIcoFlash() {
		document.getElementById("capaInfIcono").innerHTML = contAnt;
	}
	

	function marcarIcono(obj) {
		if (document.getElementById("icomark")) {
			aux = document.getElementById("icomark");
			aux.id = "";
			aux.childNodes[0].src = "/vhpromociones/recursos/img/iconos/" + aux.childNodes[0].id + ".gif";
		}
		if (obj!=-1) {		// DESMARCA TODOS LOS ICONOS MARCADOS, AHORA MISMO NO TIENE SENTIDO (14 - 12 - 2006) PORQUE SE HAN ELIMINADO LOS ICONOS DE GALERIA/TOUR, QUE ES PARA LO QUE LO HICE
			obj.parentNode.id = "icomark";
			obj.src = "/vhpromociones/recursos/img/iconos/" + obj.id + "_over.gif";
			document.getElementById("capaInfIcono").innerHTML = obj.name;
			document.getElementById("capaInfIcono").parentNode.id = obj.id + "0";
		} else {
			document.getElementById("capaInfIcono").innerHTML = "";
			document.getElementById("capaInfIcono").parentNode.id = "";
		}
	}
		
//FUNCIONALIDAD PARA LAS PESTAÑAS PARA LAS FOTOS Y EL TOUR
	function marcarPestanaHabitania(grPestanas, idPestana, nPaginasPest, nTours) {
		ind=(document.all)?0:1;
		obj = document.getElementById("infoPes");
		
		if (idPestana==0) {
			for (i=1; i<=nPaginasPest; i++) document.getElementById("capaImgExt" + i).style.display="none";
			for (i=1; i<=nTours; i++) document.getElementById("capaTourExt" + i).style.display="none";			
			document.getElementById("contenidoExteriores").style.display = "block";
			document.getElementById("contenidoInteriores").style.display = "none";
			capaImgMov(0, 1, 'capaImgExt');
			capaImgMov(0, 1, 'capaTourExt');
		} else if (idPestana==2) {
			for (i=1; i<=nPaginasPest; i++) document.getElementById("capaImgInt" + i).style.display="none";
			for (i=1; i<=nTours; i++) document.getElementById("capaTourInt" + i).style.display="none";			
			document.getElementById("contenidoInteriores").style.display = "block";
			document.getElementById("contenidoExteriores").style.display = "none";
			capaImgMov(0, 1, 'capaImgInt');
			capaImgMov(0, 1, 'capaTourInt');
		}
		
		if (document.getElementById(grPestanas))
			document.getElementById(grPestanas).id = "";
		idPestana=(document.all)?idPestana:(idPestana*2)+1;
		obj.childNodes[ind].childNodes[idPestana].id = grPestanas;
	}
	
	function marcarCasilla(obj) {
		if (document.getElementById("marca"))
			document.getElementById("marca").id = "";
		obj.parentNode.id = "marca";
	}
	
	function capaImgMov(nPaginaAct, dir, nomCapa) {
		if (document.getElementById(nomCapa + nPaginaAct))
			document.getElementById(nomCapa + nPaginaAct).style.display="none";
		nPaginaAct = nPaginaAct + dir;
		if (document.getElementById(nomCapa + nPaginaAct))
			document.getElementById(nomCapa + nPaginaAct).style.display="block";
	}
	
//PESTAÑAS DEL PUNTO DE VENTA

	function marcarPestanaPuntoVenta(grPestanas, idPestana) {
		ind=(document.all)?0:1;
		
		obj = document.getElementById("infoPes");
		
		if (document.getElementById(grPestanas))
			document.getElementById(grPestanas).id = "";
		idPestana=(document.all)?idPestana:(idPestana*2)+1;
		obj.childNodes[ind].childNodes[idPestana].id = grPestanas;
		
		
	}
	
//PESTAÑAS DEL SOLAR

	function marcarPestanaSolarBienvenida(grPestanas, idPestana, capa) {
		ind=(document.all)?0:1;
		
		obj = document.getElementById("infoPes");
		
		if (document.getElementById(grPestanas))
			document.getElementById(grPestanas).id = "";
		idPestana=(document.all)?idPestana:(idPestana*2)+1;
		obj.childNodes[ind].childNodes[idPestana].id = grPestanas;
		
		if (capa == 0) {
			document.getElementById("fotografias").style.display="block";
		} else if (capa == 1) {
			if (document.getElementById("fotografias"))
				document.getElementById("fotografias").style.display="none";
		}
	}
	
//CONVERSION DE LAS FECHAS DE ENTREGA PARA LA PESTAÑA DE BIENVENIDA
	function fechasEntrega(fechObra, fechLlaves, textTrimestre) {
		if (fechObra != "") {
			trimestre = fechObra.substring(3,5);
			anio = fechObra.substring(6,10);
			if (trimestre<=3) trimestre = "1º";
			else if (trimestre>=4 && trimestre<=6) trimestre = "2º";
			else if (trimestre>=7 && trimestre<=9) trimestre = "3º";
			else if (trimestre>=10) trimestre = "4º";
			document.getElementById("fechaFinObra").innerHTML = trimestre + " " + textTrimestre + " " + anio;
		}
		
		if (fechLlaves != "") {
			trimestre = fechLlaves.substring(3,5);
			anio = fechLlaves.substring(6,10);
			if (trimestre<=3) trimestre = "1º";
			else if (trimestre>=4 && trimestre<=6) trimestre = "2º";
			else if (trimestre>=7 && trimestre<=9) trimestre = "3º";
			else if (trimestre>=10) trimestre = "4º";
			document.getElementById("fechaEntregaLlaves").innerHTML = trimestre + " " + textTrimestre + " " + anio;
		}	
	}
	
//CONVERSION DE LAS FECHAS DE ENTREGA PARA LA PESTAÑA DE BIENVENIDA
	function fechasComercializacion(fechComer, textTrimestre) {
		if (fechComer != "") {
			trimestre = fechComer.substring(3,5);
			anio = fechComer.substring(6,10);
			if (trimestre<=3) trimestre = "1º";
			else if (trimestre>=4 && trimestre<=6) trimestre = "2º";
			else if (trimestre>=7 && trimestre<=9) trimestre = "3º";
			else if (trimestre>=10) trimestre = "4º";
			document.getElementById("fechaComercializacion").innerHTML = trimestre + " " + textTrimestre + " " + anio;
		}		
	}	
	
//FUNCIONES PARA CALCULO DE HIPOTECAS
	function calcularPrecioRestante(){
		var precioVivienda = document.getElementById("precio").value;
		var porcentaje = document.getElementById("porcentaje").value;
		//validarPorcentajeHipoteca(porcentaje);
		if((precioVivienda!=0)&&(porcentaje!=0))
		//document.getElementById("precioRestante").innerHTML =eval((precioVivienda*100)/porcentaje);
		var num = eval((precioVivienda*(porcentaje/100)));
		if(validarPorcentajeHipoteca(porcentaje)&&(esNumerico(precioVivienda))){
			document.getElementById("total").value = redondearValor(num,2);
		}
		if(!(esNumerico(precioVivienda))){
			document.getElementById("total").value = "Precio de Vivienda no válido";
		}if(!(validarPorcentajeHipoteca(porcentaje))){
			document.getElementById("total").value = "Porcentaje no válido";
		}			
	}
	
	function validarPorcentajeHipoteca(i){
		res=true;
		if((isNaN(i))||(i>100)||(i<=0)){
			res=false;
		}
		return res;
	}
	
	function esNumerico(i){
		res=true;
		if(isNaN(i)){
			res=false
		}	
		return res;
	}
	
	function calculoMensual(){
		var result;
		var m=0;
		var h=0;
		var r=0;
		var i=0;
		var n=0;
		h=document.getElementById("total").value;
		n=document.getElementById("plazo").value;
		i=document.getElementById("interes").value;
		r=eval(i/(100*12));
		if(!(validarPlazo(n))){
			result="El plazo no es válido"
		}else if(!(validarPorcentajeHipoteca(i))){
			result="El interés no es válido";
			}else if(isNaN(h)){
				result="El cálculo no es válido";
			}else{
				var temp1= eval(1+r);			
				var temp2 = eval(potencia(temp1,(-12*n)));	;
				var temp3 = eval(1-temp2);
				var temp4 = eval(h*r);
				m=temp4/temp3;
				//m=eval(((h*r)/(1-((1+r)^(-12*n)))));
				result = redondearValor(Math.abs(m),2);
			}
		document.getElementById("cuota").value = result;		
	}
	
	function redondearValor(numero,decimales)
	{
		var valor=numero*Math.pow(10,decimales);
		//Para redondear con un numero concreto de decimales mutiplico redondeo y divido
		//Compruebo si es un valor numerico
		if (isNaN(valor)) {
			valor="0";		
		}else{
			valor=Math.round(valor);
			valor=valor/Math.pow(10,decimales);		
			}
		return valor;
	}
	
	function validarPlazo(i){
		res=true;
		if((isNaN(i))||(i>35)){
			res=false;
		}
		return res;
	}
	
	function potencia(base,exponente){
	var tmp=1;
	var esNegativo=0;
	var finale=0;
		if(exponente==0){
			return tmp;
		}else{
			tmp=base;
			if(exponente<0){
				esNegativo=1;
				exponente=Math.abs(exponente);
			}
			for(i=1;i<exponente;i++){
				tmp=eval(base*tmp);
			}
			if(esNegativo==1){
				tmp=eval(1/tmp);
			}
		}
		return(tmp);
	}
	
	function setFlashWidth(divid, ancho){
		//alert(divid);
		document.getElementById(divid).style.width = ancho+"px";
	}

// FUNCION PARA CARGAR PDF'S, SE LE PASA EL PATH A PARTIR DE /VHPROMOCIONES/
	function cargaPlano(name) {
		window.open('/vhpromociones/' + name,'','scrollbars=no,resizable=yes,top=50,left=150,width=450, height=600, toolbar=0');
	}
	
// FUNCIONES PARA EL COMPORTAMIENTO DE LAS FILAS EN PROMOCION - VIVIENDAS TIPO
	var viviendasPlanos = new Array();
	
	function cargarViviedasPlanos(indice, nPlantas) {
		viviendasPlanos[indice] = nPlantas;
	}
	
	function selFilaOn(obj) {
		var i = document.all ? 0 : 1;
		obj.childNodes[i].className="fondoDormitoriosIzqOn";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosOn";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosOn";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosOn";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosOn";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosOn";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosOn";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosDerOn";
	}
	
	function selFilaOff(obj) {
		var i = document.all ? 0 : 1;
		obj.childNodes[i].className="fondoDormitoriosIzqOff";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosOff";
		obj.childNodes[document.all ? ++i : i+=2].className="";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosOff";
		obj.childNodes[document.all ? ++i : i+=2].className="";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosOff";
		obj.childNodes[document.all ? ++i : i+=2].className="fondoDormitoriosDerOff";
		obj.childNodes[document.all ? ++i : i+=2].className="";
	}
	
	function seleccionarFila(obj, vivienda, nViviendas, nPlantas) {
		check = 0;
		//buscamos si hay alguna fila marcada
		for (i=0; i < nViviendas; i++) {
			obj2 = document.getElementById("fila" + i);
			var idFil = document.all ? obj2.nextSibling.firstChild.id : obj2.nextSibling.nextSibling.childNodes[1].id;
			if (idFil=="mark") {
				check = 1;
			}
		}
		//si no hay ninguna marcada, cambiamos la del mouseover a estado on
		if (check == 0) {
			selFilaOn(obj);
			
			document.getElementById("plano" + vivienda + "0").style.display = "";
			mostrarCapaPestPlantas(vivienda);
		}
	}
	
	function deseleccionarFila(obj, vivienda, nViviendas, nPlantas) {
		var idFil = document.all ? obj.nextSibling.firstChild.id : obj.nextSibling.nextSibling.childNodes[1].id;
		//si la fila del mouseout no esta marcada, la cambiamos al estado off
		if (idFil != "mark") {
			selFilaOff(obj);
			
			for (k=0; k<nPlantas; k++) {
				document.getElementById("plano" + vivienda + k).style.display = "none";
			}
			if (document.getElementById("capaContPesPlan" + vivienda))
				document.getElementById("capaContPesPlan" + vivienda).style.display = "none";
			if (!document.getElementById("mark"))
				if (document.getElementById("markPlanta")) 
					document.getElementById("markPlanta").id = "";
		}
	}
	
	function mostrarPlano(vivienda, plano) {
		document.getElementById("plano" + vivienda + plano).style.display="block";
	}
	
	function ocultarPlanos(vivienda, plantas) {
		for (k=0; k<plantas; k++) {
			document.getElementById("plano" + vivienda + k).style.display = "none";
		}
	}
	
	function mostrarCapaPestPlantas(vivienda) {
		if (document.getElementById("capaContPesPlan" + vivienda)) {
			document.getElementById("capaContPesPlan" + vivienda).style.display="block";
			document.getElementById("capaContPesPlan" + vivienda).firstChild.firstChild.childNodes[0].id="markPlanta";
		}
	}
	
	function ocultarCapaPestPlantas(vivienda) {	
		if (document.getElementById("capaContPesPlan" + vivienda))
			document.getElementById("capaContPesPlan" + vivienda).style.display = "none";
		if (document.getElementById("markPlanta")) 
			document.getElementById("markPlanta").id = "";
	}
		
	function clickFila(obj, vivienda, nViviendas, nPlantas) {
		//desmarcamos la fila que esta marcada (en caso de que haya alguna)		
		var idFil = document.all ? obj.nextSibling.firstChild.id : obj.nextSibling.nextSibling.childNodes[1].id;
		//cambiamos la descripcion de la vivienda
		for(var h=0;h<nViviendas;h++){
			if(h==vivienda)
				document.getElementById("filaDesViv"+h).style.display="";
			else
				document.getElementById("filaDesViv"+h).style.display="none";
		}
		//si la fila esta marcada, la desmarcamos, sino, la marcamos
		if (idFil=="mark") {
			selFilaOff(obj);

			document.all ? obj.nextSibling.firstChild.id="unmark" : obj.nextSibling.nextSibling.childNodes[1].id="unmark";
			
			ocultarPlanos(vivienda, nPlantas);
			
			//pestañas de cambio de planta - ocultamos si existen y le quitamos la marca a la activa
			if (nPlantas>1) {
				ocultarCapaPestPlantas(vivienda);
			}
		} else if (idFil=="unmark") {
			selFilaOn(obj);
			
			document.all ? obj.nextSibling.firstChild.id="mark" : obj.nextSibling.nextSibling.childNodes[1].id="mark";
			
			document.getElementById("plano" + vivienda + "0").style.display = "";
			
			//desmarcamos la que esta marcada, si hay alguna
			for (i=0; i<nViviendas;i++) {
				if (i!=vivienda) {
					obj2 = document.getElementById("fila" + i);
						
					var idFil2 = document.all ? obj2.nextSibling.firstChild.id : obj2.nextSibling.nextSibling.childNodes[1].id;
					
					if (idFil2=="mark") {
						document.all ? obj2.nextSibling.firstChild.id="unmark" : obj2.nextSibling.nextSibling.childNodes[1].id="unmark";
						selFilaOff(obj2);
						
						//pestañas de cambio de planta - si tiene mas de 1 plano (planta) ocultamos las pestañas y quitamos la marca
						if (viviendasPlanos[i]>1) {
							ocultarCapaPestPlantas(i);
						}
						
						ocultarPlanos(i, viviendasPlanos[i]);
					}
				}
			}
			
			//pestañas de cambio de planta - ponemos visible la clickada y le ponemos la marca a la primera
			if (nPlantas>1) {
				mostrarCapaPestPlantas(vivienda);
			}
		}
	}
		
	function cambioPlanta(objLi, nPlano, nVivienda, nPlantas) {
		if (document.getElementById("markPlanta")) document.getElementById("markPlanta").id = "";
		objLi.id = "markPlanta";
		
		ocultarPlanos(nVivienda, nPlantas);
		mostrarPlano(nVivienda, nPlano);
	}
	
// FUNCIONES PARA CAMBIAR EL CONTENIDO DE LA PESTAÑA 'DESCRIPCION' - 'FORMA DE PAGO'
	function cambiaContenidoPestana(nPestana) {
		if (nPestana=="1") {
			document.getElementById("contenidoPestana1").style.display = "none";
			document.getElementById("contenidoPestana2").style.display = "";
		} else {
			document.getElementById("contenidoPestana2").style.display = "none";
			document.getElementById("contenidoPestana1").style.display = "";
		}
	}

	function cambiaPestanaInferior(obj, pestana, pestanaAnt) {
		var aux;
		
		obj.parentNode.className="fondoDescripcionVivTipoPestana";
		aux = document.all ? obj.parentNode.previousSibling : obj.parentNode.previousSibling.previousSibling;
		aux.className = "fondoDescripcionVivTipoPestanaIzq";
		aux = document.all ? obj.parentNode.nextSibling : obj.parentNode.nextSibling.nextSibling;
		aux.className="fondoDescripcionVivTipoPestanaDer";
		
		var nom = obj.innerHTML;
		obj.parentNode.innerHTML = "<span class='ArialAzul11Bold'>" + nom + "</span>";
		
		var obj2 = document.getElementById("pestanaInferior" + pestana);
		obj2.className="fondoDescripcionVivTipoPestanaOff";
		aux = document.all ? obj2.previousSibling : obj2.previousSibling.previousSibling;
		aux.className="fondoDescripcionVivTipoPestanaIzqOff";
		aux = document.all ? obj2.nextSibling : obj2.nextSibling.nextSibling;
		aux.className="fondoDescripcionVivTipoPestanaDerOff";
		
		var nom2 = obj2.firstChild.innerHTML;
		obj2.innerHTML = "<a href='javascript:void(null);' onclick='javascript: cambiaPestanaInferior(this, " + pestanaAnt + ", " + pestana + ");' class='ArialAzul11'>" + nom2 + "</a>";
		
		cambiaContenidoPestana(pestana);
	}
	
/******************** VALIDACIONES *************************/
		
	var whitespace = " \t\n\r";
	
	function isNumber(cadena)	{
		for (cont=0;cont<cadena.length;cont++) {
			if (isNaN(cadena.charAt(cont))){return false;}
		}
		return true
	}
	
	
	function isEmail (s)	{
		if (isWhitespace(s)) return false;	
		var i = 1;
		var sLength = s.length;
		while ((i < sLength) && (s.charAt(i) != "@"))	{
			i++;
		}
	
		if ((i >= sLength) || (s.charAt(i) != "@")) return false;
		else i += 2;
	
		while ((i < sLength) && (s.charAt(i) != "."))    {
			i++;
		}
	
		if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	
		else return true;
	}
	
	function isEmpty(s)	{
	   return ((s == null) || (s.length == 0));
	}
	
	function isWhitespace (s)	{
		var i;
		if (isEmpty(s)) return true;
		for (i = 0; i < s.length; i++)	{   
			var c = s.charAt(i);	
			if (whitespace.indexOf(c) == -1) return false;
		}
		return true;
	}
	
	
	function isDate(mydate)	{
		pares=mydate.split("/");
		day=pares[0];		
		month=pares[1];
		year=pares[2];
		var today= new Date();
		year=((!year) ? (today.getYear()) : year);
		month = ((!month) ? today.getMonth():month-1);
		if(!day) return false;
		var test=new Date(year,month,day);
		if (cadenaNavegador!="ie")
		{
				year1=parseInt(test.getYear())+1900;
		}else if(cadenaNavegador=="ie")
		{
			if (test.getYear()<100)
			{
				year1=parseInt(test.getYear())+1900
			}else{
				year1=test.getYear();
			}
		}
		if (( year==(year1) ) && ( month == (test.getMonth()) ) && ( day==(test.getDate()) ) ){
			return true;
		}else{
			return false;
		}
	}

	function solicitaVisita() 
	{
	 cadena="";
	 if (document.getElementsByName("nombre")[0].value.length<2) { cadena+="Debe rellenar correctamente su nombre.\n" }
	 if (document.getElementsByName("apellidos")[0].value.length<2) { cadena+="Debe rellenar correctamente sus apellidos.\n" }
	 if (document.getElementsByName("telefono")[0].value.length<2) { cadena+="Debe rellenar correctamente su teléfono.\n" }
	 if (!isEmail(document.getElementsByName("from")[0].value)) { cadena+="Debe rellenar correctamente su email.\n" }
	 if (!document.getElementsByName("politica")[0].checked) { cadena+="Debe aceptar la política de privacidad.\n" }
		 
	 if (cadena=="") { 
	 	document.getElementsByName("nombre")[1].value=document.getElementsByName("nombre")[0].value;
		document.getElementsByName("apellidos")[1].value=document.getElementsByName("apellidos")[0].value;
		document.getElementsByName("telefono")[1].value=document.getElementsByName("telefono")[0].value;
		document.getElementsByName("mail")[0].value=document.getElementsByName("from")[0].value;
		document.getElementsByName("asunto")[0].value=document.getElementsByName("subject")[0].value+" "+document.getElementsByName("portalWeb")[0].value;
		document.getElementsByName("subject")[0].value=document.getElementsByName("subject")[0].value+" "+document.getElementsByName("portalWeb")[0].value;
		document.getElementsByName("texto")[0].value=document.getElementsByName("text")[0].value;
		document.getElementsByName("nombrepromcom")[1].value=document.getElementsByName("nombrepromcom")[0].value;
		document.getElementById("formPDM").action="http://www.pecdm.com/vll.php";
		document.getElementById("formPDM").submit();
	 	document.getElementsByName("mailForm")[0].submit(); 
	 }
	 else { alert(cadena) 
	 }
	 
	}
	
	function checkPrivacidad() {	
		if (document.getElementsByName("politica")[0].checked == true) {
			document.getElementById("politicaImg").src="/vhpromociones/recursos/img/checkOFF.gif";
			document.getElementsByName("politica")[0].checked = false;
		} else {				
			document.getElementById("politicaImg").src="/vhpromociones/recursos/img/checkON.gif";
			document.getElementsByName("politica")[0].checked = true;
			   }
	}
	
//	FUNCION PARA CARGAR LOS CONTENIDOS EN EL CONTENEDORSWF	
	function asignarValor(value, nCombo, rutaRep){
		if (value!='0' && value!='') {
			var PeliculaObj = document.contenedorMapas;
			PeliculaObj.SetVariable("mapa",rutaRep + value);
			PeliculaObj.Play();
		}
	}

//  FUNCION PARA CARGAR LOS POPUPS PARA LOS DISTINTOS FORMULARIOS
	function cargarPopUpFormulario(name, url, w, h) {
		window.open(url,name,"width=" + w + ",height=" + h + ",scrollbars=NO,resizable=NO,Top=100,Left=300");
	}
	
	function cargarPopUpMapaWeb(name, url, w, h) {
		window.open(url,name,"width=" + w + ",height=" + h + ",scrollbars=YES,resizable=NO,Top=100,Left=300");
	}
	
// FUNCION Y DECLARACIONES PARA LA MEMORIA DE CALIDADES
	var cont = new Array();
	cont[0] = "";
	
	function cargarCalidades(nPagina, textoPagina, textoAnterior, textoSiguiente) {
		document.getElementById("calidadesIzq").innerHTML = cont[nPagina*2];
		if (cont[(nPagina*2)+1])  {
			document.getElementById("calidadesDer").innerHTML = cont[(nPagina*2)+1];
		} else {
			document.getElementById("calidadesDer").innerHTML = "";
		}
			
		obj = document.getElementById("paginacion");
		objAnt = document.getElementById("paginacionAnt");
		objSig = document.getElementById("paginacionSig");
		obj.innerHTML = textoPagina + " ";
		
		if (cont.length>2) obj.parentNode.parentNode.parentNode.parentNode.style.visibility = "visible";
		for (i=0; i<(Math.floor(cont.length/2) + cont.length%2); i++) {
			if (i==nPagina) obj.innerHTML = obj.innerHTML + "<span class='ArialAzula2b7c311Bold'>" + (i+1) + "</span>";
			else  obj.innerHTML = obj.innerHTML + "<a href='javascript: cargarCalidades(" + (i) + ", \"" + textoPagina + "\", \"" + textoAnterior + "\", \"" + textoSiguiente + "\")' class='ArialAzula2b7c311'>" + (i+1) + "</a>"; 
			
			if (i!=((Math.floor(cont.length/2) + cont.length%2)-1)) obj.innerHTML = obj.innerHTML + " > ";
		}
		
		if (nPagina>0) {
			objAnt.innerHTML = "< <a href='javascript: cargarCalidades(" + (nPagina-1) + ", \"" + textoPagina + "\", \"" + textoAnterior + "\", \"" + textoSiguiente + "\")' class='ArialAzula2b7c311'>" + textoAnterior + "</a>";
			objAnt.parentNode.parentNode.parentNode.parentNode.style.visibility = "visible";
		} else 
			objAnt.parentNode.parentNode.parentNode.parentNode.style.visibility = "hidden";
		
		if (nPagina<(Math.floor(cont.length/2) + cont.length%2) - 1) {
			objSig.innerHTML = "<a href='javascript: cargarCalidades(" + (nPagina+1) + ", \"" + textoPagina + "\", \"" + textoAnterior + "\", \"" + textoSiguiente + "\")' class='ArialAzula2b7c311'>" + textoSiguiente + "</a> >";
			objSig.parentNode.parentNode.parentNode.parentNode.style.visibility = "visible";
		} else 
			objSig.parentNode.parentNode.parentNode.parentNode.style.visibility = "hidden";
	}
	
// INFORMACION LOCAL
	function getLocalizacion(idcat, idsubcat, page, idprom) {
		document.getElementById("idcat").value=idcat;
		document.getElementById("idsubcat").value=idsubcat;
		document.getElementById("page").value=page;
		cargarContenidoEnCapaJS("/vhpromociones/promocionInformacionLocalInterior.vh?idprom=" + idprom + "&idcat=" + idcat + "&idsubcat=" + idsubcat + "&page=" + page, '', document.getElementById("infolocales"), false);
	}
	
	function getLocalizacionPreview(idcat, idsubcat, page, idprom) {
		document.getElementById("idcat").value=idcat;
		document.getElementById("idsubcat").value=idsubcat;
		document.getElementById("page").value=page;
		cargarContenidoEnCapaJS("previewPromocionLocalizacionInterior.vh?idprom=" + idprom + "&idcat=" + idcat + "&idsubcat=" + idsubcat + "&page=" + page, '', document.getElementById("infolocales"), false);
	}
	
//FUNCIONES PARA MOSTRAR LA PASTILLA DE LOS ICONOS EN INFORMACION LOCAL
	function  mostrarPastillaIconos(text, dir) {
		if (dir==1) {
			document.getElementById("pastillaContenido").innerHTML = text;
			document.getElementById("pastillaContenedora").style.visibility="visible";
		} else if (dir==-1) {
			document.getElementById("pastillaContenido").innerHTML = "";
			document.getElementById("pastillaContenedora").style.visibility="hidden";
		}
	}
	
// CARGAR FOLLETO
	function cargarFolleto(url, name, w, h) {
		window.close();
		window.open(url, name, "width=" + w + ",height=" + h + ",scrollbars=YES,resizable=NO,Top=100,Left=300");
	}
	
	function sustituirEspacios(cadena, character) {
		var oc = new String(cadena), nt = new String(""), nc;
		for(var q=0; q<oc.length; q++) {
			(oc.charAt(q)==unescape(10)) ? nc=character : nc=oc.charAt(q);
			nt+=nc;
		}
		alert(nt);
		return nt;
	}
	//Google Earth
	function llamarGE(url){
		window.open(url,'','');
	}
	
	// FERIAS EN DESTACADO CARRUSEL
	function mostrarFeria (rutaPDF){
		  
     //window.open(rutaPDF,'','');
     window.open('/vhpromociones/recursos/feria.html?rutaPDF='+rutaPDF,'','');
    
    }
    
    // VIVIENDAS PROTEGIDAS EN DESTACADO CARRUSEL
	 function mostrarVivienda (rutaPDF){
		   
     document.location.href = "/vhpromociones/mostrarVivienda1.vh"; 
        
    }
    
    
  function solicitaViviendaProtegida() 
	{
	 cadena="";
	 opcionVP=0;
	 
	 if (document.getElementsByName("nombre")[0].value.length<2) { cadena+="Debe rellenar correctamente su nombre.\n" }
	 if (document.getElementsByName("apellidos")[0].value.length<2) { cadena+="Debe rellenar correctamente sus apellidos.\n" }
	 if (document.getElementsByName("telefono")[0].value.length<2) { cadena+="Debe rellenar correctamente su teléfono.\n" }
	 if (!isEmail(document.getElementsByName("from")[0].value)) { cadena+="Debe rellenar correctamente su email.\n" }
	 
	 if ((document.getElementsByName("web")[0].checked==false) && (document.getElementsByName("ferias")[0].checked==false) &&
	    (document.getElementsByName("valla")[0].checked==false) && (document.getElementsByName("ayuntamiento")[0].checked==false) &&
	    (document.getElementsByName("buscadores")[0].checked==false) && (document.getElementsByName("otros")[0].checked==false))
	    { opcionVP=1 }
	    
	 if (document.getElementsByName("promociones")[0].selectedIndex == null || document.getElementsByName("promociones")[0].promociones == "") { cadena+="Debe al menos seleccionar una de las promociones a elegir.\n" }
	 
	 if (opcionVP==1){ cadena+="Debe al menos seleccionar una de las opciones de cómo conoció VP.\n" }
		 
	 if (cadena=="") { 
		
	  	document.getElementsByName("mailForm")[0].submit(); 
	 }
	 else { alert(cadena) 
	 }
	 
	}
	
	
	// BUSCADOR OTROS INMUEBLES
	function buscarOtrosInmuebles(provincia, garaje, garajeMoto, local, oficina, trastero){
	
	   //alert(provincia+", "+garaje+", "+garajeMoto+", "+local+", "+oficina+", "+trastero);
	   var idprovincia = provincia;
	   var idlocalidad = "0";
	   
	   if (provincia=="") {
	      idprovincia=0;
	   } 
	   
	   var codProducto = 0;
	   var codProductoTodos = 0;
	   var soloUnProducto = 0;
	   
	   
	   if ((garaje!="false") || (garajeMoto!="false")|| (local!="false") || (oficina!="false") || (trastero!="false") ) {
	         
	        if (garaje=="true") {
	          //alert(" GARAJE : "+garaje);
	          codProducto = "1";
	          soloUnProducto = soloUnProducto + 1;
	        }     
	        
	        if (garajeMoto=="true") {
	        //alert(" GARAJE MOTO : "+garajeMoto);
	            codProducto = "2";
	            soloUnProducto = soloUnProducto + 1;
	        }   
	        if (local=="true"){
	        //alert(" LOCAL : "+local);
	            codProducto = "3";
	            soloUnProducto = soloUnProducto + 1;
	        }
	        if (oficina=="true") {
	        //alert(" OFICINA : "+oficina);
	            codProducto = "4";
	            soloUnProducto = soloUnProducto + 1;
	        }
	        if (trastero=="true") {
	        //alert(" TRASTERO : "+trastero);
	            codProducto = "5";
	            soloUnProducto = soloUnProducto + 1;
	        }
			
	   }
	   
	   
	   if (soloUnProducto == 1){
	     document.location.href = '/vhpromociones/buscadorLocales.vh?provincia='+idprovincia+'&garaje='+garaje+'&garajeMoto='+garajeMoto+'&local='+local+'&oficina='+oficina+'&trastero='+trastero+'&localidad=0&pagina=&codProducto='+codProducto;
	   }
	   else{
	     document.location.href = '/vhpromociones/buscadorLocales.vh?provincia='+idprovincia+'&garaje='+garaje+'&garajeMoto='+garajeMoto+'&local='+local+'&oficina='+oficina+'&trastero='+trastero+'&localidad=0&pagina=&codProducto='+codProductoTodos;
	   }
      
    }
    

		
	// FUNCION ACTUALIZA EL VALOR DE LOS COMBOS
	function actualizaTipoInmuebles(combo, valor, idprovincia, idlocalidad){
	
		document.frmBuscador.localidad.value = 0;
		document.frmBuscador.codProducto.value = 0;
		document.frmBuscador.pagina.value = 1;
		if (combo==0) {
			document.frmBuscador.provincia.value = valor;
			document.location = "/vhpromociones/buscadorLocales/" + valor + "/0/0/1.jsp";
		} else if (combo==1) {
			document.frmBuscador.provincia.value = idprovincia;
			document.frmBuscador.localidad.value = valor;
			document.location = "/vhpromociones/buscadorLocales/" + idprovincia + "/" + valor + "/0/1.jsp";
		} else if (combo==2) {
			document.frmBuscador.provincia.value = idprovincia;
			document.frmBuscador.localidad.value = idlocalidad;
			document.frmBuscador.codProducto.value = valor;
			document.location = "/vhpromociones/buscadorLocales/" + idprovincia + "/" + idlocalidad + "/" + valor + "/1.jsp";
		}
	}
	// FUNCION ACTUALIZA EL VALOR DE LOS COMBOS
		